有了这种请求,使用GraphQL使用gatsby-source-contentful
插件从Contentful中提取帖子数据,寻找一种方法访问帖子发布日期 (post.sys.publishedAt) 或 updatedAt !
{
contentfulPost(id: { eq: 'postId' }) {
--> publishedAt ?
title
image {
responsiveResolution(width: 500, height: 500) {
src
srcSet
height
width
}
}
最佳答案
source-contentful 插件不包含 GraphQL 架构中的 sys
属性。它只包含字段和 id。作为解决方法,您可以添加一个包含日期的字段,它将在 graphQL 中对您可用。
希望对你有帮助
编辑----------------
我刚刚提交了一个 PR,将这些选项添加到 gatsbyjs
https://github.com/gatsbyjs/gatsby/pull/2398
您现在可以访问 updatedAt
和 createdAt
属性。
关于graphql - 如何使用 Contentful 从 Gatsby 中的查询中检索发布的发布日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46561916/