Skip to content

Commit

Permalink
Implement an RSS feed (at rss.xml). (#66)
Browse files Browse the repository at this point in the history
Co-authored-by: Luc van Kampen <[email protected]>
Co-authored-by: Jakob Helgesson <[email protected]>
  • Loading branch information
3 people authored Mar 7, 2024
1 parent 6c5cbbe commit a0f7a93
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
8 changes: 7 additions & 1 deletion blog/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import './globals.css';

import { Metadata } from 'next';
import { ReactNode } from 'react';

import { Navbar } from '@/components/navbar/Navbar';

export const metadata = {
export const metadata: Metadata = {
title: 'ENS Blog',
description: 'The official blog of the Ethereum Name Service',
alternates: {
types: {
'application/atom+xml': '/rss.xml',
},
},
};

export default function RootLayout({ children }: { children: ReactNode }) {
Expand Down
50 changes: 50 additions & 0 deletions blog/app/rss.xml/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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 a0f7a93

Please sign in to comment.