Welcome to your new project created with Stackbit!
Here are a few useful tips & links:
- If you haven't yet transferred this project to your GitHub account, click on the Gear icon in the visual editor to open Project Settings and start the transfer. Learn More.
- Once the repository is in your account, the Project Settings window will show you the commands to run for setting up your local environment. Learn More.
To spin up local dev, run:
- In terminal 1:
git clone
>>npm install
>> Add the Cntfl tokens to the.env
file >>npm run dev
- In terminal 2:
sudo npm i -g @stackbit/cli@0.2.4
stackbit dev \
-c contentful \
--contentful-space-id <space_id> \
--contentful-preview-token <preview_token> \
--contentful-access-token <access_token>
- It's a good idea to go through our Getting Started tutorial. It will give you a small taste of component development as well, and links for further reading.
- To go deeper into how things work, head to the Conceptual Guides.
- For more concise, practical information see the How-to Guides.
Join us on Discord for community support.
To build a static site for production, run the following command
npm run build
The generated site will be written to the out
folder. The contents of this folder can be deployed by a serverless deployment platform such as Netlify. You can start a local server serving the static files from the out
folder, for example, by installing and running http-server
:
npm install http-server -g
http-server out
To contribute to this theme, please follow the following steps:
-
Clone this repository locally
-
Create a new Space in Contentful
-
Create new Contentful Personal Access Tokens here
-
Install dependencies
npm install
-
Import the Contentful data stored in the
contentful/export.json
file to the new space by running the following command. Replace the<management_token>
with your Personal Access Token and the<space_id>
with the new space ID../contentful/import.js <management_token> <space_id>
-
Create "Content Preview API - Access Token" for the new space via Contentful app "Settings" => "API Keys" => "Content delivery / preview tokens" => "Add API Key".
-
Define the following environment variables to allow Next.js to fetch the content from Contentful when developing or building the site. Replace the
{SPACE_ID}
with your Space ID and the{CPA}
with the new Content Preview API - Access Token.export CONTENTFUL_SPACE_ID={SPACE_ID} export CONTENTFUL_PREVIEW_TOKEN={CPA}
-
Lastly, run the Next.js development server:
npm run dev
Navigate to http://localhost:3000 to see the site.
-
Now you can update site code, and the content in Contentful. The browser will automatically live-update your changes.
-
Once you finish updating the code and contents, export the contents back to the
contentful/export.json
file by running the following command. Replace the<management_token>
with your Personal Access Token and the<space_id>
with the new space ID../contentful/export.js <management_token> <space_id>
-
Commit, push and submit a pull-request π
When you update content models in Contentful, run npm run generate-types
with CONTENTFUL_ACCESS_TOKEN
and CONTENTFUL_SPACE_ID
environment variables to generate types from Contentful content models. The types will be stored at src/types/contentful.d.ts
.
Contentful types re-mapped into internal Sourcebit types inside src/types/sourcebit.ts
. And these are the types that are used by React components. The remapping is done for several reasons:
- Remove Contentful specific fields such as
sys
andmetadata
and unwrap Contentfulfields
for simplicity. - Add
__metadata
introduced by Sourcebit.
To learn more about Stackbit, take a look at the following resources:
- Stackbit Documentation
- Configure your theme using stackbit.yaml
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
To learn more about Contentful, take a look at the following resources:
To learn more about Netlify, take a look at the following resources: