Skip to content

Commit

Permalink
templates: add hero image field to posts instead of using the meta im…
Browse files Browse the repository at this point in the history
…age for the hero as well (#9999)

Adds a hero image field instead of using the meta image for the hero on
posts collection
  • Loading branch information
paulpopus authored Dec 16, 2024
1 parent 6dea111 commit 12fa4fd
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 12 deletions.
4 changes: 2 additions & 2 deletions templates/website/src/blocks/RenderBlocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export const RenderBlocks: React.FC<{
if (Block) {
return (
<div className="my-16" key={index}>
{/* @ts-expect-error */}
<Block {...block} />
{/* @ts-expect-error there may be some mismatch between the expected types here */}
<Block {...block} disableInnerContainer />
</div>
)
}
Expand Down
5 changes: 5 additions & 0 deletions templates/website/src/collections/Posts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export const Posts: CollectionConfig<'posts'> = {
tabs: [
{
fields: [
{
name: 'heroImage',
type: 'upload',
relationTo: 'media',
},
{
name: 'content',
type: 'richText',
Expand Down
1 change: 0 additions & 1 deletion templates/website/src/components/ui/card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable jsx-a11y/heading-has-content */
import { cn } from 'src/utilities/cn'
import * as React from 'react'

Expand Down
1 change: 0 additions & 1 deletion templates/website/src/components/ui/pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/button-has-type */
import type { ButtonProps } from '@/components/ui/button'

import { buttonVariants } from '@/components/ui/button'
Expand Down
5 changes: 5 additions & 0 deletions templates/website/src/endpoints/seed/image-hero-1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Media } from '@/payload-types'

export const imageHero1: Omit<Media, 'createdAt' | 'id' | 'updatedAt'> = {
alt: 'Straight metallic shapes with a blue gradient',
}
7 changes: 4 additions & 3 deletions templates/website/src/endpoints/seed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { contact as contactPageData } from './contact-page'
import { home } from './home'
import { image1 } from './image-1'
import { image2 } from './image-2'
import { imageHero1 } from './image-hero-1'
import { post1 } from './post-1'
import { post2 } from './post-2'
import { post3 } from './post-3'
Expand Down Expand Up @@ -72,7 +73,7 @@ export const seed = async ({
depth: 0,
where: {
email: {
equals: 'demo-author@payloadcms.com',
equals: 'demo-author@example.com',
},
},
})
Expand Down Expand Up @@ -111,7 +112,7 @@ export const seed = async ({
collection: 'users',
data: {
name: 'Demo Author',
email: 'demo-author@payloadcms.com',
email: 'demo-author@example.com',
password: 'password',
},
}),
Expand All @@ -132,7 +133,7 @@ export const seed = async ({
}),
payload.create({
collection: 'media',
data: image2,
data: imageHero1,
file: hero1Buffer,
}),

Expand Down
4 changes: 3 additions & 1 deletion templates/website/src/endpoints/seed/post-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Post } from '@/payload-types'
export const post1: Partial<Post> = {
slug: 'digital-horizons',
_status: 'published',
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
authors: ['{{AUTHOR}}'],
content: {
Expand Down Expand Up @@ -291,10 +292,11 @@ export const post1: Partial<Post> = {
version: 1,
},
},

heroImage: '{{IMAGE_1}}',
meta: {
description:
'Dive into the marvels of modern innovation, where the only constant is change. A journey where pixels and data converge to craft the future.',
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
image: '{{IMAGE_1}}',
title: 'Digital Horizons: A Glimpse into Tomorrow',
Expand Down
3 changes: 3 additions & 0 deletions templates/website/src/endpoints/seed/post-2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Post } from '@/payload-types'
export const post2: Partial<Post> = {
slug: 'global-gaze',
_status: 'published',
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
authors: ['{{AUTHOR}}'],
content: {
Expand Down Expand Up @@ -214,9 +215,11 @@ export const post2: Partial<Post> = {
version: 1,
},
},
heroImage: '{{IMAGE_1}}',
meta: {
description:
'Explore the untold and overlooked. A magnified view into the corners of the world, where every story deserves its spotlight.',
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
image: '{{IMAGE_1}}',
title: 'Global Gaze: Beyond the Headlines',
Expand Down
3 changes: 3 additions & 0 deletions templates/website/src/endpoints/seed/post-3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Post } from '@/payload-types'
export const post3: Partial<Post> = {
slug: 'dollar-and-sense-the-financial-forecast',
_status: 'published',
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
authors: ['{{AUTHOR}}'],
content: {
Expand Down Expand Up @@ -251,8 +252,10 @@ export const post3: Partial<Post> = {
version: 1,
},
},
heroImage: '{{IMAGE_1}}',
meta: {
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.`,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
image: '{{IMAGE_1}}',
title: 'Dollar and Sense: The Financial Forecast',
Expand Down
6 changes: 3 additions & 3 deletions templates/website/src/heros/PostHero/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { formatAuthors } from '@/utilities/formatAuthors'
export const PostHero: React.FC<{
post: Post
}> = ({ post }) => {
const { categories, meta: { image: metaImage } = {}, populatedAuthors, publishedAt, title } = post
const { categories, heroImage, populatedAuthors, publishedAt, title } = post

const hasAuthors =
populatedAuthors && populatedAuthors.length > 0 && formatAuthors(populatedAuthors) !== ''
Expand Down Expand Up @@ -63,13 +63,13 @@ export const PostHero: React.FC<{
</div>
</div>
<div className="min-h-[80vh] select-none">
{metaImage && typeof metaImage !== 'string' && (
{heroImage && typeof heroImage !== 'string' && (
<Media
fill
priority={false}
loading="lazy"
imgClassName="-z-10 object-cover"
resource={metaImage}
resource={heroImage}
/>
)}
<div className="absolute pointer-events-none left-0 bottom-0 w-full h-1/2 bg-gradient-to-t from-black to-transparent" />
Expand Down
2 changes: 2 additions & 0 deletions templates/website/src/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ export interface Category {
export interface Post {
id: string;
title: string;
heroImage?: (string | null) | Media;
content: {
root: {
type: string;
Expand Down Expand Up @@ -899,6 +900,7 @@ export interface PagesSelect<T extends boolean = true> {
*/
export interface PostsSelect<T extends boolean = true> {
title?: T;
heroImage?: T;
content?: T;
relatedPosts?: T;
categories?: T;
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/providers/Theme/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type Theme = 'dark' | 'light'

export interface ThemeContextType {
setTheme: (theme: Theme | null) => void // eslint-disable-line no-unused-vars
setTheme: (theme: Theme | null) => void
theme?: Theme | null
}

Expand Down

0 comments on commit 12fa4fd

Please sign in to comment.