Turn .mjs files into .ts files

This commit is contained in:
thiloho
2025-04-27 00:09:52 +02:00
parent 89e5dbf5ec
commit 04b1282f12
4 changed files with 44 additions and 4 deletions

37
package-lock.json generated
View File

@@ -17,6 +17,8 @@
}, },
"devDependencies": { "devDependencies": {
"@tailwindcss/typography": "0.5.16", "@tailwindcss/typography": "0.5.16",
"@types/markdown-it": "^14.1.2",
"@types/sanitize-html": "^2.15.0",
"prettier": "3.5.3", "prettier": "3.5.3",
"prettier-plugin-astro": "0.14.1" "prettier-plugin-astro": "0.14.1"
} }
@@ -1600,6 +1602,24 @@
"@types/unist": "*" "@types/unist": "*"
} }
}, },
"node_modules/@types/linkify-it": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz",
"integrity": "sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/markdown-it": {
"version": "14.1.2",
"resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-14.1.2.tgz",
"integrity": "sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/linkify-it": "^5",
"@types/mdurl": "^2"
}
},
"node_modules/@types/mdast": { "node_modules/@types/mdast": {
"version": "4.0.4", "version": "4.0.4",
"resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.4.tgz", "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.4.tgz",
@@ -1609,6 +1629,13 @@
"@types/unist": "*" "@types/unist": "*"
} }
}, },
"node_modules/@types/mdurl": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-2.0.0.tgz",
"integrity": "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/ms": { "node_modules/@types/ms": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz", "resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz",
@@ -1635,6 +1662,16 @@
"undici-types": "~6.21.0" "undici-types": "~6.21.0"
} }
}, },
"node_modules/@types/sanitize-html": {
"version": "2.15.0",
"resolved": "https://registry.npmjs.org/@types/sanitize-html/-/sanitize-html-2.15.0.tgz",
"integrity": "sha512-71Z6PbYsVKfp4i6Jvr37s5ql6if1Q/iJQT80NbaSi7uGaG8CqBMXP0pk/EsURAOuGdk5IJCd/vnzKrR7S3Txsw==",
"dev": true,
"license": "MIT",
"dependencies": {
"htmlparser2": "^8.0.0"
}
},
"node_modules/@types/unist": { "node_modules/@types/unist": {
"version": "3.0.3", "version": "3.0.3",
"resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz",

View File

@@ -19,6 +19,8 @@
}, },
"devDependencies": { "devDependencies": {
"@tailwindcss/typography": "0.5.16", "@tailwindcss/typography": "0.5.16",
"@types/markdown-it": "^14.1.2",
"@types/sanitize-html": "^2.15.0",
"prettier": "3.5.3", "prettier": "3.5.3",
"prettier-plugin-astro": "0.14.1" "prettier-plugin-astro": "0.14.1"
} }

View File

@@ -1,10 +1,11 @@
import rss from "@astrojs/rss"; import rss from "@astrojs/rss";
import type { APIContext } from "astro";
import { getCollection } from "astro:content"; import { getCollection } from "astro:content";
import sanitizeHtml from "sanitize-html"; import sanitizeHtml from "sanitize-html";
import MarkdownIt from "markdown-it"; import MarkdownIt from "markdown-it";
const parser = new MarkdownIt(); const parser = new MarkdownIt();
export const GET = async (context) => { export const GET = async (context: APIContext) => {
const blog = await getCollection("blog"); const blog = await getCollection("blog");
const latestModDate = blog.reduce((latest, article) => { const latestModDate = blog.reduce((latest, article) => {
@@ -15,18 +16,18 @@ export const GET = async (context) => {
return rss({ return rss({
title: "Thilo Hohlt's Blog", title: "Thilo Hohlt's Blog",
description: "Thilo Hohlt's Blog", description: "Thilo Hohlt's Blog",
site: context.site, site: context.url.origin,
trailingSlash: false, trailingSlash: false,
xmlns: { xmlns: {
atom: "http://www.w3.org/2005/Atom", atom: "http://www.w3.org/2005/Atom",
}, },
customData: ` customData: `
<lastBuildDate>${latestModDate.toUTCString()}</lastBuildDate> <lastBuildDate>${latestModDate.toUTCString()}</lastBuildDate>
<atom:link href="${context.site}rss.xml" rel="self" type="application/rss+xml" /> <atom:link href="${context.url.origin}/rss.xml" rel="self" type="application/rss+xml" />
`, `,
items: blog.map((article) => ({ items: blog.map((article) => ({
link: `/blog/${article.id}/`, link: `/blog/${article.id}/`,
content: sanitizeHtml(parser.render(article.body), { content: sanitizeHtml(parser.render(article.body ?? ""), {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]), allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
}), }),
...article.data, ...article.data,