feat: manage netzwerk page via payload

This commit is contained in:
syntaxbullet
2026-06-22 11:30:21 +02:00
parent a9283b2e46
commit c35e45499e
8 changed files with 1455 additions and 276 deletions

View File

@@ -0,0 +1,66 @@
import 'dotenv/config'
import config from '@payload-config'
import { getPayload, type Payload } from 'payload'
import { netzwerkContent } from '@/spa/netzwerkContent'
const mediaByFilename = async (payload: Payload, filename: string) => {
const result = await payload.find({
collection: 'media',
limit: 1,
pagination: false,
where: { filename: { equals: filename } },
})
return result.docs[0]?.id
}
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: '/netzwerk' } }, { slug: { equals: 'netzwerk' } }, { slug: { equals: 'network' } }],
},
})
const page = pageResult.docs[0]
if (!page) throw new Error('Netzwerk page not found. Expected spaPath=/netzwerk or slug=netzwerk/network.')
const heroImage = await mediaByFilename(payload, netzwerkContent.hero.imageFilename)
const sponsoringImage = await mediaByFilename(payload, netzwerkContent.sponsoring.imageFilename)
const { imageFilename: _heroFilename, ...heroContent } = netzwerkContent.hero
const { imageFilename: _sponsoringFilename, ...sponsoringContent } = netzwerkContent.sponsoring
await payload.update({
collection: 'pages',
id: page.id,
overrideAccess: true,
context: { disableRevalidate: true },
data: {
netzwerk: {
...netzwerkContent,
hero: {
...heroContent,
image: heroImage,
},
sponsoring: {
...sponsoringContent,
image: sponsoringImage,
},
},
} as never,
})
payload.logger.info(`Preloaded Netzwerk CMS fields for page ${page.id}`)
}
main().catch((error) => {
console.error(error)
process.exit(1)
})