fix: keep tenant thumbnail paths in production manuals render
This commit is contained in:
parent
508a8bbe5e
commit
7144aa4943
2 changed files with 39 additions and 16 deletions
|
|
@ -1,8 +1,7 @@
|
||||||
export const dynamic = "force-dynamic"
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
import { createHash } from "node:crypto"
|
import { createHash } from "node:crypto"
|
||||||
import { existsSync } from "fs"
|
import { existsSync } from "node:fs"
|
||||||
import { join } from "path"
|
|
||||||
import { Metadata } from "next"
|
import { Metadata } from "next"
|
||||||
import { headers } from "next/headers"
|
import { headers } from "next/headers"
|
||||||
import { businessConfig } from "@/lib/seo-config"
|
import { businessConfig } from "@/lib/seo-config"
|
||||||
|
|
@ -13,6 +12,7 @@ import { selectManualsForSite } from "@/lib/manuals-site-selection"
|
||||||
import { generateSEOMetadata, generateStructuredData } from "@/lib/seo"
|
import { generateSEOMetadata, generateStructuredData } from "@/lib/seo"
|
||||||
import { getManualsThumbnailsRoot } from "@/lib/manuals-paths"
|
import { getManualsThumbnailsRoot } from "@/lib/manuals-paths"
|
||||||
import { resolveManualsTenantDomain } from "@/lib/manuals-tenant"
|
import { resolveManualsTenantDomain } from "@/lib/manuals-tenant"
|
||||||
|
import { sanitizeManualThumbnailsForRuntime } from "@/lib/manuals-render-safety"
|
||||||
|
|
||||||
export const metadata: Metadata = generateSEOMetadata({
|
export const metadata: Metadata = generateSEOMetadata({
|
||||||
title: "Vending Machine Manuals | Rocky Mountain Vending",
|
title: "Vending Machine Manuals | Rocky Mountain Vending",
|
||||||
|
|
@ -83,20 +83,10 @@ export default async function ManualsPage() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide broken local thumbnails so the public manuals page doesn't spam 404s.
|
manuals = sanitizeManualThumbnailsForRuntime(manuals, {
|
||||||
const thumbnailsRoot = getManualsThumbnailsRoot()
|
isLocalDevelopment,
|
||||||
manuals = manuals.map((manual) => {
|
thumbnailsRoot: getManualsThumbnailsRoot(),
|
||||||
if (!manual.thumbnailUrl || /^https?:\/\//i.test(manual.thumbnailUrl)) {
|
fileExists: existsSync,
|
||||||
return manual
|
|
||||||
}
|
|
||||||
|
|
||||||
const relativeThumbnailPath = manual.thumbnailUrl.includes("/thumbnails/")
|
|
||||||
? manual.thumbnailUrl.replace(/^.*\/thumbnails\//, "")
|
|
||||||
: manual.thumbnailUrl
|
|
||||||
|
|
||||||
return existsSync(join(thumbnailsRoot, relativeThumbnailPath))
|
|
||||||
? manual
|
|
||||||
: { ...manual, thumbnailUrl: undefined }
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Generate structured data for SEO
|
// Generate structured data for SEO
|
||||||
|
|
|
||||||
33
lib/manuals-render-safety.ts
Normal file
33
lib/manuals-render-safety.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
import { join } from "node:path"
|
||||||
|
import type { Manual } from "@/lib/manuals-types"
|
||||||
|
|
||||||
|
type ThumbnailSanitizeOptions = {
|
||||||
|
isLocalDevelopment: boolean
|
||||||
|
thumbnailsRoot: string
|
||||||
|
fileExists?: (path: string) => boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sanitizeManualThumbnailsForRuntime(
|
||||||
|
manuals: Manual[],
|
||||||
|
options: ThumbnailSanitizeOptions
|
||||||
|
): Manual[] {
|
||||||
|
if (!options.isLocalDevelopment) {
|
||||||
|
return manuals
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileExists = options.fileExists ?? (() => false)
|
||||||
|
|
||||||
|
return manuals.map((manual) => {
|
||||||
|
if (!manual.thumbnailUrl || /^https?:\/\//i.test(manual.thumbnailUrl)) {
|
||||||
|
return manual
|
||||||
|
}
|
||||||
|
|
||||||
|
const relativeThumbnailPath = manual.thumbnailUrl.includes("/thumbnails/")
|
||||||
|
? manual.thumbnailUrl.replace(/^.*\/thumbnails\//, "")
|
||||||
|
: manual.thumbnailUrl
|
||||||
|
|
||||||
|
return fileExists(join(options.thumbnailsRoot, relativeThumbnailPath))
|
||||||
|
? manual
|
||||||
|
: { ...manual, thumbnailUrl: undefined }
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue