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

Add an RSS feed for blog posts #546

Merged
merged 6 commits into from
Sep 20, 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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@actions/github": "^5.1.1",
"@astrojs/mdx": "^0.19.7",
"@astrojs/react": "2.2.1",
"@astrojs/rss": "^4.0.7",
"@astrojs/tailwind": "3.1.3",
"@cloudinary/url-gen": "^1.10.0",
"@emotion/css": "^11.11.0",
Expand All @@ -36,6 +37,7 @@
"html-react-parser": "^3.0.16",
"iso-3166": "^4.2.0",
"lucide-react": "^0.220.0",
"markdown-it": "^14.1.0",
"markdown-to-jsx": "^7.2.1",
"merge-refs": "^1.2.1",
"nanostores": "^0.8.1",
Expand All @@ -49,6 +51,7 @@
"remark-gfm": "^3.0.1",
"remark-math": "^5.1.1",
"remark-oembed": "^1.2.2",
"sanitize-html": "^2.13.0",
"swiper": "^9.3.2",
"tailwind-merge": "^1.12.0",
"tailwind-scrollbar-hide": "^1.1.7",
Expand Down
83 changes: 83 additions & 0 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions src/content/blog/2024_QOSS_Survey.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: The 2024 QOSS Survey is open!
author: Kallie Ferguson
day: 9
month: 16
day: 16
month: 9
Comment on lines -4 to +5
Copy link
Member

Choose a reason for hiding this comment

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

Ha! good eye

year: 2024
tags:
- Survey
Expand Down
1 change: 1 addition & 0 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ if (title) {
<link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png" />
<link rel="alternate" type="application/rss+xml" title={titleName} href={`${Astro.url.origin}/posts/feed.xml`} />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
Expand Down
35 changes: 35 additions & 0 deletions src/pages/posts/feed.xml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import rss from '@astrojs/rss';
import { CollectionEntry, getCollection } from 'astro:content';
import sanitizeHtml from 'sanitize-html';
import MarkdownIt from 'markdown-it';

interface SiteContext {
site: string;
}

const parser = new MarkdownIt();

function getDateFromPost(post: CollectionEntry<"blog">): Date {
return new Date(`${post.data.year}-${post.data.month}-${post.data.day}`);
}

export async function get(context: SiteContext) {
const posts = await getCollection('blog');
// Sort the posts by date in descending order
const sortedPosts = posts.sort((a, b) => {
return getDateFromPost(b).getTime() - getDateFromPost(a).getTime();
});
return rss({
title: 'Unitary Fund blog',
description: 'Unitary Fund blog',
site: context.site,
items: sortedPosts
.map((post) => ({
title: post.data.title,
link: `/posts/${post.slug}/`,
pubDate: getDateFromPost(post),
content: sanitizeHtml(parser.render(post.body)),
})),
customData: `<language>en-us</language>`,
});
}