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:
parent
d38c58ce1d
commit
b11d5192c2
@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "tildefriends-app",
|
||||
"emoji": "🪵",
|
||||
"previous": "&7E+OhgnyEUUIIHPhvWCF6esqRRDdqPHhqJiGp1h6xg4=.sha256"
|
||||
"previous": "&7Ch5DjIMAEbJm05ofH1U/+wlzn9kr65DChcKKgurE8E=.sha256"
|
||||
}
|
@ -8,7 +8,7 @@ function escapeAttribute(text) {
|
||||
return (text ?? '').replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", ''');
|
||||
}
|
||||
|
||||
function markdown(md) {
|
||||
export function markdown(md) {
|
||||
let reader = new commonmark.Parser({safe: true});
|
||||
let writer = new commonmark.HtmlRenderer();
|
||||
let parsed = reader.parse(md || '');
|
||||
@ -17,10 +17,10 @@ function markdown(md) {
|
||||
while ((event = walker.next())) {
|
||||
node = event.node;
|
||||
if (event.entering) {
|
||||
if (node.type == 'image') {
|
||||
if (node.destination.startsWith('&')) {
|
||||
node.destination = '/' + node.destination + '/view';
|
||||
}
|
||||
if (node.destination?.startsWith('&')) {
|
||||
node.destination = '/' + node.destination + '/view?filename=' + node.firstChild?.literal;
|
||||
} else if (node.destination?.startsWith('@') || node.destination?.startsWith('%')) {
|
||||
node.destination = '/~core/ssb/#' + node.destination;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -31,6 +31,9 @@ export async function render_blog_post_html(blog_post) {
|
||||
let blob = utf8Decode(await ssb.blobGet(blog_post.blog));
|
||||
return `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<base target="_top">
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<div><a href="../ssb/#${escapeAttribute(blog_post.author)}">${escape(blog_post.name)}</a> ${escape(new Date(blog_post.timestamp).toString())}</div>
|
||||
@ -44,7 +47,7 @@ export async function render_blog_post_html(blog_post) {
|
||||
function render_blog_post(blog_post) {
|
||||
return `
|
||||
<div>
|
||||
<h2><a href="../ssb/#${escapeAttribute(blog_post.id)}">${escape(blog_post.title)}</a></h2>
|
||||
<h2><a href="./${escapeAttribute(blog_post.id)}">${escape(blog_post.title)}</a></h2>
|
||||
<div><a href="../ssb/#${escapeAttribute(blog_post.author)}">${escape(blog_post.name)}</a> ${escape(new Date(blog_post.timestamp).toString())}</div>
|
||||
<div>${markdown(blog_post.summary)}</div>
|
||||
</div>
|
||||
@ -62,11 +65,11 @@ export function render_html(blogs) {
|
||||
background-color: #ccc;
|
||||
}
|
||||
</style>
|
||||
<base target="_blank">
|
||||
<base target="_top">
|
||||
</head>
|
||||
<body>
|
||||
<div style="display: flex; flex-direction: row; align-items: center; gap: 1em">
|
||||
<h1>🪵Tilde Blog</h1>
|
||||
<h1>🪵Tilde Friends Blog</h1>
|
||||
<div style="font-size: xx-small; vertical-align: middle"><a href="/~cory/blog/atom">atom feed</a></div>
|
||||
</div>
|
||||
${blogs.map(blog_post => render_blog_post(blog_post)).join('\n')}
|
||||
|
@ -1,6 +1,31 @@
|
||||
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'});
|
||||
} else {
|
||||
respond({data: `Message ${id} not found.`, content_type: 'text/html; charset=utf-8'});
|
||||
}
|
||||
} 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();
|
||||
@ -9,9 +34,6 @@ async function main() {
|
||||
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'});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user