5 • Beef up your blog
Add an RSS feed
Get ready to…
- Install an Astro package for creating an RSS feed for your website
- Create a feed that can be subscribed to and read by RSS feed readers
Install Astro’s RSS package
Section titled Install Astro’s RSS packageAstro provides a custom package to quickly add an RSS feed to your website.
This official package generates a non-HTML document with information about all of your blog posts that can be read by feed readers like Feedly, The Old Reader and more. This document is updated every time your site is rebuilt.
Individuals can subscribe to your feed in a feed reader, and receive notification when you publish a new blog post on your site, making it a popular blog feature.
-
Quit the Astro development server and run the following command in the terminal to install Astro’s RSS package.
npm install @astrojs/rsspnpm install @astrojs/rssyarn add @astrojs/rss -
Restart the dev server to begin working on your Astro project again.
npm run devpnpm run devyarn run dev
Create an .xml feed document
Section titled Create an .xml feed document-
Create a new file in
src/pages/calledrss.xml.js -
Copy the following code into this new document, replacing the
siteproperty with your site’s own unique Netlify URL. Customize thetitleanddescriptionproperties, and if necessary, specify a different language incustomData:src/ pages/ rss.xml.js import rss from '@astrojs/rss'; export const get = () => rss({ title: 'Astro Learner | Blog', description: 'My journey learning Astro', site: 'https://my-blog-site.netlify.app', items: import.meta.glob('./**/*.md'), customData: `<language>en-us</language>`, }); -
This
rss.xmldocument is only created when your site is built, so you won’t be able to see this page in your browser during development. Quit the dev server and run the following commands to first, build your site locally and then, view a preview of your build:npm run build npm run previewpnpm run build pnpm run previewyarn run build yarn run preview -
Visit
localhost:3000/rss.xmland verify that you can see (unformatted) text on the page with anitemfor each of your.mdfiles. Each item should contain blog post information such astitle,urlanddescription. -
Be sure to quit the preview and restart the dev server when you want to view your site in development mode again.