update opengraph

This commit is contained in:
Thomas Camlong
2025-11-23 08:22:43 +01:00
parent fe3ccd506e
commit f8568bb0c2
4 changed files with 12 additions and 603 deletions

View File

@@ -79,11 +79,22 @@ export async function generateMetadata({ params }: Props, _parent: ResolvingMeta
type: "website",
url: pageUrl,
siteName: "Dashboard Icons",
locale: "en_US",
images: [
{
url: mainIconUrl,
width: 512,
height: 512,
alt: `${formattedIconName} icon`,
type: mainIconUrl.endsWith(".svg") ? "image/svg+xml" : mainIconUrl.endsWith(".webp") ? "image/webp" : "image/png",
},
],
},
twitter: {
card: "summary_large_image",
title: `${formattedIconName} Icon (Community) | Dashboard Icons`,
description: `Download the ${formattedIconName} community-submitted icon. Part of a collection of ${totalIcons} community icons awaiting review and addition to the Dashboard Icons collection.`,
images: [mainIconUrl],
},
alternates: {
canonical: `${WEB_URL}/community/${icon}`,

View File

@@ -1,320 +0,0 @@
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { ImageResponse } from "next/og";
import { getAllIcons } from "@/lib/api";
export const revalidate = false;
export async function generateStaticParams() {
const iconsData = await getAllIcons();
if (process.env.CI_MODE === "false") {
// This is meant to speed up the build process in local development
return Object.keys(iconsData)
.slice(0, 5)
.map((icon) => ({
icon,
}));
}
return Object.keys(iconsData).map((icon) => ({
icon,
}));
}
export const size = {
width: 1200,
height: 630,
};
export const alt = "Icon Open Graph Image";
export const contentType = "image/png";
export default async function Image({
params,
}: {
params: Promise<{ icon: string }>;
}) {
const { icon } = await params;
if (!icon) {
console.error(`[Opengraph Image] Icon not found for ${icon}`);
return new ImageResponse(
<div
style={{
display: "flex",
width: "100%",
height: "100%",
alignItems: "center",
justifyContent: "center",
backgroundColor: "white",
fontSize: 48,
fontWeight: 600,
color: "#64748b",
}}
>
Icon not found
</div>,
{ ...size },
);
}
const iconsData = await getAllIcons();
const totalIcons = Object.keys(iconsData).length;
const index = Object.keys(iconsData).indexOf(icon);
// Format the icon name for display
const formattedIconName = icon
.split("-")
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(" ");
// Read the icon file from local filesystem
let iconData: Buffer | null = null;
try {
const iconPath = join(process.cwd(), `../png/${icon}.png`);
console.log(
`Generating opengraph image for ${icon} (${index + 1} / ${totalIcons}) from path ${iconPath}`,
);
iconData = await readFile(iconPath);
} catch (_error) {
console.error(`Icon ${icon} was not found locally`);
}
// Convert the image data to a data URL or use placeholder
const iconUrl = iconData
? `data:image/png;base64,${iconData.toString("base64")}`
: null;
return new ImageResponse(
<div
style={{
display: "flex",
width: "100%",
height: "100%",
position: "relative",
fontFamily: "Inter, system-ui, sans-serif",
overflow: "hidden",
backgroundColor: "white",
backgroundImage:
"radial-gradient(circle at 25px 25px, lightgray 2%, transparent 0%), radial-gradient(circle at 75px 75px, lightgray 2%, transparent 0%)",
backgroundSize: "100px 100px",
}}
>
{/* Background blur blobs */}
<div
style={{
position: "absolute",
top: -100,
left: -100,
width: 400,
height: 400,
borderRadius: "50%",
background:
"linear-gradient(135deg, rgba(56, 189, 248, 0.1) 0%, rgba(59, 130, 246, 0.1) 100%)",
filter: "blur(80px)",
zIndex: 2,
}}
/>
<div
style={{
position: "absolute",
bottom: -150,
right: -150,
width: 500,
height: 500,
borderRadius: "50%",
background:
"linear-gradient(135deg, rgba(249, 115, 22, 0.1) 0%, rgba(234, 88, 12, 0.1) 100%)",
filter: "blur(100px)",
zIndex: 2,
}}
/>
{/* Main content layout */}
<div
style={{
display: "flex",
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
width: "100%",
height: "100%",
padding: "60px",
gap: "70px",
zIndex: 10,
}}
>
{/* Icon container */}
<div
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
width: 320,
height: 320,
borderRadius: 32,
background: "white",
boxShadow:
"0 25px 50px -12px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05)",
padding: 30,
flexShrink: 0,
position: "relative",
overflow: "hidden",
}}
>
<div
style={{
position: "absolute",
inset: 0,
background: "linear-gradient(145deg, #ffffff 0%, #f8fafc 100%)",
zIndex: 0,
}}
/>
{iconUrl && (
// biome-ignore lint/performance/noImgElement: Not using nextjs here
<img
src={iconUrl}
alt={formattedIconName}
width={260}
height={260}
style={{
objectFit: "contain",
position: "relative",
zIndex: 1,
filter: "drop-shadow(0 10px 15px rgba(0, 0, 0, 0.1))",
}}
/>
)}
{!iconUrl && (
<div
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
width: 260,
height: 260,
backgroundColor: "#f1f5f9",
color: "#475569",
border: "2px solid #e2e8f0",
borderRadius: 12,
padding: "8px 16px",
fontSize: 18,
fontWeight: 600,
boxShadow: "0 1px 2px rgba(0, 0, 0, 0.05)",
}}
>
{formattedIconName}
</div>
)}
</div>
{/* Text content */}
<div
style={{
display: "flex",
flexDirection: "column",
justifyContent: "center",
gap: 28,
maxWidth: 650,
}}
>
<div
style={{
display: "flex",
fontSize: 64,
fontWeight: 800,
color: "#0f172a",
lineHeight: 1.1,
letterSpacing: "-0.02em",
}}
>
Download {formattedIconName} icon for free
</div>
<div
style={{
display: "flex",
fontSize: 32,
fontWeight: 500,
color: "#64748b",
lineHeight: 1.4,
position: "relative",
paddingLeft: 16,
borderLeft: "4px solid #94a3b8",
}}
>
Amongst {totalIcons} other high-quality dashboard icons
</div>
<div
style={{
display: "flex",
gap: 12,
marginTop: 8,
}}
>
{["SVG", "PNG", "WEBP"].map((format) => (
<div
key={format}
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
backgroundColor: "#f1f5f9",
color: "#475569",
border: "2px solid #e2e8f0",
borderRadius: 12,
padding: "8px 16px",
fontSize: 18,
fontWeight: 600,
boxShadow: "0 1px 2px rgba(0, 0, 0, 0.05)",
}}
>
{format}
</div>
))}
</div>
</div>
</div>
{/* Footer */}
<div
style={{
position: "absolute",
bottom: 0,
left: 0,
right: 0,
height: 80,
display: "flex",
alignItems: "center",
justifyContent: "center",
background: "#ffffff",
borderTop: "2px solid rgba(0, 0, 0, 0.05)",
zIndex: 20,
}}
>
<div
style={{
display: "flex",
fontSize: 24,
fontWeight: 600,
color: "#334155",
alignItems: "center",
gap: 10,
}}
>
<div
style={{
width: 8,
height: 8,
borderRadius: "50%",
backgroundColor: "#3b82f6",
marginRight: 4,
}}
/>
dashboardicons.com
</div>
</div>
</div>,
{
...size,
},
);
}

View File

@@ -77,6 +77,7 @@ export async function generateMetadata({ params, searchParams }: Props, _parent:
type: "website",
url: pageUrl,
siteName: "Dashboard Icons",
locale: "en_US",
images: [
{
url: `${BASE_URL}/png/${icon}.png`,

View File

@@ -1,283 +0,0 @@
import { ImageResponse } from "next/og"
import { getAllIcons } from "@/lib/api"
export const dynamic = "force-static"
export const size = {
width: 1200,
height: 630,
}
// Define a fixed list of representative icons
const representativeIcons = [
"homarr",
"sonarr",
"radarr",
"lidarr",
"readarr",
"prowlarr",
"qbittorrent",
"home-assistant",
"cloudflare",
"github",
"traefik",
"portainer-alt",
"plex",
"jellyfin",
"overseerr",
]
export default async function Image() {
const iconsData = await getAllIcons()
const totalIcons = Object.keys(iconsData).length
// Round down to the nearest 100
const roundedTotalIcons = Math.round(totalIcons / 100) * 100
const iconImages = representativeIcons.map((icon) => ({
name: icon
.split("-")
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(" "),
url: `https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/${icon}.png`,
}))
return new ImageResponse(
<div
style={{
display: "flex",
width: "100%",
height: "100%",
position: "relative",
fontFamily: "Inter, system-ui, sans-serif",
overflow: "hidden",
backgroundColor: "white",
backgroundImage:
"radial-gradient(circle at 25px 25px, lightgray 2%, transparent 0%), radial-gradient(circle at 75px 75px, lightgray 2%, transparent 0%)",
backgroundSize: "100px 100px",
}}
>
<div
style={{
position: "absolute",
display: "flex",
top: -100,
left: -100,
width: 400,
height: 400,
borderRadius: "50%",
background: "linear-gradient(135deg, rgba(56, 189, 248, 0.1) 0%, rgba(59, 130, 246, 0.1) 100%)",
filter: "blur(80px)",
zIndex: 2,
}}
/>
<div
style={{
position: "absolute",
display: "flex",
bottom: -150,
right: -150,
width: 500,
height: 500,
borderRadius: "50%",
background: "linear-gradient(135deg, rgba(249, 115, 22, 0.1) 0%, rgba(234, 88, 12, 0.1) 100%)",
filter: "blur(100px)",
zIndex: 2,
}}
/>
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
width: "100%",
height: "100%",
padding: "50px",
zIndex: 10,
gap: "30px",
}}
>
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
gap: "16px",
marginBottom: "10px",
}}
>
<div
style={{
fontSize: 64,
display: "flex",
fontWeight: 800,
fontFamily: "monospace",
color: "#0f172a",
lineHeight: 1.1,
textAlign: "center",
}}
>
Dashboard Icons
</div>
<div
style={{
fontSize: 28,
display: "flex",
fontWeight: 500,
color: "#64748b",
lineHeight: 1.4,
textAlign: "center",
maxWidth: 1100,
}}
>
A curated collection of {roundedTotalIcons}+ free icons for dashboards and app directories
</div>
</div>
<div
style={{
display: "flex",
flexDirection: "row",
flexWrap: "wrap",
justifyContent: "center",
gap: "20px",
width: "1100px",
margin: "0 auto",
}}
>
{iconImages.map((icon, index) => (
<div
key={index}
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
background: "white",
borderRadius: 16,
boxShadow: "0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.05)",
padding: "20px",
position: "relative",
overflow: "hidden",
width: "120px",
height: "75px",
margin: "0",
}}
>
<div
style={{
display: "flex",
position: "absolute",
inset: 0,
background: "linear-gradient(145deg, #ffffff 0%, #f8fafc 100%)",
zIndex: 0,
}}
/>
<img
src={icon.url}
alt={icon.name}
width={50}
height={50}
style={{
objectFit: "contain",
position: "relative",
zIndex: 1,
filter: "drop-shadow(0 5px 10px rgba(0, 0, 0, 0.1))",
}}
/>
</div>
))}
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
background: "white",
borderRadius: 16,
boxShadow: "0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.05)",
padding: "20px",
position: "relative",
overflow: "hidden",
width: "120px",
height: "75px",
margin: "0",
}}
>
<div
style={{
display: "flex",
position: "absolute",
inset: 0,
background: "linear-gradient(145deg, #ffffff 0%, #f8fafc 100%)",
zIndex: 0,
}}
/>
<div
style={{
display: "flex",
fontSize: 20,
fontWeight: 600,
color: "#64748b",
zIndex: 1,
}}
>
+{totalIcons - representativeIcons.length}
</div>
</div>
</div>
<div
style={{
display: "flex",
gap: 16,
marginTop: 10,
}}
/>
</div>
<div
style={{
position: "absolute",
bottom: 0,
left: 0,
right: 0,
height: 80,
display: "flex",
alignItems: "center",
justifyContent: "center",
background: "#ffffff",
borderTop: "2px solid rgba(0, 0, 0, 0.05)",
zIndex: 20,
}}
>
<div
style={{
display: "flex",
fontSize: 24,
fontWeight: 600,
color: "#334155",
alignItems: "center",
gap: 10,
}}
>
<div
style={{
display: "flex",
width: 8,
height: 8,
borderRadius: "50%",
backgroundColor: "#3b82f6",
marginRight: 4,
}}
/>
dashboardicons.com
</div>
</div>
</div>,
{
...size,
},
)
}