From e8746c15753524cc79e6129a471f91c29ae253fa Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sat, 23 Mar 2013 22:11:23 +0000 Subject: [PATCH] On the server, start registering information about each writable tiddler file --- core/boot.js | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/core/boot.js b/core/boot.js index 270129523..e1c54a210 100644 --- a/core/boot.js +++ b/core/boot.js @@ -894,26 +894,28 @@ $tw.modules.execute = function(moduleName,moduleRoot) { }; /* -Load the tiddlers contained in a particular file (and optionally extract fields from the accompanying .meta file) returned as a hashmap of fields +Load the tiddlers contained in a particular file (and optionally extract fields from the accompanying .meta file) returned as {filepath:,type:,tiddlers:[],hasMetaFile:} */ $tw.loadTiddlersFromFile = function(filepath,fields) { var ext = path.extname(filepath), extensionInfo = $tw.config.fileExtensionInfo[ext], - typeInfo = extensionInfo ? $tw.config.contentTypeInfo[extensionInfo.type] : null, + type = extensionInfo ? extensionInfo.type : null, + typeInfo = type ? $tw.config.contentTypeInfo[type] : null, data = fs.readFileSync(filepath,typeInfo ? typeInfo.encoding : "utf8"), tiddlers = $tw.wiki.deserializeTiddlers(ext,data,fields), - metafile = filepath + ".meta"; + metafile = filepath + ".meta", + metadata; if(ext !== ".json" && tiddlers.length === 1 && fs.existsSync(metafile)) { - var metadata = fs.readFileSync(metafile,"utf8"); + metadata = fs.readFileSync(metafile,"utf8"); if(metadata) { tiddlers = [$tw.utils.parseFields(metadata,tiddlers[0])]; } } - return tiddlers; + return {filepath: filepath, type: type, tiddlers: tiddlers, hasMetaFile: !!metadata}; }; /* -Load all the tiddlers recursively from a directory, including honouring `tiddlywiki.files` files for drawing in external files. Returns an array of {filepath:,tiddlers: [{..fields...}]} +Load all the tiddlers recursively from a directory, including honouring `tiddlywiki.files` files for drawing in external files. Returns an array of {filepath:,type:,tiddlers: [{..fields...}],hasMetaFile:} */ $tw.loadTiddlersFromPath = function(filepath,excludeRegExp) { excludeRegExp = excludeRegExp || /^\.DS_Store$|.meta$/; @@ -942,9 +944,7 @@ $tw.loadTiddlersFromPath = function(filepath,excludeRegExp) { }); } } else if(stat.isFile()) { - tiddlers.push({ - filepath: filepath, - tiddlers: $tw.loadTiddlersFromFile(filepath)}); + tiddlers.push($tw.loadTiddlersFromFile(filepath)); } } return tiddlers; @@ -959,10 +959,10 @@ $tw.loadPluginFolder = function(filepath,excludeRegExp) { if(fs.existsSync(filepath)) { stat = fs.statSync(filepath); if(stat.isDirectory()) { - files = fs.readdirSync(filepath); // Read the plugin information pluginInfo = JSON.parse(fs.readFileSync(filepath + "/plugin.info","utf8")); // Read the plugin files + files = fs.readdirSync(filepath); for(f=0; f