如何在Gatsby中处理内容丰富的内容数据 [英] How to handle Contentful content data in Gatsby

查看:81
本文介绍了如何在Gatsby中处理内容丰富的内容数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣使用盖茨比来构建内容丰富的内容

I'm interested in using Gatsby to build a Netlify static site using content from Contentful

Netlify有一个不错的入门指南盖茨比指南: https://www.netlify.com/blog/2016/02/24/a-step-by-step-guide-gatsby-on-netlify

Netlify has this nice gettting started Gatsby guide: ​​https://www.netlify.com/blog/2016/02/24/a-step-by-step-guide-gatsby-on-netlify

但是我不太确定如何将Contentful纳入其中.我是否需要编写脚本以将我的内容内容转换为Gatsby'markdown'?

But I'm a bit unsure of how to bring Contentful into the mix. Do I need to write scripts to convert my Contentful content into Gatsby 'markdown'?

任何想法,想法,链接都值得赞赏!

Any ideas, ideas, links appreciated!

推荐答案

自从发布此问题以来,正式的Contentful插件已添加到Gatsby的收藏集中(由Gatsby团队创建,不是Contentful的官方):

Since this question was posted, an official Contentful plugin's been added to Gatsby's collection (official as in created by Gatsby team, not Contentful): https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-contentful

示例网站的src代码在此处: https://github .com/gatsbyjs/gatsby/tree/master/examples/using-contentful

An example site's src code is here: https://github.com/gatsbyjs/gatsby/tree/master/examples/using-contentful

该插件通过gatsby-transformer-remark处理markdown并生成结果HTML,您可以通过Gatsby的GraphQL服务器(带有来自

The plugin processes markdown via gatsby-transformer-remark and produces the resultant HTML, which you can access via Gatsby's GraphQL server w/ a query like this one from the example proj:

 contentfulProduct(id: { eq: $id }) {
      productName {
        productName
      }
      productDescription {
        childMarkdownRemark {
          html
        }
      }
      price
    }

您可以使用该插件同时连接到Content API(针对已发布的资产/内容)和/或Preview API(针对已发布的草稿内容/资产).

You can use the plugin to connect both to the Content API (for published assets/content) and/or the Preview API (for both published and draft content/assets).

我们使用NODE_ENV从dev中的Preview API和生产中的Content API中提取.

We use NODE_ENV to pull from the Preview API in dev and the Content API in production.

这篇关于如何在Gatsby中处理内容丰富的内容数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆