RS monogramRussell Schmidt
Lightbox image, just a zoomed in version of the last picture. Hit Escape to exit and return to the last page.

Gatsby RSS Feed Configuration

I have one person in the world that subscribed to my old Jekyll RSS feed and since moving to Gatsby, I cut off that special baby boy. My oldest friend! What a monster.

The Problem

The default Gatsby RSS feed gatsby-plugin-feed uses an out-of-the-box configuration that is not compatible with the starter I had built my site on.

TL;DR: Make Sure Your GraphQL Query Matches

Slugs and Paths

I was using path as defined in my frontmatter, but the out of the box config for the gatsby-plugin-feed uses slug as a field to pull the relative path to each blog post for the feed. I also use both portfolio and blog posts so I wanted to include my type frontmatter data designation.

In order to get mine to work, my config is below. I would CMD+F for 'slug' and then make sure that it is using whatever your term and query structure is using. I would also remove this line filter: {frontmatter: { draft: { ne: true } }} unless you are using drafts.

I don't use drafts because I always push straight to master and then to production on my blog. It's my blog and here, there are no rules.

The Configuration

{
  resolve: `gatsby-plugin-feed`,
  options: {
    query: `
      {
        site {
          siteMetadata {
            title
            description
            siteUrl
            site_url: siteUrl
          }
        }
      }
    `,
    feeds: [
      {
        serialize: ({ query: { site, allMarkdownRemark } }) => {
          return allMarkdownRemark.edges.map(edge => {
            return Object.assign({}, edge.node.frontmatter, {
              description: edge.node.excerpt,
              url: site.siteMetadata.siteUrl + edge.node.frontmatter.path,
              guid: site.siteMetadata.siteUrl + edge.node.frontmatter.path,
              custom_elements: [{ "content:encoded": edge.node.html }],
            });
          });
        },
        query: `
          {
            allMarkdownRemark(
              limit: 1000,
              sort: { order: DESC, fields: [frontmatter___date] }
            ) {
              edges {
                node {
                  excerpt
                  id
                  html
                  frontmatter {
                    title
                    date(formatString: "MMMM DD, YYYY")
                    path
                    type
                  }
                }
              }
            }
          }
        `,
        output: "/rss.xml",
      },
    ],
  },
}

Postscript

I am getting some UTF-8 encoding error at line 3,500 or so of my feed, but it's otherwise working. I am not sure what this is or why the error pops up there of all places, from a very early blog post (April 2016).