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

chore: optimizes website seed #9317

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions templates/website/src/Footer/hooks/revalidateFooter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 5 additions & 3 deletions templates/website/src/Header/hooks/revalidateHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
24 changes: 13 additions & 11 deletions templates/website/src/collections/Pages/hooks/revalidatePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@ 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)
}
revalidatePath(path)
}

// 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}`
// 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}`)
payload.logger.info(`Revalidating old page at path: ${oldPath}`)

revalidatePath(oldPath)
revalidatePath(oldPath)
}
}

return doc
Expand Down
24 changes: 13 additions & 11 deletions templates/website/src/collections/Posts/hooks/revalidatePost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@ 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)
}
revalidatePath(path)
}

// 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}`
// 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}`)
payload.logger.info(`Revalidating old post at path: ${oldPath}`)

revalidatePath(oldPath)
revalidatePath(oldPath)
}
}

return doc
Expand Down
Loading
Loading