Mae's website :3 maemoon.me
personal website svelte sveltekit
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

RSS Feed

+100
+45
src/routes/rss/+server.js
··· 1 + import { fetchMarkdownPosts } from '$lib/index'; 2 + 3 + const siteURL = 'https://maemoon.me'; 4 + const siteTitle = 'Mae Moon'; 5 + const siteDescription = 'My personal blog'; 6 + 7 + export const prerender = true; 8 + 9 + export const GET = async () => { 10 + const allPosts = await fetchMarkdownPosts(); 11 + const sortedPosts = allPosts.sort((a, b) => new Date(b.meta.date) - new Date(a.meta.date)); 12 + 13 + const body = render(sortedPosts); 14 + const options = { 15 + headers: { 16 + 'Cache-Control': 'max-age=0, s-maxage=3600', 17 + 'Content-Type': 'application/xml' 18 + } 19 + }; 20 + 21 + return new Response(body, options); 22 + }; 23 + 24 + const render = (posts) => `<?xml version="1.0" encoding="UTF-8" ?> 25 + <?xml-stylesheet type="text/xsl" href="/rss-stylesheet.xsl" ?> 26 + <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 27 + <channel> 28 + <title>${siteTitle}</title> 29 + <description>${siteDescription}</description> 30 + <link>${siteURL}</link> 31 + <atom:link href="${siteURL}/rss" rel="self" type="application/rss+xml"/> 32 + ${posts 33 + .map( 34 + (post) => `<item> 35 + <guid isPermaLink="true">${siteURL}/blog/${post.path}</guid> 36 + <title>${post.meta.title}</title> 37 + <link>${siteURL}/blog/${post.path}</link> 38 + <description>${post.meta.title}</description> 39 + <pubDate>${new Date(post.meta.date).toUTCString()}</pubDate> 40 + </item>` 41 + ) 42 + .join('')} 43 + </channel> 44 + </rss> 45 + `;
+55
static/rss-stylesheet.xsl
··· 1 + <?xml version="1.0" encoding="UTF-8"?> 2 + <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 3 + <xsl:template match="/"> 4 + <html> 5 + <head> 6 + <title>RSS Feed</title> 7 + <style> 8 + body { 9 + font-family: 'Inter', Arial, sans-serif; 10 + background-color: #ECEFF4; 11 + color: #2E3440; 12 + } 13 + h1 { 14 + font-size: 1.4em; 15 + } 16 + ul { 17 + list-style-type: none; 18 + padding: 0; 19 + } 20 + li { 21 + padding: 10px 0; 22 + border-bottom: 1px solid #ddd; 23 + } 24 + a { 25 + text-decoration: none; 26 + color: #3B4252; 27 + font-weight: bold; 28 + } 29 + a:hover { 30 + text-decoration: underline; 31 + } 32 + .date { 33 + font-size: 0.9em; 34 + color: #434C5E; 35 + } 36 + </style> 37 + </head> 38 + <body> 39 + <h1>Mae Moon ~ RSS Feed</h1> 40 + <ul> 41 + <xsl:for-each select="rss/channel/item"> 42 + <li> 43 + <a href="{link}"> 44 + <xsl:value-of select="title"/> 45 + </a> 46 + <div class="date"> 47 + <xsl:value-of select="pubDate"/> 48 + </div> 49 + </li> 50 + </xsl:for-each> 51 + </ul> 52 + </body> 53 + </html> 54 + </xsl:template> 55 + </xsl:stylesheet>