feat: enable notes rss
Before Width: | Height: | Size: 210 KiB |
Before Width: | Height: | Size: 112 KiB |
Before Width: | Height: | Size: 458 KiB |
Before Width: | Height: | Size: 1.1 MiB |
Before Width: | Height: | Size: 120 KiB |
Before Width: | Height: | Size: 76 KiB |
Before Width: | Height: | Size: 4.1 MiB |
Before Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 1.9 MiB |
Before Width: | Height: | Size: 219 KiB |
Before Width: | Height: | Size: 2.2 MiB |
@ -1,18 +1,44 @@
|
|||||||
import { getCollection } from "astro:content";
|
|
||||||
import { siteConfig } from "@/site.config";
|
import { siteConfig } from "@/site.config";
|
||||||
|
import { collectionDateSort } from "@/utils/date";
|
||||||
import rss from "@astrojs/rss";
|
import rss from "@astrojs/rss";
|
||||||
|
import { getCollection } from "astro:content";
|
||||||
|
import MarkdownIt from "markdown-it";
|
||||||
|
import sanitizeHtml from "sanitize-html";
|
||||||
|
|
||||||
export const GET = async () => {
|
export const GET = async () => {
|
||||||
const notes = await getCollection("note");
|
const notes = await getCollection("note");
|
||||||
|
const sortedNotes = notes.sort(collectionDateSort);
|
||||||
|
const parser = new MarkdownIt();
|
||||||
|
|
||||||
return rss({
|
return rss({
|
||||||
|
customData: `<follow_challenge>
|
||||||
|
<feedId>75113012474671104</feedId>
|
||||||
|
<userId>62156866798228480</userId>
|
||||||
|
</follow_challenge>`,
|
||||||
title: siteConfig.title,
|
title: siteConfig.title,
|
||||||
description: siteConfig.description,
|
description: siteConfig.description,
|
||||||
site: import.meta.env.SITE,
|
site: import.meta.env.SITE,
|
||||||
items: notes.map((note) => ({
|
items: sortedNotes.map((post) => {
|
||||||
title: note.data.title,
|
return {
|
||||||
pubDate: note.data.date,
|
title: post.data.title,
|
||||||
link: `notes/${note.id}/`,
|
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,
|
||||||
|
};
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|