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

Allow tiddlywiki.files to load directories recursively

This commit is contained in:
Jermolene
2015-09-15 13:35:54 +01:00
parent f917c4da1a
commit 803d70225a
2 changed files with 13 additions and 0 deletions

View File

@@ -1465,6 +1465,7 @@ $tw.loadTiddlersFromPath = function(filepath,excludeRegExp) {
if(files.indexOf("tiddlywiki.files") !== -1) {
// If so, process the files it describes
var filesInfo = JSON.parse(fs.readFileSync(filepath + path.sep + "tiddlywiki.files","utf8"));
// First the tiddlers
$tw.utils.each(filesInfo.tiddlers,function(tidInfo) {
var type = tidInfo.fields.type || "text/plain",
typeInfo = $tw.config.contentTypeInfo[type],
@@ -1493,6 +1494,13 @@ $tw.loadTiddlersFromPath = function(filepath,excludeRegExp) {
tiddlers.push({tiddlers: [tidInfo.fields]});
}
});
// Then any recursive directories
$tw.utils.each(filesInfo.directories,function(dirPath) {
var pathname = path.resolve(filepath,dirPath);
if(fs.existsSync(pathname) && fs.statSync(pathname).isDirectory()) {
tiddlers.push.apply(tiddlers,$tw.loadTiddlersFromPath(pathname,excludeRegExp));
}
});
} else {
// If not, read all the files in the directory
$tw.utils.each(files,function(file) {