1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

New command line switch to save wiki as a folder of static HTML files

This commit is contained in:
Jeremy Ruston 2012-03-03 16:50:11 +00:00
parent 193365c450
commit d6397e9d84
2 changed files with 22 additions and 5 deletions

View File

@ -126,23 +126,37 @@ var commandLineSwitches = {
savetiddler: { savetiddler: {
args: {min: 2, max: 3}, args: {min: 2, max: 3},
handler: function(args,callback) { handler: function(args,callback) {
var type = args[2] || "text/html"; var title = args[0],
fs.writeFileSync(args[1],app.store.renderTiddler(type,args[0]),"utf8"); filename = args[1],
type = args[2] || "text/html";
fs.writeFileSync(filename,app.store.renderTiddler(type,title),"utf8");
} }
}, },
savetiddlers: { savetiddlers: {
args: {min: 1, max: 1}, args: {min: 1, max: 2},
handler: function(args,callback) { handler: function(args,callback) {
var recipe = []; var outdir = args[0],
recipe = [];
app.store.forEachTiddler(function(title,tiddler) { app.store.forEachTiddler(function(title,tiddler) {
var filename = encodeURIComponent(tiddler.title.replace(/ /g,"_")) + ".tid"; 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"); recipe.push("tiddler: " + filename + "\n");
}); });
fs.writeFileSync(path.join(args[0],"split.recipe"),recipe.join("")); fs.writeFileSync(path.join(args[0],"split.recipe"),recipe.join(""));
process.nextTick(function() {callback(null);}); 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: { servewiki: {
args: {min: 0, max: 1}, args: {min: 0, max: 1},
handler: function(args,callback) { handler: function(args,callback) {

3
tw5.sh
View File

@ -9,6 +9,9 @@ mkdir -p tmp/tw5
# cook TiddlyWiki5 # cook TiddlyWiki5
node tiddlywiki.js --recipe $PWD/tiddlywiki5/tiddlywiki5.recipe --savewiki tmp/tw5 --savetiddler ReadMe readme.md || exit 1 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 the result
#open -a /Applications/Google\ Chrome.app tmp/tw5/index.html #open -a /Applications/Google\ Chrome.app tmp/tw5/index.html