1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

AWS Plugin: improve s3-savetiddlers and s3-rendertiddlers

Instead of the simple ‘prefix’ and ‘extension’ parameters, we now
accept a filename filter. As well as allowing prefixes and suffixes to
be added via filter operators, we can also transform the title
This commit is contained in:
Jermolene 2017-08-28 10:31:27 +01:00
parent 90c1c6242e
commit 2381fb5312
2 changed files with 19 additions and 15 deletions

View File

@ -43,13 +43,13 @@ 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> <prefix> <savetype>
--aws s3-savetiddlers <filter> <region> <bucket> <filenamefilter> <savetype>
```
* ''filter'': filter identifying tiddlers to render
* ''region'': AWS region
* ''bucket'': name of the bucket to save the files
* ''prefix'': prefix for rendered file names
* ''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")
! "s3-rendertiddler" subcommand
@ -74,14 +74,13 @@ 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-rendertiddler <filter> <template> <region> <bucket> <prefix> <type> <extension> <savetype>
--aws s3-rendertiddlers <filter> <template> <region> <bucket> <filenamefilter> <type> <savetype>
```
* ''filter'': filter identifying tiddlers to render
* ''template'': template for rendering each tiddler
* ''region'': AWS region
* ''bucket'': name of the bucket to save the rendered file
* ''prefix'': prefix for rendered file names
* ''filenamefilter'': filter for converting tiddler titles to filepaths (eg `[encodeuricomponent[]addprefix[files/]addsuffix[.html]]`)
* ''type'': optional render type (defaults to "text/html")
* ''extension'': optional file extension (defaults to ".html")
* ''savetype'': optional; the MIME type for the saved file (defaults to ''type'' or "text/html")

View File

@ -127,13 +127,12 @@ Command.prototype.subCommands["s3-rendertiddlers"] = function() {
template = this.params[2],
region = this.params[3],
bucket = this.params[4],
prefix = this.params[5],
filenameFilter = this.params[5],
type = this.params[6] || "text/html",
extension = this.params[7] || ".html",
saveType = this.params[8] || type,
saveType = this.params[7] || type,
tiddlers = wiki.filterTiddlers(filter);
// Check parameters
if(!filter || !template || !region || !bucket || !prefix) {
if(!filter || !template || !region || !bucket || !filenameFilter) {
throw "Missing parameters";
}
async.eachLimit(
@ -144,8 +143,11 @@ Command.prototype.subCommands["s3-rendertiddlers"] = function() {
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;
awsUtils.putFile(region,bucket,prefix + encodeURIComponent(title) + extension,text,saveType,callback);
var text = type === "text/html" ? container.innerHTML : container.textContent,
filename = wiki.filterTiddlers(filenameFilter,$tw.rootWidget,function(iterator) {
iterator(wiki.getTiddler(title),title)
})[0];
awsUtils.putFile(region,bucket,filename,text,saveType,callback);
},
function(err,results) {
self.callback(err,results);
@ -198,11 +200,11 @@ Command.prototype.subCommands["s3-savetiddlers"] = function() {
filter = this.params[1],
region = this.params[2],
bucket = this.params[3],
prefix = this.params[4],
filenameFilter = this.params[4],
saveType = this.params[5],
tiddlers = wiki.filterTiddlers(filter);
// Check parameters
if(!filter || !region || !bucket || !prefix) {
if(!filter || !region || !bucket || !filenameFilter) {
throw "Missing parameters";
}
async.eachLimit(
@ -211,8 +213,11 @@ Command.prototype.subCommands["s3-savetiddlers"] = function() {
function(title,callback) {
var tiddler = wiki.getTiddler(title),
text = tiddler.fields.text || "",
type = tiddler.fields.type || "text/vnd.tiddlywiki";
awsUtils.putFile(region,bucket,prefix + encodeURIComponent(title),text,saveType || type,callback);
type = tiddler.fields.type || "text/vnd.tiddlywiki",
filename = wiki.filterTiddlers(filenameFilter,$tw.rootWidget,function(iterator) {
iterator(wiki.getTiddler(title),title)
})[0];
awsUtils.putFile(region,bucket,filename,text,saveType || type,callback);
},
function(err,results) {
self.callback(err,results);