Gatsby source plugin for building websites using Contentstack as a data source
npm install @berlitz/gatsby-source-contentstackThis is a fork of the original repository, customized for Berlitz.
Contentstack provides a source plugin for pulling content into [Gatsby][gatsby] from [Contentstack][contentstack] stacks. It helps you query content types and entries in Gatsby using GraphQL.
Here’s an example site built using this source plugin: https://xenodochial-hodgkin-8a267e.netlify.com/
npm install --save gatsby-source-contentstack
Open the gatsby-config.js file from the root directory of your Gatsby project and configure it with below parameters
``javascriptgatsby-source-contentstack
// In your gatsby-config.js
plugins: [
{
resolve: ,api_key
options: {
// API Key is a unique key assigned to each stack. This is required.
api_key: ,
// Access Token is a read-only credential . This is required.
access_token: access_token,
// Environment where you published your data.
environment: environment,`
},
},
]
You can query nodes created from Contentstack using GraphQL.
All content types and the corresponding entries are pulled from your stack. They'll be created in your site's GraphQL schema under contentstack${contentTypeID} and allContentstack${contentTypeID}.
Note: Learn to use the GraphQL tool and Ctrl+Spacebar at
GraphQL model.
If, for example, you have Blogs as one of your content types, you will be able to query its entries in the following manner:
`graphql`
{
allContentstackBlogs {
edges {
node {
id
title
url
description
banner {
filename
url
title
}
created_at
}
}
}
}
Reference fields provide references to entries of another content type(s). Since fields from
referred entry is often needed, the referred entry data is provided at the reference field.
`graphql`
{
allContentstackBlogs {
edges {
node {
id
title
url
description
authors {
name
}
created_at
}
}
}
}
- Asset type and Image processing support using gatsby-transformer-sharp, gatsby-plugin-sharp`.
[gatsby]: https://www.gatsbyjs.org/
[contentstack]: https://www.contentstack.com/