Make blogs semi-navigable.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4753 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-01-11 00:33:53 +00:00
parent a0af058f5e
commit 576e58b1e3
3 changed files with 40 additions and 18 deletions

View File

@ -3,22 +3,9 @@ import * as blog from './blog.js';
async function main() {
if (request.path.startsWith('%') && request.path.endsWith('.sha256')) {
let id = request.path.startsWith('%25') ? '%' + request.path.substring(3) : request.path;
let blob = await ssb.messageContentGet(id);
if (blob) {
let content = JSON.parse(utf8Decode(blob));
let md = content?.text;
if (content?.type == 'blog') {
md = utf8Decode(await ssb.blobGet(content?.blog));
}
respond({data: `<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
${blog.markdown(md)}
</body>
</html>`, content_type: 'text/html; charset=utf-8'});
let message = await blog.get_blog_message(id);
if (message) {
respond({data: await blog.render_blog_post_html(message), content_type: 'text/html; charset=utf-8'});
} else {
respond({data: `Message ${id} not found.`, content_type: 'text/html; charset=utf-8'});
}