1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

AWS Plugin: More flexible specification of the output type

This commit is contained in:
Jermolene 2017-09-12 16:04:35 +01:00
parent 35a7a66b01
commit 24c325611b
2 changed files with 11 additions and 13 deletions

View File

@ -43,14 +43,14 @@ Save a raw tiddler to a file in an S3 bucket.
Save raw tiddlers matching a filter to an S3 bucket.
```
--aws s3-savetiddlers <filter> <region> <bucket> <filenamefilter> <savetype>
--aws s3-savetiddlers <filter> <region> <bucket> <filenamefilter> <savetypefilter>
```
* ''filter'': filter identifying tiddlers to render
* ''region'': AWS region
* ''bucket'': name of the bucket to save the files
* ''filenamefilter'': filter for converting tiddler titles to filepaths (eg `[encodeuricomponent[]addprefix[files/]addsuffix[.html]]`)
* ''savetype'': optional; the MIME type for the saved file (defaults to ''type'' or "text/html")
* ''savetypefilter'': optional; a filter that is passed the title of the tiddler being saved and should yield the MIME type for the saved file (defaults to a filter that yields the value of the ''type'' field)
! "s3-rendertiddler" subcommand
@ -74,7 +74,7 @@ Save the results of rendering a tiddler to a file in an S3 bucket.
Save the results of rendering tiddlers identified by a filter to files in an S3 bucket.
```
--aws s3-rendertiddlers <filter> <template> <region> <bucket> <filenamefilter> <type> <savetype>
--aws s3-rendertiddlers <filter> <template> <region> <bucket> <filenamefilter> <type> <savetypefilter>
```
* ''filter'': filter identifying tiddlers to render
@ -83,4 +83,4 @@ Save the results of rendering tiddlers identified by a filter to files in an S3
* ''bucket'': name of the bucket to save the rendered file
* ''filenamefilter'': filter for converting tiddler titles to filepaths (eg `[encodeuricomponent[]addprefix[files/]addsuffix[.html]]`)
* ''type'': optional render type (defaults to "text/html")
* ''savetype'': optional; the MIME type for the saved file (defaults to ''type'' or "text/html")
* ''savetypefilter'': optional; a filter that is passed the title of the tiddler being rendered and should yield the MIME type for the saved file (defaults to the value of the ''type'' field via `[is[tiddler]get[type]]`)

View File

@ -129,7 +129,7 @@ Command.prototype.subCommands["s3-rendertiddlers"] = function() {
bucket = this.params[4],
filenameFilter = this.params[5],
type = this.params[6] || "text/html",
saveType = this.params[7] || type,
saveTypeFilter = this.params[7] || "[[" + type + "]]",
tiddlers = wiki.filterTiddlers(filter);
// Check parameters
if(!filter || !template || !region || !bucket || !filenameFilter) {
@ -139,14 +139,13 @@ Command.prototype.subCommands["s3-rendertiddlers"] = function() {
tiddlers,
20,
function(title,callback) {
var parser = wiki.parseTiddler(template),
var parser = wiki.parseTiddler(template || title),
widgetNode = wiki.makeWidget(parser,{variables: {currentTiddler: title}}),
container = $tw.fakeDocument.createElement("div");
widgetNode.render(container,null);
var text = type === "text/html" ? container.innerHTML : container.textContent,
filename = wiki.filterTiddlers(filenameFilter,$tw.rootWidget,function(iterator) {
iterator(wiki.getTiddler(title),title)
})[0];
filename = wiki.filterTiddlers(filenameFilter,$tw.rootWidget,wiki.makeTiddlerIterator([title]))[0],
saveType = wiki.filterTiddlers(saveTypeFilter,$tw.rootWidget,wiki.makeTiddlerIterator([title]))[0];
awsUtils.putFile(region,bucket,filename,text,saveType,callback);
},
function(err,results) {
@ -201,7 +200,7 @@ Command.prototype.subCommands["s3-savetiddlers"] = function() {
region = this.params[2],
bucket = this.params[3],
filenameFilter = this.params[4],
saveType = this.params[5],
saveTypeFilter = this.params[5] || "[is[tiddler]get[type]]",
tiddlers = wiki.filterTiddlers(filter);
// Check parameters
if(!filter || !region || !bucket || !filenameFilter) {
@ -214,9 +213,8 @@ Command.prototype.subCommands["s3-savetiddlers"] = function() {
var tiddler = wiki.getTiddler(title),
text = tiddler.fields.text || "",
type = tiddler.fields.type || "text/vnd.tiddlywiki",
filename = wiki.filterTiddlers(filenameFilter,$tw.rootWidget,function(iterator) {
iterator(wiki.getTiddler(title),title)
})[0];
filename = wiki.filterTiddlers(filenameFilter,$tw.rootWidget,wiki.makeTiddlerIterator([title]))[0],
saveType = wiki.filterTiddlers(saveTypeFilter,$tw.rootWidget,wiki.makeTiddlerIterator([title]))[0];
awsUtils.putFile(region,bucket,filename,text,saveType || type,callback);
},
function(err,results) {