mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-07-06 20:12:49 +00:00
Stream wiki generation
Avoids "string too long" errors when working with big tiddlers (>100MB)
This commit is contained in:
parent
4f37355a9f
commit
4133e7d6d6
@ -19,6 +19,12 @@ exports.path = /^\/wiki\/([^\/]+)$/;
|
|||||||
exports.handler = function(request,response,state) {
|
exports.handler = function(request,response,state) {
|
||||||
// Get the recipe name from the parameters
|
// Get the recipe name from the parameters
|
||||||
var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]);
|
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
|
// Get the tiddlers in the recipe
|
||||||
var titles = $tw.sqlTiddlerStore.getRecipeTiddlers(recipe_name);
|
var titles = $tw.sqlTiddlerStore.getRecipeTiddlers(recipe_name);
|
||||||
// Render the template
|
// Render the template
|
||||||
@ -42,19 +48,17 @@ exports.handler = function(request,response,state) {
|
|||||||
if(markerPos === -1) {
|
if(markerPos === -1) {
|
||||||
throw new Error("Cannot find tiddler store in template");
|
throw new Error("Cannot find tiddler store in template");
|
||||||
}
|
}
|
||||||
var htmlParts = [];
|
response.write(template.substring(0,markerPos + marker.length));
|
||||||
htmlParts.push(template.substring(0,markerPos + marker.length));
|
|
||||||
$tw.utils.each(titles,function(title) {
|
$tw.utils.each(titles,function(title) {
|
||||||
var tiddler = $tw.sqlTiddlerStore.getTiddler(title,recipe_name);
|
var tiddler = $tw.sqlTiddlerStore.getTiddler(title,recipe_name);
|
||||||
htmlParts.push(JSON.stringify(Object.assign({},tiddler,{revision: "0", bag: "bag-gamma"})));
|
response.write(JSON.stringify(Object.assign({},tiddler,{revision: "0", bag: "bag-gamma"})));
|
||||||
htmlParts.push(",")
|
response.write(",")
|
||||||
});
|
});
|
||||||
htmlParts.push(JSON.stringify({title: "$:/config/tiddlyweb/host",text: "$protocol$//$host$$pathname$/"}));
|
response.write(JSON.stringify({title: "$:/config/tiddlyweb/host",text: "$protocol$//$host$$pathname$/"}));
|
||||||
htmlParts.push(",")
|
response.write(",")
|
||||||
htmlParts.push(template.substring(markerPos + marker.length))
|
response.write(template.substring(markerPos + marker.length))
|
||||||
// Send response
|
// Finish response
|
||||||
if(htmlParts) {
|
response.end();
|
||||||
state.sendResponse(200,{"Content-Type": "text/html"},htmlParts.join("\n"),"utf8");
|
|
||||||
} else {
|
} else {
|
||||||
response.writeHead(404);
|
response.writeHead(404);
|
||||||
response.end();
|
response.end();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user