mirror of
https://github.com/danbulant/design
synced 2026-06-19 06:11:28 +00:00
add RSS feed
This commit is contained in:
parent
da6ca6e966
commit
1806f7ffca
4 changed files with 55 additions and 3 deletions
|
|
@ -1,5 +1,3 @@
|
|||
import { DateTime } from "luxon";
|
||||
|
||||
/**
|
||||
* @type {import("@sveltejs/kit").RequestHandler}
|
||||
*/
|
||||
|
|
@ -13,7 +11,6 @@ export async function get(req) {
|
|||
if(postPath.endsWith('/index')) postPath = postPath.slice(0, -6);
|
||||
return {
|
||||
...metadata,
|
||||
relDate: DateTime.fromISO(metadata.date).toRelativeCalendar(),
|
||||
path: postPath,
|
||||
};
|
||||
})
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
<svelte:head>
|
||||
<title>Daniel Bulant - Homepage</title>
|
||||
<link href="/posts/rss.xml" type="application/rss+xml" rel="alternate" title="Blog posts - RSS" />
|
||||
<meta property="og:title" content="Daniel Bulant - Homepage"/>
|
||||
<meta name="description" content="Homepage of danbulant.eu - List of my projects, contact info.">
|
||||
<meta name="og:description" content="Homepage of danbulant.eu - List of my projects, contact info.">
|
||||
|
|
|
|||
|
|
@ -22,7 +22,15 @@
|
|||
|
||||
<svelte:head>
|
||||
<title>Blog - Daniel Bulant</title>
|
||||
<link href="/posts/rss.xml" type="application/rss+xml" rel="alternate" title="Blog posts - RSS" />
|
||||
<meta name="description" content="My personal blog about work, programming and fun stuff.">
|
||||
<meta property="og:site_name" content="Daniel Bulant"/>
|
||||
<meta property="og:locale" content="en_US" />
|
||||
<meta property="og:type" content="profile" />
|
||||
<meta property="og:profile:first_name" content="Daniel" />
|
||||
<meta property="og:profile:last_name" content="Bulant" />
|
||||
<meta property="og:profile:username" content="danbulant" />
|
||||
<meta property="og:profile:gender" content="male" />
|
||||
</svelte:head>
|
||||
|
||||
<div class="posts" class:dark={$darkmode}>
|
||||
|
|
|
|||
46
src/routes/posts/rss.xml.js
Normal file
46
src/routes/posts/rss.xml.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* @type {import("@sveltejs/kit").RequestHandler}
|
||||
*/
|
||||
export async function get(req) {
|
||||
const allPostFiles = import.meta.glob('../posts/**/*.md');
|
||||
|
||||
const allPosts = await Promise.all(
|
||||
Object.entries(allPostFiles).map(async ([path, resolver]) => {
|
||||
const { metadata } = await resolver();
|
||||
let postPath = path.slice(2, -3);
|
||||
if(postPath.endsWith('/index')) postPath = postPath.slice(0, -6);
|
||||
return {
|
||||
...metadata,
|
||||
path: postPath,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
allPosts.sort((a, b) => {
|
||||
return new Date(b.date) - new Date(a.date)
|
||||
});
|
||||
|
||||
return {
|
||||
body: `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>Blog - Daniel Bulant</title>
|
||||
<description>My personal blog about work, programming and fun stuff.</description>
|
||||
<link>https://danbulant.eu/posts</link>
|
||||
<copyright>2022 Daniel Bulant</copyright>
|
||||
<pubDate>${new Date().toUTCString()}</pubDate>
|
||||
<ttl>180</ttl>
|
||||
|
||||
${allPosts.map(t => `
|
||||
<item>
|
||||
<title>${t.title}</title>
|
||||
<description>${t.description}</description>
|
||||
<link>https://danbulant.eu${t.path}</link>
|
||||
<pubDate>${new Date(t.date).toUTCString()}</pubDate>
|
||||
<guid>${t.path}</guid>
|
||||
</item>`).join("\n")}
|
||||
|
||||
</channel>
|
||||
</rss>`
|
||||
};
|
||||
}
|
||||
Loading…
Reference in a new issue