|
| 1 | +# Documentation Site Example |
| 2 | + |
| 3 | +This is an example of a documentation site built with: |
| 4 | + |
| 5 | +- [Next.js](https://nextjs.org/) (site framework) |
| 6 | +- [Contentful](https://www.contentful.com/) (content source) |
| 7 | +- [Stackbit](https://www.stackbit.com/) (visual editor) |
| 8 | +- [Tailwind](https://tailwindcss.com/) (CSS framework) |
| 9 | + |
| 10 | +This site is an example of a site that uses a headless CMS (Contentful) to manage the content. Among other benefits, it is easier to account for multiple content editors of varying technical skill levels. |
| 11 | + |
| 12 | +The content modeling here is inspired by [Notion](https://www.notion.so/), which does an excellent job of balancing flexibility and productivity for content editors. |
| 13 | + |
| 14 | +### Features |
| 15 | + |
| 16 | +While this is only a simple example to get started, we've introduced a few features that are worth noting: |
| 17 | + |
| 18 | +- **Theme Toggle:** A simple switch, along with styles to support both light and dark modes. |
| 19 | +- **Syntax Highlighting:** The `<CodeBlock />` component uses [highlight.js](https://highlightjs.org/) for syntax highlighting. |
| 20 | +- **Composable Pages:** Every page is just a page and can be composed of any number of sections. This allows for a lot of flexibility in how content is organized. |
| 21 | +- **Stackbit-Ready:** Stackbit helps you build sites faster by providing a visual editor for content. This site works with Stackbit out of the box. |
| 22 | + |
| 23 | +## Getting Started |
| 24 | + |
| 25 | +Getting started with this project just takes a few steps. |
| 26 | + |
| 27 | +### Clone the Repository |
| 28 | + |
| 29 | +This is an official example, so you can use `create-stackbit-app` to clone it to your machine: |
| 30 | + |
| 31 | + npx create-stackbit-app@latest --example documentation stackbit-docs-example |
| 32 | + |
| 33 | +This will create a new project in a `stackbit-docs-example` directory. |
| 34 | + |
| 35 | +### Setup Contentful |
| 36 | + |
| 37 | +This project uses Contentful as a headless CMS. You'll need to do the following to get Contentful ready to go: |
| 38 | + |
| 39 | +1. Create a Contentful account (if you don't have one). |
| 40 | +1. Create a new space. This will become the `CONTENTFUL_SPACE_ID` environment variable. |
| 41 | +1. Create a new [personal access token](https://www.contentful.com/help/personal-access-tokens/). This will become the `CONTENTFUL_ACCESS_TOKEN` environment variable. |
| 42 | +1. [Add an API key](https://training.contentful.com/student/page/1050378-api-keys) to the space. You will need the delivery and preview tokens, which will become the `CONTENTFUL_DELIVERY_TOKEN` and `CONTENTFUL_PREVIEW_TOKEN` environment variables. |
| 43 | + |
| 44 | +Copy `.env.local-sample` to `.env.local` and fill in the environment variables mentioned above. |
| 45 | + |
| 46 | +### Import Content |
| 47 | + |
| 48 | +There is a script ready to import the content model and content into your Contentful space. You can run it with the following command: |
| 49 | + |
| 50 | + npm run contentful:import -- <CONTENTFUL_ACCESS_TOKEN> <CONTENTFUL_SPACE_ID> |
| 51 | + |
| 52 | +Replace `<CONTENTFUL_ACCESS_TOKEN>` and `<CONTENTFUL_SPACE_ID>` with the values from your Contentful space. |
| 53 | + |
| 54 | +### Run the Server |
| 55 | + |
| 56 | +Now you should be able to run the server: |
| 57 | + |
| 58 | + npm run dev |
| 59 | + |
| 60 | +You can also run Stackbit's development server in a parallel process. This will allow you to edit content in Stackbit's visual editor locally on your machine. |
| 61 | + |
| 62 | + npm install -g @stackbit/cli |
| 63 | + stackbit dev |
| 64 | + |
| 65 | +This will output a URL that you can open to view the visual editor. |
| 66 | + |
| 67 | +## Adding a Component |
| 68 | + |
| 69 | +If you want to add a component that can be used in a page, you'll need to do the following: |
| 70 | + |
| 71 | +1. Add the new content type in Contentful with the appropriate fields. |
| 72 | +1. Edit the `sections` field in the page model to allow for your new component. |
| 73 | +1. Export the content from your space into this project. |
| 74 | + |
| 75 | + ```txt |
| 76 | + npm run contentful:export |
| 77 | + ``` |
| 78 | +
|
| 79 | +1. Generate types for the new content type. |
| 80 | +
|
| 81 | + ```txt |
| 82 | + npm run contentful:types |
| 83 | + ``` |
| 84 | +
|
| 85 | +1. Add new, custom type(s) to `types/index.ts`, which requires: |
| 86 | + 1. Adding any new sub-components to the _Atoms_ section. |
| 87 | + 1. Add new content type ID to `SectionType` type. |
| 88 | + 1. Add a new type based on the generic `Section` type and the automatically-generated type for the new content type. |
| 89 | + 1. Add new type to the `ComposableSection` type. |
| 90 | +1. Add a new component in the `components` directory. Use the new type from `types/index.ts` as the type for the component's props. |
| 91 | +1. Add the new component to `components/DynamicComponent.tsx`. |
0 commit comments