【问题标题】:How to retrieve published post date from query in Gatsby with Contentful?如何使用 Contentful 从 Gatsby 中的查询中检索发布的发布日期?
【发布时间】:2018-03-15 16:09:39
【问题描述】:

通过这种请求,使用 gatsby-source-contentful 插件从 ContentfulGraphQL 提取帖子数据,寻找访问帖子发布日期的方法(post.sys .publishedAt) 或 updatedAt !

 {
  contentfulPost(id: { eq: 'postId' }) {
   --> publishedAt ?
   title
   image {
    responsiveResolution(width: 500, height: 500) {
      src
      srcSet
      height
      width
    }
  }

}

【问题讨论】:

    标签: graphql contentful gatsby


    【解决方案1】:

    source-contentful 插件在 GraphQL 架构中不包含 sys 属性。它只包括字段和 id。作为一种解决方法,您可以添加一个包含日期的字段,它将在 graphQL 中可供您使用。

    希望对你有帮助

    编辑---------------

    我刚刚提交了一个 PR,将这些选项添加到 gatsbyjs https://github.com/gatsbyjs/gatsby/pull/2398 您现在可以访问updatedAtcreatedAt 属性。

    【讨论】:

    • 感谢您的回答。
    • 这是否意味着编辑必须填写此字段才能发布发布日期,或者您是否知道使用已发布数据自动填写此字段的方法?
    • 我创建了一个关于将 sys 字段添加到 GraphQL github.com/gatsbyjs/gatsby/issues/2342 的问题
    • 谢谢!它可能对博客文章有用!
    • 这周我会尽量抽出时间
    猜你喜欢
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-29
    • 2011-08-11
    • 2022-08-16
    • 2019-03-14
    • 1970-01-01
    相关资源
    最近更新 更多