我正在寻求有关 GatsbyJS 和 Contentful 的帮助。文档并没有给我足够的信息。
我希望以编程方式创建基于内容数据的页面。在这种情况下,数据类型是一个零售“商店”,在 /retail_store_name 有一个 gatsby 页面
每个商店的 index.js 基本上是几个带有props的react组件,例如商店名称和谷歌地点 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 中发布新商店以在生产站点上进行更新。