Skip to content

Commit

Permalink
Create route.ts
Browse files Browse the repository at this point in the history
Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>
  • Loading branch information
gitworkflows authored Apr 11, 2024
1 parent 5249686 commit 8d2cf38
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions solutions/blog/app/rss/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { baseUrl } from 'app/sitemap'
import { getBlogPosts } from 'app/blog/utils'

export async function GET() {
let allBlogs = await getBlogPosts()

const itemsXml = allBlogs
.sort((a, b) => {
if (new Date(a.metadata.publishedAt) > new Date(b.metadata.publishedAt)) {
return -1
}
return 1
})
.map(
(post) =>
`<item>
<title>${post.metadata.title}</title>
<link>${baseUrl}/blog/${post.slug}</link>
<description>${post.metadata.summary || ''}</description>
<pubDate>${new Date(
post.metadata.publishedAt
).toUTCString()}</pubDate>
</item>`
)
.join('\n')

const rssFeed = `<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>My Portfolio</title>
<link>${baseUrl}</link>
<description>This is my portfolio RSS feed</description>
${itemsXml}
</channel>
</rss>`

return new Response(rssFeed, {
headers: {
'Content-Type': 'text/xml',
},
})
}

1 comment on commit 8d2cf38

@vercel
Copy link

@vercel vercel bot commented on 8d2cf38 Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

hand-pickr – ./

hand-pickr-git-main-devsec.vercel.app
hand-pickr.vercel.app
hand-pickr-devsec.vercel.app

Please sign in to comment.