feat: enable notes rss

This commit is contained in:
KazooTTT
2025-02-20 01:32:27 +08:00
parent dd87317456
commit a2bef5b7ad
12 changed files with 32 additions and 6 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 210 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 458 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 219 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 MiB

View File

@ -1,18 +1,44 @@
import { getCollection } from "astro:content";
import { siteConfig } from "@/site.config";
import { collectionDateSort } from "@/utils/date";
import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
import MarkdownIt from "markdown-it";
import sanitizeHtml from "sanitize-html";
export const GET = async () => {
const notes = await getCollection("note");
const sortedNotes = notes.sort(collectionDateSort);
const parser = new MarkdownIt();
return rss({
customData: `<follow_challenge>
<feedId>75113012474671104</feedId>
<userId>62156866798228480</userId>
</follow_challenge>`,
title: siteConfig.title,
description: siteConfig.description,
site: import.meta.env.SITE,
items: notes.map((note) => ({
title: note.data.title,
pubDate: note.data.date,
link: `notes/${note.id}/`,
})),
items: sortedNotes.map((post) => {
return {
title: post.data.title,
description: post.data.description ?? "",
pubDate: post.data.date,
link: `notes/${post.id}/`,
content: post.body
? sanitizeHtml(
parser
.render(post.body)
.replace(/<img\s+src="\/images\//g, `<img src="${import.meta.env.SITE}images/`),
{
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
textFilter: function (text: string) {
return text.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F\uFFF0-\uFFFF]/g, "");
},
},
)
: "",
author: siteConfig.author,
};
}),
});
};