mirror of
https://github.com/walkxcode/dashboard-icons.git
synced 2025-11-19 10:07:29 +01:00
refactor: improve opengraph image generation with better fallback handling
- Add `revalidate = false` to disable revalidation for static images - Refactor iconUrl to be null when icon not found, using placeholder only in img src - This provides cleaner separation between data and presentation logic
This commit is contained in:
@@ -4,6 +4,8 @@ import { ImageResponse } from "next/og"
|
|||||||
import { getAllIcons } from "@/lib/api"
|
import { getAllIcons } from "@/lib/api"
|
||||||
|
|
||||||
export const dynamic = "force-static"
|
export const dynamic = "force-static"
|
||||||
|
export const revalidate = false
|
||||||
|
|
||||||
|
|
||||||
export async function generateStaticParams() {
|
export async function generateStaticParams() {
|
||||||
const iconsData = await getAllIcons()
|
const iconsData = await getAllIcons()
|
||||||
@@ -72,7 +74,7 @@ export default async function Image({ params }: { params: Promise<{ icon: string
|
|||||||
// Convert the image data to a data URL or use placeholder
|
// Convert the image data to a data URL or use placeholder
|
||||||
const iconUrl = iconData
|
const iconUrl = iconData
|
||||||
? `data:image/png;base64,${iconData.toString("base64")}`
|
? `data:image/png;base64,${iconData.toString("base64")}`
|
||||||
: `https://placehold.co/600x400?text=${formattedIconName}`
|
: null
|
||||||
|
|
||||||
return new ImageResponse(
|
return new ImageResponse(
|
||||||
<div
|
<div
|
||||||
@@ -157,7 +159,7 @@ export default async function Image({ params }: { params: Promise<{ icon: string
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<img
|
<img
|
||||||
src={iconUrl}
|
src={iconUrl || `https://placehold.co/600x400?text=${formattedIconName}`}
|
||||||
alt={formattedIconName}
|
alt={formattedIconName}
|
||||||
width={260}
|
width={260}
|
||||||
height={260}
|
height={260}
|
||||||
|
|||||||
Reference in New Issue
Block a user