mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-06-22 08:24:06 +00:00
On the server, start registering information about each writable tiddler file
This commit is contained in:
parent
d7b000fd6b
commit
e8746c1575
45
core/boot.js
45
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) {
|
$tw.loadTiddlersFromFile = function(filepath,fields) {
|
||||||
var ext = path.extname(filepath),
|
var ext = path.extname(filepath),
|
||||||
extensionInfo = $tw.config.fileExtensionInfo[ext],
|
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"),
|
data = fs.readFileSync(filepath,typeInfo ? typeInfo.encoding : "utf8"),
|
||||||
tiddlers = $tw.wiki.deserializeTiddlers(ext,data,fields),
|
tiddlers = $tw.wiki.deserializeTiddlers(ext,data,fields),
|
||||||
metafile = filepath + ".meta";
|
metafile = filepath + ".meta",
|
||||||
|
metadata;
|
||||||
if(ext !== ".json" && tiddlers.length === 1 && fs.existsSync(metafile)) {
|
if(ext !== ".json" && tiddlers.length === 1 && fs.existsSync(metafile)) {
|
||||||
var metadata = fs.readFileSync(metafile,"utf8");
|
metadata = fs.readFileSync(metafile,"utf8");
|
||||||
if(metadata) {
|
if(metadata) {
|
||||||
tiddlers = [$tw.utils.parseFields(metadata,tiddlers[0])];
|
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) {
|
$tw.loadTiddlersFromPath = function(filepath,excludeRegExp) {
|
||||||
excludeRegExp = excludeRegExp || /^\.DS_Store$|.meta$/;
|
excludeRegExp = excludeRegExp || /^\.DS_Store$|.meta$/;
|
||||||
@ -942,9 +944,7 @@ $tw.loadTiddlersFromPath = function(filepath,excludeRegExp) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if(stat.isFile()) {
|
} else if(stat.isFile()) {
|
||||||
tiddlers.push({
|
tiddlers.push($tw.loadTiddlersFromFile(filepath));
|
||||||
filepath: filepath,
|
|
||||||
tiddlers: $tw.loadTiddlersFromFile(filepath)});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tiddlers;
|
return tiddlers;
|
||||||
@ -959,10 +959,10 @@ $tw.loadPluginFolder = function(filepath,excludeRegExp) {
|
|||||||
if(fs.existsSync(filepath)) {
|
if(fs.existsSync(filepath)) {
|
||||||
stat = fs.statSync(filepath);
|
stat = fs.statSync(filepath);
|
||||||
if(stat.isDirectory()) {
|
if(stat.isDirectory()) {
|
||||||
files = fs.readdirSync(filepath);
|
|
||||||
// Read the plugin information
|
// Read the plugin information
|
||||||
pluginInfo = JSON.parse(fs.readFileSync(filepath + "/plugin.info","utf8"));
|
pluginInfo = JSON.parse(fs.readFileSync(filepath + "/plugin.info","utf8"));
|
||||||
// Read the plugin files
|
// Read the plugin files
|
||||||
|
files = fs.readdirSync(filepath);
|
||||||
for(f=0; f<files.length; f++) {
|
for(f=0; f<files.length; f++) {
|
||||||
file = files[f];
|
file = files[f];
|
||||||
if(!excludeRegExp.test(file) && file !== "plugin.info" && file !== "tiddlywiki.files") {
|
if(!excludeRegExp.test(file) && file !== "plugin.info" && file !== "tiddlywiki.files") {
|
||||||
@ -995,15 +995,20 @@ $tw.loadPluginFolder = function(filepath,excludeRegExp) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$tw.loadTiddlers = function() {
|
$tw.loadTiddlers = function() {
|
||||||
// On the server, we load tiddlers from specified folders
|
// Load the core tiddlers
|
||||||
var folders = [
|
$tw.utils.each($tw.loadTiddlersFromPath($tw.boot.bootPath),function(tiddlerFile) {
|
||||||
$tw.boot.bootPath,
|
$tw.wiki.addTiddlers(tiddlerFile.tiddlers);
|
||||||
path.resolve($tw.boot.wikiPath,$tw.config.wikiTiddlersSubDir)
|
});
|
||||||
];
|
// Load the wiki files, registering them as writable
|
||||||
$tw.utils.each(folders,function(folder) {
|
var wikiTiddlersPath = path.resolve($tw.boot.wikiPath,$tw.config.wikiTiddlersSubDir);
|
||||||
var tiddlerFiles = $tw.loadTiddlersFromPath(folder);
|
$tw.utils.each($tw.loadTiddlersFromPath(wikiTiddlersPath),function(tiddlerFile) {
|
||||||
$tw.utils.each(tiddlerFiles,function(tiddlerFile) {
|
$tw.wiki.addTiddlers(tiddlerFile.tiddlers);
|
||||||
$tw.wiki.addTiddlers(tiddlerFile.tiddlers);
|
$tw.utils.each(tiddlerFile.tiddlers,function(tiddler) {
|
||||||
|
$tw.boot.files[tiddler.title] = {
|
||||||
|
filepath: tiddlerFile.filepath,
|
||||||
|
type: tiddlerFile.type,
|
||||||
|
hasMetaFile: tiddlerFile.hasMetaFile
|
||||||
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// Load any plugins listed in the wiki info file
|
// Load any plugins listed in the wiki info file
|
||||||
@ -1039,6 +1044,8 @@ $tw.loadTiddlers = function() {
|
|||||||
|
|
||||||
$tw.boot.startup = function() {
|
$tw.boot.startup = function() {
|
||||||
if(!$tw.browser) {
|
if(!$tw.browser) {
|
||||||
|
// For writable tiddler files, a hashmap of title to {filepath:,type:,hasMetaFile:}
|
||||||
|
$tw.boot.files = {};
|
||||||
// System paths and filenames
|
// System paths and filenames
|
||||||
$tw.boot.bootPath = path.dirname(module.filename);
|
$tw.boot.bootPath = path.dirname(module.filename);
|
||||||
// If the first command line argument doesn't start with `--` then we
|
// If the first command line argument doesn't start with `--` then we
|
||||||
|
Loading…
x
Reference in New Issue
Block a user