Reputation: 19
first question on StackOverflow!
Using the Gatsby blog template, I've modified the graphql query and verified that it returns the correct data in GraphiQL, which is being pulled from a "redirect:" property in the blog post frontmatter.
Unfortunately it isn't being passed in the data when running the index.js file.
gatsby-config.js
feeds: [
{
serialize: ({ query: { site, allMarkdownRemark } }) => {
return allMarkdownRemark.nodes.map(node => {
return Object.assign({}, node.frontmatter, {
description: node.excerpt,
redirect: node.frontmatter.redirect,
date: node.frontmatter.date,
url: site.siteMetadata.siteUrl + node.fields.slug,
guid: site.siteMetadata.siteUrl + node.fields.slug,
custom_elements: [{ "content:encoded": node.html }],
})
})
},
query: `
{
allMarkdownRemark(
sort: { order: DESC, fields: [frontmatter___date] },
) {
nodes {
excerpt
html
fields {
slug
}
frontmatter {
redirect
title
date
}
}
}
}
`,
output: "/rss.xml",
},
],
gatsby-node
type Frontmatter {
redirect: String
title: String
description: String
date: Date @dateformat
}
My code repository, https://github.com/tomvaillant/my_blog
Thanks for any support!
Upvotes: 1
Views: 213
Reputation: 29320
You need to query for the redirect
field in the same way you do in the gatsby-config
. Your query should look like:
export const pageQuery = graphql`
query {
site {
siteMetadata {
title
}
}
allMarkdownRemark(sort: { fields: [frontmatter___date], order: DESC }) {
nodes {
excerpt
fields {
slug
}
frontmatter {
date(formatString: "MMMM DD, YYYY")
title
description
redirect # <-- here
}
}
}
}
`
Upvotes: 2