1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Revise support for external tiddler files

Fixes #1884
This commit is contained in:
Jermolene 2015-07-18 11:45:30 +01:00
parent dfc935b520
commit ecbd97b4b4
3 changed files with 50 additions and 31 deletions

View File

@ -1464,9 +1464,10 @@ $tw.loadTiddlersFromPath = function(filepath,excludeRegExp) {
$tw.utils.each(filesInfo.tiddlers,function(tidInfo) { $tw.utils.each(filesInfo.tiddlers,function(tidInfo) {
var type = tidInfo.fields.type || "text/plain", var type = tidInfo.fields.type || "text/plain",
typeInfo = $tw.config.contentTypeInfo[type], typeInfo = $tw.config.contentTypeInfo[type],
pathname = path.resolve(filepath,tidInfo.file), pathname = path.resolve(filepath,tidInfo.file || tidInfo.tiddlerFile),
text = fs.readFileSync(pathname,typeInfo ? typeInfo.encoding : "utf8"), text = fs.readFileSync(pathname,typeInfo ? typeInfo.encoding : "utf8");
fileTiddlers = $tw.wiki.deserializeTiddlers(path.extname(pathname),text) || []; if(tidInfo.tiddlerFile) {
var fileTiddlers = $tw.wiki.deserializeTiddlers(path.extname(pathname),text) || [];
$tw.utils.each(fileTiddlers,function(tiddler) { $tw.utils.each(fileTiddlers,function(tiddler) {
$tw.utils.extend(tiddler,tidInfo.fields); $tw.utils.extend(tiddler,tidInfo.fields);
if(tidInfo.prefix) { if(tidInfo.prefix) {
@ -1477,6 +1478,16 @@ $tw.loadTiddlersFromPath = function(filepath,excludeRegExp) {
} }
}); });
tiddlers.push({tiddlers: fileTiddlers}); tiddlers.push({tiddlers: fileTiddlers});
} else {
if(tidInfo.prefix) {
text = tidInfo.prefix + text;
}
if(tidInfo.suffix) {
text = text + tidInfo.suffix;
}
tidInfo.fields.text = text;
tiddlers.push({tiddlers: [tidInfo.fields]});
}
}); });
} else { } else {
// If not, read all the files in the directory // If not, read all the files in the directory

View File

@ -1,5 +1,5 @@
created: 20130825214200000 created: 20130825214200000
modified: 20141113122142639 modified: 20150718104424501
tags: [[TiddlyWiki on Node.js]] tags: [[TiddlyWiki on Node.js]]
title: TiddlyWikiFolders title: TiddlyWikiFolders
type: text/vnd.tiddlywiki type: text/vnd.tiddlywiki
@ -76,7 +76,7 @@ For example:
All the TiddlerFiles in the `tiddlers` folder are read into the wiki at startup. Sub-folders are scanned recursively for TiddlerFiles. All the TiddlerFiles in the `tiddlers` folder are read into the wiki at startup. Sub-folders are scanned recursively for TiddlerFiles.
Sub-folders within the `tiddlers` folder can also be given a `tiddlywiki.files` JSON file that overrides the default processing for that folder. The file format is illustrated with this example from the D3 plugin: Sub-folders within the `tiddlers` folder can also be given a `tiddlywiki.files` JSON file that overrides the default processing for that folder. The file format is illustrated with this example:
``` ```
{ {
@ -98,6 +98,12 @@ Sub-folders within the `tiddlers` folder can also be given a `tiddlywiki.files`
"title": "$:/plugins/tiddlywiki/d3/d3.layout.cloud.js", "title": "$:/plugins/tiddlywiki/d3/d3.layout.cloud.js",
"module-type": "library" "module-type": "library"
} }
},
{
"tiddlerFile": "local/mytiddler.tid",
"fields": {
"title": "A different title"
}
} }
] ]
} }
@ -105,6 +111,8 @@ Sub-folders within the `tiddlers` folder can also be given a `tiddlywiki.files`
The JSON data consists of an object with a `tiddlers` property that contains an array of information about each tiddler to be loaded into the wiki. That information consists of: The JSON data consists of an object with a `tiddlers` property that contains an array of information about each tiddler to be loaded into the wiki. That information consists of:
* `file`: the relative or absolute path to the file to include * The relative or absolute path to the file to include as either:
** `file`: a plain file that will not be deserialised
** `tiddlerFile`: a tiddler file that will be deserialised to extract the tiddlers
* `fields`: an object containing fields that override any provided in the tiddler file * `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 * `prefix` & `suffix`: (optional) specify strings to be prefixed and suffixed to the tiddler file text content

View File

@ -1,7 +1,7 @@
{ {
"tiddlers": [ "tiddlers": [
{ {
"file": "../../../../../languages/ca-ES/icon.tid", "tiddlerFile": "../../../../../languages/ca-ES/icon.tid",
"fields": { "fields": {
"title": "Language Icon: ca-ES", "title": "Language Icon: ca-ES",
"language": "ca-ES", "language": "ca-ES",
@ -9,7 +9,7 @@
} }
}, },
{ {
"file": "../../../../../languages/cs-CZ/icon.tid", "tiddlerFile": "../../../../../languages/cs-CZ/icon.tid",
"fields": { "fields": {
"title": "Language Icon: cs-CZ", "title": "Language Icon: cs-CZ",
"language": "cs-CZ", "language": "cs-CZ",
@ -17,7 +17,7 @@
} }
}, },
{ {
"file": "../../../../../languages/da-DK/icon.tid", "tiddlerFile": "../../../../../languages/da-DK/icon.tid",
"fields": { "fields": {
"title": "Language Icon: da-DK", "title": "Language Icon: da-DK",
"language": "da-DK", "language": "da-DK",
@ -25,7 +25,7 @@
} }
}, },
{ {
"file": "../../../../../languages/de-AT/icon.tid", "tiddlerFile": "../../../../../languages/de-AT/icon.tid",
"fields": { "fields": {
"title": "Language Icon: de-AT", "title": "Language Icon: de-AT",
"language": "de-AT", "language": "de-AT",
@ -33,7 +33,7 @@
} }
}, },
{ {
"file": "../../../../../languages/de-DE/icon.tid", "tiddlerFile": "../../../../../languages/de-DE/icon.tid",
"fields": { "fields": {
"title": "Language Icon: de-DE", "title": "Language Icon: de-DE",
"language": "de-DE", "language": "de-DE",
@ -41,7 +41,7 @@
} }
}, },
{ {
"file": "../../../../../languages/el-GR/icon.tid", "tiddlerFile": "../../../../../languages/el-GR/icon.tid",
"fields": { "fields": {
"title": "Language Icon: el-GR", "title": "Language Icon: el-GR",
"language": "el-GR", "language": "el-GR",
@ -49,7 +49,7 @@
} }
}, },
{ {
"file": "../../../../../languages/es-ES/icon.tid", "tiddlerFile": "../../../../../languages/es-ES/icon.tid",
"fields": { "fields": {
"title": "Language Icon: es-ES", "title": "Language Icon: es-ES",
"language": "es-ES", "language": "es-ES",
@ -57,7 +57,7 @@
} }
}, },
{ {
"file": "../../../../../languages/fr-FR/icon.tid", "tiddlerFile": "../../../../../languages/fr-FR/icon.tid",
"fields": { "fields": {
"title": "Language Icon: fr-FR", "title": "Language Icon: fr-FR",
"language": "fr-FR", "language": "fr-FR",
@ -65,7 +65,7 @@
} }
}, },
{ {
"file": "../../../../../languages/hi-IN/icon.tid", "tiddlerFile": "../../../../../languages/hi-IN/icon.tid",
"fields": { "fields": {
"title": "Language Icon: hi-IN", "title": "Language Icon: hi-IN",
"language": "hi-IN", "language": "hi-IN",
@ -73,7 +73,7 @@
} }
}, },
{ {
"file": "../../../../../languages/ia-IA/icon.tid", "tiddlerFile": "../../../../../languages/ia-IA/icon.tid",
"fields": { "fields": {
"title": "Language Icon: ia-IA", "title": "Language Icon: ia-IA",
"language": "ia-IA", "language": "ia-IA",
@ -81,7 +81,7 @@
} }
}, },
{ {
"file": "../../../../../languages/it-IT/icon.tid", "tiddlerFile": "../../../../../languages/it-IT/icon.tid",
"fields": { "fields": {
"title": "Language Icon: it-IT", "title": "Language Icon: it-IT",
"language": "it-IT", "language": "it-IT",
@ -89,7 +89,7 @@
} }
}, },
{ {
"file": "../../../../../languages/ja-JP/icon.tid", "tiddlerFile": "../../../../../languages/ja-JP/icon.tid",
"fields": { "fields": {
"title": "Language Icon: ja-JP", "title": "Language Icon: ja-JP",
"language": "ja-JP", "language": "ja-JP",
@ -97,7 +97,7 @@
} }
}, },
{ {
"file": "../../../../../languages/nl-NL/icon.tid", "tiddlerFile": "../../../../../languages/nl-NL/icon.tid",
"fields": { "fields": {
"title": "Language Icon: nl-NL", "title": "Language Icon: nl-NL",
"language": "nl-NL", "language": "nl-NL",
@ -105,7 +105,7 @@
} }
}, },
{ {
"file": "../../../../../languages/pa-IN/icon.tid", "tiddlerFile": "../../../../../languages/pa-IN/icon.tid",
"fields": { "fields": {
"title": "Language Icon: pa-IN", "title": "Language Icon: pa-IN",
"language": "pa-IN", "language": "pa-IN",
@ -113,7 +113,7 @@
} }
}, },
{ {
"file": "../../../../../languages/pt-PT/icon.tid", "tiddlerFile": "../../../../../languages/pt-PT/icon.tid",
"fields": { "fields": {
"title": "Language Icon: pt-PT", "title": "Language Icon: pt-PT",
"language": "pt-PT", "language": "pt-PT",
@ -121,7 +121,7 @@
} }
}, },
{ {
"file": "../../../../../languages/ru-RU/icon.tid", "tiddlerFile": "../../../../../languages/ru-RU/icon.tid",
"fields": { "fields": {
"title": "Language Icon: ru-RU", "title": "Language Icon: ru-RU",
"language": "ru-RU", "language": "ru-RU",
@ -129,7 +129,7 @@
} }
}, },
{ {
"file": "../../../../../languages/sk-SK/icon.tid", "tiddlerFile": "../../../../../languages/sk-SK/icon.tid",
"fields": { "fields": {
"title": "Language Icon: sk-SK", "title": "Language Icon: sk-SK",
"language": "sk-SK", "language": "sk-SK",
@ -137,7 +137,7 @@
} }
}, },
{ {
"file": "../../../../../languages/zh-Hans/icon.tid", "tiddlerFile": "../../../../../languages/zh-Hans/icon.tid",
"fields": { "fields": {
"title": "Language Icon: zh-Hans", "title": "Language Icon: zh-Hans",
"language": "zh-Hans", "language": "zh-Hans",
@ -145,7 +145,7 @@
} }
}, },
{ {
"file": "../../../../../languages/zh-Hant/icon.tid", "tiddlerFile": "../../../../../languages/zh-Hant/icon.tid",
"fields": { "fields": {
"title": "Language Icon: zh-Hant", "title": "Language Icon: zh-Hant",
"language": "zh-Hant", "language": "zh-Hant",