From 53072dd7aa635bd0010d1a6af90d2b2c971353b7 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Tue, 23 Jun 2015 08:55:21 +0100 Subject: [PATCH] Extended tiddlywiki.files to support tiddler files Previously, we just read the target file as a block of UTF-8. With this update, we deserialise the file, allowing us to use file formats like .tid within the tiddlywiki.files file. --- boot/boot.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/boot/boot.js b/boot/boot.js index 35bd84bab..e8557c603 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -1446,17 +1446,21 @@ $tw.loadTiddlersFromPath = function(filepath,excludeRegExp) { // If so, process the files it describes var filesInfo = JSON.parse(fs.readFileSync(filepath + path.sep + "tiddlywiki.files","utf8")); $tw.utils.each(filesInfo.tiddlers,function(tidInfo) { - var typeInfo = $tw.config.contentTypeInfo[tidInfo.fields.type || "text/plain"], + var type = tidInfo.fields.type || "text/plain", + typeInfo = $tw.config.contentTypeInfo[type], pathname = path.resolve(filepath,tidInfo.file), - text = fs.readFileSync(pathname,typeInfo ? typeInfo.encoding : "utf8"); - if(tidInfo.prefix) { - text = tidInfo.prefix + text; - } - if(tidInfo.suffix) { - text = text + tidInfo.suffix; - } - tidInfo.fields.text = text; - tiddlers.push({tiddlers: [tidInfo.fields]}); + text = fs.readFileSync(pathname,typeInfo ? typeInfo.encoding : "utf8"), + fileTiddlers = $tw.wiki.deserializeTiddlers(path.extname(pathname),text) || []; + $tw.utils.each(fileTiddlers,function(tiddler) { + $tw.utils.extend(tiddler,tidInfo.fields); + if(tidInfo.prefix) { + tiddler.text = tidInfo.prefix + tiddler.text; + } + if(tidInfo.suffix) { + tiddler.text = tiddler.text + tidInfo.suffix; + } + }); + tiddlers.push({tiddlers: fileTiddlers}); }); } else { // If not, read all the files in the directory