${blogs.map(blog_post => render_blog_post(blog_post)).join('\n')}
`;
}
function render_blog_post_atom(blog_post) {
return `${escape(blog_post.title)}${blog_post.id}${escape(new Date(blog_post.timestamp).toString())}${escape(blog_post.summary)}${escape(blog_post.name)}${escape(blog_post.author)}`;
}
export function render_atom(blogs) {
return `
🪵Tilde BlogA subtitle.https://www.tildefriends.net/~cory/blog/${new Date().toString()}
${blogs.map(blog_post => render_blog_post_atom(blog_post)).join('\n')}
`;
}
export async function get_posts() {
let blogs = [];
await ssb.sqlAsync(`
WITH
blogs AS (
SELECT
messages.author,
messages.id,
json_extract(messages.content, '$.title') AS title,
json_extract(messages.content, '$.summary') AS summary,
json_extract(messages.content, '$.blog') AS blog,
messages.timestamp
FROM messages_fts('blog')
JOIN messages ON messages.rowid = messages_fts.rowid
WHERE json_extract(messages.content, '$.type') = 'blog'),
public AS (
SELECT author FROM (
SELECT
messages.author,
RANK() OVER (PARTITION BY messages.author ORDER BY messages.sequence DESC) AS author_rank,
json_extract(messages.content, '$.publicWebHosting') AS is_public
FROM messages_fts('about')
JOIN messages ON messages.rowid = messages_fts.rowid
WHERE json_extract(messages.content, '$.type') = 'about' AND is_public IS NOT NULL)
WHERE author_rank = 1 AND is_public),
names AS (
SELECT author, name FROM (
SELECT
messages.author,
RANK() OVER (PARTITION BY messages.author ORDER BY messages.sequence DESC) AS author_rank,
json_extract(messages.content, '$.name') AS name
FROM messages_fts('about')
JOIN messages ON messages.rowid = messages_fts.rowid
WHERE json_extract(messages.content, '$.type') = 'about' AND
json_extract(messages.content, '$.about') = messages.author AND
name IS NOT NULL)
WHERE author_rank = 1)
SELECT blogs.*, names.name FROM blogs
JOIN public ON public.author = blogs.author
LEFT OUTER JOIN names ON names.author = blogs.author
ORDER BY blogs.timestamp DESC LIMIT 20
`, [], function(row) {
blogs.push(row);
});
return blogs;
}