- 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.
71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
import 'dotenv/config'
|
|
|
|
import config from '@payload-config'
|
|
import { getPayload, type Payload } from 'payload'
|
|
import { mediaByFilename } from './mediaByFilename'
|
|
|
|
import { participationContent } from '@/spa/participationContent'
|
|
|
|
async function main() {
|
|
const payload = await getPayload({ config })
|
|
|
|
const pageResult = await payload.find({
|
|
collection: 'pages',
|
|
limit: 1,
|
|
pagination: false,
|
|
draft: true,
|
|
overrideAccess: true,
|
|
where: {
|
|
or: [{ spaPath: { equals: '/teilnahme' } }, { slug: { equals: 'teilnahme' } }, { slug: { equals: 'participation' } }],
|
|
} as never,
|
|
})
|
|
|
|
const page = pageResult.docs[0]
|
|
if (!page) throw new Error('Participation page not found. Expected spaPath=/teilnahme or slug=teilnahme/participation.')
|
|
|
|
const [heroImage, evaluationImage, formImage] = await Promise.all([
|
|
mediaByFilename(payload, participationContent.hero.backgroundImageFilename),
|
|
mediaByFilename(payload, participationContent.evaluation.imageFilename),
|
|
mediaByFilename(payload, participationContent.applicationForm.imageFilename),
|
|
])
|
|
const { backgroundImageFilename: _heroFilename, ...heroContent } = participationContent.hero
|
|
const { imageFilename: _evaluationFilename, ...evaluationContent } = participationContent.evaluation
|
|
const { imageFilename: _formFilename, ...applicationFormContent } = participationContent.applicationForm
|
|
|
|
await payload.update({
|
|
collection: 'pages',
|
|
id: page.id,
|
|
overrideAccess: true,
|
|
context: { disableRevalidate: true },
|
|
data: {
|
|
participation: {
|
|
hero: {
|
|
...heroContent,
|
|
backgroundImage: heroImage,
|
|
},
|
|
process: participationContent.process,
|
|
eligibility: participationContent.eligibility,
|
|
evaluation: {
|
|
...evaluationContent,
|
|
image: evaluationImage,
|
|
},
|
|
applicationWays: participationContent.applicationWays,
|
|
datesBanner: participationContent.datesBanner,
|
|
applicationForm: {
|
|
...applicationFormContent,
|
|
image: formImage,
|
|
},
|
|
form: participationContent.form,
|
|
},
|
|
} as never,
|
|
})
|
|
|
|
payload.logger.info(`Preloaded participation CMS fields for page ${page.id}`)
|
|
process.exit(0)
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error)
|
|
process.exit(1)
|
|
})
|