Skip to content

Commit 382c65a

Browse files
committed
Update
1 parent 7e5fb6b commit 382c65a

35 files changed

+2150
-416
lines changed

.env.local.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
PREPRIO_API=https://graphql.prepr.io/graphql
22
PREPRIO_PRODUCTION_TOKEN=
33
PREPRIO_PREVIEW_TOKEN=
4-
PREPRIO_PREVIEW_KEY=
4+
PREPRIO_PREVIEW_SECRET=YOURSECRET

LICENSE

-21
This file was deleted.

README.md

+79-54
Original file line numberDiff line numberDiff line change
@@ -4,113 +4,138 @@ This example showcases Next.js's [Static Generation](https://nextjs.org/docs/bas
44

55
## Demo
66

7-
- **Live**: [https://next-blog-prepr.now.sh/](https://next-blog-prepr.now.sh/)
8-
- **Preview Mode**: [https://next-blog-prepr.now.sh/api/preview...](https://next-blog-prepr.now.sh/api/preview?secret=237864ihasdhj283768&slug=discover-enjoy-amsterdam)
7+
Check out our Blog page example:
98

10-
### [https://next-blog-prepr.now.sh/](https://next-blog-prepr.now.sh/)
11-
12-
## Getting Started
13-
14-
Once you have access to [the environment variables you'll need](#step-3-set-up-environment-variables), deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):
15-
16-
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/cms-prepr&project-name=cms-prepr&repository-name=cms-prepr&env=PREPRIO_API,PREPRIO_PRODUCTION_TOKEN,PREPRIO_PREVIEW_TOKEN,PREPRIO_PREVIEW_KEY&envDescription=Required%20to%20connect%20the%20app%20with%20Prepr&envLink=https://vercel.link/cms-prepr-env)
9+
* **Live**: [https://next-blog-prepr.vercel.app/](https://next-blog-prepr.vercel.app/)
10+
* **Preview**: [https://next-blog-prepr.vercel.app/api/preview...](https://next-blog-prepr.vercel.app/api/preview?secret=237864ihasdhj283768&slug=as-easy-as-appelbol)
1711

1812
## How to use
1913

20-
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:
14+
Execute one of the following [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) commands using [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to create a new Next.js app and connect it to Prepr:
2115

2216
```bash
2317
npx create-next-app --example cms-prepr cms-prepr-app
24-
# or
25-
yarn create next-app --example cms-prepr cms-prepr-app
2618
```
2719

28-
## Configuration
20+
```bash
21+
yarn create next-app --example cms-prepr cms-prepr-app
22+
```
2923

30-
### Step 1. Create an account and a environment in Prepr
24+
```bash
25+
pnpm create next-app --example cms-prepr cms-prepr-app
26+
```
3127

32-
First, [create an account in Prepr](https://prepr.io).
28+
## Configuration
3329

34-
### Step 2. Create Author model
30+
### Step 1. Set up Prepr
3531

36-
From your Prepr dashboard, click **Settings** -> **Models**
32+
**1.1** First, [sign up for a Prepr account](https://signup.prepr.io/).
3733

38-
Click on the arrow next to **Add model** and select **Import**.
34+
**1.2** After you sign up, create a new environment in Prepr. For more details, [check out the environment docs](https://docs.prepr.io/developing-with-prepr/set-up-environments).
3935

40-
Import the [`models/author.json`](models/author.json) file.
36+
![Create Prepr environment](https://assets-site.prepr.io//1bynxkn1084r-create-enviroment.png)
4137

42-
After that
38+
**1.3** Once you’ve created the environment, choose to **Load demo data**. With that, Prepr will automatically upload sample models, content items, and other data you can use for your example Next.js app.
4339

44-
Import the [`models/post.json`](models/post.json) file.
40+
![Load Prepr demo data](https://assets-site.prepr.io//2xrbs9aquhij-import-demo-data.png)
4541

46-
Click on the Author field and select `Author` at the option `Publication model` and click **Save**.
42+
### Step 2. Set up environment variables
4743

48-
### Step 3. Set up environment variables
44+
Once you’ve set up your Prepr environment, you can define environment variables for your project. Please proceed with the steps below.
4945

50-
Copy the `.env.local.example` file in this directory to `.env.local` (which will be ignored by Git):
46+
**2.1** Run the following command to copy and rename the `.env.local.example` file as follows:
5147

5248
```bash
5349
cp .env.local.example .env.local
5450
```
5551

56-
Inside your environment, navigate to **Settings > Development > Access Tokens**.
52+
The `.env.local` file will be ignored by Git.
53+
54+
**2.2** In your environment, navigate to **Settings > Development > Access Tokens**. You will see the automatically generated access tokens for your Prepr environment.
5755

58-
Click **Add access token**, enter the name `Next.js Preview` and add the scope `graphql_preview` and click **Save**.
56+
![Access tokens](https://assets-site.prepr.io//6jouln4xi3wp-default-access-tokens.png)
5957

60-
Copy the generated access token and set the variable `PREPRIO_PREVIEW_TOKEN` in `.env.local`.
58+
Copy the *GraphQL Production* access token and paste it as the `PREPRIO_PRODUCTION_TOKEN` variable in `.env.local`. Then copy and paste the *GraphQL Preview* access token as the `PREPRIO_PREVIEW_TOKEN` variable.
6159

62-
Go back to the Access token overview and click **Add access token**.
60+
Alternatively, you can create access tokens yourself by clicking **Add access token**. If so, make sure to [choose the right GraphQL permissions](https://docs.prepr.io/reference/graphql/v1/authorization) for the access tokens.
6361

64-
Enter the name `Next.js Production` and add the scope `graphql_published` and click **Save**.
62+
**2.3** Set a custom value with no spaces as the `PREPRIO_PREVIEW_SECRET` variable, for example, a UUID. This value will be used to enable [preview mode](https://nextjs.org/docs/advanced-features/preview-mode).
6563

66-
Copy the generated access token and set the variable `PREPRIO_PRODUCTION_TOKEN` in `.env.local`.
64+
Once done, your `.env.local` file should look like this:
65+
66+
```bash
67+
PREPRIO_API=https://graphql.prepr.io/graphql
68+
PREPRIO_PRODUCTION_TOKEN='your Production access token'
69+
PREPRIO_PREVIEW_TOKEN='your Preview access token'
70+
PREPRIO_PREVIEW_SECRET='your secret id'
71+
```
6772

68-
The `PREPRIO_PREVIEW_KEY` can be any random string (but avoid spaces), like a UUID`, this is used
69-
for [Preview Mode](https://nextjs.org/docs/advanced-features/preview-mode).
73+
### Step 3. Run Next.js in development mode
7074

71-
### Step 4. Run Next.js in development mode
75+
Now that you've finished preparing the project, you may proceed to run it.
76+
77+
**3.1** Execute one of the following commands to install the packages listed in the `package.json` file:
7278

7379
```bash
7480
npm install
75-
npm run dev
76-
77-
# or
81+
```
7882

83+
```bash
7984
yarn install
85+
```
86+
**3.2** Execute one of the following commands to run the dev script defined in the `package.json` file:
87+
88+
```bash
89+
npm run dev
90+
```
91+
92+
```bash
8093
yarn dev
8194
```
8295

83-
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).
96+
Your example Blog website should be up and running on [http://localhost:3000](http://localhost:3000). If it doesn't work, please post on [GitHub discussions](https://github.com/vercel/next.js/discussions).
97+
98+
### Step 4. Optional: Try Preview mode
99+
100+
Great progress has been made! You are just a few steps away from getting your example website live.
101+
Before proceeding, you can test how the content preview works in Prepr. This step is optional. Proceed to Step 5 if you don’t want to use preview mode.
84102

85-
### Step 5. Try preview mode
103+
To try preview mode, follow these steps:
86104

87-
In Prepr, go to one of the posts in your environment and:
105+
**4.1** In Prepr, go to one of the content items of the *Article model* and update the item title. For example, you can add *[PREVIEW]* in front of the title. After you edit the content item, save it with the *Review status*.
88106

89-
- **Update the title**. For example, you can add `[REVIEW]` in front of the title.
90-
- After you edit the publication save the post with a review state.
107+
**4.2** To preview the content item, transform its URL to the following format:
91108

92-
To view the preview, transform the url to the following format: `http://localhost:3000/api/preview?secret=<YOUR_SECRET_TOKEN>&slug=<SLUG_TO_PREVIEW>` where `<YOUR_SECRET_TOKEN>` is
93-
the same secret you defined in the `.env.local` file and `<SLUG_TO_PREVIEW>` is the slug of one of the posts you want to preview.
109+
`http://localhost:3000/api/preview?secret=<PREPRIO_PREVIEW_SECRET>&slug=<SLUG_TO_PREVIEW>`,
110+
where:
111+
- `<PREPRIO_PREVIEW_SECRET>` is the same preview secret you defined in the `.env.local` file;
112+
- `<SLUG_TO_PREVIEW>` is the slug of the content item you want to preview.
94113

95-
You should now be able to see post that are in Review and Done state. To exit the preview mode, you can click on _"Click here to exit preview mode"_ at the top.
114+
**Note:** To exit the preview mode, you must click on **Click here to exit preview mode** at the top of the page.
96115

97-
### Step 6. Deploy on Vercel
116+
![Preview content item](https://assets-site.prepr.io//4hd7vgoyke24-web-page.png)
98117

99-
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)).
118+
### Step 5. Deploy on Vercel
100119

101-
#### Deploy Your Local Project
120+
To make your Next.js app available online, deploy it to the cloud using [Vercel](https://vercel.com/?utm_source=github&utm_medium=readme&utm_campaign=next-example). Vercel provides a user-friendly platform for deploying and managing web applications. For more information, please [refer to the Next.js documentation](https://nextjs.org/docs/deployment).
102121

103-
To deploy your local project to Vercel, push it to GitHub/GitLab/Bitbucket and [import to Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example).
122+
You can go for one of the following options:
104123

105-
**Important**: When you import your project on Vercel, make sure to click on **Environment Variables** and set them to match your `.env.local` file.
124+
* **Deploy your local project**</br>
125+
To deploy your local project to Vercel, push it to GitHub/GitLab/Bitbucket and [import it to Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example).
106126

107-
#### Deploy from Our Template
127+
**Important:** When you import your project on Vercel, make sure to click on **Environment Variables** and set them to match your `.env.local` file.
108128

109-
Alternatively, you can deploy using our template by clicking on the Deploy button below.
129+
* **Deploy from our template**</br>
130+
Alternatively, you can deploy using our template by clicking on the **Deploy** button below.
110131

111-
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/cms-prepr&project-name=cms-prepr&repository-name=cms-prepr&env=PREPRIO_API,PREPRIO_PRODUCTION_TOKEN,PREPRIO_PREVIEW_TOKEN,PREPRIO_PREVIEW_KEY&envDescription=Required%20to%20connect%20the%20app%20with%20Prepr&envLink=https://vercel.link/cms-prepr-env)
132+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/cms-prepr&project-name=cms-prepr&repository-name=cms-prepr&env=PREPRIO_API,PREPRIO_PRODUCTION_TOKEN,PREPRIO_PREVIEW_TOKEN,PREPRIO_PREVIEW_SECRET&envDescription=Required%20to%20connect%20the%20app%20with%20Prepr&envLink=https://vercel.link/cms-prepr-env)
112133

134+
## Next steps
113135

114-
### Questions?
136+
For more advanced topics, please refer to the Prepr’s documentation:
137+
* [A/B testing](https://docs.prepr.io/optimization-and-personalization/ab-testing)
138+
* [Personalization](https://docs.prepr.io/optimization-and-personalization/personalized-stack)
139+
* [Recommendations](https://docs.prepr.io/optimization-and-personalization/recommendations)
115140

116-
Join us on [Slack](https://slack.prepr.io) or contact support at support@prepr.io.
141+
If you have questions, please [get in touch](https://prepr.io/get-in-touch) with one of our specialists or [join our Slack community](https://slack.prepr.io/).

apollo-client.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ApolloClient, InMemoryCache } from '@apollo/client'
2+
3+
const client = new ApolloClient({
4+
uri: process.env.PREPRIO_API,
5+
cache: new InMemoryCache(),
6+
})
7+
8+
export default client

components/alert.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Container from './container'
22
import cn from 'classnames'
3-
import { EXAMPLE_PATH } from '../lib/constants'
3+
import { EXAMPLE_PATH } from '@/lib/constants'
44

55
export default function Alert({ preview }) {
66
return (
@@ -14,7 +14,7 @@ export default function Alert({ preview }) {
1414
<div className="py-2 text-center text-sm">
1515
{preview ? (
1616
<>
17-
This page is a preview.{' '}
17+
This is page is a preview.{' '}
1818
<a
1919
href="/api/exit-preview"
2020
className="underline hover:text-cyan duration-200 transition-colors"

components/cover-image.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1+
import cn from 'classnames'
12
import Image from 'next/image'
23
import Link from 'next/link'
3-
import cn from 'classnames'
44

55
export default function CoverImage({ title, url, slug }) {
66
const image = (
77
<Image
88
width={2000}
99
height={1000}
1010
alt={`Cover Image for ${title}`}
11+
src={url}
1112
className={cn('shadow-small', {
1213
'hover:shadow-medium transition-shadow duration-200': slug,
1314
})}
14-
src={url}
1515
/>
1616
)
17-
1817
return (
1918
<div className="sm:mx-0">
2019
{slug ? (
21-
<Link as={`/posts/${slug}`} href="/posts/[slug]">
22-
<a aria-label={title}>{image}</a>
20+
<Link href={`/posts/${slug}`} aria-label={title}>
21+
{image}
2322
</Link>
2423
) : (
2524
image

components/date.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { parseISO, format } from 'date-fns'
2+
import { useEffect, useState } from 'react'
23

3-
export default function Date({ dateString }) {
4-
const date = parseISO(dateString)
5-
return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time>
4+
// dateString might be null for unpublished posts
5+
export default function DateComponent({ dateString }) {
6+
const [date, setDate] = useState(dateString ? parseISO(dateString) : null)
7+
useEffect(() => {
8+
if (!date) {
9+
setDate(new Date())
10+
}
11+
}, [date])
12+
return date && <time dateTime={date}>{format(date, 'LLLL d, yyyy')}</time>
613
}

components/footer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Container from './container'
2-
import { EXAMPLE_PATH } from '../lib/constants'
2+
import { EXAMPLE_PATH } from '@/lib/constants'
33

44
export default function Footer() {
55
return (

components/header.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import Link from 'next/link'
33
export default function Header() {
44
return (
55
<h2 className="text-2xl md:text-4xl font-bold tracking-tight md:tracking-tighter leading-tight mb-20 mt-8">
6-
<Link href="/">
7-
<a className="hover:underline">Blog</a>
6+
<Link href="/" className="hover:underline">
7+
Blog
88
</Link>
99
.
1010
</h2>

components/hero-post.js

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import Avatar from '../components/avatar'
2-
import Date from '../components/date'
3-
import CoverImage from '../components/cover-image'
1+
import Avatar from './avatar'
2+
import Date from './date'
3+
import CoverImage from './cover-image'
44
import Link from 'next/link'
55

66
export default function HeroPost({
@@ -11,27 +11,30 @@ export default function HeroPost({
1111
author,
1212
slug,
1313
}) {
14-
return (
14+
return (
1515
<section>
1616
<div className="mb-8 md:mb-16">
17-
<CoverImage slug={slug} title={title} url={coverImage} />
17+
<CoverImage title={title} url={coverImage} slug={slug} />
1818
</div>
19-
<div className="mb-20 md:grid md:grid-cols-2 md:col-gap-16 lg:col-gap-8 md:mb-28">
19+
<div className="md:grid md:grid-cols-2 md:gap-x-16 lg:gap-x-8 mb-20 md:mb-28">
2020
<div>
21-
<h3 className="mb-4 text-4xl leading-tight lg:text-6xl">
22-
<Link as={`/posts/${slug}`} href="/posts/[slug]">
23-
<a className="hover:underline">{title}</a>
24-
</Link>
25-
</h3>
26-
<div className="mb-4 text-lg md:mb-0">
27-
<Date dateString={date} />
28-
</div>
21+
<h3 className="mb-4 text-4xl lg:text-6xl leading-tight">
22+
<Link href={`/posts/${slug}`} className="hover:underline">
23+
{title}
24+
</Link>
25+
</h3>
26+
<div className="mb-4 md:mb-0 text-lg">
27+
<Date dateString={date} />
2928
</div>
29+
</div>
3030
<div>
31-
<p className="mb-4 text-lg leading-relaxed">{excerpt}</p>
32-
<Avatar name={author.name} picture={author.cover[0].cdn_files[0].url} />
31+
<div
32+
className="text-lg leading-relaxed mb-4"
33+
dangerouslySetInnerHTML={{ __html: excerpt }}
34+
></div>
35+
<Avatar name={author.full_name} picture={author.profile_pic[0].url} />
3336
</div>
34-
</div>
37+
</div>
3538
</section>
3639
)
37-
}
40+
}

components/intro.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CMS_NAME, CMS_URL } from '../lib/constants'
1+
import { CMS_NAME, CMS_URL } from '@/lib/constants'
22

33
export default function Intro() {
44
return (

components/layout.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import Alert from '../components/alert'
2-
import Footer from '../components/footer'
3-
import Meta from '../components/meta'
1+
import Alert from './alert'
2+
import Footer from './footer'
3+
import Meta from './meta'
44

55
export default function Layout({ preview, children }) {
66
return (

0 commit comments

Comments
 (0)