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

@ -8,7 +8,7 @@ function escapeAttribute(text) {
return (text ?? '').replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll("'", '&#39;');
}
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')}