feat: manage press kit download via payload
This commit is contained in:
@@ -144,6 +144,7 @@ export const pressIndexFields: Field[] = [
|
|||||||
textarea('description', 'Description', pressIndexContent.downloads.description),
|
textarea('description', 'Description', pressIndexContent.downloads.description),
|
||||||
text('kitLabel', 'Kit label', pressIndexContent.downloads.kitLabel),
|
text('kitLabel', 'Kit label', pressIndexContent.downloads.kitLabel),
|
||||||
text('kitMeta', 'Kit metadata', pressIndexContent.downloads.kitMeta),
|
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('kitUrl', 'Kit URL', pressIndexContent.downloads.kitUrl),
|
||||||
text('kitDownloadName', 'Kit download filename', pressIndexContent.downloads.kitDownloadName),
|
text('kitDownloadName', 'Kit download filename', pressIndexContent.downloads.kitDownloadName),
|
||||||
text('contactEyebrow', 'Contact eyebrow', pressIndexContent.downloads.contactEyebrow),
|
text('contactEyebrow', 'Contact eyebrow', pressIndexContent.downloads.contactEyebrow),
|
||||||
|
|||||||
@@ -1584,6 +1584,10 @@ export interface Page {
|
|||||||
description?: string | null;
|
description?: string | null;
|
||||||
kitLabel?: string | null;
|
kitLabel?: string | null;
|
||||||
kitMeta?: string | null;
|
kitMeta?: string | null;
|
||||||
|
/**
|
||||||
|
* Current frontend file: /Print_BMP.zip
|
||||||
|
*/
|
||||||
|
kitFile?: (number | null) | Media;
|
||||||
kitUrl?: string | null;
|
kitUrl?: string | null;
|
||||||
kitDownloadName?: string | null;
|
kitDownloadName?: string | null;
|
||||||
contactEyebrow?: string | null;
|
contactEyebrow?: string | null;
|
||||||
@@ -4474,6 +4478,7 @@ export interface PagesSelect<T extends boolean = true> {
|
|||||||
description?: T;
|
description?: T;
|
||||||
kitLabel?: T;
|
kitLabel?: T;
|
||||||
kitMeta?: T;
|
kitMeta?: T;
|
||||||
|
kitFile?: T;
|
||||||
kitUrl?: T;
|
kitUrl?: T;
|
||||||
kitDownloadName?: T;
|
kitDownloadName?: T;
|
||||||
contactEyebrow?: T;
|
contactEyebrow?: T;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ const mediaExtensions = new Set([
|
|||||||
'.svg',
|
'.svg',
|
||||||
'.webm',
|
'.webm',
|
||||||
'.webp',
|
'.webp',
|
||||||
|
'.zip',
|
||||||
])
|
])
|
||||||
|
|
||||||
const mimeByExt: Record<string, string> = {
|
const mimeByExt: Record<string, string> = {
|
||||||
@@ -33,6 +34,7 @@ const mimeByExt: Record<string, string> = {
|
|||||||
'.svg': 'image/svg+xml',
|
'.svg': 'image/svg+xml',
|
||||||
'.webm': 'video/webm',
|
'.webm': 'video/webm',
|
||||||
'.webp': 'image/webp',
|
'.webp': 'image/webp',
|
||||||
|
'.zip': 'application/zip',
|
||||||
}
|
}
|
||||||
|
|
||||||
async function walk(dir: string): Promise<string[]> {
|
async function walk(dir: string): Promise<string[]> {
|
||||||
@@ -59,7 +61,7 @@ function isMediaSource(value: string) {
|
|||||||
async function findSpaSources() {
|
async function findSpaSources() {
|
||||||
const files = (await walk(spaDir)).filter((file) => /\.(tsx?|jsx?)$/.test(file))
|
const files = (await walk(spaDir)).filter((file) => /\.(tsx?|jsx?)$/.test(file))
|
||||||
const sources = new Set<string>()
|
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
|
const cssUrl = /url\((['"]?)(.*?)\1\)/g
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
|
|||||||
@@ -32,10 +32,11 @@ async function main() {
|
|||||||
const page = pageResult.docs[0]
|
const page = pageResult.docs[0]
|
||||||
if (!page) throw new Error('Press index page not found. Expected spaPath=/presse or slug=presse/press.')
|
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.hero.imageFilename),
|
||||||
mediaByFilename(payload, pressIndexContent.events.collectionFallbackImageFilename),
|
mediaByFilename(payload, pressIndexContent.events.collectionFallbackImageFilename),
|
||||||
mediaByFilename(payload, pressIndexContent.news.collectionFallbackImageFilename),
|
mediaByFilename(payload, pressIndexContent.news.collectionFallbackImageFilename),
|
||||||
|
mediaByFilename(payload, pressIndexContent.downloads.kitDownloadName),
|
||||||
])
|
])
|
||||||
const { imageFilename: _heroFilename, ...heroContent } = pressIndexContent.hero
|
const { imageFilename: _heroFilename, ...heroContent } = pressIndexContent.hero
|
||||||
const { collectionFallbackImageFilename: _eventFallbackFilename, ...eventsContent } = pressIndexContent.events
|
const { collectionFallbackImageFilename: _eventFallbackFilename, ...eventsContent } = pressIndexContent.events
|
||||||
@@ -61,6 +62,10 @@ async function main() {
|
|||||||
...newsContent,
|
...newsContent,
|
||||||
collectionFallbackImage: newsFallbackImage,
|
collectionFallbackImage: newsFallbackImage,
|
||||||
},
|
},
|
||||||
|
downloads: {
|
||||||
|
...pressIndexContent.downloads,
|
||||||
|
kitFile,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
} as never,
|
} as never,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ type PressIndexCms = Partial<typeof pressIndexContent> & {
|
|||||||
hero?: Partial<typeof pressIndexContent.hero> & { image?: unknown }
|
hero?: Partial<typeof pressIndexContent.hero> & { image?: unknown }
|
||||||
events?: Partial<typeof pressIndexContent.events> & { collectionFallbackImage?: unknown }
|
events?: Partial<typeof pressIndexContent.events> & { collectionFallbackImage?: unknown }
|
||||||
news?: Partial<typeof pressIndexContent.news> & { collectionFallbackImage?: unknown }
|
news?: Partial<typeof pressIndexContent.news> & { collectionFallbackImage?: unknown }
|
||||||
|
downloads?: Partial<typeof pressIndexContent.downloads> & { kitFile?: unknown }
|
||||||
}
|
}
|
||||||
|
|
||||||
type PressEventItem = (typeof pressIndexContent.events.fallbackItems)[number]
|
type PressEventItem = (typeof pressIndexContent.events.fallbackItems)[number]
|
||||||
@@ -575,7 +576,7 @@ const Press: React.FC = () => {
|
|||||||
|
|
||||||
{/* Download button */}
|
{/* Download button */}
|
||||||
<a
|
<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)}
|
download={fallbackText(downloads.kitDownloadName, pressIndexContent.downloads.kitDownloadName)}
|
||||||
onMouseEnter={() => setDlHovered(true)}
|
onMouseEnter={() => setDlHovered(true)}
|
||||||
onMouseLeave={() => setDlHovered(false)}
|
onMouseLeave={() => setDlHovered(false)}
|
||||||
|
|||||||
Reference in New Issue
Block a user