Skip to content

Commit

Permalink
templates: fix nested docs url generation for categories (#10403)
Browse files Browse the repository at this point in the history
Fixes #10374
  • Loading branch information
paulpopus authored Jan 6, 2025
1 parent eadce5e commit 398b609
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 74 deletions.
2 changes: 2 additions & 0 deletions templates/website/src/collections/Categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { CollectionConfig } from 'payload'

import { anyone } from '../access/anyone'
import { authenticated } from '../access/authenticated'
import { slugField } from '@/fields/slug'

export const Categories: CollectionConfig = {
slug: 'categories',
Expand All @@ -20,5 +21,6 @@ export const Categories: CollectionConfig = {
type: 'text',
required: true,
},
...slugField(),
],
}
36 changes: 36 additions & 0 deletions templates/website/src/endpoints/seed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,40 +141,76 @@ export const seed = async ({
collection: 'categories',
data: {
title: 'Technology',
breadcrumbs: [
{
label: 'Technology',
url: '/technology',
},
],
},
}),

payload.create({
collection: 'categories',
data: {
title: 'News',
breadcrumbs: [
{
label: 'News',
url: '/news',
},
],
},
}),

payload.create({
collection: 'categories',
data: {
title: 'Finance',
breadcrumbs: [
{
label: 'Finance',
url: '/finance',
},
],
},
}),
payload.create({
collection: 'categories',
data: {
title: 'Design',
breadcrumbs: [
{
label: 'Design',
url: '/design',
},
],
},
}),

payload.create({
collection: 'categories',
data: {
title: 'Software',
breadcrumbs: [
{
label: 'Software',
url: '/software',
},
],
},
}),

payload.create({
collection: 'categories',
data: {
title: 'Engineering',
breadcrumbs: [
{
label: 'Engineering',
url: '/engineering',
},
],
},
}),
])
Expand Down
33 changes: 33 additions & 0 deletions templates/website/src/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ export interface Page {
} | null);
url?: string | null;
label: string;
/**
* Choose how the link should be rendered.
*/
appearance?: ('default' | 'outline') | null;
};
id?: string | null;
Expand All @@ -127,6 +130,9 @@ export interface Page {
layout: (CallToActionBlock | ContentBlock | MediaBlock | ArchiveBlock | FormBlock)[];
meta?: {
title?: string | null;
/**
* Maximum upload file size: 12MB. Recommended file size for images is <500KB.
*/
image?: (string | null) | Media;
description?: string | null;
};
Expand Down Expand Up @@ -164,6 +170,9 @@ export interface Post {
categories?: (string | Category)[] | null;
meta?: {
title?: string | null;
/**
* Maximum upload file size: 12MB. Recommended file size for images is <500KB.
*/
image?: (string | null) | Media;
description?: string | null;
};
Expand Down Expand Up @@ -280,6 +289,8 @@ export interface Media {
export interface Category {
id: string;
title: string;
slug?: string | null;
slugLock?: boolean | null;
parent?: (string | null) | Category;
breadcrumbs?:
| {
Expand Down Expand Up @@ -346,6 +357,9 @@ export interface CallToActionBlock {
} | null);
url?: string | null;
label: string;
/**
* Choose how the link should be rendered.
*/
appearance?: ('default' | 'outline') | null;
};
id?: string | null;
Expand Down Expand Up @@ -393,6 +407,9 @@ export interface ContentBlock {
} | null);
url?: string | null;
label: string;
/**
* Choose how the link should be rendered.
*/
appearance?: ('default' | 'outline') | null;
};
id?: string | null;
Expand Down Expand Up @@ -588,6 +605,9 @@ export interface Form {
)[]
| null;
submitButtonLabel?: string | null;
/**
* Choose whether to display an on-page message or redirect to a different page after they submit the form.
*/
confirmationType?: ('message' | 'redirect') | null;
confirmationMessage?: {
root: {
Expand All @@ -607,6 +627,9 @@ export interface Form {
redirect?: {
url: string;
};
/**
* 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.
*/
emails?:
| {
emailTo?: string | null;
Expand All @@ -615,6 +638,9 @@ export interface Form {
replyTo?: string | null;
emailFrom?: string | null;
subject: string;
/**
* Enter the message that should be sent in this email.
*/
message?: {
root: {
type: string;
Expand Down Expand Up @@ -642,6 +668,9 @@ export interface Form {
*/
export interface Redirect {
id: string;
/**
* You will need to rebuild the website when changing this field.
*/
from: string;
to?: {
type?: ('reference' | 'custom') | null;
Expand Down Expand Up @@ -677,6 +706,8 @@ export interface FormSubmission {
createdAt: string;
}
/**
* 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.
*
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "search".
*/
Expand Down Expand Up @@ -1054,6 +1085,8 @@ export interface MediaSelect<T extends boolean = true> {
*/
export interface CategoriesSelect<T extends boolean = true> {
title?: T;
slug?: T;
slugLock?: T;
parent?: T;
breadcrumbs?:
| T
Expand Down
1 change: 1 addition & 0 deletions templates/website/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const plugins: Plugin[] = [
}),
nestedDocsPlugin({
collections: ['categories'],
generateURL: (docs) => docs.reduce((url, doc) => `${url}/${doc.slug}`, ''),
}),
seoPlugin({
generateTitle,
Expand Down
2 changes: 2 additions & 0 deletions templates/with-vercel-website/src/collections/Categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { CollectionConfig } from 'payload'

import { anyone } from '../access/anyone'
import { authenticated } from '../access/authenticated'
import { slugField } from '@/fields/slug'

export const Categories: CollectionConfig = {
slug: 'categories',
Expand All @@ -20,5 +21,6 @@ export const Categories: CollectionConfig = {
type: 'text',
required: true,
},
...slugField(),
],
}
36 changes: 36 additions & 0 deletions templates/with-vercel-website/src/endpoints/seed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,40 +141,76 @@ export const seed = async ({
collection: 'categories',
data: {
title: 'Technology',
breadcrumbs: [
{
label: 'Technology',
url: '/technology',
},
],
},
}),

payload.create({
collection: 'categories',
data: {
title: 'News',
breadcrumbs: [
{
label: 'News',
url: '/news',
},
],
},
}),

payload.create({
collection: 'categories',
data: {
title: 'Finance',
breadcrumbs: [
{
label: 'Finance',
url: '/finance',
},
],
},
}),
payload.create({
collection: 'categories',
data: {
title: 'Design',
breadcrumbs: [
{
label: 'Design',
url: '/design',
},
],
},
}),

payload.create({
collection: 'categories',
data: {
title: 'Software',
breadcrumbs: [
{
label: 'Software',
url: '/software',
},
],
},
}),

payload.create({
collection: 'categories',
data: {
title: 'Engineering',
breadcrumbs: [
{
label: 'Engineering',
url: '/engineering',
},
],
},
}),
])
Expand Down
Loading

0 comments on commit 398b609

Please sign in to comment.