mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-12 07:12:52 +01:00
feat: add RSS xml (#34)
* feat: add RSS xml --------- Co-authored-by: saicaca <zephyird@gmail.com>
This commit is contained in:
@@ -7,7 +7,7 @@ import ImageWrapper from "@components/misc/ImageWrapper.astro";
|
||||
|
||||
import {pathsEqual} from "@utils/url-utils";
|
||||
import ConfigCarrier from "@components/ConfigCarrier.astro";
|
||||
import {siteConfig} from "@/config";
|
||||
import {profileConfig, siteConfig} from "@/config";
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
@@ -84,6 +84,8 @@ if (title) {
|
||||
|
||||
<link rel="stylesheet" href="https://cdn.staticfile.org/KaTeX/0.16.9/katex.min.css" integrity="sha384-n8MVd4RsNIU0tAv4ct0nTaAbDJwPJzDEaqSD1odI+WdtXRGWt2kTvGFasHpSy3SV" crossorigin="anonymous">
|
||||
|
||||
<link rel="alternate" type="application/rss+xml" title={profileConfig.name} href={`${Astro.site}rss.xml`}/>
|
||||
|
||||
<style define:vars={{ configHue }}></style> <!-- defines global css variables. This will be applied to <html> <body> and some other elements idk why -->
|
||||
|
||||
</head>
|
||||
|
||||
25
src/pages/rss.xml.ts
Normal file
25
src/pages/rss.xml.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import rss from '@astrojs/rss';
|
||||
import {siteConfig} from '@/config';
|
||||
import { getCollection } from 'astro:content';
|
||||
import sanitizeHtml from 'sanitize-html';
|
||||
import MarkdownIt from 'markdown-it';
|
||||
const parser = new MarkdownIt();
|
||||
|
||||
export async function GET(context: any) {
|
||||
const blog = await getCollection('posts');
|
||||
return rss({
|
||||
title: siteConfig.title,
|
||||
description: siteConfig.subtitle || 'No description',
|
||||
site: context.site,
|
||||
items: blog.map((post) => ({
|
||||
title: post.data.title,
|
||||
pubDate: post.data.published,
|
||||
description: post.data.description,
|
||||
link: `/posts/${post.slug}/`,
|
||||
content: sanitizeHtml(parser.render(post.body), {
|
||||
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img'])
|
||||
}),
|
||||
})),
|
||||
customData: `<language>${siteConfig.lang}</language>`,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user