“What’s on your newsfeed is feeding your mind.” ― Jay Shetty, Think Like a Monk: Train Your Mind for Peace and Purpose Every Day
Social media newsfeeds aim to maximize engagement, often prioritizing popular content over educational value. In contrast, a customized RSS feed allows you to selectively subscribe to sources that enrich your mind with substantive ideas. By carefully curating thought-provoking sources aligned to your interests, an RSS feed provides focused knowledge to stimulate intellectual curiosity. Tailoring your RSS feed with enlightening sources fuels personal growth by making the most of your limited time.
Not only this, but also if you have a personal website with an RSS feed, it can help you stand out from the crowd in many ways. Having an RSS feed allows more frequent and efficient content indexing by search engines, establishes freshness signals, and improves website crawling - all beneficial for SEO. Furthermore, by curating an RSS feed with engaging topical content on your personal site, you can build a loyal audience and earn quality backlinks by getting your content shared and syndicated. In short, maintaining an active RSS feed fuels better SEO and allows personal websites to flourish by reaching the right readers.
I assume that you have a basic knowledge of Astro, one of the fastest growing SSG (not only limited to this now 🤯) and its Content Collection. So, without further introduction let’s jump into the main part ——
⁕ ⁕ ⁕
Valid Parameters in RSS Feed for a Blog Post Item
• title: title of the blog post
• description: description of the post
• pubDate: publication date of the blog post
• link: link to the blog post
• categories: Catergories related to the post in an array
• author: email address of the author of the post
• commentsUrl: URL of a web page that contains comments on the item
• source: An object that defines the title and url of the original feed for items that have been republished from another source.
• enclosure: An object to specify properties for an included media source with three required values: url, length, and type
See 👉: @astrojs/rss Documentation
How to Ship Any Data to RSS Feed: The Tutorial
Important Points to Keep in Mind
• The customData variable is used only for passing valid XML attributes like <language>en</language>, <atom:link /> etc. and it can not be passed inside an item tag. In this context, one thing to keep in mind about using customData variable that
customData variable should be explicitly used here to pass custom valid XML attributes. No other variable xyz or myData etc. can be used here.
• Each blog data is parsed inside a content tag in the final XML code. So, our custom data should also be inside the post’s corresponding content tag.
• Each item has to contain only one content tag. If multiple content tags are passed, only one will be available in the final XML data.
Deep Diving into the code
Frontmatter Structure & Goal
I have several data associated with each of my blog post. The following is my frontmatter of this article —
Out of all the items in the frontmatter, only title, description, cover image (enclosure), tags and publication date (pubDate) can be send to RSS feed by default. But, I want to send subtitle and duration (readeing time) of the post along with title, description, tags and pubDate, and show them on my styled webfeed page.
As of now, the stylesheet (commented out) is not linked to the RSS feed, so that the parsed data can be viewed easily. Following is the screenshot of the content data [custom data is marked with a red rectangle] of this article encoded inside the feed.
Screenshot of the content section with marked area containing custom data in an unstyled RSS feed
Retrieve Custom Data to Show in Styled Web Feed
Now, we can see our each of the custom data is inside the <content:encoded></content:encoded> element under a <p></p> tag of an item. Here, we have to use some logic in our XSLT code to get our required data. The steps are like following—
• Storing the whole text of each 𝗰𝗼𝗻𝘁𝗲𝗻𝘁 element of an item inside a variable
• Getting the required value using the 𝘀𝘂𝗯𝘀𝘁𝗿𝗶𝗻𝗴-𝗯𝗲𝗳𝗼𝗿𝗲 and 𝘀𝘂𝗯𝘀𝘁𝗿𝗶𝗻𝗴-𝗮𝗳𝘁𝗲𝗿 functions
’<p>Subtitle: ’ and ‘<p>Duration: ’ are used to get the string after this parameters till a closing </p> tag. Following is the code for all items —
Some headings, website description and styles are added later on which can be found in this GitHub gist.
Final View & Feed Validation
A screenshot of the styled web feed page is given below, and the red rectangular areas are indicating custom data (subtitle and duration) appeared on the page. However, the complete styled RSS feed page can be viewed on my website.
Screenshot of the styled web feed page with marked area containing the custom data
Now, it’s time for feed validation, and for that I used W3C Feed Validation Service. And yes, you gussed it right, my feed is valid—
⁕ ⁕ ⁕
Thank you for reading.
I hope you found this “How to Send Any Data to Your RSS Feed? A Guide with Astro + RSS” article helpful. Please share if you like and leave any comment to let me know your thoughts. Also, subscribe to my Newsletter to get notification of my latest posts.