diff --git a/bun.lockb b/bun.lockb index 6bda38a..37c5f71 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 43a8072..e31a398 100644 --- a/package.json +++ b/package.json @@ -34,11 +34,13 @@ "remark-github-beta-blockquote-admonitions": "^2.2.1", "remark-math": "^5.1.1", "remark-parse": "^10.0.2", + "sanitize-html": "^2.13.1", "sharp": "^0.33.4" }, "devDependencies": { "@biomejs/biome": "^1.8.2", "@types/lodash-es": "^4.17.12", + "@types/sanitize-html": "^2.13.0", "date-fns": "^2.30.0", "hast-util-from-html": "^2.0.1", "hast-util-to-html": "^9.0.1", diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts index eb384ce..0bcdc89 100644 --- a/src/pages/rss.xml.ts +++ b/src/pages/rss.xml.ts @@ -1,18 +1,41 @@ import rss from "@astrojs/rss"; -import { getCollection } from "astro:content"; +import sanitizeHtml from "sanitize-html"; import { SITE_TITLE, SITE_DESCRIPTION } from "../consts"; +const BLACKLIST = ["../content/posts/_index.md"]; + export async function GET(context) { - const posts = await getCollection("posts"); + // const posts = Array.from(await getCollection("posts")); + const posts = Object.entries( + import.meta.glob("../content/posts/**/*.{md,mdx}", { + eager: true, + }), + ) + .filter( + ([file, post]) => + !BLACKLIST.includes(file) && post.frontmatter.draft !== true, + ) + .toSorted(([fileA, a], [fileB, b]) => { + return new Date(b.frontmatter.date) - new Date(a.frontmatter.date); + }) + .slice(0, 30) + .map(([file, post]) => { + console.log("post", { file, post }); + return { + title: post.frontmatter.title ?? "", + pubDate: new Date(post.frontmatter.date), + link: "/", + content: sanitizeHtml(post.compiledContent?.()), + // link: `/posts/${post.slug}/`, + }; + }); + + console.log("posts", posts); + return rss({ title: SITE_TITLE, description: SITE_DESCRIPTION, site: context.site, - items: posts.map((post) => ({ - title: post.data.title, - pubDate: post.data.date, - // ...post.data, - link: `/${post.slug}/`, - })), + items: posts, }); }