mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +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:
parent
8e12d4cb70
commit
53072dd7aa
16
boot/boot.js
16
boot/boot.js
@ -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"),
|
||||||
|
fileTiddlers = $tw.wiki.deserializeTiddlers(path.extname(pathname),text) || [];
|
||||||
|
$tw.utils.each(fileTiddlers,function(tiddler) {
|
||||||
|
$tw.utils.extend(tiddler,tidInfo.fields);
|
||||||
if(tidInfo.prefix) {
|
if(tidInfo.prefix) {
|
||||||
text = tidInfo.prefix + text;
|
tiddler.text = tidInfo.prefix + tiddler.text;
|
||||||
}
|
}
|
||||||
if(tidInfo.suffix) {
|
if(tidInfo.suffix) {
|
||||||
text = text + tidInfo.suffix;
|
tiddler.text = tiddler.text + tidInfo.suffix;
|
||||||
}
|
}
|
||||||
tidInfo.fields.text = text;
|
});
|
||||||
tiddlers.push({tiddlers: [tidInfo.fields]});
|
tiddlers.push({tiddlers: fileTiddlers});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// If not, read all the files in the directory
|
// If not, read all the files in the directory
|
||||||
|
Loading…
Reference in New Issue
Block a user