Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSS Feed + route added #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ type socialsType = {
class?: string;
};

export const siteName = 'Prabhu Kiran Konda'
export const siteUrl = 'https://prabhukirankonda.vercel.app/'
export const siteTitle = 'Prabhu Kiran Konda'
export const siteImage = `${siteUrl}og.png`


// nav routes
export const routes: routesType[] = [
{
Expand Down
36 changes: 36 additions & 0 deletions src/routes/rss.xml/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { getPosts } from '$lib/posts.js';
import * as config from '$lib/config';

export const prerender = true;

export async function GET() {
const posts = await getPosts();

const headers = { 'Content-Type': 'application/xml' };

const xml = `
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>${config.siteName}</title>
<link>${config.siteUrl}</link>
<atom:link href="${config.siteUrl}rss.xml" rel="self" type="application/rss+xml"/>
${posts
.reverse()
.map(
(post) => `
<item>
<title>${post.title}</title>
<description>${post.description}</description>
<link>${config.siteUrl}${post.slug}</link>
<guid isPermaLink="true">${config.siteUrl}${post.slug}</guid>
<pubDate>${new Date(post.date).toUTCString()}</pubDate>
</item>
`
)
.join('')}
</channel>
</rss>
`.trim();

return new Response(xml, { headers });
}