feat: manage press kit download via payload

This commit is contained in:
syntaxbullet
2026-06-22 13:11:35 +02:00
parent c5feeaee16
commit e21e2f1210
5 changed files with 17 additions and 3 deletions

View File

@@ -144,6 +144,7 @@ export const pressIndexFields: Field[] = [
textarea('description', 'Description', pressIndexContent.downloads.description),
text('kitLabel', 'Kit label', pressIndexContent.downloads.kitLabel),
text('kitMeta', 'Kit metadata', pressIndexContent.downloads.kitMeta),
uploadField('kitFile', 'Press kit file', `Current frontend file: ${pressIndexContent.downloads.kitUrl}`),
text('kitUrl', 'Kit URL', pressIndexContent.downloads.kitUrl),
text('kitDownloadName', 'Kit download filename', pressIndexContent.downloads.kitDownloadName),
text('contactEyebrow', 'Contact eyebrow', pressIndexContent.downloads.contactEyebrow),

View File

@@ -1584,6 +1584,10 @@ export interface Page {
description?: string | null;
kitLabel?: string | null;
kitMeta?: string | null;
/**
* Current frontend file: /Print_BMP.zip
*/
kitFile?: (number | null) | Media;
kitUrl?: string | null;
kitDownloadName?: string | null;
contactEyebrow?: string | null;
@@ -4474,6 +4478,7 @@ export interface PagesSelect<T extends boolean = true> {
description?: T;
kitLabel?: T;
kitMeta?: T;
kitFile?: T;
kitUrl?: T;
kitDownloadName?: T;
contactEyebrow?: T;

View File

@@ -20,6 +20,7 @@ const mediaExtensions = new Set([
'.svg',
'.webm',
'.webp',
'.zip',
])
const mimeByExt: Record<string, string> = {
@@ -33,6 +34,7 @@ const mimeByExt: Record<string, string> = {
'.svg': 'image/svg+xml',
'.webm': 'video/webm',
'.webp': 'image/webp',
'.zip': 'application/zip',
}
async function walk(dir: string): Promise<string[]> {
@@ -59,7 +61,7 @@ function isMediaSource(value: string) {
async function findSpaSources() {
const files = (await walk(spaDir)).filter((file) => /\.(tsx?|jsx?)$/.test(file))
const sources = new Set<string>()
const quotedUrl = /["'`]((?:https?:\/\/images\.unsplash\.com\/[^"'`\s)]+)|(?:\/(?:images\/)?[^"'`\s)]+\.(?:avif|gif|jpe?g|mov|mp4|png|svg|webm|webp)(?:\?[^"'`\s)]*)?))["'`]/gi
const quotedUrl = /["'`]((?:https?:\/\/images\.unsplash\.com\/[^"'`\s)]+)|(?:\/(?:images\/)?[^"'`\s)]+\.(?:avif|gif|jpe?g|mov|mp4|png|svg|webm|webp|zip)(?:\?[^"'`\s)]*)?))["'`]/gi
const cssUrl = /url\((['"]?)(.*?)\1\)/g
for (const file of files) {

View File

@@ -32,10 +32,11 @@ async function main() {
const page = pageResult.docs[0]
if (!page) throw new Error('Press index page not found. Expected spaPath=/presse or slug=presse/press.')
const [heroImage, eventFallbackImage, newsFallbackImage] = await Promise.all([
const [heroImage, eventFallbackImage, newsFallbackImage, kitFile] = await Promise.all([
mediaByFilename(payload, pressIndexContent.hero.imageFilename),
mediaByFilename(payload, pressIndexContent.events.collectionFallbackImageFilename),
mediaByFilename(payload, pressIndexContent.news.collectionFallbackImageFilename),
mediaByFilename(payload, pressIndexContent.downloads.kitDownloadName),
])
const { imageFilename: _heroFilename, ...heroContent } = pressIndexContent.hero
const { collectionFallbackImageFilename: _eventFallbackFilename, ...eventsContent } = pressIndexContent.events
@@ -61,6 +62,10 @@ async function main() {
...newsContent,
collectionFallbackImage: newsFallbackImage,
},
downloads: {
...pressIndexContent.downloads,
kitFile,
},
},
} as never,
})

View File

@@ -18,6 +18,7 @@ type PressIndexCms = Partial<typeof pressIndexContent> & {
hero?: Partial<typeof pressIndexContent.hero> & { image?: unknown }
events?: Partial<typeof pressIndexContent.events> & { collectionFallbackImage?: unknown }
news?: Partial<typeof pressIndexContent.news> & { collectionFallbackImage?: unknown }
downloads?: Partial<typeof pressIndexContent.downloads> & { kitFile?: unknown }
}
type PressEventItem = (typeof pressIndexContent.events.fallbackItems)[number]
@@ -575,7 +576,7 @@ const Press: React.FC = () => {
{/* Download button */}
<a
href={fallbackText(downloads.kitUrl, pressIndexContent.downloads.kitUrl)}
href={mediaUrl(downloads.kitFile, fallbackText(downloads.kitUrl, pressIndexContent.downloads.kitUrl))}
download={fallbackText(downloads.kitDownloadName, pressIndexContent.downloads.kitDownloadName)}
onMouseEnter={() => setDlHovered(true)}
onMouseLeave={() => setDlHovered(false)}