Skip to content

Overview & Quick Start

Payload CMS to Next.js SEO

@nexload-sdk/seo

v1.0.0 Released

SEO contracts, Next.js metadata/sitemap/robots and a Payload CMS SEO plugin.

Examples follow workspace source. Check pending Changesets against your installed version.

SDK dependencies: @nexload-sdk/logger, @nexload-sdk/persian

@nexload-sdk/seo ships the SEO publishing path from Payload CMS to Next.js App Router across three independent ESM entries: portable JSON contracts and pure mappers (.), Next.js Metadata, JSON-LD, sitemap, and robots helpers (./next), and a Payload CMS plugin (./payload).

EntryRuntimePeersPurpose
@nexload-sdk/seoUniversal (Node / Browser)NonePortable JSON contracts (SeoSite, SeoDocument, SeoRoute) and pure mappers (toSeoSite, toSeoDocument, toRedirectKey)
@nexload-sdk/seo/nextNext.js App RouternextresolveSeo, createSitemap, createRobots
@nexload-sdk/seo/payloadNode.js / Payload CMSpayload, @payloadcms/plugin-seonexloadSeo plugin (meta fields, seo-settings global, Persian labels, publishedAt/contentUpdatedAt, automatic redirects)
@nexload-sdk/seo/payload/admin.cssPayload Admin UIpayloadBidirectional/RTL search preview rules (.nexload-seo-meta)
Terminal window
pnpm add @nexload-sdk/seo

Peer dependencies: next >=16.0.0 <17.0.0 (optional, ./next only), payload >=3.85.0 <4.0.0 (optional, ./payload only), @payloadcms/plugin-seo >=3.85.0 <4.0.0 (optional, ./payload only)

For automatic redirects (redirects: true), also install and configure @payloadcms/plugin-redirects before nexloadSeo.

Configure @payloadcms/plugin-redirects before nexloadSeo, set serverURL to your public CMS origin, and restrict settingsAccess.update to authorized roles:

import { redirectsPlugin } from "@payloadcms/plugin-redirects";
import { nexloadSeo } from "@nexload-sdk/seo/payload";
import { buildConfig } from "payload";
export default buildConfig({
serverURL: process.env.CMS_PUBLIC_URL,
// collections: users, media (with required `alt`), posts (with unique `slug`)
// endpoints: seoEndpoints (you own /api/seo/route, /api/seo/settings, /api/seo/sitemap/:source)
plugins: [
redirectsPlugin({ collections: ["posts"] }),
nexloadSeo({
siteUrl: "https://example.com",
uploadsCollection: "media",
redirects: true,
sitemapSources: ["posts"],
settingsAccess: {
update: ({ req }) => Boolean(req.user?.roles?.some((r) => r === "admin" || r === "seo")),
},
collections: {
posts: {
freshness: ["title", "content"],
path: (doc) => `/blog/${doc.slug ?? ""}`,
},
},
}),
],
});

Next.js App Router (app/[...path]/page.tsx)

Section titled “Next.js App Router (app/[...path]/page.tsx)”

Fetch public JSON from your CMS endpoints (check res.ok before parsing), map settings with toSeoSite, and render metadata and jsonLd from resolveSeo:

import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { toSeoSite, type SeoRoute, type SeoSettingsDoc } from "@nexload-sdk/seo";
import { resolveSeo } from "@nexload-sdk/seo/next";
export async function generateMetadata({ params }: { params: Promise<{ path: string[] }> }): Promise<Metadata> {
const { path: segments } = await params;
const routeRes = await fetch(`${process.env.CMS_URL}/api/seo/route?path=${encodeURIComponent(`/${segments.join("/")}`)}`, { cache: "no-store" });
if (!routeRes.ok) throw new Error(`Failed to fetch SEO route: ${routeRes.status}`);
const route = (await routeRes.json()) as SeoRoute;
if (route.kind !== "page") return {};
const settingsRes = await fetch(`${process.env.CMS_URL}/api/seo/settings`, { cache: "no-store" });
if (!settingsRes.ok) throw new Error(`Failed to fetch SEO settings: ${settingsRes.status}`);
const site = toSeoSite((await settingsRes.json()) as SeoSettingsDoc, { url: process.env.SITE_URL! });
return resolveSeo(route.page, site).metadata;
}
  • No built-in HTTP endpoints: @nexload-sdk/seo ships no Payload routes. Your CMS must expose /api/seo/route, /api/seo/settings, and /api/seo/sitemap/:source with overrideAccess: false for content reads.
  • No cache invalidation: The consumer owns HTTP reads, route lookup, and cache policy. Pair with @nexload-sdk/payload-revalidate when caching pages, sitemap, or robots.
  • No slug normalization: The plugin requires a unique slug field on SEO collections; it does not generate or normalize slugs itself.
  • No direct Payload calls from Next.js: The root and ./next entries never import payload. Next.js reads public JSON from the CMS over HTTP.
  • Not supported in v1: Content localization (config.localization), experimental.localizeStatus, auth collections, an existing seo-settings global, or existing top-level meta, publishedAt, or contentUpdatedAt fields (these throw a startup error).

See guides for the full CMS endpoints implementation, sitemap.ts, robots.ts, proxy.ts, AI crawler presets, Persian URLs, and limits, and the API reference for exports and logging events.

Production Guides & Recipes

Optimization

Agent usage