templates: bump for v3.4.0 (#9752)

Automated bump of templates for v3.4.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
github-actions[bot]
2024-12-04 19:46:32 +00:00
committed by GitHub
parent fa7ed3f621
commit fa39b37a44
15 changed files with 260 additions and 206 deletions

View File

@@ -1,5 +1,5 @@
{
"id": "965f2138-755a-4bb6-b83c-ad7827a6a425",
"id": "a621cec0-90cd-4514-bf1a-f98a91b06006",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",

View File

@@ -1,9 +1,9 @@
import * as migration_20241204_154138_initial from './20241204_154138_initial'
import * as migration_20241204_184308_initial from './20241204_184308_initial'
export const migrations = [
{
up: migration_20241204_154138_initial.up,
down: migration_20241204_154138_initial.down,
name: '20241204_154138_initial',
up: migration_20241204_184308_initial.up,
down: migration_20241204_184308_initial.down,
name: '20241204_184308_initial',
},
]

View File

@@ -1,5 +1,5 @@
{
"id": "7b4ead3c-1d17-460a-b8a8-7b202a4fa16c",
"id": "9c8b4aed-7504-439b-a8cd-1911cd4da6d1",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",

View File

@@ -1,9 +1,9 @@
import * as migration_20241204_154113_initial from './20241204_154113_initial'
import * as migration_20241204_184240_initial from './20241204_184240_initial'
export const migrations = [
{
up: migration_20241204_154113_initial.up,
down: migration_20241204_154113_initial.down,
name: '20241204_154113_initial',
up: migration_20241204_184240_initial.up,
down: migration_20241204_184240_initial.down,
name: '20241204_184240_initial',
},
]

View File

@@ -2,10 +2,12 @@ import type { GlobalAfterChangeHook } from 'payload'
import { revalidateTag } from 'next/cache'
export const revalidateFooter: GlobalAfterChangeHook = ({ doc, req: { payload } }) => {
payload.logger.info(`Revalidating footer`)
export const revalidateFooter: GlobalAfterChangeHook = ({ doc, req: { payload, context } }) => {
if (!context.disableRevalidate) {
payload.logger.info(`Revalidating footer`)
revalidateTag('global_footer')
revalidateTag('global_footer')
}
return doc
}

View File

@@ -2,10 +2,12 @@ import type { GlobalAfterChangeHook } from 'payload'
import { revalidateTag } from 'next/cache'
export const revalidateHeader: GlobalAfterChangeHook = ({ doc, req: { payload } }) => {
payload.logger.info(`Revalidating header`)
export const revalidateHeader: GlobalAfterChangeHook = ({ doc, req: { payload, context } }) => {
if (!context.disableRevalidate) {
payload.logger.info(`Revalidating header`)
revalidateTag('global_header')
revalidateTag('global_header')
}
return doc
}

View File

@@ -3,7 +3,6 @@ import { seed } from '@/endpoints/seed'
import config from '@payload-config'
import { headers } from 'next/headers'
const payloadToken = 'payload-token'
export const maxDuration = 60 // This function can run for a maximum of 60 seconds
export async function POST(

View File

@@ -7,34 +7,37 @@ import type { Page } from '../../../payload-types'
export const revalidatePage: CollectionAfterChangeHook<Page> = ({
doc,
previousDoc,
req: { payload },
req: { payload, context },
}) => {
if (doc._status === 'published') {
const path = doc.slug === 'home' ? '/' : `/${doc.slug}`
if (!context.disableRevalidate) {
if (doc._status === 'published') {
const path = doc.slug === 'home' ? '/' : `/${doc.slug}`
payload.logger.info(`Revalidating page at path: ${path}`)
payload.logger.info(`Revalidating page at path: ${path}`)
revalidatePath(path)
revalidateTag('pages-sitemap')
}
// If the page was previously published, we need to revalidate the old path
if (previousDoc?._status === 'published' && doc._status !== 'published') {
const oldPath = previousDoc.slug === 'home' ? '/' : `/${previousDoc.slug}`
payload.logger.info(`Revalidating old page at path: ${oldPath}`)
revalidatePath(oldPath)
revalidateTag('pages-sitemap')
}
}
return doc
}
export const revalidateDelete: CollectionAfterDeleteHook<Page> = ({ doc, req: { context } }) => {
if (!context.disableRevalidate) {
const path = doc?.slug === 'home' ? '/' : `/${doc?.slug}`
revalidatePath(path)
revalidateTag('pages-sitemap')
}
// If the page was previously published, we need to revalidate the old path
if (previousDoc?._status === 'published' && doc._status !== 'published') {
const oldPath = previousDoc.slug === 'home' ? '/' : `/${previousDoc.slug}`
payload.logger.info(`Revalidating old page at path: ${oldPath}`)
revalidatePath(oldPath)
revalidateTag('pages-sitemap')
}
return doc
}
export const revalidateDelete: CollectionAfterDeleteHook<Page> = ({ doc }) => {
const path = doc?.slug === 'home' ? '/' : `/${doc?.slug}`
revalidatePath(path)
revalidateTag('pages-sitemap')
return doc
}

View File

@@ -7,35 +7,38 @@ import type { Post } from '../../../payload-types'
export const revalidatePost: CollectionAfterChangeHook<Post> = ({
doc,
previousDoc,
req: { payload },
req: { payload, context },
}) => {
if (doc._status === 'published') {
const path = `/posts/${doc.slug}`
if (!context.disableRevalidate) {
if (doc._status === 'published') {
const path = `/posts/${doc.slug}`
payload.logger.info(`Revalidating post at path: ${path}`)
payload.logger.info(`Revalidating post at path: ${path}`)
revalidatePath(path)
revalidateTag('posts-sitemap')
}
// If the post was previously published, we need to revalidate the old path
if (previousDoc._status === 'published' && doc._status !== 'published') {
const oldPath = `/posts/${previousDoc.slug}`
payload.logger.info(`Revalidating old post at path: ${oldPath}`)
revalidatePath(oldPath)
revalidateTag('posts-sitemap')
}
}
return doc
}
export const revalidateDelete: CollectionAfterDeleteHook<Post> = ({ doc, req: { context } }) => {
if (!context.disableRevalidate) {
const path = `/posts/${doc?.slug}`
revalidatePath(path)
revalidateTag('posts-sitemap')
}
// If the post was previously published, we need to revalidate the old path
if (previousDoc._status === 'published' && doc._status !== 'published') {
const oldPath = `/posts/${previousDoc.slug}`
payload.logger.info(`Revalidating old post at path: ${oldPath}`)
revalidatePath(oldPath)
revalidateTag('posts-sitemap')
}
return doc
}
export const revalidateDelete: CollectionAfterDeleteHook<Post> = ({ doc }) => {
const path = `/posts/${doc?.slug}`
revalidatePath(path)
revalidateTag('posts-sitemap')
return doc
}

View File

@@ -42,35 +42,52 @@ export const seed = async ({
payload.logger.info(`— Clearing collections and globals...`)
// clear the database
for (const global of globals) {
await payload.updateGlobal({
slug: global,
data: {
navItems: [],
},
})
}
for (const collection of collections) {
await payload.delete({
collection: collection,
where: {
id: {
exists: true,
await Promise.all(
globals.map((global) =>
payload.updateGlobal({
slug: global,
data: {
navItems: [],
},
},
})
}
depth: 0,
context: {
disableRevalidate: true,
},
}),
),
)
await Promise.all(
collections.map((collection) =>
payload.delete({
collection: collection,
where: {
id: {
exists: true,
},
},
depth: 0,
context: {
disableRevalidate: true,
},
}),
),
)
const pages = await payload.delete({
collection: 'pages',
where: {},
context: {
disableRevalidate: true,
},
depth: 0,
})
payload.logger.info(`— Seeding demo author and user...`)
await payload.delete({
collection: 'users',
depth: 0,
where: {
email: {
equals: 'demo-author@payloadcms.com',
@@ -78,17 +95,6 @@ export const seed = async ({
},
})
const demoAuthor = await payload.create({
collection: 'users',
data: {
name: 'Demo Author',
email: 'demo-author@payloadcms.com',
password: 'password',
},
})
let demoAuthorID: number | string = demoAuthor.id
payload.logger.info(`— Seeding media...`)
const [image1Buffer, image2Buffer, image3Buffer, hero1Buffer] = await Promise.all([
fetchFileByURL(
@@ -105,48 +111,67 @@ export const seed = async ({
),
])
const image1Doc = await payload.create({
collection: 'media',
data: image1,
file: image1Buffer,
})
const image2Doc = await payload.create({
collection: 'media',
data: image2,
file: image2Buffer,
})
const image3Doc = await payload.create({
collection: 'media',
data: image2,
file: image3Buffer,
})
const imageHomeDoc = await payload.create({
collection: 'media',
data: image2,
file: hero1Buffer,
})
const [
demoAuthor,
image1Doc,
image2Doc,
image3Doc,
imageHomeDoc,
technologyCategory,
newsCategory,
financeCategory,
] = await Promise.all([
payload.create({
collection: 'users',
data: {
name: 'Demo Author',
email: 'demo-author@payloadcms.com',
password: 'password',
},
}),
payload.create({
collection: 'media',
data: image1,
file: image1Buffer,
}),
payload.create({
collection: 'media',
data: image2,
file: image2Buffer,
}),
payload.create({
collection: 'media',
data: image2,
file: image3Buffer,
}),
payload.create({
collection: 'media',
data: image2,
file: hero1Buffer,
}),
payload.logger.info(`— Seeding categories...`)
const technologyCategory = await payload.create({
collection: 'categories',
data: {
title: 'Technology',
},
})
payload.create({
collection: 'categories',
data: {
title: 'Technology',
},
}),
const newsCategory = await payload.create({
collection: 'categories',
data: {
title: 'News',
},
})
payload.create({
collection: 'categories',
data: {
title: 'News',
},
}),
const financeCategory = await payload.create({
collection: 'categories',
data: {
title: 'Finance',
},
})
payload.create({
collection: 'categories',
data: {
title: 'Finance',
},
}),
])
let demoAuthorID: number | string = demoAuthor.id
await payload.create({
collection: 'categories',
@@ -188,6 +213,11 @@ export const seed = async ({
// This way we can sort them by `createdAt` or `publishedAt` and they will be in the expected order
const post1Doc = await payload.create({
collection: 'posts',
depth: 0,
context: {
disableRevalidate: true,
},
select: { content: false },
data: JSON.parse(
JSON.stringify({ ...post1, categories: [technologyCategory.id] })
.replace(/"\{\{IMAGE_1\}\}"/g, String(image1ID))
@@ -198,6 +228,11 @@ export const seed = async ({
const post2Doc = await payload.create({
collection: 'posts',
depth: 0,
context: {
disableRevalidate: true,
},
select: { content: false },
data: JSON.parse(
JSON.stringify({ ...post2, categories: [newsCategory.id] })
.replace(/"\{\{IMAGE_1\}\}"/g, String(image2ID))
@@ -208,6 +243,11 @@ export const seed = async ({
const post3Doc = await payload.create({
collection: 'posts',
depth: 0,
context: {
disableRevalidate: true,
},
select: { content: false },
data: JSON.parse(
JSON.stringify({ ...post3, categories: [financeCategory.id] })
.replace(/"\{\{IMAGE_1\}\}"/g, String(image3ID))
@@ -239,21 +279,12 @@ export const seed = async ({
},
})
payload.logger.info(`— Seeding home page...`)
await payload.create({
collection: 'pages',
data: JSON.parse(
JSON.stringify(home)
.replace(/"\{\{IMAGE_1\}\}"/g, String(imageHomeID))
.replace(/"\{\{IMAGE_2\}\}"/g, String(image2ID)),
),
})
payload.logger.info(`— Seeding contact form...`)
const contactForm = await payload.create({
collection: 'forms',
depth: 0,
select: { title: true },
data: JSON.parse(JSON.stringify(contactFormData)),
})
@@ -263,74 +294,88 @@ export const seed = async ({
contactFormID = `"${contactFormID}"`
}
payload.logger.info(`— Seeding contact page...`)
payload.logger.info(`— Seeding pages...`)
const contactPage = await payload.create({
collection: 'pages',
data: JSON.parse(
JSON.stringify(contactPageData).replace(/"\{\{CONTACT_FORM_ID\}\}"/g, String(contactFormID)),
),
})
const [_, contactPage] = await Promise.all([
payload.create({
collection: 'pages',
depth: 0,
data: JSON.parse(
JSON.stringify(home)
.replace(/"\{\{IMAGE_1\}\}"/g, String(imageHomeID))
.replace(/"\{\{IMAGE_2\}\}"/g, String(image2ID)),
),
}),
payload.create({
collection: 'pages',
depth: 0,
data: JSON.parse(
JSON.stringify(contactPageData).replace(
/"\{\{CONTACT_FORM_ID\}\}"/g,
String(contactFormID),
),
),
}),
])
payload.logger.info(`— Seeding header...`)
payload.logger.info(`— Seeding globals...`)
await payload.updateGlobal({
slug: 'header',
data: {
navItems: [
{
link: {
type: 'custom',
label: 'Posts',
url: '/posts',
},
},
{
link: {
type: 'reference',
label: 'Contact',
reference: {
relationTo: 'pages',
value: contactPage.id,
await Promise.all([
payload.updateGlobal({
slug: 'header',
data: {
navItems: [
{
link: {
type: 'custom',
label: 'Posts',
url: '/posts',
},
},
},
],
},
})
payload.logger.info(`— Seeding footer...`)
await payload.updateGlobal({
slug: 'footer',
data: {
navItems: [
{
link: {
type: 'custom',
label: 'Admin',
url: '/admin',
{
link: {
type: 'reference',
label: 'Contact',
reference: {
relationTo: 'pages',
value: contactPage.id,
},
},
},
},
{
link: {
type: 'custom',
label: 'Source Code',
newTab: true,
url: 'https://github.com/payloadcms/payload/tree/main/templates/website',
],
},
}),
payload.updateGlobal({
slug: 'footer',
data: {
navItems: [
{
link: {
type: 'custom',
label: 'Admin',
url: '/admin',
},
},
},
{
link: {
type: 'custom',
label: 'Payload',
newTab: true,
url: 'https://payloadcms.com/',
{
link: {
type: 'custom',
label: 'Source Code',
newTab: true,
url: 'https://github.com/payloadcms/payload/tree/main/templates/website',
},
},
},
],
},
})
{
link: {
type: 'custom',
label: 'Payload',
newTab: true,
url: 'https://payloadcms.com/',
},
},
],
},
}),
])
payload.logger.info('Seeded database successfully!')
}

View File

@@ -1,5 +1,5 @@
{
"id": "2f41000e-8aae-4bb9-831b-425897cec349",
"id": "18b0f107-11d7-4757-8aaa-9a5183c37960",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",

View File

@@ -1,9 +1,9 @@
import * as migration_20241204_154128_initial from './20241204_154128_initial'
import * as migration_20241204_184256_initial from './20241204_184256_initial'
export const migrations = [
{
up: migration_20241204_154128_initial.up,
down: migration_20241204_154128_initial.down,
name: '20241204_154128_initial',
up: migration_20241204_184256_initial.up,
down: migration_20241204_184256_initial.down,
name: '20241204_184256_initial',
},
]