mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-08 14:55:17 +00:00
Add a new static index route
This commit is contained in:
parent
6a673e6aea
commit
259b3dca1b
@ -38,26 +38,15 @@ exports.handler = function(request,response,state) {
|
|||||||
response.writeHead(200, "OK",{
|
response.writeHead(200, "OK",{
|
||||||
"Content-Type": "text/html"
|
"Content-Type": "text/html"
|
||||||
});
|
});
|
||||||
response.write(`
|
var html = $tw.mws.store.adminWiki.renderTiddler("text/plain","$:/plugins/tiddlywiki/multiwikiserver/templates/page",{
|
||||||
<!doctype html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
`);
|
|
||||||
// Render the html
|
|
||||||
var html = $tw.mws.store.adminWiki.renderTiddler("text/html","$:/plugins/tiddlywiki/multiwikiserver/templates/get-bag",{
|
|
||||||
variables: {
|
variables: {
|
||||||
|
"page-content": "$:/plugins/tiddlywiki/multiwikiserver/templates/get-bag",
|
||||||
"bag-name": bag_name,
|
"bag-name": bag_name,
|
||||||
"bag-titles": JSON.stringify(bagTiddlers.map(bagTiddler => bagTiddler.title)),
|
"bag-titles": JSON.stringify(bagTiddlers.map(bagTiddler => bagTiddler.title)),
|
||||||
"bag-tiddlers": JSON.stringify(bagTiddlers)
|
"bag-tiddlers": JSON.stringify(bagTiddlers)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
response.write(html);
|
response.write(html);
|
||||||
response.write(`
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
`);
|
|
||||||
response.end();
|
response.end();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/plugins/tiddlywiki/multiwikiserver/routes/handlers/get-index.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: mws-route
|
||||||
|
|
||||||
|
GET /
|
||||||
|
|
||||||
|
\*/
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.method = "GET";
|
||||||
|
|
||||||
|
exports.path = /^\/$/;
|
||||||
|
|
||||||
|
exports.handler = function(request,response,state) {
|
||||||
|
// Get the bag and recipe information
|
||||||
|
var bagList = $tw.mws.store.listBags(),
|
||||||
|
recipeList = $tw.mws.store.listRecipes();
|
||||||
|
// If application/json is requested then this is an API request, and gets the response in JSON
|
||||||
|
if(request.headers.accept && request.headers.accept.indexOf("application/json") !== -1) {
|
||||||
|
state.sendResponse(200,{"Content-Type": "application/json"},JSON.stringify(recipes),"utf8");
|
||||||
|
} else {
|
||||||
|
// This is not a JSON API request, we should return the raw tiddler content
|
||||||
|
response.writeHead(200, "OK",{
|
||||||
|
"Content-Type": "text/html"
|
||||||
|
});
|
||||||
|
// Render the html
|
||||||
|
var html = $tw.mws.store.adminWiki.renderTiddler("text/plain","$:/plugins/tiddlywiki/multiwikiserver/templates/page",{
|
||||||
|
variables: {
|
||||||
|
"page-content": "$:/plugins/tiddlywiki/multiwikiserver/templates/get-index",
|
||||||
|
"bag-list": JSON.stringify(bagList),
|
||||||
|
"recipe-list": JSON.stringify(recipeList)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
response.write(html);
|
||||||
|
response.end();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}());
|
62
plugins/tiddlywiki/multiwikiserver/templates/get-index.tid
Normal file
62
plugins/tiddlywiki/multiwikiserver/templates/get-index.tid
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
title: $:/plugins/tiddlywiki/multiwikiserver/templates/get-index
|
||||||
|
|
||||||
|
! Wikis Available Here
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<$list filter="[<recipe-list>jsonindexes[]] :sort[<currentTiddler>jsonget[recipe_name]]" variable="recipe-index">
|
||||||
|
<li>
|
||||||
|
<$let
|
||||||
|
recipe-info={{{ [<recipe-list>jsonextract<recipe-index>] }}}
|
||||||
|
recipe-name={{{ [<recipe-info>jsonget[recipe_name]] }}}
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href=`/wiki/${ [<recipe-name>encodeuricomponent[]] }$`
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
<$text text={{{ [<recipe-info>jsonget[recipe_name]] }}}/>
|
||||||
|
</strong>
|
||||||
|
: <$text text={{{ [<recipe-info>jsonget[description]] }}}/>
|
||||||
|
</a>
|
||||||
|
<ul>
|
||||||
|
<$list filter="[<recipe-info>jsonget[bag_names]]" variable="bag-name">
|
||||||
|
<li>
|
||||||
|
<a
|
||||||
|
href=`/wiki/${ [<bag-name>encodeuricomponent[]] }$/bags/${ [<bag-name>encodeuricomponent[]] }$`
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
<$text text=<<bag-name>>/>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</$list>
|
||||||
|
</ul>
|
||||||
|
</$let>
|
||||||
|
</li>
|
||||||
|
</$list>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
! Bags
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<$list filter="[<bag-list>jsonindexes[]] :sort[<currentTiddler>jsonget[bag_name]]" variable="bag-index">
|
||||||
|
<li>
|
||||||
|
<$let
|
||||||
|
bag-info={{{ [<bag-list>jsonextract<bag-index>] }}}
|
||||||
|
bag-name={{{ [<bag-info>jsonget[bag_name]] }}}
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href=`/wiki/${ [<bag-name>encodeuricomponent[]] }$/bags/${ [<bag-name>encodeuricomponent[]] }$`
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
<$text text={{{ [<bag-info>jsonget[bag_name]] }}}/>
|
||||||
|
</strong>
|
||||||
|
: <$text text={{{ [<bag-info>jsonget[description]] }}}/>
|
||||||
|
</a>
|
||||||
|
</$let>
|
||||||
|
</li>
|
||||||
|
</$list>
|
||||||
|
</ul>
|
19
plugins/tiddlywiki/multiwikiserver/templates/page.tid
Normal file
19
plugins/tiddlywiki/multiwikiserver/templates/page.tid
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
title: $:/plugins/tiddlywiki/multiwikiserver/templates/page
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Template for the basic HTML page layout. Expects the following variables:
|
||||||
|
|
||||||
|
page-content: title of tiddler containing the main page content
|
||||||
|
-->
|
||||||
|
`
|
||||||
|
<!doctype html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
`
|
||||||
|
<$view tiddler=<<page-content>> field="text" format="htmlwikified" />
|
||||||
|
`
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`
|
Loading…
x
Reference in New Issue
Block a user