Первый блог + простой генератор RSS-фида (работает в Thunderbird)
This commit is contained in:
parent
6a60ce55e5
commit
8e09b8f0d9
4 changed files with 72 additions and 0 deletions
32
src/routes/blog/rss.xml/+server.ts
Normal file
32
src/routes/blog/rss.xml/+server.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { fetchPostsSorted } from "$src/lib/util/Blogs";
|
||||
|
||||
function escapeXml(unsafe: string): string {
|
||||
return unsafe
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
export async function GET({ setHeaders }) {
|
||||
setHeaders({
|
||||
'Cache-Control': 'max-age=0, s-maxage=3600',
|
||||
'Content-Type': 'application/rss+xml',
|
||||
});
|
||||
const posts = await fetchPostsSorted();
|
||||
return new Response(String(`<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:atom="https://www.w3.org/2005/Atom" version="2.0">
|
||||
<channel>
|
||||
<title>Блог Tea Sanctuary</title>
|
||||
<link>https://teasanctuary.ru/blog</link>
|
||||
<ttl>1800</ttl>
|
||||
${posts.map((post) => `<item>
|
||||
<title>${escapeXml(post.title)}</title>
|
||||
<description>${escapeXml(post.description)}</description>
|
||||
<link>https://teasanctuary.ru/blog/${post.slug}</link>
|
||||
<pubDate>${(new Date(post.date)).toUTCString()}</pubDate>
|
||||
</item>`).join("\n")}
|
||||
</channel>
|
||||
</rss>`))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue