completefrontend

Predict the outputMedium

Tea pages and journal posts each have an opengraph-image.tsx, and both pages list their slugs. What does next build print?

Leaf and Kettle draws a social card for the shop, one for each tea, and one for each journal post, with ImageResponse from next/og. Both [slug] pages export generateStaticParams. The tea card's file has no generateStaticParams of its own; the post card's file has one. What does the route table say about each picture?

lib/teas.ts
export type Tea = { slug: string; name: string; about: string };
 
const teas: Tea[] = [
  { slug: "green", name: "Green tea", about: "Light and fresh." },
  { slug: "mint", name: "Mint tea", about: "Cool and sweet." },
];
 
/** Every tea the shop sells, in the shop's order. */
export async function getTeas(): Promise<Tea[]> {
  return teas;
}
 
/** The tea with this slug, or undefined when the shop doesn't sell it. */
export async function getTea(slug: string): Promise<Tea | undefined> {
  return teas.find((tea) => tea.slug === slug);
}
lib/journal.ts
export type Post = { slug: string; title: string; summary: string };
 
const posts: Post[] = [
  { slug: "first-flush", title: "The first flush is in", summary: "Spring's first picking has arrived." },
  { slug: "cold-brew", title: "Cold brew season", summary: "Steep it overnight in the fridge." },
];
 
/** Every published post, newest first. */
export async function getPosts(): Promise<Post[]> {
  return posts;
}
 
/** The post with this slug, or undefined when there's none. */
export async function getPost(slug: string): Promise<Post | undefined> {
  return posts.find((post) => post.slug === slug);
}
app/layout.tsx
import type { Metadata } from "next";
 
export const metadata: Metadata = {
  metadataBase: new URL("https://leafandkettle.example"),
  title: "Leaf and Kettle",
};
 
export default function RootLayout({ children }: LayoutProps<"/">) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  );
}
app/page.tsx
export default function HomePage() {
  return (
    <main>
      <h1>Leaf and Kettle</h1>
      <p>Loose-leaf teas, packed by hand.</p>
    </main>
  );
}
app/opengraph-image.tsx
import { ImageResponse } from "next/og";
 
export const alt = "Leaf and Kettle, loose-leaf teas";
export const size = { width: 1200, height: 630 };
export const contentType = "image/png";
 
export default function Image() {
  return new ImageResponse(
    (
      <div style={{ display: "flex", width: "100%", height: "100%", alignItems: "center", justifyContent: "center", background: "#2f5d3a", color: "white", fontSize: 96 }}>
        Leaf and Kettle
      </div>
    ),
    size,
  );
}
app/teas/[slug]/page.tsx
import { notFound } from "next/navigation";
import { getTea, getTeas } from "@/lib/teas";
 
export async function generateStaticParams() {
  const teas = await getTeas();
  return teas.map((tea) => ({ slug: tea.slug }));
}
 
export default async function TeaPage({ params }: PageProps<"/teas/[slug]">) {
  const { slug } = await params;
  const tea = await getTea(slug);
  if (!tea) notFound();
 
  return (
    <main>
      <h1>{tea.name}</h1>
      <p>{tea.about}</p>
    </main>
  );
}
app/teas/[slug]/opengraph-image.tsx
import { ImageResponse } from "next/og";
import { notFound } from "next/navigation";
import { getTea } from "@/lib/teas";
 
export const alt = "A tea from Leaf and Kettle";
export const size = { width: 1200, height: 630 };
export const contentType = "image/png";
 
export default async function Image({ params }: { params: Promise<{ slug: string }> }) {
  const { slug } = await params;
  const tea = await getTea(slug);
  if (!tea) notFound();
 
  return new ImageResponse(
    (
      <div style={{ display: "flex", width: "100%", height: "100%", alignItems: "center", justifyContent: "center", background: "#2f5d3a", color: "white", fontSize: 96 }}>
        {tea.name}
      </div>
    ),
    size,
  );
}
app/journal/[slug]/page.tsx
import { notFound } from "next/navigation";
import { getPost, getPosts } from "@/lib/journal";
 
export async function generateStaticParams() {
  const posts = await getPosts();
  return posts.map((post) => ({ slug: post.slug }));
}
 
export default async function PostPage({ params }: PageProps<"/journal/[slug]">) {
  const { slug } = await params;
  const post = await getPost(slug);
  if (!post) notFound();
 
  return (
    <article>
      <h1>{post.title}</h1>
      <p>{post.summary}</p>
    </article>
  );
}
app/journal/[slug]/opengraph-image.tsx
import { ImageResponse } from "next/og";
import { notFound } from "next/navigation";
import { getPost, getPosts } from "@/lib/journal";
 
export const alt = "A post from the Leaf and Kettle journal";
export const size = { width: 1200, height: 630 };
export const contentType = "image/png";
 
export async function generateStaticParams() {
  const posts = await getPosts();
  return posts.map((post) => ({ slug: post.slug }));
}
 
export default async function Image({ params }: { params: Promise<{ slug: string }> }) {
  const { slug } = await params;
  const post = await getPost(slug);
  if (!post) notFound();
 
  return new ImageResponse(
    (
      <div style={{ display: "flex", width: "100%", height: "100%", alignItems: "center", justifyContent: "center", background: "#fbf8f1", color: "#2f5d3a", fontSize: 80 }}>
        {post.title}
      </div>
    ),
    size,
  );
}

It's a project create-next-app made (Next.js 16.4.3, TypeScript, the App Router, and Cache Components on) with these files, built with next build and run with next start. What happens:

  1. You run next build.
  2. You start the app with next start and ask for the mint tea's card and the first-flush post's card.

The answer

Work out what Next.js does at each step: what the build prints, what each request answers, and what the page shows. Then check.

Checking your sign-in…