mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-12 15:22:52 +01:00
fix: fixing rss by cleaning invalid characters (#492)
Some checks failed
Code quality / quality (push) Failing after 4s
Build and Check / Astro Check for Node.js 22 (push) Failing after 5s
Build and Check / Astro Check for Node.js 23 (push) Failing after 4s
Build and Check / Astro Build for Node.js 22 (push) Failing after 4s
Build and Check / Astro Build for Node.js 23 (push) Failing after 4s
Some checks failed
Code quality / quality (push) Failing after 4s
Build and Check / Astro Check for Node.js 22 (push) Failing after 5s
Build and Check / Astro Check for Node.js 23 (push) Failing after 4s
Build and Check / Astro Build for Node.js 22 (push) Failing after 4s
Build and Check / Astro Build for Node.js 23 (push) Failing after 4s
* fix: fixing rss by cleaning invalid characters * style: format code for consistency in rss.xml.ts --------- Co-authored-by: L4Ph <4ranci0ne@gmail.com>
This commit is contained in:
@@ -7,6 +7,14 @@ import sanitizeHtml from "sanitize-html";
|
|||||||
|
|
||||||
const parser = new MarkdownIt();
|
const parser = new MarkdownIt();
|
||||||
|
|
||||||
|
function stripInvalidXmlChars(str: string): string {
|
||||||
|
return str.replace(
|
||||||
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: https://www.w3.org/TR/xml/#charsets
|
||||||
|
/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F\uFDD0-\uFDEF\uFFFE\uFFFF]/g,
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export async function GET(context: APIContext) {
|
export async function GET(context: APIContext) {
|
||||||
const blog = await getSortedPosts();
|
const blog = await getSortedPosts();
|
||||||
|
|
||||||
@@ -17,13 +25,13 @@ export async function GET(context: APIContext) {
|
|||||||
items: blog.map((post) => {
|
items: blog.map((post) => {
|
||||||
const content =
|
const content =
|
||||||
typeof post.body === "string" ? post.body : String(post.body || "");
|
typeof post.body === "string" ? post.body : String(post.body || "");
|
||||||
|
const cleanedContent = stripInvalidXmlChars(content);
|
||||||
return {
|
return {
|
||||||
title: post.data.title,
|
title: post.data.title,
|
||||||
pubDate: post.data.published,
|
pubDate: post.data.published,
|
||||||
description: post.data.description || "",
|
description: post.data.description || "",
|
||||||
link: `/posts/${post.slug}/`,
|
link: `/posts/${post.slug}/`,
|
||||||
content: sanitizeHtml(parser.render(content), {
|
content: sanitizeHtml(parser.render(cleanedContent), {
|
||||||
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
|
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user