mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +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:
parent
90c1c6242e
commit
2381fb5312
@ -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.
|
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
|
* ''filter'': filter identifying tiddlers to render
|
||||||
* ''region'': AWS region
|
* ''region'': AWS region
|
||||||
* ''bucket'': name of the bucket to save the files
|
* ''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")
|
* ''savetype'': optional; the MIME type for the saved file (defaults to ''type'' or "text/html")
|
||||||
|
|
||||||
! "s3-rendertiddler" subcommand
|
! "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.
|
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
|
* ''filter'': filter identifying tiddlers to render
|
||||||
* ''template'': template for rendering each tiddler
|
* ''template'': template for rendering each tiddler
|
||||||
* ''region'': AWS region
|
* ''region'': AWS region
|
||||||
* ''bucket'': name of the bucket to save the rendered file
|
* ''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")
|
* ''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")
|
* ''savetype'': optional; the MIME type for the saved file (defaults to ''type'' or "text/html")
|
||||||
|
@ -127,13 +127,12 @@ Command.prototype.subCommands["s3-rendertiddlers"] = function() {
|
|||||||
template = this.params[2],
|
template = this.params[2],
|
||||||
region = this.params[3],
|
region = this.params[3],
|
||||||
bucket = this.params[4],
|
bucket = this.params[4],
|
||||||
prefix = this.params[5],
|
filenameFilter = this.params[5],
|
||||||
type = this.params[6] || "text/html",
|
type = this.params[6] || "text/html",
|
||||||
extension = this.params[7] || ".html",
|
saveType = this.params[7] || type,
|
||||||
saveType = this.params[8] || type,
|
|
||||||
tiddlers = wiki.filterTiddlers(filter);
|
tiddlers = wiki.filterTiddlers(filter);
|
||||||
// Check parameters
|
// Check parameters
|
||||||
if(!filter || !template || !region || !bucket || !prefix) {
|
if(!filter || !template || !region || !bucket || !filenameFilter) {
|
||||||
throw "Missing parameters";
|
throw "Missing parameters";
|
||||||
}
|
}
|
||||||
async.eachLimit(
|
async.eachLimit(
|
||||||
@ -144,8 +143,11 @@ Command.prototype.subCommands["s3-rendertiddlers"] = function() {
|
|||||||
widgetNode = wiki.makeWidget(parser,{variables: {currentTiddler: title}}),
|
widgetNode = wiki.makeWidget(parser,{variables: {currentTiddler: title}}),
|
||||||
container = $tw.fakeDocument.createElement("div");
|
container = $tw.fakeDocument.createElement("div");
|
||||||
widgetNode.render(container,null);
|
widgetNode.render(container,null);
|
||||||
var text = type === "text/html" ? container.innerHTML : container.textContent;
|
var text = type === "text/html" ? container.innerHTML : container.textContent,
|
||||||
awsUtils.putFile(region,bucket,prefix + encodeURIComponent(title) + extension,text,saveType,callback);
|
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) {
|
function(err,results) {
|
||||||
self.callback(err,results);
|
self.callback(err,results);
|
||||||
@ -198,11 +200,11 @@ Command.prototype.subCommands["s3-savetiddlers"] = function() {
|
|||||||
filter = this.params[1],
|
filter = this.params[1],
|
||||||
region = this.params[2],
|
region = this.params[2],
|
||||||
bucket = this.params[3],
|
bucket = this.params[3],
|
||||||
prefix = this.params[4],
|
filenameFilter = this.params[4],
|
||||||
saveType = this.params[5],
|
saveType = this.params[5],
|
||||||
tiddlers = wiki.filterTiddlers(filter);
|
tiddlers = wiki.filterTiddlers(filter);
|
||||||
// Check parameters
|
// Check parameters
|
||||||
if(!filter || !region || !bucket || !prefix) {
|
if(!filter || !region || !bucket || !filenameFilter) {
|
||||||
throw "Missing parameters";
|
throw "Missing parameters";
|
||||||
}
|
}
|
||||||
async.eachLimit(
|
async.eachLimit(
|
||||||
@ -211,8 +213,11 @@ Command.prototype.subCommands["s3-savetiddlers"] = function() {
|
|||||||
function(title,callback) {
|
function(title,callback) {
|
||||||
var tiddler = wiki.getTiddler(title),
|
var tiddler = wiki.getTiddler(title),
|
||||||
text = tiddler.fields.text || "",
|
text = tiddler.fields.text || "",
|
||||||
type = tiddler.fields.type || "text/vnd.tiddlywiki";
|
type = tiddler.fields.type || "text/vnd.tiddlywiki",
|
||||||
awsUtils.putFile(region,bucket,prefix + encodeURIComponent(title),text,saveType || type,callback);
|
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) {
|
function(err,results) {
|
||||||
self.callback(err,results);
|
self.callback(err,results);
|
||||||
|
Loading…
Reference in New Issue
Block a user