1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-11-16 07:17:21 +00:00

Revise support for external tiddler files

Fixes #1884
This commit is contained in:
Jermolene
2015-07-18 11:45:30 +01:00
parent dfc935b520
commit ecbd97b4b4
3 changed files with 50 additions and 31 deletions

View File

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