-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add RSS feed to the blog * Include rss link in the head for the blog page * Include RSS icon and link in the footer * Fix base url for preview
- Loading branch information
1 parent
fbf38a2
commit ff3fcf8
Showing
6 changed files
with
63 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { fetchMarkdownPosts } from "$lib/utils"; | ||
import { siteUrl, blogTitle, description, comment } from "$lib/config"; | ||
|
||
export async function GET() { | ||
const posts = await fetchMarkdownPosts(); | ||
|
||
if (!Array.isArray(posts) || posts.length === 0) { | ||
console.error('No posts found or invalid posts data'); | ||
return new Response('Error generating RSS feed', { status: 500 }); | ||
} | ||
|
||
const feedItems = posts.map(post => ` | ||
<item> | ||
<title>${post.meta.title}</title> | ||
<link>${siteUrl}blog/${post.path}</link> | ||
<description>${post.meta.summary || ''}</description> | ||
<category>${post.meta.category || ''}</category> | ||
<pubDate>${new Date(post.meta.pub_date).toUTCString()}</pubDate> | ||
</item> | ||
`).join(''); | ||
|
||
const rss = ` | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> | ||
<channel> | ||
<title>${blogTitle}</title> | ||
<link>${siteUrl}blog</link> | ||
<description>${description} | ${comment}</description> | ||
<atom:link href="${siteUrl}blog/feed.xml" rel="self" type="application/rss+xml"/> | ||
${feedItems} | ||
</channel> | ||
</rss> | ||
`.trim(); | ||
|
||
return new Response(rss, { | ||
headers: { | ||
'Content-Type': 'application/xml', | ||
}, | ||
}); | ||
} | ||
|
||
export const prerender = true |