Skip to content

Commit 605cf42

Browse files
authored
templates: add Posts to internal links in website template (#10063)
Posts were previously not selectable as part of the internal links (reference fields) in the website template.
1 parent 97c120a commit 605cf42

File tree

6 files changed

+256
-206
lines changed

6 files changed

+256
-206
lines changed

templates/website/src/fields/link.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const link: LinkType = ({ appearances, disableLabel = false, overrides =
7575
condition: (_, siblingData) => siblingData?.type === 'reference',
7676
},
7777
label: 'Document to link to',
78-
relationTo: ['pages'],
78+
relationTo: ['pages', 'posts'],
7979
required: true,
8080
},
8181
{

templates/website/src/payload-types.ts

Lines changed: 126 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,15 @@ export interface Page {
106106
link: {
107107
type?: ('reference' | 'custom') | null;
108108
newTab?: boolean | null;
109-
reference?: {
110-
relationTo: 'pages';
111-
value: string | Page;
112-
} | null;
109+
reference?:
110+
| ({
111+
relationTo: 'pages';
112+
value: string | Page;
113+
} | null)
114+
| ({
115+
relationTo: 'posts';
116+
value: string | Post;
117+
} | null);
113118
url?: string | null;
114119
label: string;
115120
appearance?: ('default' | 'outline') | null;
@@ -132,6 +137,50 @@ export interface Page {
132137
createdAt: string;
133138
_status?: ('draft' | 'published') | null;
134139
}
140+
/**
141+
* This interface was referenced by `Config`'s JSON-Schema
142+
* via the `definition` "posts".
143+
*/
144+
export interface Post {
145+
id: string;
146+
title: string;
147+
heroImage?: (string | null) | Media;
148+
content: {
149+
root: {
150+
type: string;
151+
children: {
152+
type: string;
153+
version: number;
154+
[k: string]: unknown;
155+
}[];
156+
direction: ('ltr' | 'rtl') | null;
157+
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
158+
indent: number;
159+
version: number;
160+
};
161+
[k: string]: unknown;
162+
};
163+
relatedPosts?: (string | Post)[] | null;
164+
categories?: (string | Category)[] | null;
165+
meta?: {
166+
title?: string | null;
167+
image?: (string | null) | Media;
168+
description?: string | null;
169+
};
170+
publishedAt?: string | null;
171+
authors?: (string | User)[] | null;
172+
populatedAuthors?:
173+
| {
174+
id?: string | null;
175+
name?: string | null;
176+
}[]
177+
| null;
178+
slug?: string | null;
179+
slugLock?: boolean | null;
180+
updatedAt: string;
181+
createdAt: string;
182+
_status?: ('draft' | 'published') | null;
183+
}
135184
/**
136185
* This interface was referenced by `Config`'s JSON-Schema
137186
* via the `definition` "media".
@@ -224,6 +273,43 @@ export interface Media {
224273
};
225274
};
226275
}
276+
/**
277+
* This interface was referenced by `Config`'s JSON-Schema
278+
* via the `definition` "categories".
279+
*/
280+
export interface Category {
281+
id: string;
282+
title: string;
283+
parent?: (string | null) | Category;
284+
breadcrumbs?:
285+
| {
286+
doc?: (string | null) | Category;
287+
url?: string | null;
288+
label?: string | null;
289+
id?: string | null;
290+
}[]
291+
| null;
292+
updatedAt: string;
293+
createdAt: string;
294+
}
295+
/**
296+
* This interface was referenced by `Config`'s JSON-Schema
297+
* via the `definition` "users".
298+
*/
299+
export interface User {
300+
id: string;
301+
name?: string | null;
302+
updatedAt: string;
303+
createdAt: string;
304+
email: string;
305+
resetPasswordToken?: string | null;
306+
resetPasswordExpiration?: string | null;
307+
salt?: string | null;
308+
hash?: string | null;
309+
loginAttempts?: number | null;
310+
lockUntil?: string | null;
311+
password?: string | null;
312+
}
227313
/**
228314
* This interface was referenced by `Config`'s JSON-Schema
229315
* via the `definition` "CallToActionBlock".
@@ -249,10 +335,15 @@ export interface CallToActionBlock {
249335
link: {
250336
type?: ('reference' | 'custom') | null;
251337
newTab?: boolean | null;
252-
reference?: {
253-
relationTo: 'pages';
254-
value: string | Page;
255-
} | null;
338+
reference?:
339+
| ({
340+
relationTo: 'pages';
341+
value: string | Page;
342+
} | null)
343+
| ({
344+
relationTo: 'posts';
345+
value: string | Post;
346+
} | null);
256347
url?: string | null;
257348
label: string;
258349
appearance?: ('default' | 'outline') | null;
@@ -291,10 +382,15 @@ export interface ContentBlock {
291382
link?: {
292383
type?: ('reference' | 'custom') | null;
293384
newTab?: boolean | null;
294-
reference?: {
295-
relationTo: 'pages';
296-
value: string | Page;
297-
} | null;
385+
reference?:
386+
| ({
387+
relationTo: 'pages';
388+
value: string | Page;
389+
} | null)
390+
| ({
391+
relationTo: 'posts';
392+
value: string | Post;
393+
} | null);
298394
url?: string | null;
299395
label: string;
300396
appearance?: ('default' | 'outline') | null;
@@ -350,87 +446,6 @@ export interface ArchiveBlock {
350446
blockName?: string | null;
351447
blockType: 'archive';
352448
}
353-
/**
354-
* This interface was referenced by `Config`'s JSON-Schema
355-
* via the `definition` "categories".
356-
*/
357-
export interface Category {
358-
id: string;
359-
title: string;
360-
parent?: (string | null) | Category;
361-
breadcrumbs?:
362-
| {
363-
doc?: (string | null) | Category;
364-
url?: string | null;
365-
label?: string | null;
366-
id?: string | null;
367-
}[]
368-
| null;
369-
updatedAt: string;
370-
createdAt: string;
371-
}
372-
/**
373-
* This interface was referenced by `Config`'s JSON-Schema
374-
* via the `definition` "posts".
375-
*/
376-
export interface Post {
377-
id: string;
378-
title: string;
379-
heroImage?: (string | null) | Media;
380-
content: {
381-
root: {
382-
type: string;
383-
children: {
384-
type: string;
385-
version: number;
386-
[k: string]: unknown;
387-
}[];
388-
direction: ('ltr' | 'rtl') | null;
389-
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
390-
indent: number;
391-
version: number;
392-
};
393-
[k: string]: unknown;
394-
};
395-
relatedPosts?: (string | Post)[] | null;
396-
categories?: (string | Category)[] | null;
397-
meta?: {
398-
title?: string | null;
399-
image?: (string | null) | Media;
400-
description?: string | null;
401-
};
402-
publishedAt?: string | null;
403-
authors?: (string | User)[] | null;
404-
populatedAuthors?:
405-
| {
406-
id?: string | null;
407-
name?: string | null;
408-
}[]
409-
| null;
410-
slug?: string | null;
411-
slugLock?: boolean | null;
412-
updatedAt: string;
413-
createdAt: string;
414-
_status?: ('draft' | 'published') | null;
415-
}
416-
/**
417-
* This interface was referenced by `Config`'s JSON-Schema
418-
* via the `definition` "users".
419-
*/
420-
export interface User {
421-
id: string;
422-
name?: string | null;
423-
updatedAt: string;
424-
createdAt: string;
425-
email: string;
426-
resetPasswordToken?: string | null;
427-
resetPasswordExpiration?: string | null;
428-
salt?: string | null;
429-
hash?: string | null;
430-
loginAttempts?: number | null;
431-
lockUntil?: string | null;
432-
password?: string | null;
433-
}
434449
/**
435450
* This interface was referenced by `Config`'s JSON-Schema
436451
* via the `definition` "FormBlock".
@@ -1285,10 +1300,15 @@ export interface Header {
12851300
link: {
12861301
type?: ('reference' | 'custom') | null;
12871302
newTab?: boolean | null;
1288-
reference?: {
1289-
relationTo: 'pages';
1290-
value: string | Page;
1291-
} | null;
1303+
reference?:
1304+
| ({
1305+
relationTo: 'pages';
1306+
value: string | Page;
1307+
} | null)
1308+
| ({
1309+
relationTo: 'posts';
1310+
value: string | Post;
1311+
} | null);
12921312
url?: string | null;
12931313
label: string;
12941314
};
@@ -1309,10 +1329,15 @@ export interface Footer {
13091329
link: {
13101330
type?: ('reference' | 'custom') | null;
13111331
newTab?: boolean | null;
1312-
reference?: {
1313-
relationTo: 'pages';
1314-
value: string | Page;
1315-
} | null;
1332+
reference?:
1333+
| ({
1334+
relationTo: 'pages';
1335+
value: string | Page;
1336+
} | null)
1337+
| ({
1338+
relationTo: 'posts';
1339+
value: string | Post;
1340+
} | null);
13161341
url?: string | null;
13171342
label: string;
13181343
};

templates/website/src/plugins/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const plugins: Plugin[] = [
2828
redirectsPlugin({
2929
collections: ['pages', 'posts'],
3030
overrides: {
31-
// @ts-expect-error
31+
// @ts-expect-error - This is a valid override, mapped fields don't resolve to the same type
3232
fields: ({ defaultFields }) => {
3333
return defaultFields.map((field) => {
3434
if ('name' in field && field.name === 'from') {

templates/with-vercel-website/src/fields/link.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const link: LinkType = ({ appearances, disableLabel = false, overrides =
7575
condition: (_, siblingData) => siblingData?.type === 'reference',
7676
},
7777
label: 'Document to link to',
78-
relationTo: ['pages'],
78+
relationTo: ['pages', 'posts'],
7979
required: true,
8080
},
8181
{

0 commit comments

Comments
 (0)