applyThoughts / starter-nextjs-contentful-theme

Starter Next.js & Contentful theme for Stackbit V2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A New Stackbit Project

Welcome to your new project created with Stackbit!

Here are a few useful tips & links:

Set up

  1. 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.
  2. 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.

Develop with Stackbit Locally

To spin up local dev, run:

  1. In terminal 1: git clone >> npm install >> Add the Cntfl tokens to the .env file >> npm run dev
  2. 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>

Learn the basics

  1. 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.
  2. To go deeper into how things work, head to the Conceptual Guides.
  3. For more concise, practical information see the How-to Guides.

Get answers

Join us on Discord for community support.

Building for production πŸ—

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

Contributing πŸ™

To contribute to this theme, please follow the following steps:

  1. Clone this repository locally

  2. Create a new Space in Contentful

  3. Create new Contentful Personal Access Tokens here

  4. Install dependencies

    npm install
  5. 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>
  6. Create "Content Preview API - Access Token" for the new space via Contentful app "Settings" => "API Keys" => "Content delivery / preview tokens" => "Add API Key".

  7. 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}
  8. Lastly, run the Next.js development server:

    npm run dev

    Navigate to http://localhost:3000 to see the site.

  9. Now you can update site code, and the content in Contentful. The browser will automatically live-update your changes.

  10. 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>
  11. Commit, push and submit a pull-request πŸŽ‰

Working with types

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:

  1. Remove Contentful specific fields such as sys and metadata and unwrap Contentful fields for simplicity.
  2. Add __metadata introduced by Sourcebit.

Learn More πŸ“š

To learn more about Stackbit, take a look at the following resources:

To learn more about Next.js, take a look at the following resources:

To learn more about Contentful, take a look at the following resources:

To learn more about Netlify, take a look at the following resources:

About

Starter Next.js & Contentful theme for Stackbit V2


Languages

Language:TypeScript 81.5%Language:JavaScript 13.7%Language:CSS 4.4%Language:Shell 0.4%