【发布时间】:2022-01-23 14:59:18
【问题描述】:
关于 StackOverflow 的第一个问题!
使用 Gatsby blog template,我修改了 graphql 查询并验证它在 GraphiQL 中返回了正确的数据,该数据是从博文 frontmatter 中的“redirect:”属性中提取的。
不幸的是,在运行 index.js 文件时它没有被传入数据。
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
}
我的代码库,https://github.com/tomvaillant/my_blog
感谢大家的支持!
【问题讨论】: