Programmatic Content in a Next.js Repo: When It Works and When It Doesn't

Generating hundreds of pages from a data file takes an afternoon in the App Router. Getting Google to index them is the hard part. Here is what separates the two, with the rules our own repo runs.

8 min read
Programmatic Content in a Next.js Repo: When It Works and When It Doesn't
On this page

TL;DR — Programmatic content in Next.js works when every generated URL answers a question that only that URL's data can answer. It fails when the pages are one template with a keyword swapped in. The code to generate pages is a dozen lines (generateStaticParams plus a data source). The work that decides the outcome is a per-page quality gate: pages below it get noindex and stay out of the sitemap, and pages above it ship with their own title, description and canonical.

This guide covers both halves: the App Router pattern, and the rules that decide whether the pages deserve to be indexed. The examples come from the repo behind seoagent.com, which runs programmatic pages of its own: comparisons, features, per-agent landing pages and a skill directory.

What "programmatic" means in a repo

A programmatic page is a route whose content comes from a data record, not from a hand-written file. In the App Router that is a dynamic segment like app/compare/[slug]/page.tsx, a registry that lists the valid slugs, and a template that renders one record.

The data can be a TypeScript registry, JSON or Markdown files, or rows in a database. Where it lives matters less than one property: each record must carry something specific. A comparison of two named products has two sets of facts. A skill report card has a repo's real grade. A city page that only swaps the city name has nothing.

The pattern in the App Router

This is the whole mechanism. The registry gives you slugs, generateStaticParams pre-renders them, and generateMetadata gives each page its own head:

// app/compare/[slug]/page.tsx
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { getComparisonContent, getComparisonSlugs } from '@/content/comparisons';

export async function generateStaticParams() {
  return getComparisonSlugs().map((slug) => ({ slug }));
}

export async function generateMetadata(
  { params }: { params: Promise<{ slug: string }> }
): Promise<Metadata> {
  const content = getComparisonContent((await params).slug);
  if (!content) return { title: 'Comparison Not Found' };
  return {
    title: content.title,
    description: content.description,
    alternates: { canonical: content.canonical },
  };
}

export default async function Page({ params }: { params: Promise<{ slug: string }> }) {
  const content = getComparisonContent((await params).slug);
  if (!content) notFound();
  return <ComparisonPageTemplate content={content} />;
}

Three details do real SEO work here:

  • Per-record title, description and canonical. If these come from a string template (${city} plumbers | Brand), you have shipped the same page many times. Store them on the record.
  • notFound() for unknown slugs. An unknown slug should return a 404, not render an empty template with a 200. Set export const dynamicParams = false if the registry is the complete list of valid pages.
  • One registry feeds the sitemap. The same getComparisonSlugs() call goes into app/sitemap.ts, so a page cannot exist without being listed, or be listed without existing. The sitemap guide shows the full file.

For data that changes (prices, rankings, scores), add export const revalidate = 3600 to the page, or use on-demand revalidation, so pages refresh without a rebuild. For very large sets, don't pre-render everything: return the top slice from generateStaticParams and let the rest render on first request.

When it works

From the registries we run, the pages that earn their place share four traits:

  1. A distinct data record per URL. Two products, one repo, one coding agent. The facts differ between pages, so the pages are not near-duplicates.
  2. A query the page answers directly. "X vs Y" has a person behind it deciding between X and Y. The template is built around that decision, not around the keyword.
  3. Enough substance to stand alone. If you would be embarrassed to link to one generated page from a hand-written article, it isn't ready.
  4. A real reason to exist after the first crawl. The page gets internal links from related pages, and its data stays accurate.

When it doesn't work

  • Keyword-swap templates. The same paragraphs with {city} or {tool} replaced. Google treats these as thin or duplicate, and a large set can pull down how it sees the whole directory.
  • No data behind the page. A page whose only unique token is the name has nothing to rank for.
  • Pages with no inbound links. A sitemap entry alone is a weak discovery signal. Programmatic pages need links from a hub page and from related records.
  • Ignoring crawl and index signals. Hundreds of near-empty URLs spend crawl attention that your good pages needed.

You can ship these pages in an afternoon, so the cost of getting it wrong is easy to underestimate. Check rankings page by page, not in aggregate: a few strong pages can hide a long tail that is not being indexed.

The quality gate: index only what clears a threshold

The rule we use in our own repo is that a page's robots metadata and its sitemap entry read the same function. A page below the threshold gets noindex, follow and is absent from the sitemap. The page and the sitemap cannot disagree because they share the rule.

Our skill directory, for example, has category pages at /skills/[category]. A category page is indexable only once it holds at least five graded skills (MIN_INDEXABLE_CATEGORY_SKILLS = 5 in lib/skill-grader/directory.ts). The page reads it like this:

// app/skills/[category]/page.tsx (generateMetadata)
robots: { index: isCategoryIndexable(entries.length), follow: true },

And app/sitemap.ts filters on the same value:

skillDirectoryPages = summarizeCategories(ranked, 0)
  .filter((c) => c.indexable)
  .map((c) => ({ url: `${baseUrl}${skillDirectoryPath(c.category)}` /* … */ }));

The per-skill report cards follow the same idea with different thresholds: a repo needs at least 25 stars (MIN_INDEXABLE_STARS) and a bundle of at least 2,000 tokens (MIN_INDEXABLE_BUNDLE_TOKENS) before its page is indexable. Pages below that still exist for people who land on them directly, but they carry noindex and stay out of the sitemap.

Pick thresholds that match your own data: a minimum count of records on a hub, a minimum amount of unique text or fields on a leaf, a minimum age for data that needs time to be meaningful. The numbers matter less than having one rule, in one place, that both the page and the sitemap use.

Sitemap mistakes that bite programmatic sites

Two mistakes from our own sitemap history, both documented in comments in app/sitemap.ts:

  • Stamping lastModified: new Date() on everything. When every URL claims to have changed at build time, crawlers learn to discount <lastmod> across the whole site. Our registry entries now omit it unless the record carries a real date, and the guides, which record publishedAt and updatedAt, pass theirs through.
  • Listing duplicate URLs. We once listed plain-Markdown mirrors of pages next to the HTML pages. They declared the HTML page as canonical, so each mirror sent two opposing signals, and 64 of 151 sitemap entries on 2026-08-27 were self-declared duplicates. A sitemap should hold canonical URLs only.

Also split by size only when you need to: a single sitemap holds up to 50,000 URLs, and generateSitemaps covers anything larger.

A review checklist before you ship a set

Before merging a new batch of generated pages, open three of them at random and check:

  • Is the <title> different from the other two in more than the swapped word?
  • Does the body contain facts that exist only on this record?
  • Does the canonical point at itself, and does the page appear in the sitemap exactly once?
  • Does at least one existing page link to it in running text?
  • If the record is thin, does the page return noindex and stay out of the sitemap?

Then watch Search Console's Pages report for "Crawled – currently not indexed". A rising count there means Google looked at your pages and passed. That points to thin content, not a technical fault.

How SEOAgent fits

SEOAgent installs as a GitHub App on your repo. It reads your routes, registries and sitemap, drafts the new pages or fixes (a missing canonical, a sitemap entry, an internal link into a generated page), and opens a pull request. You review the diff and merge it; nothing ships without that approval. It edits the repository, so a fix for a programmatic set lands as code in the PR, not as a recommendation in a report. It only works on sites whose code lives in a GitHub repo.

Frequently asked questions

Does programmatic SEO work with Next.js?

Yes, technically: generateStaticParams, generateMetadata and app/sitemap.ts give each generated page its own HTML, head and sitemap entry. Whether the pages get indexed depends on the content behind each URL, not on the framework.

Should I use static generation or on-demand rendering?

Pre-render the pages that matter with generateStaticParams and let the long tail render on first request, with revalidate for data that changes. Both produce HTML a crawler can read. Avoid client-only rendering for content you want indexed.

How many programmatic pages is too many?

There is no safe number. Count the pages that clear your quality gate, not the pages you can generate. If only a fraction clear it, ship those, and noindex the rest until the data improves.

Can I mix programmatic and hand-written pages?

You should. Programmatic leaf pages work best underneath a hand-written hub that explains the set and links into it. See the Next.js SEO guide for the rest of the metadata and rendering checklist.

Conclusion

Generating pages from data is cheap in Next.js, so the decision is about which pages deserve an index entry. Give every record its own metadata, send unknown slugs to a 404, drive the sitemap and the robots tag from the same rule, and keep thin pages out of the index until their data catches up. For the wider set of habits behind that, start with SEO for developers.

Tags:Next.jsSEOSEO for Developers
Photo of Alec Lindsay

About the author

Founder

Founder of SEOAgent and Baxter, ex-HeyGen.

SEOAgent for GitHub

Your first SEO pull request in about 5 minutes.

Connect the repo your site lives in. SEOAgent finds what holds the site back in search and fixes it in pull requests. You review and merge every change.

  • 14 days free
  • No card
  • $79/site/month after
OpenExample
Set up SEOAgent
  • What SEOAgent found, and the plan for your site
  • Meta descriptions for 14 pages
  • Sitemap and robots.txt
  • Organization schema
+412 −3 · 9 files · Checks passed
  • 370+sites
  • 1,100+articles written
  • 3,500+SEO changes made