|
|
|
@ -1,4 +1,4 @@
|
|
|
|
import { get_blog_data, get_blog_list } from '$lib/server/blog/index.js';
|
|
|
|
import { get_blog_data, get_rss_contents } from '$lib/server/blog/index.js';
|
|
|
|
|
|
|
|
|
|
|
|
export const prerender = true;
|
|
|
|
export const prerender = true;
|
|
|
|
|
|
|
|
|
|
|
|
@ -18,11 +18,13 @@ function escapeHTML(html) {
|
|
|
|
'>': 'gt'
|
|
|
|
'>': 'gt'
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return html.replace(/["'&<>]/g, (c) => `&${chars[c]};`);
|
|
|
|
return html
|
|
|
|
|
|
|
|
.replace(/<a[^>]*class="permalink"[^>]*>.*?<\/a>/gi, '') // remove anchor permalinks
|
|
|
|
|
|
|
|
.replace(/["'&<>]/g, (c) => `&${chars[c]};`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @param {import('$lib/server/blog/types').BlogPostSummary[]} posts */
|
|
|
|
/** @param {import('$lib/server/blog/types').BlogPostRSS[]} posts */
|
|
|
|
const get_rss = (posts) =>
|
|
|
|
const get_rss = (posts) =>
|
|
|
|
`
|
|
|
|
`
|
|
|
|
<?xml version="1.0" encoding="UTF-8" ?>
|
|
|
|
<?xml version="1.0" encoding="UTF-8" ?>
|
|
|
|
<rss version="2.0">
|
|
|
|
<rss version="2.0">
|
|
|
|
@ -43,6 +45,7 @@ const get_rss = (posts) =>
|
|
|
|
<item>
|
|
|
|
<item>
|
|
|
|
<title>${escapeHTML(post.title)}</title>
|
|
|
|
<title>${escapeHTML(post.title)}</title>
|
|
|
|
<link>https://svelte.dev/blog/${post.slug}</link>
|
|
|
|
<link>https://svelte.dev/blog/${post.slug}</link>
|
|
|
|
|
|
|
|
<author>${escapeHTML(post.author.name)}</author>
|
|
|
|
<description>${escapeHTML(post.content)}</description>
|
|
|
|
<description>${escapeHTML(post.content)}</description>
|
|
|
|
<pubDate>${formatPubdate(post.date)}</pubDate>
|
|
|
|
<pubDate>${formatPubdate(post.date)}</pubDate>
|
|
|
|
</item>
|
|
|
|
</item>
|
|
|
|
@ -58,7 +61,8 @@ const get_rss = (posts) =>
|
|
|
|
.trim();
|
|
|
|
.trim();
|
|
|
|
|
|
|
|
|
|
|
|
export async function GET() {
|
|
|
|
export async function GET() {
|
|
|
|
const posts = get_blog_list(await get_blog_data());
|
|
|
|
const blogData = await get_blog_data();
|
|
|
|
|
|
|
|
const posts = await get_rss_contents(blogData);
|
|
|
|
|
|
|
|
|
|
|
|
return new Response(get_rss(posts), {
|
|
|
|
return new Response(get_rss(posts), {
|
|
|
|
headers: {
|
|
|
|
headers: {
|
|
|
|
|