Start creating blog posts
This commit is contained in:
parent
9ff1986adc
commit
4a3ee88f77
35 changed files with 1015 additions and 157 deletions
|
|
@ -106,6 +106,35 @@ async function gameFeedItem(
|
|||
};
|
||||
}
|
||||
|
||||
async function blogFeedItem(
|
||||
site: URL | undefined,
|
||||
data: EntryWithPubDate<"blog">["data"],
|
||||
slug: CollectionEntry<"blog">["slug"],
|
||||
body: string,
|
||||
): Promise<FeedItem> {
|
||||
return {
|
||||
title: `New blog post! "${data.title}"`,
|
||||
pubDate: toNoonUTCDate(data.pubDate),
|
||||
link: `/blog/${slug}`,
|
||||
description: markdownToPlaintext(await qualifyLocalURLsInMarkdown(data.description, data.lang, site)).replaceAll(
|
||||
/[\n ]+/g,
|
||||
" ",
|
||||
),
|
||||
categories: ["blog post"],
|
||||
commentsUrl: data.posts.mastodon?.link,
|
||||
content: sanitizeHtml(
|
||||
`<h1>${data.title}</h1>` +
|
||||
`<p>${t(
|
||||
data.lang,
|
||||
"story/authors",
|
||||
(await getEntries(data.authors)).map((author) => getLinkForUser(author, data.lang)),
|
||||
)}</p>` +
|
||||
`<hr>${await markdown(await qualifyLocalURLsInMarkdown(data.description, data.lang, site))}` +
|
||||
`<hr>${await markdown(body)}`,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
export const GET: APIRoute = async ({ site }) => {
|
||||
const stories = (
|
||||
(await getCollection(
|
||||
|
|
@ -120,6 +149,11 @@ export const GET: APIRoute = async ({ site }) => {
|
|||
)
|
||||
.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime())
|
||||
.slice(0, MAX_ITEMS);
|
||||
const posts = (
|
||||
(await getCollection("blog", (post) => !post.data.isDraft && post.data.pubDate)) as EntryWithPubDate<"blog">[]
|
||||
)
|
||||
.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime())
|
||||
.slice(0, MAX_ITEMS);
|
||||
|
||||
return rss({
|
||||
title: "Gallery | Bad Manners",
|
||||
|
|
@ -135,6 +169,10 @@ export const GET: APIRoute = async ({ site }) => {
|
|||
date: data.pubDate,
|
||||
fn: () => gameFeedItem(site, data, slug, body),
|
||||
})),
|
||||
posts.map(({ data, slug, body }) => ({
|
||||
date: data.pubDate,
|
||||
fn: () => blogFeedItem(site, data, slug, body),
|
||||
})),
|
||||
]
|
||||
.flat()
|
||||
.sort((a, b) => b.date.getTime() - a.date.getTime())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue