Sitemap
Generate the marketing sitemap and robots.txt for search engines.
The sitemap lists the pages of your app. It helps search engines discover and understand your routes.
Next.js serves the marketing sitemap from apps/marketing/src/app/sitemap.ts. When you add public pages or change routes, update this file so the sitemap stays accurate.
Configuration
import { locales } from "@repo/i18n";
import { clientEnv } from "@repo/env/client";
import type { MetadataRoute } from "next";
export default function sitemap(): MetadataRoute.Sitemap {
const origin = clientEnv.NEXT_PUBLIC_MARKETING_URL;
const paths = ["", "/privacy-policy", "/terms-of-service", "/license"];
return paths.flatMap((path) =>
locales.map((locale) => {
const languages = Object.fromEntries(
locales.map((alt) => [alt, `${origin}/${alt}${path}`]),
);
return {
url: `${origin}/${locale}${path}`,
lastModified: new Date(),
changeFrequency: path ? "monthly" : "weekly",
priority: path ? 0.5 : 1,
alternates: { languages },
};
}),
);
}| Piece | Source |
|---|---|
| Origin | NEXT_PUBLIC_MARKETING_URL via @repo/env/client |
| Locales | locales from @repo/i18n (en, id) |
| Static routes | paths array |
| Hreflang | alternates.languages for each locale |
Home uses changeFrequency: "weekly" and priority: 1; other paths use "monthly" and 0.5.
Add a static page
Append the path (without locale prefix) to paths:
const paths = ["", "/privacy-policy", "/terms-of-service", "/license", "/changelog"];That emits entries for every locale, for example https://yoursite.com/en/changelog and https://yoursite.com/id/changelog.
Dynamic paths
No content collections
Marketing does not use content-collections for blog or legal MDX. Legal copy
lives in i18n + React pages. For dynamic routes, collect every path (from
the filesystem, a CMS, or a query) and map them the same way as the static
flatMap above.
/checkout/success is intentionally omitted from the sitemap today — it is a post-purchase page, not a discovery target.
The docs app has its own sitemap at apps/docs/src/app/sitemap.ts (Fumadocs page tree). This guide covers marketing only.
Learn more in the Next.js sitemap docs.
Robots
apps/marketing/src/app/robots.ts allows all crawlers and points them at the sitemap:
export default function robots(): MetadataRoute.Robots {
return {
rules: [{ userAgent: "*", allow: "/" }],
sitemap: `${clientEnv.NEXT_PUBLIC_MARKETING_URL}/sitemap.xml`,
};
}Set NEXT_PUBLIC_MARKETING_URL correctly in each environment — see Environment.