Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

templates: add Posts to internal links in website template #10063

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/website/src/fields/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const link: LinkType = ({ appearances, disableLabel = false, overrides =
condition: (_, siblingData) => siblingData?.type === 'reference',
},
label: 'Document to link to',
relationTo: ['pages'],
relationTo: ['pages', 'posts'],
required: true,
},
{
Expand Down
227 changes: 126 additions & 101 deletions templates/website/src/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,15 @@ export interface Page {
link: {
type?: ('reference' | 'custom') | null;
newTab?: boolean | null;
reference?: {
relationTo: 'pages';
value: string | Page;
} | null;
reference?:
| ({
relationTo: 'pages';
value: string | Page;
} | null)
| ({
relationTo: 'posts';
value: string | Post;
} | null);
url?: string | null;
label: string;
appearance?: ('default' | 'outline') | null;
Expand All @@ -132,6 +137,50 @@ export interface Page {
createdAt: string;
_status?: ('draft' | 'published') | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "posts".
*/
export interface Post {
id: string;
title: string;
heroImage?: (string | null) | Media;
content: {
root: {
type: string;
children: {
type: string;
version: number;
[k: string]: unknown;
}[];
direction: ('ltr' | 'rtl') | null;
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
indent: number;
version: number;
};
[k: string]: unknown;
};
relatedPosts?: (string | Post)[] | null;
categories?: (string | Category)[] | null;
meta?: {
title?: string | null;
image?: (string | null) | Media;
description?: string | null;
};
publishedAt?: string | null;
authors?: (string | User)[] | null;
populatedAuthors?:
| {
id?: string | null;
name?: string | null;
}[]
| null;
slug?: string | null;
slugLock?: boolean | null;
updatedAt: string;
createdAt: string;
_status?: ('draft' | 'published') | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "media".
Expand Down Expand Up @@ -224,6 +273,43 @@ export interface Media {
};
};
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "categories".
*/
export interface Category {
id: string;
title: string;
parent?: (string | null) | Category;
breadcrumbs?:
| {
doc?: (string | null) | Category;
url?: string | null;
label?: string | null;
id?: string | null;
}[]
| null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "users".
*/
export interface User {
id: string;
name?: string | null;
updatedAt: string;
createdAt: string;
email: string;
resetPasswordToken?: string | null;
resetPasswordExpiration?: string | null;
salt?: string | null;
hash?: string | null;
loginAttempts?: number | null;
lockUntil?: string | null;
password?: string | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "CallToActionBlock".
Expand All @@ -249,10 +335,15 @@ export interface CallToActionBlock {
link: {
type?: ('reference' | 'custom') | null;
newTab?: boolean | null;
reference?: {
relationTo: 'pages';
value: string | Page;
} | null;
reference?:
| ({
relationTo: 'pages';
value: string | Page;
} | null)
| ({
relationTo: 'posts';
value: string | Post;
} | null);
url?: string | null;
label: string;
appearance?: ('default' | 'outline') | null;
Expand Down Expand Up @@ -291,10 +382,15 @@ export interface ContentBlock {
link?: {
type?: ('reference' | 'custom') | null;
newTab?: boolean | null;
reference?: {
relationTo: 'pages';
value: string | Page;
} | null;
reference?:
| ({
relationTo: 'pages';
value: string | Page;
} | null)
| ({
relationTo: 'posts';
value: string | Post;
} | null);
url?: string | null;
label: string;
appearance?: ('default' | 'outline') | null;
Expand Down Expand Up @@ -350,87 +446,6 @@ export interface ArchiveBlock {
blockName?: string | null;
blockType: 'archive';
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "categories".
*/
export interface Category {
id: string;
title: string;
parent?: (string | null) | Category;
breadcrumbs?:
| {
doc?: (string | null) | Category;
url?: string | null;
label?: string | null;
id?: string | null;
}[]
| null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "posts".
*/
export interface Post {
id: string;
title: string;
heroImage?: (string | null) | Media;
content: {
root: {
type: string;
children: {
type: string;
version: number;
[k: string]: unknown;
}[];
direction: ('ltr' | 'rtl') | null;
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
indent: number;
version: number;
};
[k: string]: unknown;
};
relatedPosts?: (string | Post)[] | null;
categories?: (string | Category)[] | null;
meta?: {
title?: string | null;
image?: (string | null) | Media;
description?: string | null;
};
publishedAt?: string | null;
authors?: (string | User)[] | null;
populatedAuthors?:
| {
id?: string | null;
name?: string | null;
}[]
| null;
slug?: string | null;
slugLock?: boolean | null;
updatedAt: string;
createdAt: string;
_status?: ('draft' | 'published') | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "users".
*/
export interface User {
id: string;
name?: string | null;
updatedAt: string;
createdAt: string;
email: string;
resetPasswordToken?: string | null;
resetPasswordExpiration?: string | null;
salt?: string | null;
hash?: string | null;
loginAttempts?: number | null;
lockUntil?: string | null;
password?: string | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "FormBlock".
Expand Down Expand Up @@ -1285,10 +1300,15 @@ export interface Header {
link: {
type?: ('reference' | 'custom') | null;
newTab?: boolean | null;
reference?: {
relationTo: 'pages';
value: string | Page;
} | null;
reference?:
| ({
relationTo: 'pages';
value: string | Page;
} | null)
| ({
relationTo: 'posts';
value: string | Post;
} | null);
url?: string | null;
label: string;
};
Expand All @@ -1309,10 +1329,15 @@ export interface Footer {
link: {
type?: ('reference' | 'custom') | null;
newTab?: boolean | null;
reference?: {
relationTo: 'pages';
value: string | Page;
} | null;
reference?:
| ({
relationTo: 'pages';
value: string | Page;
} | null)
| ({
relationTo: 'posts';
value: string | Post;
} | null);
url?: string | null;
label: string;
};
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const plugins: Plugin[] = [
redirectsPlugin({
collections: ['pages', 'posts'],
overrides: {
// @ts-expect-error
// @ts-expect-error - This is a valid override, mapped fields don't resolve to the same type
fields: ({ defaultFields }) => {
return defaultFields.map((field) => {
if ('name' in field && field.name === 'from') {
Expand Down
2 changes: 1 addition & 1 deletion templates/with-vercel-website/src/fields/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const link: LinkType = ({ appearances, disableLabel = false, overrides =
condition: (_, siblingData) => siblingData?.type === 'reference',
},
label: 'Document to link to',
relationTo: ['pages'],
relationTo: ['pages', 'posts'],
required: true,
},
{
Expand Down
Loading