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

chore: Add RSS feed #2283

Merged
merged 2 commits into from
Oct 8, 2024
Merged
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
37 changes: 37 additions & 0 deletions apps/www/app/feed.xml/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import RSS from "rss";
import { type Post, allPosts } from "content-collections";
import { authors } from "@/content/blog/authors";
const feed = new RSS({
title: "Unkey",
description: "Open Source API Development platform",
site_url: "https://unkey.com",
feed_url: `https://unkey.com/feed.xml`,
copyright: `${new Date().getFullYear()} Unkey`,
language: "en",
pubDate: new Date(),
});

const posts = allPosts.sort((a: Post, b: Post) => {
return new Date(b.date).getTime() - new Date(a.date).getTime();
});

export async function GET() {
posts.map((post) => {
const author = authors[post.author];
feed.item({
title: post.title,
guid: `https://unkey.com/blog/${post.slug}`,
url: `https://unkey.com/blog/${post.slug}`,
date: post.date,
description: post.description,
author: author.name,
categories: post.tags || [],
});
});

return new Response(feed.xml({ indent: true }), {
headers: {
"Content-Type": "application/atom+xml; charset=utf-8",
},
});
}
2 changes: 2 additions & 0 deletions apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"react-syntax-highlighter": "^15.5.0",
"rehype-raw": "^7.0.0",
"remark-gfm": "^3.0.1",
"rss": "^1.2.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using a more up-to-date RSS library.

The addition of the rss package aligns with the PR objective of adding an RSS feed. However, version 1.2.2 is quite old (last updated in 2017). Consider using a more modern alternative or a newer version if available. Some options to explore:

  1. feed (https://www.npmjs.com/package/feed)
  2. rss-generator (https://www.npmjs.com/package/rss-generator)
  3. Check if there's a newer version of rss that's compatible with your project

Would you like me to research and suggest a specific alternative with an example of how to integrate it?

"shiki": "^1.12.0",
"tailwind-merge": "^2.2.2",
"tailwindcss-animate": "^1.0.7",
Expand All @@ -70,6 +71,7 @@
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.0",
"@types/react-syntax-highlighter": "^15.5.13",
"@types/rss": "^0.0.32",
"autoprefixer": "^10.4.19",
"postcss": "^8",
"tailwindcss": "^3.4.3",
Expand Down
Loading
Loading