diff options
feat: an RSS
Diffstat (limited to 'src/routes/blog')
| -rw-r--r-- | src/routes/blog/+page.svelte | 26 | ||||
| -rw-r--r-- | src/routes/blog/feed.xml/+server.ts | 41 | ||||
| -rw-r--r-- | src/routes/blog/posts/LICENSE | 2 |
3 files changed, 68 insertions, 1 deletions
diff --git a/src/routes/blog/+page.svelte b/src/routes/blog/+page.svelte index fb4592a..bd6e806 100644 --- a/src/routes/blog/+page.svelte +++ b/src/routes/blog/+page.svelte @@ -59,15 +59,39 @@ </div> </div> {/each} + <div class="flex gap-2"> + <div class="flex flex-col items-end"> + <span class="h-0 opacity-0 select-none">short</span> + <a href={resolve('/blog/feed.xml')} class="quicklink">rss</a> + </div> + <div class="flex flex-col"> + <table> + <tbody> + <tr> + <td + >content under cc-by-nc-sa 4.0 international unless + otherwise noted.</td + > + </tr> + </tbody> + </table> + </div> + </div> </div> {:else} <h2 class="font-space-grotesk text-5xl mt-8 mb-4"> <span class="text-accent-primary select-none">zsh: </span>no matches found<span class="text-accent-primary select-none">.</span> </h2> - <p class="mt-1.5"> + <p class="my-1.5"> Feel free to check back once some posts are published. </p> + <p class="my-1.5"> + Want posts to show up on an RSS reader once they exist? Here's a <a + href={resolve('/blog/feed.xml')} + class="quicklink">feed.xml</a + >. + </p> {/if} </div> </div> diff --git a/src/routes/blog/feed.xml/+server.ts b/src/routes/blog/feed.xml/+server.ts new file mode 100644 index 0000000..a2a80f5 --- /dev/null +++ b/src/routes/blog/feed.xml/+server.ts @@ -0,0 +1,41 @@ +import { RSS_ROOT } from '$/lib'; +import { RSSChannelElement, RSSItemElement, RSSRootElement } from '$/lib/vendor/rss/rss'; +import { XMLDeclaration, XMLDocumentRoot, XMLElement, XMLRootElement, XMLText } from '$/lib/vendor/rss/xml' +import { dev } from '$app/environment'; +import posts from '../posts'; + +export const GET = async (req) => { + const doc = new XMLDocumentRoot().child( + new XMLDeclaration().version().encoding(), + new RSSRootElement() + .channel( + new RSSChannelElement( + 'Latest blog posts for 7222e800', + 'Some Fancy Description Here', + RSS_ROOT + ) + .pubDate(new Date('2026-01-14T15:53:57Z') /* When the last item was published */) + .lastBuildDate(new Date() /* When this file was last updated - usually when your build process last ran */) + .language('en') + .child(new XMLElement('nonStandardElement').attribute('non-standard', 'true')) + .generator() + .items( + ...(await Promise.all(Object.values(posts))) + .filter(v => v.metadata.published === true || (dev && req.url.searchParams.has('include-unpublished'))) + .map(({ metadata }) => { + const item = new RSSItemElement(`${metadata.published === true ? '' : metadata.published ? '🚧 ' : '🛑 '}${metadata.title}`, metadata.blurb, new URL(`${metadata.id}-${metadata.slug}`, RSS_ROOT)); + if (metadata.author) + item.author(metadata.author); + item.pubDate(new Date(metadata.created)); + item.guid(new URL(`${metadata.id}`, RSS_ROOT).href, true) + return item; + }) + ), + ) + ) + return new Response(doc.toString(), { + headers: { + 'Content-Type': 'application/rss+xml;charset=utf-8' + } + }) +} diff --git a/src/routes/blog/posts/LICENSE b/src/routes/blog/posts/LICENSE new file mode 100644 index 0000000..e349d1c --- /dev/null +++ b/src/routes/blog/posts/LICENSE @@ -0,0 +1,2 @@ +All content in this directory is under the license CC-BY-NC-SA 4.0 International. +This does not apply to the code outside of it, just the mdx data inside of it. |