Next.js + SEO
Meta/OG tags, canonical URL, JSON-LD, robots.txt and sitemap.xml. This page shows exactly what pickstack adds to a Next.js project for SEO: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.
$ npm create pickstack@latest my-app -- --framework next --modules seo --yesCustomize in the configurator
New files
import type { MetadataRoute } from "next";
import { siteUrl } from "@/lib/site";
export default function robots(): MetadataRoute.Robots {
return {
rules: [{ userAgent: "*", allow: "/" }],
sitemap: `${siteUrl}/sitemap.xml`,
};
}
import type { MetadataRoute } from "next";
import { siteUrl } from "@/lib/site";
export default function sitemap(): MetadataRoute.Sitemap {
return [{ url: `${siteUrl}/` }, { url: `${siteUrl}/about` }];
}
export const siteUrl =
process.env.NEXT_PUBLIC_SITE_URL ?? "https://example.com";
export const siteName = "my-app";
export const siteDescription = "my-app: a web app.";
Changes to existing files
+import type { Metadata } from "next";+ +export const metadata: Metadata = {+ title: "About",+ alternates: { canonical: "/about" },+ openGraph: { url: "/about" },+};+ export default function About() { return ( <section className="page"> <h1 className="title">About</h1> <p className="text">+ Built with Next.js (App Router), React 19, TypeScript, SEO.− Built with Next.js (App Router), React 19, TypeScript. </p> </section> );⋯ 2 unchanged lines
import type { Metadata } from "next"; import Link from "next/link";+import { siteDescription, siteName, siteUrl } from "@/lib/site"; import "./globals.css"; export const metadata: Metadata = {+ metadataBase: new URL(siteUrl),+ title: { default: siteName, template: `%s | ${siteName}` },+ description: siteDescription,+ alternates: { canonical: "/" },+ openGraph: { type: "website", siteName },+ twitter: { card: "summary" },+};+ +const jsonLd = {+ "@context": "https://schema.org",+ "@type": "WebSite",+ name: siteName,+ url: siteUrl,− title: "my-app",− description: "Generated by pickstack", }; export default function RootLayout({ children }: LayoutProps<"/">) { return ( <html lang="en"> <body>+ <script+ type="application/ld+json"+ dangerouslySetInnerHTML={{+ __html: JSON.stringify(jsonLd).replace(/</g, "\u003c"),+ }}+ /> <main className="app"> <nav className="nav"> <Link className="link" href="/">⋯ 13 unchanged lines
Project files
.gitignoreREADME.mdapp/about/page.tsxapp/globals.cssapp/layout.tsxapp/page.tsxapp/robots.tsapp/sitemap.tscomponents/Counter.tsxlib/site.tsnext.config.tspackage.jsontsconfig.json