From cfb3baa79deb45c8f56e58e43261bfdcd83e3c3f Mon Sep 17 00:00:00 2001 From: dusk Date: Thu, 19 Sep 2024 15:46:31 +0300 Subject: [PATCH] feat: add rss feed --- src/routes/entries/+layout.ts | 37 +++++++++++++++++++++++++++++- src/routes/entries/+page.svelte | 2 +- src/routes/entries/+page.ts | 34 --------------------------- src/routes/entries/_rss/+server.ts | 31 +++++++++++++++++++++++++ tsconfig.json | 3 ++- 5 files changed, 70 insertions(+), 37 deletions(-) delete mode 100644 src/routes/entries/+page.ts create mode 100644 src/routes/entries/_rss/+server.ts diff --git a/src/routes/entries/+layout.ts b/src/routes/entries/+layout.ts index c8cacf0..9c3b7c5 100644 --- a/src/routes/entries/+layout.ts +++ b/src/routes/entries/+layout.ts @@ -1 +1,36 @@ -export const prerender = true; \ No newline at end of file +import convertDate from "$lib/convertDate"; + +export const prerender = true; + +export interface PostData { + path: string, + published: string, + metadata: Record, +} + +const allPostFiles: Record = import.meta.glob('./*/+page.md', { eager: true }); +const allPosts: PostData[] = Object.entries(allPostFiles).map(([path, post]) => { + const postPath = path.slice(2, -8); + return { + metadata: post.metadata, + path: postPath, + published: convertDate(post.metadata.date) + }; +}).map((post) => { + if (!("excerpt" in post.metadata)) { + post.metadata.excerpt = "" + } + return post; +}).toSorted((post, opost) => { + const date = new Date(post.metadata.date); + const odate = new Date(opost.metadata.date); + return odate.getTime() - date.getTime() +}); +export const _allPosts = allPosts; + +export async function load({}) { + if (!allPosts.length) { + return { status: 404 }; + } + return { posts: allPosts }; +} \ No newline at end of file diff --git a/src/routes/entries/+page.svelte b/src/routes/entries/+page.svelte index e1f293c..1677250 100644 --- a/src/routes/entries/+page.svelte +++ b/src/routes/entries/+page.svelte @@ -1,6 +1,6 @@