added xml feed for blogs
This commit is contained in:
38
src/routes/blog/feed.xml/+server.ts
Normal file
38
src/routes/blog/feed.xml/+server.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
export const prerender = true;
|
||||||
|
import { posts, type BlogPostDetails } from "../posts";
|
||||||
|
|
||||||
|
const xml = (tposts: Map<string, BlogPostDetails>) => `<rss version="2.0">
|
||||||
|
<channel>
|
||||||
|
<title>denizk0461's Blog</title>
|
||||||
|
<link>https://denizk0461.dev/blog/</link>
|
||||||
|
<description><![CDATA[denizk0461 blogs about stuff here]]></description>
|
||||||
|
${getEntries()}
|
||||||
|
</channel>
|
||||||
|
</rss>`;
|
||||||
|
|
||||||
|
function getEntries(): String {
|
||||||
|
var val = "";
|
||||||
|
var entries = posts.entries().map((post, index) =>
|
||||||
|
`<item>
|
||||||
|
<title><![CDATA[${post[1].title}]]></title>
|
||||||
|
<description><![CDATA[${post[1].description}]]></description>
|
||||||
|
<link>https://denizk0461.dev/blog/${post[0]}</link>
|
||||||
|
<guid isPermaLink="true">https://denizk0461.dev/blog/${post[0]}</guid>
|
||||||
|
<pubDate><![CDATA[${new Date(`${post[1].date}T${post[1].time}`).toUTCString()}]]></pubDate>
|
||||||
|
</item>
|
||||||
|
`)
|
||||||
|
entries.forEach(entry => {
|
||||||
|
val += entry;
|
||||||
|
})
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||||
|
export async function GET() {
|
||||||
|
const headers = {
|
||||||
|
'Cache-Control': 'max-age=0, s-maxage=600',
|
||||||
|
'Content-Type': 'application/xml',
|
||||||
|
};
|
||||||
|
const body = xml(posts);
|
||||||
|
return new Response(body);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user