diff --git a/apps/blog.json b/apps/blog.json index 8fbf41e4..b3e771e2 100644 --- a/apps/blog.json +++ b/apps/blog.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "🪵", - "previous": "&7Ch5DjIMAEbJm05ofH1U/+wlzn9kr65DChcKKgurE8E=.sha256" + "previous": "&k+K+38dqVUjSDSspsyQhFkZexug/umccp20SSrsUq3o=.sha256" } \ No newline at end of file diff --git a/apps/blog/blog.js b/apps/blog/blog.js index 0958f96b..c5cfee7e 100644 --- a/apps/blog/blog.js +++ b/apps/blog/blog.js @@ -8,6 +8,39 @@ function escapeAttribute(text) { return (text ?? '').replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", '''); } +export async function get_blog_message(id) { + let message; + await ssb.sqlAsync( + 'SELECT author, timestamp, content FROM messages WHERE id = ?', + [id], + function(row) { + let content = JSON.parse(row.content); + message = { + author: row.author, + timestamp: row.timestamp, + blog: content?.blog, + title: content?.title, + }; + }); + if (message) { + await ssb.sqlAsync( + ` + SELECT json_extract(content, '$.name') AS name + FROM messages + WHERE author = ? + AND json_extract(content, '$.type') = 'about' + AND json_extract(content, '$.about') = author + AND name IS NOT NULL + ORDER BY sequence DESC LIMIT 1 + `, + [message.author], + function(row) { + message.name = row.name; + }); + } + return message; +} + export function markdown(md) { let reader = new commonmark.Parser({safe: true}); let writer = new commonmark.HtmlRenderer(); @@ -20,7 +53,7 @@ export function markdown(md) { 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; + node.destination = '/~core/ssb/#' + escape(node.destination); } } } @@ -32,9 +65,11 @@ export async function render_blog_post_html(blog_post) { return `
+