Add the blog app.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4669 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
22
apps/blog/handler.js
Normal file
22
apps/blog/handler.js
Normal file
@ -0,0 +1,22 @@
|
||||
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 == 'atom') {
|
||||
respond({data: blog.render_atom(blogs), content_type: 'application/atom+xml'});
|
||||
} else {
|
||||
respond({data: blog.render_html(blogs), content_type: 'text/html; charset=utf-8'});
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(function(error) {
|
||||
respond({data: `<!DOCTYPE html>
|
||||
<pre style="color: #f00">${error.message}\n${error.stack}</pre>`, content_type: 'text/html'});
|
||||
});
|
Reference in New Issue
Block a user