import { BASE_URL } from "@/constants" import { getAllIcons } from "@/lib/api" import { ImageResponse } from "next/og" export const dynamic = "force-static" export async function generateStaticParams() { const iconsData = await getAllIcons() return Object.keys(iconsData).map((icon) => ({ icon, })) } export const size = { width: 1200, height: 630, } export default async function Image({ params }: { params: { icon: string } }) { const { icon } = params const iconsData = await getAllIcons() const totalIcons = Object.keys(iconsData).length const index = Object.keys(iconsData).indexOf(icon) let iconUrl = `${BASE_URL}/png/${icon}.png` console.log(`Generating opengraph image for ${icon} (${index + 1} / ${totalIcons}) with url ${iconUrl}`) // Format the icon name for display const formattedIconName = icon .split("-") .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) .join(" ") // Get the icon URL // Check if the image exists if the return type of the image is of image type try { const response = await fetch(iconUrl) if (!response.ok) { console.error(`Icon ${icon} was not found at ${iconUrl}`) iconUrl = `https://placehold.co/600x400?text=${formattedIconName}` } } catch (error) { console.error(`Icon ${icon} was not found at ${iconUrl}`) iconUrl = `https://placehold.co/600x400?text=${formattedIconName}` } return new ImageResponse(
{/* Background with gradient */}
{/* Subtle pattern overlay */}
{/* Decorative elements */}
{/* Content container - horizontal layout */}
{/* Left side - Icon container with enhanced styling */}
{/* Subtle gradient in icon background */}
{/* Icon image */} {formattedIconName}
{/* Right side - Text content with improved typography */}
{/* Main title with enhanced styling */}
Download {formattedIconName} icon for free
{/* Subtitle with improved styling */}
Amongst {totalIcons.toLocaleString()} other high-quality dashboard icons
{/* Format badges */}
{["SVG", "PNG", "WEBP"].map((format) => (
{format}
))}
{/* Footer with enhanced branding */}
dashboardicons.com
, { ...size, }, ) }