Overview & Quick Start
Payload CMS to Next.js SEO
@nexload-sdk/seo
v1.0.0 ReleasedSEO 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).
Entries
Section titled “Entries”| Entry | Runtime | Peers | Purpose |
|---|---|---|---|
@nexload-sdk/seo | Universal (Node / Browser) | None | Portable JSON contracts (SeoSite, SeoDocument, SeoRoute) and pure mappers (toSeoSite, toSeoDocument, toRedirectKey) |
@nexload-sdk/seo/next | Next.js App Router | next | resolveSeo, createSitemap, createRobots |
@nexload-sdk/seo/payload | Node.js / Payload CMS | payload, @payloadcms/plugin-seo | nexloadSeo plugin (meta fields, seo-settings global, Persian labels, publishedAt/contentUpdatedAt, automatic redirects) |
@nexload-sdk/seo/payload/admin.css | Payload Admin UI | payload | Bidirectional/RTL search preview rules (.nexload-seo-meta) |
Installation
Section titled “Installation”pnpm add @nexload-sdk/seonpm install @nexload-sdk/seoyarn add @nexload-sdk/seobun add @nexload-sdk/seoPeer 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.
Quick Start
Section titled “Quick Start”Payload CMS (payload.config.ts)
Section titled “Payload CMS (payload.config.ts)”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;}What it does not do
Section titled “What it does not do”- No built-in HTTP endpoints:
@nexload-sdk/seoships no Payload routes. Your CMS must expose/api/seo/route,/api/seo/settings, and/api/seo/sitemap/:sourcewithoverrideAccess: falsefor content reads. - No cache invalidation: The consumer owns HTTP reads, route lookup, and cache policy. Pair with
@nexload-sdk/payload-revalidatewhen 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
./nextentries never importpayload. Next.js reads public JSON from the CMS over HTTP. - Not supported in v1: Content localization (
config.localization),experimental.localizeStatus, auth collections, an existingseo-settingsglobal, or existing top-levelmeta,publishedAt, orcontentUpdatedAtfields (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.