1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-10-02 00:40:47 +00:00

Track source filepath for tiddlers in tiddler file store

This commit is contained in:
Jeremy Ruston 2012-04-03 16:26:40 +01:00
parent 1b2e5fc53e
commit a2cd450cbe

View File

@ -18,6 +18,7 @@ function FileStore(dirpath,store,callback) {
this.dirpath = dirpath; this.dirpath = dirpath;
this.store = store; this.store = store;
this.callback = callback; this.callback = callback;
this.sources = {}; // A hashmap of <tiddlername>: <srcpath>
var self = this; var self = this;
// Set up a queue for loading tiddler files // Set up a queue for loading tiddler files
this.loadQueue = async.queue(function(task,callback) { this.loadQueue = async.queue(function(task,callback) {
@ -27,8 +28,7 @@ function FileStore(dirpath,store,callback) {
} else { } else {
// Use the filepath as the default title and src for the tiddler // Use the filepath as the default title and src for the tiddler
var fields = { var fields = {
title: data.path, title: data.path
src: data.path
}; };
var tiddlers = self.store.deserializeTiddlers(data.extname,data.text,fields); var tiddlers = self.store.deserializeTiddlers(data.extname,data.text,fields);
// Check for the .meta file // Check for the .meta file
@ -45,12 +45,12 @@ function FileStore(dirpath,store,callback) {
fields = self.store.deserializeTiddlers("application/x-tiddler",text,fields)[0]; fields = self.store.deserializeTiddlers("application/x-tiddler",text,fields)[0];
} }
} }
self.store.addTiddler(fields); task.callback(task,[fields]);
callback(null); callback(null);
} }
}); });
} else { } else {
self.store.addTiddlers(tiddlers); task.callback(task,tiddlers);
callback(null); callback(null);
} }
} }
@ -69,7 +69,14 @@ function FileStore(dirpath,store,callback) {
var f = files[t]; var f = files[t];
if(["..",".",".DS_Store"].indexOf(f) === -1 && f.indexOf(".meta") !== f.length-5) { if(["..",".",".DS_Store"].indexOf(f) === -1 && f.indexOf(".meta") !== f.length-5) {
self.loadQueue.push({ self.loadQueue.push({
filepath: path.resolve(self.dirpath,f) filepath: path.resolve(self.dirpath,f),
callback: function(task,tiddlers) {
for(var t=0; t<tiddlers.length; t++) {
var tiddler = tiddlers[t];
self.sources[tiddler.title] = task.filepath;
self.store.addTiddler(tiddler);
}
}
}); });
} }
} }