From 1806f7ffca3555942338fc7b1f957a36ed1b39dd Mon Sep 17 00:00:00 2001 From: Daniel Bulant Date: Sun, 10 Apr 2022 21:23:52 +0200 Subject: [PATCH] add RSS feed --- src/routes/api/posts.json.js | 3 --- src/routes/index.svelte | 1 + src/routes/posts/index.svelte | 8 ++++++ src/routes/posts/rss.xml.js | 46 +++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/routes/posts/rss.xml.js diff --git a/src/routes/api/posts.json.js b/src/routes/api/posts.json.js index 1fb1808..1b50027 100644 --- a/src/routes/api/posts.json.js +++ b/src/routes/api/posts.json.js @@ -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, }; }) diff --git a/src/routes/index.svelte b/src/routes/index.svelte index 4ae51a0..457e4c5 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -33,6 +33,7 @@ Daniel Bulant - Homepage + diff --git a/src/routes/posts/index.svelte b/src/routes/posts/index.svelte index 3dd1641..cc1b8e3 100644 --- a/src/routes/posts/index.svelte +++ b/src/routes/posts/index.svelte @@ -22,7 +22,15 @@ Blog - Daniel Bulant + + + + + + + +
diff --git a/src/routes/posts/rss.xml.js b/src/routes/posts/rss.xml.js new file mode 100644 index 0000000..c27796c --- /dev/null +++ b/src/routes/posts/rss.xml.js @@ -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: ` + + + Blog - Daniel Bulant + My personal blog about work, programming and fun stuff. + https://danbulant.eu/posts + 2022 Daniel Bulant + ${new Date().toUTCString()} + 180 + + ${allPosts.map(t => ` + + ${t.title} + ${t.description} + https://danbulant.eu${t.path} + ${new Date(t.date).toUTCString()} + ${t.path} + `).join("\n")} + + +` + }; +} \ No newline at end of file