Fiddling with blog links.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4749 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-01-10 02:23:40 +00:00
parent d38c58ce1d
commit b11d5192c2
3 changed files with 42 additions and 17 deletions

View File

@ -1,17 +1,39 @@
import * as blog from './blog.js';
async function main() {
let blogs = await blog.get_posts();
for (let blog_post of blogs) {
let title = (blog_post.title || '').replaceAll(/\W/g, '_').toLowerCase();
if (request.path === title) {
respond({data: await blog.render_blog_post_html(blog_post), content_type: 'text/html; charset=utf-8'});
return;
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'});
} else {
respond({data: `Message ${id} not found.`, content_type: 'text/html; charset=utf-8'});
}
}
if (request.path == 'atom') {
} else if (request.path == 'atom') {
let blogs = await blog.get_posts();
respond({data: blog.render_atom(blogs), content_type: 'application/atom+xml'});
} else {
let blogs = await blog.get_posts();
for (let blog_post of blogs) {
let title = (blog_post.title || '').replaceAll(/\W/g, '_').toLowerCase();
if (request.path === title) {
respond({data: await blog.render_blog_post_html(blog_post), content_type: 'text/html; charset=utf-8'});
return;
}
}
respond({data: blog.render_html(blogs), content_type: 'text/html; charset=utf-8'});
}
}