mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Allow tiddlywiki.files to load directories recursively
This commit is contained in:
parent
f917c4da1a
commit
803d70225a
@ -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) {
|
||||
|
@ -106,6 +106,9 @@ Sub-folders within the `tiddlers` folder can also be given a `tiddlywiki.files`
|
||||
"title": "A different title"
|
||||
}
|
||||
}
|
||||
],
|
||||
"directories": [
|
||||
"../../mytiddlers/store"
|
||||
]
|
||||
}
|
||||
```
|
||||
@ -117,3 +120,5 @@ The JSON data consists of an object with a `tiddlers` property that contains an
|
||||
** `isTiddlerFile`: if `true`, the file will be deserialised to extract the tiddlers. Otherwise, the raw content of the file is assigned to the `text` field without any parsing
|
||||
* `fields`: an object containing fields that override any provided in the tiddler file
|
||||
* `prefix` & `suffix`: (optional) specify strings to be prefixed and suffixed to the tiddler file text content
|
||||
|
||||
The ''directories'' property allows a list of directories to be specified. All tiddlers will be recursively loaded from each directory listed.
|
||||
|
Loading…
Reference in New Issue
Block a user