From dae681d2c2121703b1b9a9f930248315574a5ca3 Mon Sep 17 00:00:00 2001 From: Silas Date: Thu, 13 Jun 2024 15:26:29 -0400 Subject: [PATCH] add rss feeds (/rss, /poetry/rss, and /thoughts/rss) --- src/lib/utils/index.ts | 1 - src/routes/(app)/poetry/+page.svelte | 28 +++++++-------- src/routes/(app)/poetry/rss/+server.ts | 43 ++++++++++++++++++++++++ src/routes/(app)/rss/+server.ts | 43 ++++++++++++++++++++++++ src/routes/(app)/thoughts/rss/+server.ts | 43 ++++++++++++++++++++++++ 5 files changed, 142 insertions(+), 16 deletions(-) create mode 100644 src/routes/(app)/poetry/rss/+server.ts create mode 100644 src/routes/(app)/rss/+server.ts create mode 100644 src/routes/(app)/thoughts/rss/+server.ts diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 8275569..ff0efcb 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -8,7 +8,6 @@ export interface Metadata { export interface Section { poetry: 'poetry'; thoughts: 'thoughts'; - services: 'services'; all: 'all'; } diff --git a/src/routes/(app)/poetry/+page.svelte b/src/routes/(app)/poetry/+page.svelte index 6dc8d16..d8e616b 100644 --- a/src/routes/(app)/poetry/+page.svelte +++ b/src/routes/(app)/poetry/+page.svelte @@ -70,20 +70,18 @@ {/each} - {#if total > 1} - - {/if} + {/if} diff --git a/src/routes/(app)/poetry/rss/+server.ts b/src/routes/(app)/poetry/rss/+server.ts new file mode 100644 index 0000000..8977ae5 --- /dev/null +++ b/src/routes/(app)/poetry/rss/+server.ts @@ -0,0 +1,43 @@ +import { fetchMarkdownPosts, type Post } from '$lib/utils'; + +const siteURL = 'https://silentsilas.com'; +const siteTitle = 'silentsilas - Poetry'; +const siteDescription = 'Read some bad poetry.'; + +export const prerender = true; + +export const GET = async () => { + const { posts } = await fetchMarkdownPosts('poetry'); + + const body = render(posts); + const options = { + headers: { + 'Cache-Control': 'max-age=0, s-maxage=3600', + 'Content-Type': 'application/xml' + } + }; + + return new Response(body, options); +}; + +const render = (posts: Post[]) => ` + + +${siteTitle} +${siteDescription} +${siteURL} + +${posts + .map( + (post) => ` +${siteURL}/${post.section}/${post.filename} +${post.meta.title} +${siteURL}/${post.section}/${post.filename} +${post.meta.title} +${new Date(post.meta.date).toUTCString()} +` + ) + .join('')} + + +`; diff --git a/src/routes/(app)/rss/+server.ts b/src/routes/(app)/rss/+server.ts new file mode 100644 index 0000000..d924bf4 --- /dev/null +++ b/src/routes/(app)/rss/+server.ts @@ -0,0 +1,43 @@ +import { fetchMarkdownPosts, type Post } from '$lib/utils'; + +const siteURL = 'https://silentsilas.com'; +const siteTitle = 'silentsilas - Thoughts & Poems'; +const siteDescription = 'Read some bad takes and poetry.'; + +export const prerender = true; + +export const GET = async () => { + const { posts } = await fetchMarkdownPosts('all'); + + const body = render(posts); + const options = { + headers: { + 'Cache-Control': 'max-age=0, s-maxage=3600', + 'Content-Type': 'application/xml' + } + }; + + return new Response(body, options); +}; + +const render = (posts: Post[]) => ` + + +${siteTitle} +${siteDescription} +${siteURL} + +${posts + .map( + (post) => ` +${siteURL}/${post.section}/${post.filename} +${post.meta.title} +${siteURL}/${post.section}/${post.filename} +${post.meta.title} +${new Date(post.meta.date).toUTCString()} +` + ) + .join('')} + + +`; diff --git a/src/routes/(app)/thoughts/rss/+server.ts b/src/routes/(app)/thoughts/rss/+server.ts new file mode 100644 index 0000000..2b6ed62 --- /dev/null +++ b/src/routes/(app)/thoughts/rss/+server.ts @@ -0,0 +1,43 @@ +import { fetchMarkdownPosts, type Post } from '$lib/utils'; + +const siteURL = 'https://silentsilas.com'; +const siteTitle = 'silentsilas - Thoughts'; +const siteDescription = 'Read some bad takes.'; + +export const prerender = true; + +export const GET = async () => { + const { posts } = await fetchMarkdownPosts('thoughts'); + + const body = render(posts); + const options = { + headers: { + 'Cache-Control': 'max-age=0, s-maxage=3600', + 'Content-Type': 'application/xml' + } + }; + + return new Response(body, options); +}; + +const render = (posts: Post[]) => ` + + +${siteTitle} +${siteDescription} +${siteURL} + +${posts + .map( + (post) => ` +${siteURL}/${post.section}/${post.filename} +${post.meta.title} +${siteURL}/${post.section}/${post.filename} +${post.meta.title} +${new Date(post.meta.date).toUTCString()} +` + ) + .join('')} + + +`;