I am looking for help with GatsbyJS and Contentful. The docs aren't quite giving me enough info.
I am looking to programmatically create pages based on contentful data. In this case, the data type is a retail "Store" with a gatsby page at /retail_store_name
The index.js for each store is basically a couple of react components with props passed in e.g. shop name and google place ID.
Add data to contentful. Here is my example data model:
{ "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 } }
I've added the contentful site data to gatsby-config.js
// In gatsby-config.js plugins: [ { resolve: `gatsby-source-contentful`, options: { spaceId: `your_space_id`, accessToken: `your_access_token` }, }, ];
Query contentful - I'm not sure where this should happen. I've got a template file that would be the model for each store webpage created from contentful data.
As mentioned this is just some components with props passed in. Example:
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} />
);
}
I'm really not sure how to go about this. The end goal is auto publishing for non-tech users, who post new stores in Contentful to be updated on the production site.