Skip to content

Commit 12fa4fd

Browse files
authored
templates: add hero image field to posts instead of using the meta image for the hero as well (#9999)
Adds a hero image field instead of using the meta image for the hero on posts collection
1 parent 6dea111 commit 12fa4fd

File tree

12 files changed

+31
-12
lines changed

12 files changed

+31
-12
lines changed

templates/website/src/blocks/RenderBlocks.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export const RenderBlocks: React.FC<{
3636
if (Block) {
3737
return (
3838
<div className="my-16" key={index}>
39-
{/* @ts-expect-error */}
40-
<Block {...block} />
39+
{/* @ts-expect-error there may be some mismatch between the expected types here */}
40+
<Block {...block} disableInnerContainer />
4141
</div>
4242
)
4343
}

templates/website/src/collections/Posts/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ export const Posts: CollectionConfig<'posts'> = {
7979
tabs: [
8080
{
8181
fields: [
82+
{
83+
name: 'heroImage',
84+
type: 'upload',
85+
relationTo: 'media',
86+
},
8287
{
8388
name: 'content',
8489
type: 'richText',

templates/website/src/components/ui/card.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable jsx-a11y/heading-has-content */
21
import { cn } from 'src/utilities/cn'
32
import * as React from 'react'
43

templates/website/src/components/ui/pagination.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable react/button-has-type */
21
import type { ButtonProps } from '@/components/ui/button'
32

43
import { buttonVariants } from '@/components/ui/button'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { Media } from '@/payload-types'
2+
3+
export const imageHero1: Omit<Media, 'createdAt' | 'id' | 'updatedAt'> = {
4+
alt: 'Straight metallic shapes with a blue gradient',
5+
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { contact as contactPageData } from './contact-page'
55
import { home } from './home'
66
import { image1 } from './image-1'
77
import { image2 } from './image-2'
8+
import { imageHero1 } from './image-hero-1'
89
import { post1 } from './post-1'
910
import { post2 } from './post-2'
1011
import { post3 } from './post-3'
@@ -72,7 +73,7 @@ export const seed = async ({
7273
depth: 0,
7374
where: {
7475
email: {
75-
equals: 'demo-author@payloadcms.com',
76+
equals: 'demo-author@example.com',
7677
},
7778
},
7879
})
@@ -111,7 +112,7 @@ export const seed = async ({
111112
collection: 'users',
112113
data: {
113114
name: 'Demo Author',
114-
email: 'demo-author@payloadcms.com',
115+
email: 'demo-author@example.com',
115116
password: 'password',
116117
},
117118
}),
@@ -132,7 +133,7 @@ export const seed = async ({
132133
}),
133134
payload.create({
134135
collection: 'media',
135-
data: image2,
136+
data: imageHero1,
136137
file: hero1Buffer,
137138
}),
138139

templates/website/src/endpoints/seed/post-1.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Post } from '@/payload-types'
33
export const post1: Partial<Post> = {
44
slug: 'digital-horizons',
55
_status: 'published',
6+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
67
// @ts-ignore
78
authors: ['{{AUTHOR}}'],
89
content: {
@@ -291,10 +292,11 @@ export const post1: Partial<Post> = {
291292
version: 1,
292293
},
293294
},
294-
295+
heroImage: '{{IMAGE_1}}',
295296
meta: {
296297
description:
297298
'Dive into the marvels of modern innovation, where the only constant is change. A journey where pixels and data converge to craft the future.',
299+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
298300
// @ts-ignore
299301
image: '{{IMAGE_1}}',
300302
title: 'Digital Horizons: A Glimpse into Tomorrow',

templates/website/src/endpoints/seed/post-2.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Post } from '@/payload-types'
33
export const post2: Partial<Post> = {
44
slug: 'global-gaze',
55
_status: 'published',
6+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
67
// @ts-ignore
78
authors: ['{{AUTHOR}}'],
89
content: {
@@ -214,9 +215,11 @@ export const post2: Partial<Post> = {
214215
version: 1,
215216
},
216217
},
218+
heroImage: '{{IMAGE_1}}',
217219
meta: {
218220
description:
219221
'Explore the untold and overlooked. A magnified view into the corners of the world, where every story deserves its spotlight.',
222+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
220223
// @ts-ignore
221224
image: '{{IMAGE_1}}',
222225
title: 'Global Gaze: Beyond the Headlines',

templates/website/src/endpoints/seed/post-3.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Post } from '@/payload-types'
33
export const post3: Partial<Post> = {
44
slug: 'dollar-and-sense-the-financial-forecast',
55
_status: 'published',
6+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
67
// @ts-ignore
78
authors: ['{{AUTHOR}}'],
89
content: {
@@ -251,8 +252,10 @@ export const post3: Partial<Post> = {
251252
version: 1,
252253
},
253254
},
255+
heroImage: '{{IMAGE_1}}',
254256
meta: {
255257
description: `Money isn't just currency; it's a language. Dive deep into its nuances, where strategy meets intuition in the vast sea of finance.`,
258+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
256259
// @ts-ignore
257260
image: '{{IMAGE_1}}',
258261
title: 'Dollar and Sense: The Financial Forecast',

templates/website/src/heros/PostHero/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { formatAuthors } from '@/utilities/formatAuthors'
99
export const PostHero: React.FC<{
1010
post: Post
1111
}> = ({ post }) => {
12-
const { categories, meta: { image: metaImage } = {}, populatedAuthors, publishedAt, title } = post
12+
const { categories, heroImage, populatedAuthors, publishedAt, title } = post
1313

1414
const hasAuthors =
1515
populatedAuthors && populatedAuthors.length > 0 && formatAuthors(populatedAuthors) !== ''
@@ -63,13 +63,13 @@ export const PostHero: React.FC<{
6363
</div>
6464
</div>
6565
<div className="min-h-[80vh] select-none">
66-
{metaImage && typeof metaImage !== 'string' && (
66+
{heroImage && typeof heroImage !== 'string' && (
6767
<Media
6868
fill
6969
priority={false}
7070
loading="lazy"
7171
imgClassName="-z-10 object-cover"
72-
resource={metaImage}
72+
resource={heroImage}
7373
/>
7474
)}
7575
<div className="absolute pointer-events-none left-0 bottom-0 w-full h-1/2 bg-gradient-to-t from-black to-transparent" />

0 commit comments

Comments
 (0)