Add Astro Blog RSS feed (#2301)

* Generate RSS feed

* Add RSS feed link
This commit is contained in:
Rafael Bardini 2022-01-10 23:00:42 +01:00 committed by GitHub
parent 263e39a94d
commit 612dfd3bd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View file

@ -14,6 +14,7 @@ const { title, description, image = 'https://astro.build/social.jpg?v=1', canoni
<meta name="theme-color" content="#ff5e00" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="alternate icon" type="image/x-icon" href="/favicon.ico" />
<link rel="alternate" type="application/rss+xml" href="/rss.xml" title="RSS" />
<link rel="sitemap" href="/sitemap.xml" />
<!-- Primary Meta Tags -->

View file

@ -4,10 +4,26 @@ import BlogHeader from '../../components/BlogHeader.astro';
import BlogPost from '../../components/BlogPost.astro';
import GoogleAnalytics from '../../components/GoogleAnalytics.astro';
export function getStaticPaths() {
const posts = Astro.fetchContent('../../data/blog-posts/*.md');
export function getPostSlug(post) {
return post.file.pathname.split('/').pop().split('.').shift();
}
export function getStaticPaths({rss}) {
const posts = Astro.fetchContent('../../data/blog-posts/*.md').sort((a, b) => new Date(b.publishDate) - new Date(a.publishDate));
rss({
title: 'Astro Blog',
description: 'Everything you need to know about Astro, direct from mission control.',
items: posts.map(p => ({
title: p.title,
description: p.description,
link: `blog/${getPostSlug(p)}`,
pubDate: p.publishDate,
}))
});
return posts.map((p) => ({
params: { slug: p.file.pathname.split('/').pop().split('.').shift() },
params: { slug: getPostSlug(p) },
props: { post: p },
}));
}