From 5bfcbb99baf574aa6328280529eefa7c243427e9 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Mon, 25 Mar 2013 18:55:41 +0000 Subject: [PATCH] Add support for wiki directories to recursively include other wiki directories --- core/boot.js | 67 +++++++++++++++++++-------- editions/clientserver/tiddlywiki.info | 4 +- 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/core/boot.js b/core/boot.js index 8b089acc2..a341ccb85 100644 --- a/core/boot.js +++ b/core/boot.js @@ -998,13 +998,43 @@ $tw.loadPluginFolder = function(filepath,excludeRegExp) { } : null; }; -$tw.loadTiddlers = function() { - // Load the core tiddlers - $tw.utils.each($tw.loadTiddlersFromPath($tw.boot.bootPath),function(tiddlerFile) { - $tw.wiki.addTiddlers(tiddlerFile.tiddlers); - }); +/* +path: path of wiki directory +parentPaths: array of parent paths that we mustn't recurse into +*/ +$tw.loadWikiTiddlers = function(wikiPath,parentPaths) { + parentPaths = parentPaths || []; + var wikiInfoPath = path.resolve(wikiPath,$tw.config.wikiInfo), + wikiInfo = {}, + pluginFields; + // Load the wiki info file + if(fs.existsSync(wikiInfoPath)) { + wikiInfo = JSON.parse(fs.readFileSync(wikiInfoPath,"utf8")); + // Load any parent wikis + if(wikiInfo.includeWikis) { + parentPaths = parentPaths.slice(0); + parentPaths.push(wikiPath); + $tw.utils.each(wikiInfo.includeWikis,function(includedWikiPath) { + var resolvedIncludedWikiPath = path.resolve(wikiPath,includedWikiPath); + if(parentPaths.indexOf(resolvedIncludedWikiPath) === -1) { + $tw.loadWikiTiddlers(resolvedIncludedWikiPath,parentPaths); + } + }); + } + // Load any plugins listed in the wiki info file + if(wikiInfo.plugins) { + var pluginBasePath = path.resolve($tw.boot.bootPath,$tw.config.pluginsPath); + for(var t=0; t