From d6397e9d845bfe2da973698d449c1b85be9b3ea1 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sat, 3 Mar 2012 16:50:11 +0000 Subject: [PATCH] New command line switch to save wiki as a folder of static HTML files --- tiddlywiki.js | 24 +++++++++++++++++++----- tw5.sh | 3 +++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/tiddlywiki.js b/tiddlywiki.js index 76000de44..3fc0c21cd 100644 --- a/tiddlywiki.js +++ b/tiddlywiki.js @@ -126,23 +126,37 @@ var commandLineSwitches = { savetiddler: { args: {min: 2, max: 3}, handler: function(args,callback) { - var type = args[2] || "text/html"; - fs.writeFileSync(args[1],app.store.renderTiddler(type,args[0]),"utf8"); + var title = args[0], + filename = args[1], + type = args[2] || "text/html"; + fs.writeFileSync(filename,app.store.renderTiddler(type,title),"utf8"); } }, savetiddlers: { - args: {min: 1, max: 1}, + args: {min: 1, max: 2}, handler: function(args,callback) { - var recipe = []; + var outdir = args[0], + recipe = []; app.store.forEachTiddler(function(title,tiddler) { var filename = encodeURIComponent(tiddler.title.replace(/ /g,"_")) + ".tid"; - fs.writeFileSync(path.resolve(args[0],filename),app.store.serializeTiddler("application/x-tiddler",tiddler),"utf8"); + fs.writeFileSync(path.resolve(outdir,filename),app.store.serializeTiddler("application/x-tiddler",tiddler),"utf8"); recipe.push("tiddler: " + filename + "\n"); }); fs.writeFileSync(path.join(args[0],"split.recipe"),recipe.join("")); process.nextTick(function() {callback(null);}); } }, + savehtml: { + args: {min: 1, max: 1}, + handler: function(args,callback) { + var outdir = args[0]; + app.store.forEachTiddler(function(title,tiddler) { + var filename = encodeURIComponent(title.replace(/ /g,"_")) + ".html"; + fs.writeFileSync(path.resolve(outdir,filename),app.store.renderTiddler("text/html",title),"utf8"); + }); + process.nextTick(function() {callback(null);}); + } + }, servewiki: { args: {min: 0, max: 1}, handler: function(args,callback) { diff --git a/tw5.sh b/tw5.sh index 8fdf95242..3614caa15 100755 --- a/tw5.sh +++ b/tw5.sh @@ -9,6 +9,9 @@ mkdir -p tmp/tw5 # cook TiddlyWiki5 node tiddlywiki.js --recipe $PWD/tiddlywiki5/tiddlywiki5.recipe --savewiki tmp/tw5 --savetiddler ReadMe readme.md || exit 1 +# cook a static version too +#mkdir -p tmp/tw5/static +#node tiddlywiki.js --recipe $PWD/tiddlywiki5/tiddlywiki5.recipe --savehtml tmp/tw5/static # open the result #open -a /Applications/Google\ Chrome.app tmp/tw5/index.html