Skip to content

Commit 398b609

Browse files
authored
templates: fix nested docs url generation for categories (#10403)
Fixes #10374
1 parent eadce5e commit 398b609

File tree

8 files changed

+233
-74
lines changed

8 files changed

+233
-74
lines changed

templates/website/src/collections/Categories.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { CollectionConfig } from 'payload'
22

33
import { anyone } from '../access/anyone'
44
import { authenticated } from '../access/authenticated'
5+
import { slugField } from '@/fields/slug'
56

67
export const Categories: CollectionConfig = {
78
slug: 'categories',
@@ -20,5 +21,6 @@ export const Categories: CollectionConfig = {
2021
type: 'text',
2122
required: true,
2223
},
24+
...slugField(),
2325
],
2426
}

templates/website/src/endpoints/seed/index.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,40 +141,76 @@ export const seed = async ({
141141
collection: 'categories',
142142
data: {
143143
title: 'Technology',
144+
breadcrumbs: [
145+
{
146+
label: 'Technology',
147+
url: '/technology',
148+
},
149+
],
144150
},
145151
}),
146152

147153
payload.create({
148154
collection: 'categories',
149155
data: {
150156
title: 'News',
157+
breadcrumbs: [
158+
{
159+
label: 'News',
160+
url: '/news',
161+
},
162+
],
151163
},
152164
}),
153165

154166
payload.create({
155167
collection: 'categories',
156168
data: {
157169
title: 'Finance',
170+
breadcrumbs: [
171+
{
172+
label: 'Finance',
173+
url: '/finance',
174+
},
175+
],
158176
},
159177
}),
160178
payload.create({
161179
collection: 'categories',
162180
data: {
163181
title: 'Design',
182+
breadcrumbs: [
183+
{
184+
label: 'Design',
185+
url: '/design',
186+
},
187+
],
164188
},
165189
}),
166190

167191
payload.create({
168192
collection: 'categories',
169193
data: {
170194
title: 'Software',
195+
breadcrumbs: [
196+
{
197+
label: 'Software',
198+
url: '/software',
199+
},
200+
],
171201
},
172202
}),
173203

174204
payload.create({
175205
collection: 'categories',
176206
data: {
177207
title: 'Engineering',
208+
breadcrumbs: [
209+
{
210+
label: 'Engineering',
211+
url: '/engineering',
212+
},
213+
],
178214
},
179215
}),
180216
])

templates/website/src/payload-types.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ export interface Page {
117117
} | null);
118118
url?: string | null;
119119
label: string;
120+
/**
121+
* Choose how the link should be rendered.
122+
*/
120123
appearance?: ('default' | 'outline') | null;
121124
};
122125
id?: string | null;
@@ -127,6 +130,9 @@ export interface Page {
127130
layout: (CallToActionBlock | ContentBlock | MediaBlock | ArchiveBlock | FormBlock)[];
128131
meta?: {
129132
title?: string | null;
133+
/**
134+
* Maximum upload file size: 12MB. Recommended file size for images is <500KB.
135+
*/
130136
image?: (string | null) | Media;
131137
description?: string | null;
132138
};
@@ -164,6 +170,9 @@ export interface Post {
164170
categories?: (string | Category)[] | null;
165171
meta?: {
166172
title?: string | null;
173+
/**
174+
* Maximum upload file size: 12MB. Recommended file size for images is <500KB.
175+
*/
167176
image?: (string | null) | Media;
168177
description?: string | null;
169178
};
@@ -280,6 +289,8 @@ export interface Media {
280289
export interface Category {
281290
id: string;
282291
title: string;
292+
slug?: string | null;
293+
slugLock?: boolean | null;
283294
parent?: (string | null) | Category;
284295
breadcrumbs?:
285296
| {
@@ -346,6 +357,9 @@ export interface CallToActionBlock {
346357
} | null);
347358
url?: string | null;
348359
label: string;
360+
/**
361+
* Choose how the link should be rendered.
362+
*/
349363
appearance?: ('default' | 'outline') | null;
350364
};
351365
id?: string | null;
@@ -393,6 +407,9 @@ export interface ContentBlock {
393407
} | null);
394408
url?: string | null;
395409
label: string;
410+
/**
411+
* Choose how the link should be rendered.
412+
*/
396413
appearance?: ('default' | 'outline') | null;
397414
};
398415
id?: string | null;
@@ -588,6 +605,9 @@ export interface Form {
588605
)[]
589606
| null;
590607
submitButtonLabel?: string | null;
608+
/**
609+
* Choose whether to display an on-page message or redirect to a different page after they submit the form.
610+
*/
591611
confirmationType?: ('message' | 'redirect') | null;
592612
confirmationMessage?: {
593613
root: {
@@ -607,6 +627,9 @@ export interface Form {
607627
redirect?: {
608628
url: string;
609629
};
630+
/**
631+
* Send custom emails when the form submits. Use comma separated lists to send the same email to multiple recipients. To reference a value from this form, wrap that field's name with double curly brackets, i.e. {{firstName}}. You can use a wildcard {{*}} to output all data and {{*:table}} to format it as an HTML table in the email.
632+
*/
610633
emails?:
611634
| {
612635
emailTo?: string | null;
@@ -615,6 +638,9 @@ export interface Form {
615638
replyTo?: string | null;
616639
emailFrom?: string | null;
617640
subject: string;
641+
/**
642+
* Enter the message that should be sent in this email.
643+
*/
618644
message?: {
619645
root: {
620646
type: string;
@@ -642,6 +668,9 @@ export interface Form {
642668
*/
643669
export interface Redirect {
644670
id: string;
671+
/**
672+
* You will need to rebuild the website when changing this field.
673+
*/
645674
from: string;
646675
to?: {
647676
type?: ('reference' | 'custom') | null;
@@ -677,6 +706,8 @@ export interface FormSubmission {
677706
createdAt: string;
678707
}
679708
/**
709+
* This is a collection of automatically created search results. These results are used by the global site search and will be updated automatically as documents in the CMS are created or updated.
710+
*
680711
* This interface was referenced by `Config`'s JSON-Schema
681712
* via the `definition` "search".
682713
*/
@@ -1054,6 +1085,8 @@ export interface MediaSelect<T extends boolean = true> {
10541085
*/
10551086
export interface CategoriesSelect<T extends boolean = true> {
10561087
title?: T;
1088+
slug?: T;
1089+
slugLock?: T;
10571090
parent?: T;
10581091
breadcrumbs?:
10591092
| T

templates/website/src/plugins/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const plugins: Plugin[] = [
4949
}),
5050
nestedDocsPlugin({
5151
collections: ['categories'],
52+
generateURL: (docs) => docs.reduce((url, doc) => `${url}/${doc.slug}`, ''),
5253
}),
5354
seoPlugin({
5455
generateTitle,

templates/with-vercel-website/src/collections/Categories.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { CollectionConfig } from 'payload'
22

33
import { anyone } from '../access/anyone'
44
import { authenticated } from '../access/authenticated'
5+
import { slugField } from '@/fields/slug'
56

67
export const Categories: CollectionConfig = {
78
slug: 'categories',
@@ -20,5 +21,6 @@ export const Categories: CollectionConfig = {
2021
type: 'text',
2122
required: true,
2223
},
24+
...slugField(),
2325
],
2426
}

templates/with-vercel-website/src/endpoints/seed/index.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,40 +141,76 @@ export const seed = async ({
141141
collection: 'categories',
142142
data: {
143143
title: 'Technology',
144+
breadcrumbs: [
145+
{
146+
label: 'Technology',
147+
url: '/technology',
148+
},
149+
],
144150
},
145151
}),
146152

147153
payload.create({
148154
collection: 'categories',
149155
data: {
150156
title: 'News',
157+
breadcrumbs: [
158+
{
159+
label: 'News',
160+
url: '/news',
161+
},
162+
],
151163
},
152164
}),
153165

154166
payload.create({
155167
collection: 'categories',
156168
data: {
157169
title: 'Finance',
170+
breadcrumbs: [
171+
{
172+
label: 'Finance',
173+
url: '/finance',
174+
},
175+
],
158176
},
159177
}),
160178
payload.create({
161179
collection: 'categories',
162180
data: {
163181
title: 'Design',
182+
breadcrumbs: [
183+
{
184+
label: 'Design',
185+
url: '/design',
186+
},
187+
],
164188
},
165189
}),
166190

167191
payload.create({
168192
collection: 'categories',
169193
data: {
170194
title: 'Software',
195+
breadcrumbs: [
196+
{
197+
label: 'Software',
198+
url: '/software',
199+
},
200+
],
171201
},
172202
}),
173203

174204
payload.create({
175205
collection: 'categories',
176206
data: {
177207
title: 'Engineering',
208+
breadcrumbs: [
209+
{
210+
label: 'Engineering',
211+
url: '/engineering',
212+
},
213+
],
178214
},
179215
}),
180216
])

0 commit comments

Comments
 (0)