diff --git a/empty.html b/empty.html
index 9908262..823d3f1 100644
--- a/empty.html
+++ b/empty.html
@@ -10,7 +10,7 @@
-
+
@@ -19,7 +19,7 @@
-
-
Mastodon
+
This TiddlyWiki contains the following tiddlers:
+
+- $:/core
+
+- $:/isEncrypted
+
+- $:/themes/tiddlywiki/snowwhite
+
+- $:/themes/tiddlywiki/vanilla
+
+
+
@@ -151,10 +172,10 @@
@@ -246,9 +267,13 @@
$tw = $tw || Object.create(null);
$tw.boot = $tw.boot || Object.create(null);
+// Config
+$tw.config = $tw.config || Object.create(null);
+$tw.config.maxEditFileSize = 100 * 1024 * 1024; // 100MB
+
// Detect platforms
if(!("browser" in $tw)) {
- $tw.browser = typeof(window) !== "undefined" ? {} : null;
+ $tw.browser = typeof(window) !== "undefined" && typeof(document) !== "undefined" ? {} : null;
}
if(!("node" in $tw)) {
$tw.node = typeof(process) === "object" ? {} : null;
@@ -583,10 +608,10 @@
var link = dm("a"),
text = JSON.stringify(tiddlers);
if(Blob !== undefined) {
- var blob = new Blob([text], {type: "text/html"});
+ var blob = new Blob([text], {type: "application/json"});
link.setAttribute("href", URL.createObjectURL(blob));
} else {
- link.setAttribute("href","data:text/html," + encodeURIComponent(text));
+ link.setAttribute("href","data:application/json," + encodeURIComponent(text));
}
link.setAttribute("download","emergency-tiddlers-" + (new Date()) + ".json");
document.body.appendChild(link);
@@ -737,8 +762,8 @@
parseInt(value.substr(10,2)||"00",10),
parseInt(value.substr(12,2)||"00",10),
parseInt(value.substr(14,3)||"000",10)));
- d.setUTCFullYear(year); // See https://stackoverflow.com/a/5870822
- return d;
+ d.setUTCFullYear(year); // See https://stackoverflow.com/a/5870822
+ return d;
} else if($tw.utils.isDate(value)) {
return value;
} else {
@@ -1821,17 +1846,15 @@
// Unpack the currently registered plugins, creating shadow tiddlers for their constituent tiddlers
this.unpackPluginTiddlers = function() {
var self = this;
- // Sort the plugin titles by the `plugin-priority` field
- pluginTiddlers.sort(function(a,b) {
- if("plugin-priority" in a.fields && "plugin-priority" in b.fields) {
- return a.fields["plugin-priority"] - b.fields["plugin-priority"];
- } else if("plugin-priority" in a.fields) {
+ // Sort the plugin titles by the `plugin-priority` field, if this field is missing, default to 1
+ pluginTiddlers.sort(function(a, b) {
+ var priorityA = "plugin-priority" in a.fields ? a.fields["plugin-priority"] : 1;
+ var priorityB = "plugin-priority" in b.fields ? b.fields["plugin-priority"] : 1;
+ if (priorityA !== priorityB) {
+ return priorityA - priorityB;
+ } else if (a.fields.title < b.fields.title) {
return -1;
- } else if("plugin-priority" in b.fields) {
- return +1;
- } else if(a.fields.title < b.fields.title) {
- return -1;
- } else if(a.fields.title === b.fields.title) {
+ } else if (a.fields.title === b.fields.title) {
return 0;
} else {
return +1;
@@ -2255,8 +2278,16 @@
extensionInfo = $tw.utils.getFileExtensionInfo(ext),
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),
+ fileSize = fs.statSync(filepath).size,
+ data;
+ if(fileSize > $tw.config.maxEditFileSize) {
+ data = "File " + filepath + "not loaded because it is too large";
+ console.log("Warning: " + data);
+ ext = ".txt";
+ } else {
+ data = fs.readFileSync(filepath,typeInfo ? typeInfo.encoding : "utf8");
+ }
+ var tiddlers = $tw.wiki.deserializeTiddlers(ext,data,fields),
metadata = $tw.loadMetadataForFile(filepath);
if(metadata) {
if(type === "application/json") {
@@ -2345,7 +2376,7 @@
var value = tiddler[name];
switch(fieldInfo.source) {
case "subdirectories":
- value = path.relative(rootPath, filename).split(path.sep).slice(0, -1);
+ value = $tw.utils.stringifyList(path.relative(rootPath, filename).split(path.sep).slice(0, -1));
break;
case "filepath":
value = path.relative(rootPath, filename).split(path.sep).join('/');
@@ -2366,10 +2397,10 @@
value = path.extname(filename);
break;
case "created":
- value = new Date(fs.statSync(pathname).birthtime);
+ value = $tw.utils.stringifyDate(new Date(fs.statSync(pathname).birthtime));
break;
case "modified":
- value = new Date(fs.statSync(pathname).mtime);
+ value = $tw.utils.stringifyDate(new Date(fs.statSync(pathname).mtime));
break;
}
if(fieldInfo.prefix) {
@@ -2816,13 +2847,15 @@
$tw.utils.registerFileType("image/webp","base64",".webp",{flags:["image"]});
$tw.utils.registerFileType("image/heic","base64",".heic",{flags:["image"]});
$tw.utils.registerFileType("image/heif","base64",".heif",{flags:["image"]});
+ $tw.utils.registerFileType("image/avif","base64",".avif",{flags:["image"]});
$tw.utils.registerFileType("image/svg+xml","utf8",".svg",{flags:["image"]});
$tw.utils.registerFileType("image/vnd.microsoft.icon","base64",".ico",{flags:["image"]});
$tw.utils.registerFileType("image/x-icon","base64",".ico",{flags:["image"]});
$tw.utils.registerFileType("application/wasm","base64",".wasm");
- $tw.utils.registerFileType("application/font-woff","base64",".woff");
- $tw.utils.registerFileType("application/x-font-ttf","base64",".woff");
- $tw.utils.registerFileType("application/font-woff2","base64",".woff2");
+ $tw.utils.registerFileType("font/woff","base64",".woff");
+ $tw.utils.registerFileType("font/woff2","base64",".woff2");
+ $tw.utils.registerFileType("font/ttf","base64",".ttf");
+ $tw.utils.registerFileType("font/otf","base64",".otf");
$tw.utils.registerFileType("audio/ogg","base64",".ogg");
$tw.utils.registerFileType("audio/mp4","base64",[".mp4",".m4a"]);
$tw.utils.registerFileType("video/ogg","base64",[".ogm",".ogv",".ogg"]);
@@ -3123,3 +3156,4 @@