2024-01-02 14:39:14 +00:00
|
|
|
/*\
|
2024-01-19 19:27:54 +00:00
|
|
|
title: $:/plugins/tiddlywiki/multiwikiserver/route-get-recipe.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";
|
|
|
|
|
2024-01-03 16:27:13 +00:00
|
|
|
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]);
|
2024-01-19 10:52:12 +00:00
|
|
|
// Check request is valid
|
|
|
|
if(recipe_name) {
|
|
|
|
// Start the response
|
|
|
|
response.writeHead(200, "OK",{
|
|
|
|
"Content-Type": "text/html"
|
|
|
|
});
|
|
|
|
// Get the tiddlers in the recipe
|
2024-02-05 14:49:08 +00:00
|
|
|
var recipeTiddlers = $tw.mws.store.getRecipeTiddlers(recipe_name);
|
2024-01-19 10:52:12 +00:00
|
|
|
// Render the template
|
2024-02-05 14:49:08 +00:00
|
|
|
var template = $tw.mws.store.adminWiki.renderTiddler("text/plain","$:/core/templates/tiddlywiki5.html",{
|
2024-01-19 10:52:12 +00:00
|
|
|
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
|
|
|
}
|
2024-01-19 10:52:12 +00:00
|
|
|
response.write(template.substring(0,markerPos + marker.length));
|
2024-01-20 20:22:46 +00:00
|
|
|
$tw.utils.each(recipeTiddlers,function(recipeTiddlerInfo) {
|
2024-02-05 14:49:08 +00:00
|
|
|
var result = $tw.mws.store.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name);
|
2024-01-26 15:48:39 +00:00
|
|
|
if(result) {
|
|
|
|
var tiddlerFields = result.tiddler;
|
2024-02-05 14:49:08 +00:00
|
|
|
tiddlerFields = $tw.mws.store.processCanonicalUriTiddler(tiddlerFields,null,recipe_name);
|
2024-01-26 15:48:39 +00:00
|
|
|
response.write(JSON.stringify(tiddlerFields).replace(/</g,"\\u003c"));
|
|
|
|
response.write(",\n")
|
|
|
|
}
|
2024-01-19 10:52:12 +00:00
|
|
|
});
|
|
|
|
response.write(JSON.stringify({title: "$:/config/tiddlyweb/host",text: "$protocol$//$host$$pathname$/"}));
|
2024-01-23 16:52:49 +00:00
|
|
|
response.write(",\n")
|
2024-01-19 10:52:12 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}());
|