Skip to content

Commit 6c0e389

Browse files
author
Marco Monti
committed
docs(next-drupal): updated learn section
1 parent d67f2cf commit 6c0e389

File tree

11 files changed

+93
-91
lines changed

11 files changed

+93
-91
lines changed

www/content/tutorials/draft-mode/configure-content-types.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
title: Configure Content Types
33
excerpt: Configure preview for content types
44
weight: 150
5-
group: Preview Mode
5+
group: Draft Mode
66
---
77

8-
Next, we need to configure preview mode for the content types. This will display an inline preview in an iframe when you visit the content pages.
8+
Next, we need to configure draft mode for the content types. This will display an inline draft in an iframe when you visit the content pages.
99

1010
---
1111

12-
## Configure Preview
12+
## Configure Draft
1313

14-
To enable content preview inside Drupal, we need to configure a site resolver for the **Article** content type.
14+
To enable content draft inside Drupal, we need to configure a site resolver for the **Article** content type.
1515

1616
<Callout>
1717

18-
A _site resolver_ tells Drupal how to resolve the preview URL for an entity.
18+
A _site resolver_ tells Drupal how to resolve the draft URL for an entity.
1919

2020
</Callout>
2121

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Configure Draft Routes
3+
excerpt: Draft routes in Next.js
4+
weight: 140
5+
group: Draft Mode
6+
---
7+
8+
Implement draft mode using two API routes.
9+
10+
<Callout>
11+
12+
If you're using the Basic Starter, draft routes are already created for you.
13+
14+
</Callout>
15+
16+
## /app/api/draft/route.ts
17+
18+
```ts title=app/api/draft/route.ts
19+
import { drupal } from "@/lib/drupal"
20+
import { enableDraftMode } from "next-drupal/draft"
21+
import type { NextRequest } from "next/server"
22+
23+
export async function GET(request: NextRequest): Promise<Response | never> {
24+
return enableDraftMode(request, drupal)
25+
}
26+
```
27+
28+
---
29+
30+
## /app/api/disable-draft/route.ts
31+
32+
```ts title=app/api/disable-draft/route.ts
33+
import { disableDraftMode } from "next-drupal/draft"
34+
import type { NextRequest } from "next/server"
35+
36+
export async function GET(request: NextRequest) {
37+
return disableDraftMode()
38+
}
39+
```

www/content/tutorials/draft-mode/configure-preview-routes.mdx

Lines changed: 0 additions & 43 deletions
This file was deleted.

www/content/tutorials/draft-mode/create-oauth-client.mdx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Create OAuth Client
33
excerpt: Setup an OAuth client to be used for authenticated content.
44
weight: 110
5-
group: Preview Mode
5+
group: Draft Mode
66
---
77

88
Before we can create an OAuth consumer, we need to create a new role and a user for OAuth scopes.
@@ -38,7 +38,7 @@ We are assigning the _Bypass content access control_ permission to allow Next.js
3838
This scope is only going to be used when making authenticated requests from Next.js to Drupal.
3939

4040
```ts
41-
const articles = await drupal.getResource(
41+
const article = await drupal.getResource(
4242
"node--article",
4343
"dad82fe9-f2b7-463e-8c5f-02f73018d6cb",
4444
// highlight-start
@@ -108,20 +108,17 @@ DRUPAL_CLIENT_SECRET=
108108

109109
---
110110

111-
## 7. Update DrupalClient
111+
## 7. Update NextDrupal client.
112112

113-
Update the `DrupalClient` to use the **Bearer** authentication header.
113+
Update the `NextDrupal` to use the **Bearer** authentication header.
114114

115115
```ts title=lib/drupal.ts
116-
import { DrupalClient } from "next-drupal"
117-
118-
export const drupal = new DrupalClient(
119-
process.env.NEXT_PUBLIC_DRUPAL_BASE_URL,
120-
{
121-
auth: {
122-
clientId: process.env.DRUPAL_CLIENT_ID,
123-
clientSecret: process.env.DRUPAL_CLIENT_SECRET,
124-
},
125-
}
126-
)
116+
import { NextDrupal } from "next-drupal"
117+
118+
export const drupal = new NextDrupal(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, {
119+
auth: {
120+
clientId: process.env.DRUPAL_CLIENT_ID,
121+
clientSecret: process.env.DRUPAL_CLIENT_SECRET,
122+
},
123+
})
127124
```

www/content/tutorials/draft-mode/create-site.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
title: Create Next.js site
33
excerpt: Create a Next.js site on Drupal
44
weight: 105
5-
group: Preview Mode
5+
group: Draft Mode
66
---
77

8-
Start by creating a Next.js site so that we can render the preview on Drupal.
8+
Start by creating a Next.js site so that we can render the draft on Drupal.
99

1010
1. Visit `/admin/config/services/next`.
1111
2. Click **Add Next.js site**.
1212
3. Fill in the following values:
1313

1414
- **Label**: `Next.js`
1515
- **Base URL**: `http://localhost:3000`
16-
- **Preview URL**: `http://localhost:3000/api/preview`
17-
- **Preview secret**: `secret`
16+
- **Draft URL (or Preview URL)**: `http://localhost:3000/api/draft`
17+
- **Secret key**: `secret`
1818

1919
<Callout>
2020

www/content/tutorials/draft-mode/done.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
title: Done
33
weight: 160
4-
group: Preview Mode
4+
group: Draft Mode
55
---
66

7-
Congratulations. You have successfully configured preview mode for your content types.
7+
Congratulations. You have successfully configured draft mode for your content types.
88

99
You should see the iframe preview when you visit your content pages.
1010

www/content/tutorials/graphql/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ weight: 10
55
group: Quick Start (GraphQL)
66
---
77

8-
This tutorial will help you get started with Next.js for Drupal using the [`DrupalClient`](/docs/client) and **GraphQL**.
8+
This tutorial will help you get started with Next.js for Drupal using the [`NextDrupal`](/docs/client) and **GraphQL**.
99

1010
<Callout>
1111

www/content/tutorials/on-demand-revalidation/configure-entity-types.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ weight: 350
55
group: On-demand Revalidation
66
---
77

8+
<!--
9+
************************************************************
10+
* TODO: Remove this block before publishing.
11+
12+
* Comment: The revalidator plugin used to work out of the box with path-based revalidation. However, Next.js implemented Tag-based revalidation, which is
13+
pretty useful for revalidating Menus on the FE whenever a Drupal Menu is updating. I'm just leaving this comment to note this, since I do not know
14+
if the new version of drupal module supports this out of the box.
15+
************************************************************
16+
-->
17+
818
Next, we need to configure on-demand revalidation for the entity types.
919

1020
To enable on-demand revalidation for an entity type, we need to configure a **revalidator** plugin.

www/content/tutorials/on-demand-revalidation/configure-revalidate-route.mdx

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,43 @@ weight: 360
55
group: On-demand Revalidation
66
---
77

8-
Implement on-demand revalidation using an API routes at `/revalidate`.
8+
Implement on-demand revalidation using an API route at `/revalidate`.
99

1010
<Callout>
1111

1212
If you're using the Basic Starter, revalidate route are already created for you. You can skip this step.
1313

1414
</Callout>
1515

16-
## /pages/api/revalidate.ts
16+
## /app/api/revalidate/route.ts
1717

18-
```ts title=pages/api/revalidate.ts
19-
import { NextApiRequest, NextApiResponse } from "next"
18+
```ts title=app/api/revalidate/route.ts
19+
import { revalidatePath } from "next/cache"
20+
import type { NextRequest } from "next/server"
2021

21-
export default async function handler(
22-
request: NextApiRequest,
23-
response: NextApiResponse
24-
) {
25-
let slug = request.query.slug as string
26-
const secret = request.query.secret as string
22+
async function handler(request: NextRequest) {
23+
const searchParams = request.nextUrl.searchParams
24+
const path = searchParams.get("path")
25+
const secret = searchParams.get("secret")
2726

2827
// Validate secret.
2928
if (secret !== process.env.DRUPAL_REVALIDATE_SECRET) {
30-
return response.status(401).json({ message: "Invalid secret." })
29+
return new Response("Invalid secret.", { status: 401 })
3130
}
3231

33-
// Validate slug.
34-
if (!slug) {
35-
return response.status(400).json({ message: "Invalid slug." })
32+
// Validate path.
33+
if (!path) {
34+
return new Response("Invalid path.", { status: 400 })
3635
}
3736

3837
try {
39-
await response.revalidate(slug)
38+
revalidatePath(path)
4039

41-
return response.json({})
40+
return new Response("Revalidated.")
4241
} catch (error) {
43-
return response.status(404).json({
44-
message: error.message,
45-
})
42+
return new Response((error as Error).message, { status: 500 })
4643
}
4744
}
45+
46+
export { handler as GET, handler as POST }
4847
```

www/content/tutorials/quick-start/configure-path-aliases.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ weight: 50
55
group: Quick Start
66
---
77

8-
The `next-drupal` plugin uses paths to resolve resources for `getStaticProps`. To make this work, we need to configure path aliases for our content types.
8+
The `next-drupal` plugin uses paths to resolve resources for the Next.js Frontend. To make this work, we need to configure path aliases for our content types.
99

1010
Let's add a pattern for the **Article** content type.
1111

0 commit comments

Comments
 (0)