- Introduced a new script for setting up a fresh database with ordered migration tasks. - Added a utility function to find media by filename, improving media handling in various scripts. - Updated preload scripts to utilize the new media fetching utility. - Refactored datenschutz, impressum, and mitglied-werden fields to use stable IDs and anchor IDs. - Enhanced home and network pages to accommodate new field structures. - Added new preload script for global CMS settings. - Improved code readability and organization across multiple files.
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import 'dotenv/config'
|
|
|
|
import config from '@payload-config'
|
|
import { getPayload, type Payload } from 'payload'
|
|
import { mediaByFilename } from './mediaByFilename'
|
|
|
|
import { blogDetailContent } from '@/spa/blogDetailContent'
|
|
|
|
async function main() {
|
|
const payload = await getPayload({ config })
|
|
const fallbackImage = await mediaByFilename(payload, blogDetailContent.fallbackImageFilename)
|
|
const { fallbackImageFilename: _fallbackImageFilename, ...detailContent } = blogDetailContent
|
|
|
|
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: {
|
|
...detailContent,
|
|
fallbackImage,
|
|
metaCopy: blogDetailContent.meta,
|
|
},
|
|
} as never,
|
|
}),
|
|
),
|
|
)
|
|
|
|
payload.logger.info(`Preloaded Blog detail CMS fields for ${posts.docs.length} records`)
|
|
process.exit(0)
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error)
|
|
process.exit(1)
|
|
})
|