diff --git a/apps/web/app/blog/[slug]/opengraph-image.tsx b/apps/web/app/blog/[slug]/opengraph-image.tsx index 5024191..7a6b5a6 100644 --- a/apps/web/app/blog/[slug]/opengraph-image.tsx +++ b/apps/web/app/blog/[slug]/opengraph-image.tsx @@ -1,7 +1,7 @@ import { ImageResponse } from "next/og"; import { allPosts } from "contentlayer/generated"; import { blogThumbnails } from "../../../src/components/blog/blogThumbnails"; -import { OGImageTemplate } from "../../../src/components/OGImageTemplate"; +import { BlogOGImageTemplate } from "../../../src/components/BlogOGImageTemplate"; import { getOgFonts, OG_IMAGE_SIZE } from "../../../src/lib/og-helper"; import * as fs from "node:fs/promises"; import * as path from "node:path"; @@ -18,20 +18,21 @@ export default async function Image({ const { slug } = await params; const post = allPosts.find((p) => p.slug === slug); - // If we have a custom generated thumbnail, serve it directly as the OG image + let backgroundImageSrc: string | undefined = undefined; + + // If we have a custom generated thumbnail, convert it to a data URI for Satori if (post?.thumbnail) { try { const filePath = path.join(process.cwd(), "public", post.thumbnail); const fileBuffer = await fs.readFile(filePath); - return new Response(fileBuffer, { - headers: { - "Content-Type": "image/png", - "Cache-Control": "public, max-age=31536000, immutable", - }, - }); + + const ext = path.extname(post.thumbnail).substring(1).toLowerCase(); + const mimeType = ext === "jpg" || ext === "jpeg" ? "image/jpeg" : "image/png"; + + backgroundImageSrc = `data:${mimeType};base64,${fileBuffer.toString("base64")}`; } catch (err) { - console.warn(`[OG Image Generator] Could not read thumbnail file for ${slug}:`, err); - // Fall through to dynamic generation + console.warn(`[OG Image Generator] Could not read thumbnail file for ${slug} to use as background:`, err); + // Fall through to standard plain background } } @@ -48,12 +49,13 @@ export default async function Image({ const fonts = await getOgFonts(); return new ImageResponse( - , { ...OG_IMAGE_SIZE, diff --git a/apps/web/src/components/BlogOGImageTemplate.tsx b/apps/web/src/components/BlogOGImageTemplate.tsx new file mode 100644 index 0000000..c7fc279 --- /dev/null +++ b/apps/web/src/components/BlogOGImageTemplate.tsx @@ -0,0 +1,258 @@ +import React from "react"; + +interface BlogOGImageTemplateProps { + title: string; + description?: string; + label?: string; + accentColor?: string; + keyword?: string; + backgroundImageSrc?: string; +} + +export function BlogOGImageTemplate({ + title, + description, + label, + accentColor, + keyword, + backgroundImageSrc, +}: BlogOGImageTemplateProps) { + const accent = accentColor || "#3b82f6"; + const white = "#ffffff"; + const slateLight = "#cbd5e1"; // slate-300 for readable descriptions on dark bg + + const containerStyle: React.CSSProperties = { + height: "100%", + width: "100%", + display: "flex", + flexDirection: "column", + alignItems: "flex-start", + justifyContent: "center", + backgroundColor: "#0f172a", // base dark slate + padding: "80px", + position: "relative", + fontFamily: "Inter", + }; + + return ( +
+ {/* Primary Thumbnail Background Image */} + {backgroundImageSrc && ( + + )} + + {/* Dark overlay to make text highly legible */} +
+ + {/* Subtle Grid Pattern overlay */} +
+ + {/* Accent geometric block (right side) */} +
+
+ +
+ {/* Label / Category */} + {label && ( +
+ {label} +
+ )} + + {/* Title */} +
40 ? "56px" : "72px", + fontWeight: 700, + color: white, + lineHeight: "1.1", + marginBottom: "28px", + display: "flex", + letterSpacing: "-0.03em", + }} + > + {title} +
+ + {/* Description */} + {description && ( +
+ {description.length > 120 + ? description.substring(0, 117) + "..." + : description} +
+ )} +
+ + {/* Brand Footer */} +
+
+
+ mintel.me +
+
+ + {/* Keyword badge (bottom-right) */} + {keyword && ( +
+
+
+ {keyword} +
+
+ )} + + {/* Accent Strip */} +
+
+ ); +}