mirror of
https://github.com/thiloho/thiloho.github.io.git
synced 2025-11-22 10:21:36 +01:00
Turn .mjs files into .ts files
This commit is contained in:
36
src/pages/rss.xml.ts
Normal file
36
src/pages/rss.xml.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import rss from "@astrojs/rss";
|
||||
import type { APIContext } from "astro";
|
||||
import { getCollection } from "astro:content";
|
||||
import sanitizeHtml from "sanitize-html";
|
||||
import MarkdownIt from "markdown-it";
|
||||
const parser = new MarkdownIt();
|
||||
|
||||
export const GET = async (context: APIContext) => {
|
||||
const blog = await getCollection("blog");
|
||||
|
||||
const latestModDate = blog.reduce((latest, article) => {
|
||||
const modDate = article.data.modDate || article.data.pubDate;
|
||||
return modDate > latest ? modDate : latest;
|
||||
}, new Date(0));
|
||||
|
||||
return rss({
|
||||
title: "Thilo Hohlt's Blog",
|
||||
description: "Thilo Hohlt's Blog",
|
||||
site: context.url.origin,
|
||||
trailingSlash: false,
|
||||
xmlns: {
|
||||
atom: "http://www.w3.org/2005/Atom",
|
||||
},
|
||||
customData: `
|
||||
<lastBuildDate>${latestModDate.toUTCString()}</lastBuildDate>
|
||||
<atom:link href="${context.url.origin}/rss.xml" rel="self" type="application/rss+xml" />
|
||||
`,
|
||||
items: blog.map((article) => ({
|
||||
link: `/blog/${article.id}/`,
|
||||
content: sanitizeHtml(parser.render(article.body ?? ""), {
|
||||
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
|
||||
}),
|
||||
...article.data,
|
||||
})),
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user