diff --git a/templates/website/src/fields/link.ts b/templates/website/src/fields/link.ts index 74d64d865d7..344d551cdd6 100644 --- a/templates/website/src/fields/link.ts +++ b/templates/website/src/fields/link.ts @@ -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, }, { diff --git a/templates/website/src/payload-types.ts b/templates/website/src/payload-types.ts index 10cee117c1d..4663ca9feb9 100644 --- a/templates/website/src/payload-types.ts +++ b/templates/website/src/payload-types.ts @@ -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; @@ -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". @@ -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". @@ -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; @@ -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; @@ -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". @@ -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; }; @@ -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; }; diff --git a/templates/website/src/plugins/index.ts b/templates/website/src/plugins/index.ts index b8a3df19583..f958a52ac77 100644 --- a/templates/website/src/plugins/index.ts +++ b/templates/website/src/plugins/index.ts @@ -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') { diff --git a/templates/with-vercel-website/src/fields/link.ts b/templates/with-vercel-website/src/fields/link.ts index 74d64d865d7..344d551cdd6 100644 --- a/templates/with-vercel-website/src/fields/link.ts +++ b/templates/with-vercel-website/src/fields/link.ts @@ -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, }, { diff --git a/templates/with-vercel-website/src/payload-types.ts b/templates/with-vercel-website/src/payload-types.ts index c273ffd4b5c..19a638fc1ad 100644 --- a/templates/with-vercel-website/src/payload-types.ts +++ b/templates/with-vercel-website/src/payload-types.ts @@ -106,10 +106,15 @@ export interface Page { link: { type?: ('reference' | 'custom') | null; newTab?: boolean | null; - reference?: { - relationTo: 'pages'; - value: number | Page; - } | null; + reference?: + | ({ + relationTo: 'pages'; + value: number | Page; + } | null) + | ({ + relationTo: 'posts'; + value: number | Post; + } | null); url?: string | null; label: string; appearance?: ('default' | 'outline') | null; @@ -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: number; + title: string; + heroImage?: (number | 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?: (number | Post)[] | null; + categories?: (number | Category)[] | null; + meta?: { + title?: string | null; + image?: (number | null) | Media; + description?: string | null; + }; + publishedAt?: string | null; + authors?: (number | 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". @@ -224,6 +273,43 @@ export interface Media { }; }; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "categories". + */ +export interface Category { + id: number; + title: string; + parent?: (number | null) | Category; + breadcrumbs?: + | { + doc?: (number | 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: number; + 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". @@ -249,10 +335,15 @@ export interface CallToActionBlock { link: { type?: ('reference' | 'custom') | null; newTab?: boolean | null; - reference?: { - relationTo: 'pages'; - value: number | Page; - } | null; + reference?: + | ({ + relationTo: 'pages'; + value: number | Page; + } | null) + | ({ + relationTo: 'posts'; + value: number | Post; + } | null); url?: string | null; label: string; appearance?: ('default' | 'outline') | null; @@ -291,10 +382,15 @@ export interface ContentBlock { link?: { type?: ('reference' | 'custom') | null; newTab?: boolean | null; - reference?: { - relationTo: 'pages'; - value: number | Page; - } | null; + reference?: + | ({ + relationTo: 'pages'; + value: number | Page; + } | null) + | ({ + relationTo: 'posts'; + value: number | Post; + } | null); url?: string | null; label: string; appearance?: ('default' | 'outline') | null; @@ -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: number; - title: string; - parent?: (number | null) | Category; - breadcrumbs?: - | { - doc?: (number | 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: number; - title: string; - heroImage?: (number | 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?: (number | Post)[] | null; - categories?: (number | Category)[] | null; - meta?: { - title?: string | null; - image?: (number | null) | Media; - description?: string | null; - }; - publishedAt?: string | null; - authors?: (number | 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: number; - 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". @@ -1300,10 +1315,15 @@ export interface Header { link: { type?: ('reference' | 'custom') | null; newTab?: boolean | null; - reference?: { - relationTo: 'pages'; - value: number | Page; - } | null; + reference?: + | ({ + relationTo: 'pages'; + value: number | Page; + } | null) + | ({ + relationTo: 'posts'; + value: number | Post; + } | null); url?: string | null; label: string; }; @@ -1324,10 +1344,15 @@ export interface Footer { link: { type?: ('reference' | 'custom') | null; newTab?: boolean | null; - reference?: { - relationTo: 'pages'; - value: number | Page; - } | null; + reference?: + | ({ + relationTo: 'pages'; + value: number | Page; + } | null) + | ({ + relationTo: 'posts'; + value: number | Post; + } | null); url?: string | null; label: string; }; diff --git a/templates/with-vercel-website/src/plugins/index.ts b/templates/with-vercel-website/src/plugins/index.ts index b8a3df19583..f958a52ac77 100644 --- a/templates/with-vercel-website/src/plugins/index.ts +++ b/templates/with-vercel-website/src/plugins/index.ts @@ -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') {