2011-11-25 19:20:35 +00:00
|
|
|
// Break apart a TiddlyWiki HTML file into separate .tid files
|
|
|
|
//
|
|
|
|
// Usage: node ginsu.js <tiddlywikifile> <outputdir>
|
|
|
|
//
|
|
|
|
// The .html extension is optional
|
|
|
|
//
|
|
|
|
// Ginsu creates the specified places the .tid files in the specified directory (which must already exist)
|
2011-11-30 17:27:00 +00:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2011-11-29 18:27:26 +00:00
|
|
|
var fs = require("fs"),
|
2011-11-25 19:20:35 +00:00
|
|
|
path = require("path"),
|
2011-11-27 09:46:02 +00:00
|
|
|
Tiddler = require("./js/Tiddler.js").Tiddler,
|
2011-11-25 19:20:35 +00:00
|
|
|
tiddlyWikiInput = require("./js/TiddlyWikiInput.js"),
|
|
|
|
tiddlerOutput = require("./js/TiddlerOutput.js");
|
|
|
|
|
|
|
|
var tiddlywikifilename = process.argv[2];
|
|
|
|
var outputdir = process.argv[3];
|
|
|
|
|
|
|
|
var tiddlywikidoc = fs.readFileSync(tiddlywikifilename,"utf8");
|
|
|
|
var tiddlers = tiddlyWikiInput.parseTiddlyWiki(tiddlywikidoc);
|
|
|
|
|
|
|
|
var recipe = [];
|
|
|
|
for(var t=0; t<tiddlers.length; t++) {
|
2011-11-27 09:46:02 +00:00
|
|
|
var tid = new Tiddler(tiddlers[t]);
|
2011-11-26 12:52:09 +00:00
|
|
|
var filename = encodeURIComponent(tid.fields.title.replace(/ /g,"_")) + ".tid";
|
2011-11-25 19:20:35 +00:00
|
|
|
fs.writeFileSync(path.join(outputdir,filename),tiddlerOutput.outputTiddler(tid));
|
|
|
|
recipe.push("tiddler: " + filename + "\n");
|
|
|
|
}
|
|
|
|
|
2011-11-26 13:22:50 +00:00
|
|
|
fs.writeFileSync(path.join(outputdir,"split.recipe"),recipe.join(""));
|
2011-11-25 19:20:35 +00:00
|
|
|
|