Skip to content

Commit

Permalink
Implement RSS
Browse files Browse the repository at this point in the history
  • Loading branch information
Jontes-Tech committed Mar 6, 2024
1 parent 6c5cbbe commit e61a538
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
7 changes: 7 additions & 0 deletions blog/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export const metadata = {
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<head>
<link
rel="alternative"
type="application/atom+xml"
href="/rss.xml"
/>
</head>
<body>
<div className="">
<Navbar />
Expand Down
49 changes: 49 additions & 0 deletions blog/app/rss.xml/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { covers } from 'assets/assets';
import { Feed } from 'feed';

import { getPostsMetadata } from '@/lib/get_posts';
export const GET = async (request: Request) => {
const feed = new Feed({
title: 'ENS Blog',
description: 'The official blog of the Ethereum Name Service',
link: 'https://blog.ens.domains',
language: 'en',
image: 'https://blog.ens.domains/opengraph.jpg',
generator: 'NextJS on Edgeserver',
feedLinks: {
atom: 'https://blog.ens.domains/rss.xml',
},
id: 'https://blog.ens.domains',
copyright: '© ENS Domains',
});

const posts = await getPostsMetadata();

for (const post of posts) {
const postCovers = covers[post.file as keyof typeof covers];
const postCoverThumb = await postCovers['cover-thumb'].then(
(cover) => cover.default
);

feed.addItem({
title: post.title,
guid: 'https://blog.ens.domains/post/' + post.slug,
link: 'https://blog.ens.domains/post/' + post.slug,
date: new Date(post.date),
description: post.description,
author: post.authors.map((author) => {
return {
name: author,
link: 'https://blog.ens.domains/author/' + author,
};
}),
image: postCoverThumb.src,
});
}

return new Response(feed.atom1(), {
headers: {
'Content-Type': 'application/atom+xml; charset=utf-8',
},
});
};
1 change: 1 addition & 0 deletions blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"deepmerge-ts": "^5.1.0",
"ens-tools": "0.0.15-1",
"eslint-plugin-tailwindcss": "^3.13.0",
"feed": "^4.2.2",
"framer-motion": "^10.16.0",
"mdast-util-to-markdown": "^2.1.0",
"mdast-util-to-string": "^4.0.0",
Expand Down
21 changes: 21 additions & 0 deletions blog/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e61a538

Please sign in to comment.