Set canonical and social metadata, include every published article in the sitemap, and choose how quickly cached content updates.
The article route includes generateMetadata and JSON-LD. The SEO title and description fall back to the article title and excerpt. The social image falls back to the cover. WEBSITE_URL must be your public website origin.
The example sets canonical, Open Graph, and Twitter metadata, plus author and publication/modification timestamps. It escapes < in JSON-LD so article text cannot close the script element.
The server renders the article and its metadata into the initial HTML. Keep the fetch on the server to preserve this behavior.
The sitemap requests up to 100 articles per API page and continues until it has traversed the result set. Fetching only the first page would omit older articles.
import type { MetadataRoute } from "next";
import { getArticles, websiteUrl } from "../lib/content";
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const urls: MetadataRoute.Sitemap = [
{ url: websiteUrl },
{ url: `${websiteUrl}/blog` },
];
let page = 1;
while (true) {
const data = await getArticles({ page, pageSize: 100 });
urls.push(
...data.items.map((a) => ({
url: `${websiteUrl}/blog/${a.slug}`,
lastModified: a.updatedAt,
})),
);
if (page * data.pageSize >= data.total) break;
page++;
}
return urls;
}
The example’s robots file allows indexing on the website. The Postparticle workspace and developer guides remain noindex; do not copy their noindex headers to your public website.
import type { MetadataRoute } from "next";
import { websiteUrl } from "../lib/content";
export const dynamic = "force-dynamic";
export default function robots(): MetadataRoute.Robots {
return {
rules: { userAgent: "*", allow: "/" },
sitemap: `${websiteUrl}/sitemap.xml`,
};
}
The article metadata endpoint is edge-cached for 45 seconds, with up to 15 seconds of stale-while-revalidate. Other API responses use Cache-Control: no-store. The example sets its server-side fetch cache with next: { revalidate: 60 }. After publishing or unpublishing, a cached page can continue to show the previous content until the cache refreshes. Revalidation occurs on a later request; 60 seconds is an interval, not a delivery guarantee.
Browser router caches and your website’s CDN can extend the delay. Use { cache: "no-store" } to bypass your website’s fetch cache; it does not bypass the metadata endpoint’s 45-second freshness window or its 15-second stale-while-revalidate window. Do not combine the options. Avoid build-only fetching if content must update without a redeployment.
Unpublishing removes the article from the API. Previously cached pages and public media URLs may remain available.