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: improvements to seed speed on website template and updated hero and collapsible fields #9779

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
13 changes: 13 additions & 0 deletions templates/website/src/Footer/RowLabel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use client'
import { Header } from '@/payload-types'
import { RowLabelProps, useRowLabel } from '@payloadcms/ui'

export const RowLabel: React.FC<RowLabelProps> = (props) => {
const data = useRowLabel<NonNullable<Header['navItems']>[number]>()

const label = data?.data?.link?.label
? `Nav item ${data.rowNumber !== undefined ? data.rowNumber + 1 : ''}: ${data?.data?.link?.label}`
: 'Row'

return <div>{label}</div>
}
6 changes: 6 additions & 0 deletions templates/website/src/Footer/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export const Footer: GlobalConfig = {
}),
],
maxRows: 6,
admin: {
initCollapsed: true,
components: {
RowLabel: '@/Footer/RowLabel#RowLabel',
},
},
},
],
hooks: {
Expand Down
13 changes: 13 additions & 0 deletions templates/website/src/Header/RowLabel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use client'
import { Header } from '@/payload-types'
import { RowLabelProps, useRowLabel } from '@payloadcms/ui'

export const RowLabel: React.FC<RowLabelProps> = (props) => {
const data = useRowLabel<NonNullable<Header['navItems']>[number]>()

const label = data?.data?.link?.label
? `Nav item ${data.rowNumber !== undefined ? data.rowNumber + 1 : ''}: ${data?.data?.link?.label}`
: 'Row'

return <div>{label}</div>
}
6 changes: 6 additions & 0 deletions templates/website/src/Header/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export const Header: GlobalConfig = {
}),
],
maxRows: 6,
admin: {
initCollapsed: true,
components: {
RowLabel: '@/Header/RowLabel#RowLabel',
},
},
},
],
hooks: {
Expand Down
4 changes: 4 additions & 0 deletions templates/website/src/app/(payload)/admin/importMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { HorizontalRuleFeatureClient as HorizontalRuleFeatureClient_e70f5e05f09f
import { BlocksFeatureClient as BlocksFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
import { LinkToDoc as LinkToDoc_aead06e4cbf6b2620c5c51c9ab283634 } from '@payloadcms/plugin-search/client'
import { ReindexButton as ReindexButton_aead06e4cbf6b2620c5c51c9ab283634 } from '@payloadcms/plugin-search/client'
import { RowLabel as RowLabel_ec255a65fa6fa8d1faeb09cf35284224 } from '@/Header/RowLabel'
import { RowLabel as RowLabel_1f6ff6ff633e3695d348f4f3c58f1466 } from '@/Footer/RowLabel'
import { default as default_1a7510af427896d367a49dbf838d2de6 } from '@/components/BeforeDashboard'
import { default as default_8a7ab0eb7ab5c511aba12e68480bfe5e } from '@/components/BeforeLogin'

Expand Down Expand Up @@ -59,6 +61,8 @@ export const importMap = {
BlocksFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
'@payloadcms/plugin-search/client#LinkToDoc': LinkToDoc_aead06e4cbf6b2620c5c51c9ab283634,
'@payloadcms/plugin-search/client#ReindexButton': ReindexButton_aead06e4cbf6b2620c5c51c9ab283634,
'@/Header/RowLabel#RowLabel': RowLabel_ec255a65fa6fa8d1faeb09cf35284224,
'@/Footer/RowLabel#RowLabel': RowLabel_1f6ff6ff633e3695d348f4f3c58f1466,
'@/components/BeforeDashboard#default': default_1a7510af427896d367a49dbf838d2de6,
'@/components/BeforeLogin#default': default_8a7ab0eb7ab5c511aba12e68480bfe5e,
}
3 changes: 3 additions & 0 deletions templates/website/src/blocks/Content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export const Content: Block = {
{
name: 'columns',
type: 'array',
admin: {
initCollapsed: true,
},
fields: columnFields,
},
],
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/blocks/RelatedPosts/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const RelatedPosts: React.FC<RelatedPostsProps> = (props) => {
const { className, docs, introContent } = props

return (
<div className={clsx('container', className)}>
<div className={clsx('lg:container', className)}>
{introContent && <RichText data={introContent} enableGutter={false} />}

<div className="grid grid-cols-1 md:grid-cols-2 gap-4 md:gap-8 items-stretch">
Expand Down
3 changes: 3 additions & 0 deletions templates/website/src/collections/Pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export const Pages: CollectionConfig<'pages'> = {
type: 'blocks',
blocks: [CallToAction, Content, MediaBlock, Archive, FormBlock],
required: true,
admin: {
initCollapsed: true,
},
},
],
label: 'Content',
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/components/RichText/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function RichText(props: Props) {
{
'container ': enableGutter,
'max-w-none': !enableGutter,
'mx-auto prose dark:prose-invert ': enableProse,
'mx-auto prose md:prose-md dark:prose-invert ': enableProse,
},
className,
)}
Expand Down
102 changes: 51 additions & 51 deletions templates/website/src/endpoints/seed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const seed = async ({
// this is because while `yarn seed` drops the database
// the custom `/api/seed` endpoint does not
payload.logger.info(`— Clearing collections and globals...`)

// clear the database
await Promise.all(
globals.map((global) =>
Expand All @@ -54,16 +55,9 @@ export const seed = async ({
),
)

for (const collection of collections) {
await payload.delete({
collection: collection,
where: {},
depth: 0,
context: {
disableRevalidate: true,
},
})
}
await Promise.all(
collections.map((collection) => payload.db.deleteMany({ collection, req, where: {} })),
)

payload.logger.info(`— Seeding demo author and user...`)

Expand All @@ -78,6 +72,7 @@ export const seed = async ({
})

payload.logger.info(`— Seeding media...`)

const [image1Buffer, image2Buffer, image3Buffer, hero1Buffer] = await Promise.all([
fetchFileByURL(
'https://raw.githubusercontent.com/payloadcms/payload/refs/heads/main/templates/website/src/endpoints/seed/image-post1.webp',
Expand All @@ -102,6 +97,9 @@ export const seed = async ({
technologyCategory,
newsCategory,
financeCategory,
designCategory,
softwareCategory,
engineeringCategory,
] = await Promise.all([
payload.create({
collection: 'users',
Expand Down Expand Up @@ -152,29 +150,29 @@ export const seed = async ({
title: 'Finance',
},
}),
])
let demoAuthorID: number | string = demoAuthor.id
payload.create({
collection: 'categories',
data: {
title: 'Design',
},
}),

await payload.create({
collection: 'categories',
data: {
title: 'Design',
},
})
payload.create({
collection: 'categories',
data: {
title: 'Software',
},
}),

await payload.create({
collection: 'categories',
data: {
title: 'Software',
},
})
payload.create({
collection: 'categories',
data: {
title: 'Engineering',
},
}),
])

await payload.create({
collection: 'categories',
data: {
title: 'Engineering',
},
})
let demoAuthorID: number | string = demoAuthor.id

let image1ID: number | string = image1Doc.id
let image2ID: number | string = image2Doc.id
Expand Down Expand Up @@ -236,27 +234,29 @@ export const seed = async ({
})

// update each post with related posts
await payload.update({
id: post1Doc.id,
collection: 'posts',
data: {
relatedPosts: [post2Doc.id, post3Doc.id],
},
})
await payload.update({
id: post2Doc.id,
collection: 'posts',
data: {
relatedPosts: [post1Doc.id, post3Doc.id],
},
})
await payload.update({
id: post3Doc.id,
collection: 'posts',
data: {
relatedPosts: [post1Doc.id, post2Doc.id],
},
})
await Promise.all([
payload.update({
id: post1Doc.id,
collection: 'posts',
data: {
relatedPosts: [post2Doc.id, post3Doc.id],
},
}),
payload.update({
id: post2Doc.id,
collection: 'posts',
data: {
relatedPosts: [post1Doc.id, post3Doc.id],
},
}),
payload.update({
id: post3Doc.id,
collection: 'posts',
data: {
relatedPosts: [post1Doc.id, post2Doc.id],
},
}),
])

payload.logger.info(`— Seeding contact form...`)

Expand Down
3 changes: 3 additions & 0 deletions templates/website/src/fields/linkGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const linkGroup: LinkGroupType = ({ appearances, overrides = {} } = {}) =
appearances,
}),
],
admin: {
initCollapsed: true,
},
}

return deepMerge(generatedLinkGroup, overrides)
Expand Down
4 changes: 2 additions & 2 deletions templates/website/src/heros/HighImpact/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export const HighImpactHero: React.FC<Page['hero']> = ({ links, media, richText
data-theme="dark"
>
<div className="container mb-8 z-10 relative flex items-center justify-center">
<div className="max-w-[36.5rem] text-center">
<div className="max-w-[36.5rem] md:text-center">
{richText && <RichText className="mb-6" data={richText} enableGutter={false} />}
{Array.isArray(links) && links.length > 0 && (
<ul className="flex justify-center gap-4">
<ul className="flex md:justify-center gap-4">
{links.map(({ link }, i) => {
return (
<li key={i}>
Expand Down
42 changes: 34 additions & 8 deletions templates/website/tailwind.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,41 @@ export default {
},
typography: ({ theme }) => ({
DEFAULT: {
css: {
'--tw-prose-body': 'var(--text)',
'--tw-prose-headings': 'var(--text)',
h1: {
fontSize: '3.5rem',
fontWeight: 'normal',
marginBottom: '0.25em',
css: [
{
'--tw-prose-body': 'var(--text)',
'--tw-prose-headings': 'var(--text)',
h1: {
fontWeight: 'normal',
marginBottom: '0.25em',
},
},
},
],
},
base: {
css: [
{
h1: {
fontSize: '2.5rem',
},
h2: {
fontSize: '1.25rem',
fontWeight: 600,
},
},
],
},
md: {
css: [
{
h1: {
fontSize: '3.5rem',
},
h2: {
fontSize: '1.5rem',
},
},
],
},
}),
},
Expand Down
Loading