This commit is contained in:
parent
c2510fea83
commit
8f8e2bb4bd
3 changed files with 33 additions and 8 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
@ -34,11 +34,13 @@
|
||||||
"remark-github-beta-blockquote-admonitions": "^2.2.1",
|
"remark-github-beta-blockquote-admonitions": "^2.2.1",
|
||||||
"remark-math": "^5.1.1",
|
"remark-math": "^5.1.1",
|
||||||
"remark-parse": "^10.0.2",
|
"remark-parse": "^10.0.2",
|
||||||
|
"sanitize-html": "^2.13.1",
|
||||||
"sharp": "^0.33.4"
|
"sharp": "^0.33.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "^1.8.2",
|
"@biomejs/biome": "^1.8.2",
|
||||||
"@types/lodash-es": "^4.17.12",
|
"@types/lodash-es": "^4.17.12",
|
||||||
|
"@types/sanitize-html": "^2.13.0",
|
||||||
"date-fns": "^2.30.0",
|
"date-fns": "^2.30.0",
|
||||||
"hast-util-from-html": "^2.0.1",
|
"hast-util-from-html": "^2.0.1",
|
||||||
"hast-util-to-html": "^9.0.1",
|
"hast-util-to-html": "^9.0.1",
|
||||||
|
|
|
@ -1,18 +1,41 @@
|
||||||
import rss from "@astrojs/rss";
|
import rss from "@astrojs/rss";
|
||||||
import { getCollection } from "astro:content";
|
import sanitizeHtml from "sanitize-html";
|
||||||
import { SITE_TITLE, SITE_DESCRIPTION } from "../consts";
|
import { SITE_TITLE, SITE_DESCRIPTION } from "../consts";
|
||||||
|
|
||||||
|
const BLACKLIST = ["../content/posts/_index.md"];
|
||||||
|
|
||||||
export async function GET(context) {
|
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({
|
return rss({
|
||||||
title: SITE_TITLE,
|
title: SITE_TITLE,
|
||||||
description: SITE_DESCRIPTION,
|
description: SITE_DESCRIPTION,
|
||||||
site: context.site,
|
site: context.site,
|
||||||
items: posts.map((post) => ({
|
items: posts,
|
||||||
title: post.data.title,
|
|
||||||
pubDate: post.data.date,
|
|
||||||
// ...post.data,
|
|
||||||
link: `/${post.slug}/`,
|
|
||||||
})),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue