1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

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.
This commit is contained in:
Jermolene 2015-06-23 08:55:21 +01:00
parent 8e12d4cb70
commit 53072dd7aa

View File

@ -1446,17 +1446,21 @@ $tw.loadTiddlersFromPath = function(filepath,excludeRegExp) {
// If so, process the files it describes // If so, process the files it describes
var filesInfo = JSON.parse(fs.readFileSync(filepath + path.sep + "tiddlywiki.files","utf8")); var filesInfo = JSON.parse(fs.readFileSync(filepath + path.sep + "tiddlywiki.files","utf8"));
$tw.utils.each(filesInfo.tiddlers,function(tidInfo) { $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), pathname = path.resolve(filepath,tidInfo.file),
text = fs.readFileSync(pathname,typeInfo ? typeInfo.encoding : "utf8"); text = fs.readFileSync(pathname,typeInfo ? typeInfo.encoding : "utf8"),
if(tidInfo.prefix) { fileTiddlers = $tw.wiki.deserializeTiddlers(path.extname(pathname),text) || [];
text = tidInfo.prefix + text; $tw.utils.each(fileTiddlers,function(tiddler) {
} $tw.utils.extend(tiddler,tidInfo.fields);
if(tidInfo.suffix) { if(tidInfo.prefix) {
text = text + tidInfo.suffix; tiddler.text = tidInfo.prefix + tiddler.text;
} }
tidInfo.fields.text = text; if(tidInfo.suffix) {
tiddlers.push({tiddlers: [tidInfo.fields]}); tiddler.text = tiddler.text + tidInfo.suffix;
}
});
tiddlers.push({tiddlers: fileTiddlers});
}); });
} else { } else {
// If not, read all the files in the directory // If not, read all the files in the directory