1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-06 10:06:19 +00:00
TiddlyWiki5/plugins/tiddlywiki/multiwikiserver/modules/route-get-wiki.js

81 lines
2.2 KiB
JavaScript
Raw Normal View History

2024-01-02 14:39:14 +00:00
/*\
title: $:/plugins/tiddlywiki/multiwikiserver/route-get-wiki.js
2024-01-02 14:39:14 +00:00
type: application/javascript
module-type: route
GET /wikis/:recipe_name
\*/
(function() {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.method = "GET";
exports.path = /^\/wiki\/([^\/]+)$/;
2024-01-02 14:39:14 +00:00
exports.handler = function(request,response,state) {
// Get the recipe name from the parameters
var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]);
// Check request is valid
if(recipe_name) {
// Start the response
response.writeHead(200, "OK",{
"Content-Type": "text/html"
});
// Get the tiddlers in the recipe
var titles = $tw.sqlTiddlerStore.getRecipeTiddlers(recipe_name);
// Render the template
2024-01-19 19:25:58 +00:00
var template = $tw.sqlTiddlerStore.adminWiki.renderTiddler("text/plain","$:/core/templates/tiddlywiki5.html",{
variables: {
saveTiddlerFilter: `
$:/boot/boot.css
$:/boot/boot.js
$:/boot/bootprefix.js
$:/core
$:/library/sjcl.js
$:/plugins/tiddlywiki/tiddlyweb
$:/themes/tiddlywiki/snowwhite
$:/themes/tiddlywiki/vanilla
`
}
});
// Splice in our tiddlers
var marker = `<` + `script class="tiddlywiki-tiddler-store" type="application/json">[`,
markerPos = template.indexOf(marker);
if(markerPos === -1) {
throw new Error("Cannot find tiddler store in template");
2024-01-02 14:39:14 +00:00
}
response.write(template.substring(0,markerPos + marker.length));
$tw.utils.each(titles,function(title) {
var tiddler = $tw.sqlTiddlerStore.getTiddler(title,recipe_name);
if((tiddler.text || "").length > 10 * 1024 * 1024) {
response.write(JSON.stringify(Object.assign({},tiddler,{
revision: "0",
bag: "bag-gamma",
text: undefined,
_canonical_uri: `/wiki/${recipe_name}/recipes/${recipe_name}/tiddlers/${title}`
})));
} else {
response.write(JSON.stringify(Object.assign({},tiddler,{
revision: "0",
bag: "bag-gamma"
})));
}
response.write(",")
});
response.write(JSON.stringify({title: "$:/config/tiddlyweb/host",text: "$protocol$//$host$$pathname$/"}));
response.write(",")
response.write(template.substring(markerPos + marker.length))
// Finish response
response.end();
2024-01-02 14:39:14 +00:00
} else {
response.writeHead(404);
response.end();
}
};
}());