sc
Scott avatar
ttwillsey

Astro RSS Compiled Content

Part of the Astro series

It’s been awhile and I have lots of news, but just a short one today: Astro now supports full RSS feed content if you use md files for your content. It works like this:

src/pages/rss.xml.js
export const get = () =>
rss({
title: config.get("title"),
description: config.get("description"),
site: config.get("url"),
items: Array.from(episodes).map((episode) => ({
title: episode.frontmatter.title,
link: `${config.get("url")}${config.get("episodes.path")}${
episode.frontmatter.slug
}`,
pubDate: rfc2822(episode.frontmatter.pubDate),
description: episode.frontmatter.description,
customData: `<enclosure url="${config.get("episodes.audioPrefix")}/${
episode.frontmatter.audiofile
}" length="${episode.frontmatter.bytes}" type="audio/mpeg" />`,
content: sanitizeHtml(episode.compiledContent()),
})),
});

See the last line of code?

content: sanitizeHtml(episode.compiledContent());

That’s directly telling Astro RSS that for a given item, the content is equal to the post’s compiledContent property (and run through sanitize-html for good measure).

You can find the Astro docs for it here: Including Full Post Content

There is one caveat I need to mention that directly affects this site. If you use mdx instead of md for your posts like I do here, compiledContent() doesn’t work. Since I don’t like my current RSS feed generation tweak for this site in order to get full content RSS items, my plan is to work on converting back to md and figuring out a way to process images such that I get the benefit of Astro Image’s Picture and Image components while using standard markdown files.