feat: manage press fallback card media
This commit is contained in:
@@ -15,6 +15,22 @@ const mediaByFilename = async (payload: Payload, filename: string) => {
|
||||
return result.docs[0]?.id
|
||||
}
|
||||
|
||||
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 })
|
||||
|
||||
@@ -41,6 +57,10 @@ 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',
|
||||
@@ -57,10 +77,12 @@ 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