README.md 6.8 KB
Newer Older
S
Shu Uesugi 已提交
1 2 3 4 5 6 7 8
# A statically generated blog example using Next.js and TakeShape

This example showcases Next.js's [Static Generation](https://nextjs.org/docs/basic-features/pages) feature using [TakeShape](https://www.takeshape.io/) as the data source.

## Demo

### [https://next-blog-takeshape.now.sh/](https://next-blog-takeshape.now.sh/)

9 10 11 12
## Deploy your own

Once you have access to [the environment variables you'll need](#step-5-set-up-environment-variables), deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):

13
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/git?s=https://github.com/vercel/next.js/tree/canary/examples/cms-takeshape&env=TAKESHAPE_PROJECT_ID,TAKESHAPE_API_KEY,TAKESHAPE_PREVIEW_SECRET&envDescription=Required%20to%20connect%20the%20app%20with%20TakeShape&envLink=https://vercel.link/cms-takeshape-env)
14

S
Shu Uesugi 已提交
15 16
### Related examples

17
- [WordPress](/examples/cms-wordpress)
S
Shu Uesugi 已提交
18 19
- [DatoCMS](/examples/cms-datocms)
- [Sanity](/examples/cms-sanity)
T
Tim Neutkens 已提交
20
- [Prismic](/examples/cms-prismic)
21
- [Contentful](/examples/cms-contentful)
S
Shu Uesugi 已提交
22
- [Strapi](/examples/cms-strapi)
23
- [Agility CMS](/examples/cms-agilitycms)
J
Jazib Sawar 已提交
24
- [Cosmic](/examples/cms-cosmic)
S
Shu Uesugi 已提交
25
- [ButterCMS](/examples/cms-buttercms)
S
Shu Uesugi 已提交
26
- [Storyblok](/examples/cms-storyblok)
J
Jesse 已提交
27
- [GraphCMS](/examples/cms-graphcms)
28
- [Blog Starter](/examples/blog-starter)
S
Shu Uesugi 已提交
29 30 31 32 33

## How to use

### Using `create-next-app`

34
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
S
Shu Uesugi 已提交
35 36

```bash
37
npx create-next-app --example cms-takeshape cms-takeshape-app
S
Shu Uesugi 已提交
38 39 40 41 42 43 44 45 46
# or
yarn create next-app --example cms-takeshape cms-takeshape-app
```

### Download manually

Download the example:

```bash
47
curl https://codeload.github.com/vercel/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/cms-takeshape
S
Shu Uesugi 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
cd cms-takeshape
```

## Configuration

### Step 1. Create an account and a project on TakeShape

First, [create an account on TakeShape](https://www.takeshape.io/).

After creating an account, create a **new project** from the dashboard. You can select a **Blank Project**.

### Step 2. Create an `Author` model

From the project settings page, create a new **content type**.

- The title should be `Author`.

Next, drag these widgets:

- **Single Line** widget: Set the title as **Name**.
- **Asset** widget: Set the title as **Picture**.

When you’re done, click "Create Content Type".

### Step 3. Create a `Post` model

Click **Add Content Type** again.

- The title should be `Post`.

Next, add these fields (you don't have to modify the settings unless specified):

- **Single Line** widget: Set the title as **Title**.
- **Markdown** widget: Set the title as **Content**.
- **Single Line** widget: Set the title as **Excerpt**.
- **Asset** widget: Set the title as **Cover Image**.
- **Date** widget: Set the title as **Date**.
- **Single Line** widget: Set the title as **Slug**.
- **Relationship** widget: Set the title as **Author**, then set **Relationship Type** to `Single` and check the `Author` checkbox under **Allowed Content Types**.

When you’re done, click "Create Content Type".

### Step 4. Populate Content

Select **Author** and create a new record.

- You just need **1 Author record**.
- Use dummy data for the text.
- For the image, you can download one from [Unsplash](https://unsplash.com/).

When you’re done, make sure to click **Enabled** under **Workflow Status**.

Next, select **Post** and create a new record.

- We recommend creating at least **2 Post records**.
- Use dummy data for the text.
- You can write markdown for the **Content** field.
- For the images, you can download ones from [Unsplash](https://unsplash.com/).
- Pick the **Author** you created earlier.

When you’re done, make sure to click **Enabled** under **Workflow Status**.

### Step 5. Set up environment variables

From the dropdown next to the project name, click **API Keys**.

Create a new API Key with the **Read** permission.

116
Next, copy the `.env.local.example` file in this directory to `.env.local` (which will be ignored by Git):
S
Shu Uesugi 已提交
117 118

```bash
119
cp .env.local.example .env.local
S
Shu Uesugi 已提交
120 121
```

122
Then set each variable on `.env.local`:
S
Shu Uesugi 已提交
123

124 125 126
- `TAKESHAPE_API_KEY` should be the API token you just copied.
- `TAKESHAPE_PROJECT_ID` should be the project ID, which is a substring in the project page URL: `https://app.takeshape.io/projects/<project-id>/...`
- `TAKESHAPE_PREVIEW_SECRET` can be any random string (but avoid spaces), like `MY_SECRET` - this is used for [the Preview Mode](https://nextjs.org/docs/advanced-features/preview-mode).
S
Shu Uesugi 已提交
127

128
Your `.env.local` file should look like this:
S
Shu Uesugi 已提交
129 130

```bash
131 132 133
TAKESHAPE_PROJECT_ID=...
TAKESHAPE_API_KEY=...
TAKESHAPE_PREVIEW_SECRET=...
S
Shu Uesugi 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147
```

### Step 6. Run Next.js in development mode

```bash
npm install
npm run dev

# or

yarn install
yarn dev
```

148
Your blog should be up and running on [http://localhost:3000](http://localhost:3000)! If it doesn't work, post on [GitHub discussions](https://github.com/vercel/next.js/discussions).
S
Shu Uesugi 已提交
149 150 151 152 153

### Step 7. Try preview mode

On TakeShape, create a new post like before. But **DO NOT** click **Enabled** under **Workflow Status**.

154
Now, if you go to `http://localhost:3000/posts/<slug>` (replace `<slug>`), you won’t see the post. However, if you use the **Preview Mode**, you'll be able to see the change ([Documentation](https://nextjs.org/docs/advanced-features/preview-mode)).
S
Shu Uesugi 已提交
155 156 157 158 159 160 161

To enable the Preview Mode, go to this URL:

```
http://localhost:3000/api/preview?secret=<secret>&slug=<slug>
```

162
- `<secret>` should be the string you entered for `TAKESHAPE_PREVIEW_SECRET`.
S
Shu Uesugi 已提交
163 164 165 166
- `<slug>` should be the post's `slug` attribute (you can check on TakeShape).

You should now be able to see this post. To exit the preview mode, you can click **Click here to exit preview mode** at the top.

T
Tim Neutkens 已提交
167
### Step 8. Deploy on Vercel
S
Shu Uesugi 已提交
168

169
You can deploy this app to the cloud with [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
S
Shu Uesugi 已提交
170

171
#### Deploy Your Local Project
S
Shu Uesugi 已提交
172

173
To deploy your local project to Vercel, push it to GitHub/GitLab/Bitbucket and [import to Vercel](https://vercel.com/import/git?utm_source=github&utm_medium=readme&utm_campaign=next-example).
S
Shu Uesugi 已提交
174

175 176 177 178 179
**Important**: When you import your project on Vercel, make sure to click on **Environment Variables** and set them to match your `.env.local` file.

#### Deploy from Our Template

Alternatively, you can deploy using our template by clicking on the Deploy button below.
S
Shu Uesugi 已提交
180

181
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/git?s=https://github.com/vercel/next.js/tree/canary/examples/cms-takeshape&env=TAKESHAPE_PROJECT_ID,TAKESHAPE_API_KEY,TAKESHAPE_PREVIEW_SECRET&envDescription=Required%20to%20connect%20the%20app%20with%20TakeShape&envLink=https://vercel.link/cms-takeshape-env)