Skip to content

Commit

Permalink
Add main/complete RSS feed
Browse files Browse the repository at this point in the history
  • Loading branch information
puf committed Aug 22, 2024
1 parent de3d683 commit 318806a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/components/BaseHead.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// all pages through the use of the <BaseHead /> component.
import '../styles/global.css';
import { SITE_TITLE } from '../consts';
interface Props {
title: string;
description: string;
Expand All @@ -24,6 +26,9 @@ const { title, description, image = '/blog-placeholder-1.jpg' } = Astro.props;
<link rel="preload" href="/fonts/atkinson-regular.woff" as="font" type="font/woff" crossorigin />
<link rel="preload" href="/fonts/atkinson-bold.woff" as="font" type="font/woff" crossorigin />

<!-- RSS -->
<link rel="alternate" type="application/rss+xml" title={SITE_TITLE} href={new URL("feed.xml", Astro.site)} />

<!-- Canonical URL -->
<link rel="canonical" href={canonicalURL} />

Expand Down
23 changes: 23 additions & 0 deletions src/pages/feed.xml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import rss from '@astrojs/rss';
import { getNotes } from '../components/Notes.astro';

export async function GET(context) {
const notes = await getNotes({ keepIf: (note) => note.props.frontmatter?.title?.length > 0 && note.params.pubDate?.length > 0 && !/readme.md$/.test(note.props.file) });

console.log("Notes for RSS", notes);

return rss({
title: 'puf.io',
description: 'All notes and thoughts by puf',
site: context.site,
items: notes.map((note) => {
return {
title: note.props.frontmatter.title,
description: note.content, // TODO: there's nothing here yet
link: note.params.slug,
pubDate: note.params.pubDate,
};
}),
customData: `<language>en-us</language>`,
});
}
2 changes: 1 addition & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const CATEGORIES = ["posts", "socials", "books"]
// load recent notes (per category: maxcount=3, maxage=6m)
let notesCount = 0;
notes.forEach((note) => {
const { name, type } = note.params;
const { type } = note.params;
if (/readme.md$/.test(note.props.file)) {
if (readmes[type]) readmes[type] = note;
return; // don't further process readmes
Expand Down

0 comments on commit 318806a

Please sign in to comment.