【发布时间】:2018-06-23 15:26:41
【问题描述】:
我正在寻求有关 GatsbyJS 和 Contentful 的帮助。文档没有给我足够的信息。
我希望基于内容数据以编程方式创建页面。在这种情况下,数据类型是一个零售“商店”,其 gatsby 页面位于 /retail_store_name
每个商店的 index.js 基本上是几个带有 props 的 react 组件,例如商店名称和 Google 地点 ID。
-
将数据添加到内容。这是我的示例数据模型:
{ "name": "Store" "displayField": "shopName", "fields": [ { "id": "shopName", "name": "Shop Name", "type": "Symbol", "localized": false, "required": true, "validations": [ { "unique": true } ], "disabled": false, "omitted": false }, { "id": "placeId", "name": "Place ID", "type": "Symbol", "localized": false, "required": true, "validations": [ { "unique": true } ], "disabled": false, "omitted": false } } -
我已将内容丰富的网站数据添加到 gatsby-config.js
// In gatsby-config.js plugins: [ { resolve: `gatsby-source-contentful`, options: { spaceId: `your_space_id`, accessToken: `your_access_token` }, }, ]; 查询内容 - 我不确定这应该发生在哪里。我有一个模板文件,该文件将作为从内容数据创建的每个商店网页的模型。
如前所述,这只是一些传入 props 的组件。示例:
import React, { Component } from "react";
export default class IndexPage extends Component {
constructor(props) {
super(props);
this.state = {
placeId: "",
shopName: "",
};
}
render (){
return (
<ComponentExampleOne shopName={this.state.shopName} />
<ComponentExampleTwo placeId={this.state.placeId} />
);
}
我真的不知道该怎么做。最终目标是为非技术用户自动发布,他们在 Contentful 中发布新商店以在生产站点上更新。
【问题讨论】:
标签: javascript reactjs graphql contentful gatsby