summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Rafael Bardini <rbardini@users.noreply.github.com> 2022-01-10 23:00:42 +0100
committerGravatar GitHub <noreply@github.com> 2022-01-10 17:00:42 -0500
commit612dfd3bd82035894beeee54259c723dff3d8bb6 (patch)
tree7e4e3aacd9b13fef1160069fd3687b9fb3148fc6
parent263e39a94d51004dfe0ad0f2f2e930ddd766265f (diff)
downloadastro-612dfd3bd82035894beeee54259c723dff3d8bb6.tar.gz
astro-612dfd3bd82035894beeee54259c723dff3d8bb6.tar.zst
astro-612dfd3bd82035894beeee54259c723dff3d8bb6.zip
Add Astro Blog RSS feed (#2301)
* Generate RSS feed * Add RSS feed link
-rw-r--r--www/src/components/BaseHead.astro1
-rw-r--r--www/src/pages/blog/[slug].astro22
2 files changed, 20 insertions, 3 deletions
diff --git a/www/src/components/BaseHead.astro b/www/src/components/BaseHead.astro
index dbebff48c..53b52ce77 100644
--- a/www/src/components/BaseHead.astro
+++ b/www/src/components/BaseHead.astro
@@ -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 -->
diff --git a/www/src/pages/blog/[slug].astro b/www/src/pages/blog/[slug].astro
index 0390801cc..93260f90e 100644
--- a/www/src/pages/blog/[slug].astro
+++ b/www/src/pages/blog/[slug].astro
@@ -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 },
}));
}