examples/cms-takeshape/README.md
This example showcases Next.js's Static Generation feature using TakeShape as the data source.
Once you have access to the environment variables you'll need, deploy the example using Vercel.
Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:
npx create-next-app --example cms-takeshape cms-takeshape-app
yarn create next-app --example cms-takeshape cms-takeshape-app
pnpm create next-app --example cms-takeshape cms-takeshape-app
First, create an account on TakeShape.
After creating an account, create a new project from the dashboard. You can select a Blank Project.
Author modelFrom the project settings page, create a new content type.
Author.Next, drag these widgets:
When you’re done, click "Create Content Type".
Post modelClick Add Content Type again.
Post.Next, add these fields (you don't have to modify the settings unless specified):
Single and check the Author checkbox under Allowed Content Types.When you’re done, click "Create Content Type".
Select Author and create a new record.
When you’re done, make sure to click Enabled under Workflow Status.
Next, select Post and create a new record.
When you’re done, make sure to click Enabled under Workflow Status.
From the dropdown next to the project name, click API Keys.
Create a new API Key with the Read permission.
Next, copy the .env.local.example file in this directory to .env.local (which will be ignored by Git):
cp .env.local.example .env.local
Then set each variable on .env.local:
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.Your .env.local file should look like this:
TAKESHAPE_PROJECT_ID=...
TAKESHAPE_API_KEY=...
TAKESHAPE_PREVIEW_SECRET=...
npm install
npm run dev
# or
yarn install
yarn dev
Your blog should be up and running on http://localhost:3000! If it doesn't work, post on GitHub discussions.
On TakeShape, create a new post like before. But DO NOT click Enabled under Workflow Status.
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).
To enable the Preview Mode, go to this URL:
http://localhost:3000/api/preview?secret=<secret>&slug=<slug>
<secret> should be the string you entered for TAKESHAPE_PREVIEW_SECRET.<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.
You can deploy this app to the cloud with Vercel (Documentation).
To deploy your local project to Vercel, push it to GitHub/GitLab/Bitbucket and import to Vercel.
Important: When you import your project on Vercel, make sure to click on Environment Variables and set them to match your .env.local file.
Alternatively, you can deploy using our template by clicking on the Deploy button below.