fix(cms): remove unpublished content fallbacks
This commit is contained in:
@@ -1,27 +1,11 @@
|
||||
import 'dotenv/config'
|
||||
|
||||
import config from '@payload-config'
|
||||
import { getPayload, type Payload } from 'payload'
|
||||
import { getPayload } from 'payload'
|
||||
import { mediaByFilename } from './mediaByFilename'
|
||||
|
||||
import { pressIndexContent } from '@/spa/pressIndexContent'
|
||||
|
||||
const filenameFromPath = (source: string) => source.split('?')[0]?.split('/').filter(Boolean).pop()
|
||||
|
||||
const fallbackItemsWithImages = async <T extends { img?: string }>(
|
||||
payload: Payload,
|
||||
items: T[],
|
||||
) =>
|
||||
Promise.all(
|
||||
items.map(async (item) => {
|
||||
const filename = item.img ? filenameFromPath(item.img) : undefined
|
||||
return {
|
||||
...item,
|
||||
image: filename ? await mediaByFilename(payload, filename) : undefined,
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
async function main() {
|
||||
const payload = await getPayload({ config })
|
||||
|
||||
@@ -48,11 +32,6 @@ async function main() {
|
||||
const { imageFilename: _heroFilename, ...heroContent } = pressIndexContent.hero
|
||||
const { collectionFallbackImageFilename: _eventFallbackFilename, ...eventsContent } = pressIndexContent.events
|
||||
const { collectionFallbackImageFilename: _newsFallbackFilename, ...newsContent } = pressIndexContent.news
|
||||
const [eventFallbackItems, newsFallbackItems] = await Promise.all([
|
||||
fallbackItemsWithImages(payload, pressIndexContent.events.fallbackItems),
|
||||
fallbackItemsWithImages(payload, pressIndexContent.news.fallbackItems),
|
||||
])
|
||||
|
||||
await payload.update({
|
||||
collection: 'pages',
|
||||
id: page.id,
|
||||
@@ -68,12 +47,10 @@ async function main() {
|
||||
events: {
|
||||
...eventsContent,
|
||||
collectionFallbackImage: eventFallbackImage,
|
||||
fallbackItems: eventFallbackItems,
|
||||
},
|
||||
news: {
|
||||
...newsContent,
|
||||
collectionFallbackImage: newsFallbackImage,
|
||||
fallbackItems: newsFallbackItems,
|
||||
},
|
||||
downloads: {
|
||||
...pressIndexContent.downloads,
|
||||
|
||||
Reference in New Issue
Block a user