Today I added a RSS feed to this blog. I’m not happy with it.
This blog runs on Gatsby and uses mdx instead of Markdown.
Adding a new plugin, the gatsby-plugin-feed, was easy. But it doesn’t work with mdx.
Although the RSS feed gets rendered, I can’t add a title or description to the feed.
It looks like it’s a bug.
Here’s how the config looks:
plugins: [
{
resolve: `gatsby-plugin-feed`,
options: {
query: `
{
site {
siteMetadata {
siteTitle
siteDescription
siteUrl
site_url: siteUrl
}
}
}
`,
feeds: [
{
serialize: ({ query: { site, allMdx } }) =>
allMdx.edges.map(edge =>
Object.assign({}, edge.node.frontmatter, {
description: edge.node.excerpt,
date: edge.node.frontmatter.date,
url: site.siteMetadata.siteUrl + edge.node.fields.slug,
guid: site.siteMetadata.siteUrl + edge.node.fields.slug,
custom_elements: [{ 'content:encoded': edge.node.html }],
})
),
query: `
{
allMdx(
limit: 1000,
sort: { fields: [frontmatter___date], order: DESC }
) {
edges {
node {
fields {
slug
}
frontmatter {
title
tags
}
excerpt
}
}
}
}
`,
output: '/rss.xml',
title: `${config.siteTitle} RSS Feed`,
description: `${config.siteDescription}`,
},
],
},
},
]
Here’s the excerpt from the xml
:
<rss xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:atom="https://www.w3.org/2005/Atom" version="2.0">
<script/>
<channel>
<title>
<![CDATA[ Untitled RSS Feed ]]>
</title>
<description>
<![CDATA[ Untitled RSS Feed ]]>
</description>
It somehow works, but not really?