Question presented to candidate: "Marketing wants every blog post to have a generated social preview image with the post title. How would you build that in Next.js?"
What a strong answer should cover:
- Add an
opengraph-image.tsx(ortwitter-image.tsx) file in the route segment; its default export returns anImageResponsefrom next/og. ImageResponserenders JSX with a subset of CSS (flexbox) to a PNG using Satori; exportsize,contentTypeandalt.- Next.js serves the image at a route and adds
og:image, width, height, type and alt tags to that page automatically. - It can read params and fetch data, so each post gets its own image; static ones are generated at build time.
- Set
metadataBase, otherwise the og:image URL points at localhost.
Clarifying questions expected:
- "Does every page need its own image or one per section?" β the file applies to its segment and below.
- "Which fonts and brand assets are needed?" β they must be loaded explicitly into ImageResponse.
Code / implementation expected: Yes β an opengraph-image file for a dynamic route.