feat: manage blog detail chrome via payload
This commit is contained in:
42
src/scripts/preload-blog-detail-cms.ts
Normal file
42
src/scripts/preload-blog-detail-cms.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'dotenv/config'
|
||||
|
||||
import config from '@payload-config'
|
||||
import { getPayload } from 'payload'
|
||||
|
||||
import { blogDetailContent } from '@/spa/blogDetailContent'
|
||||
|
||||
async function main() {
|
||||
const payload = await getPayload({ config })
|
||||
|
||||
const posts = await payload.find({
|
||||
collection: 'posts',
|
||||
draft: true,
|
||||
overrideAccess: true,
|
||||
pagination: false,
|
||||
limit: 1000,
|
||||
})
|
||||
|
||||
await Promise.all(
|
||||
posts.docs.map((post) =>
|
||||
payload.update({
|
||||
collection: 'posts',
|
||||
id: post.id,
|
||||
overrideAccess: true,
|
||||
context: { disableRevalidate: true },
|
||||
data: {
|
||||
detailPage: {
|
||||
...blogDetailContent,
|
||||
metaCopy: blogDetailContent.meta,
|
||||
},
|
||||
} as never,
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
payload.logger.info(`Preloaded Blog detail CMS fields for ${posts.docs.length} records`)
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user