| 1 | --- |
| 2 | name: seo-setup |
| 3 | description: >- |
| 4 | Set up a reusable blog, SEO, and discovery foundation for a Next.js App |
| 5 | Router project: site constants, reusable metadata helpers, MDX content |
| 6 | collections, Zod frontmatter validation, blog index/detail routes, article |
| 7 | JSON-LD, CSP and security headers in `next.config.ts`, `llms.txt`, RSS, |
| 8 | sitemap, robots, and Open Graph image resolution. Use when creating or |
| 9 | refactoring a content-driven site or blog that needs consistent metadata, |
| 10 | crawlable outputs, and contributor rules documented in `AGENTS.md` and/or |
| 11 | `README.md`. |
| 12 | --- |
| 13 | |
| 14 | # Setup Blog SEO Foundation |
| 15 | |
| 16 | Set up a reusable Next.js content system with clean separation between site constants, content logic, metadata generation, and discovery/security outputs. |
| 17 | |
| 18 | ## Core Pattern |
| 19 | |
| 20 | - Keep site-wide URLs, brand text, and OG path helpers in `lib/site.ts`. |
| 21 | - Keep generic metadata generation in `lib/metadata.ts`. |
| 22 | - Keep content schema, query helpers, and content SEO helpers under `lib/content/`. |
| 23 | - Keep authored MDX in `content/` and compile it through `content-collections.ts`. |
| 24 | - Keep CSP and the shared security header set in `next.config.ts`, applied to `/:path*`. |
| 25 | - Keep content pages inside an `app/(content)/` route group or equivalent shared content shell. |
| 26 | - Use Next.js metadata routes for `app/sitemap.ts` and `app/robots.ts`, plus `app/feed.xml/route.ts` for RSS. |
| 27 | - Keep `llms.txt` content in a source-of-truth helper and expose it through `app/llms.txt/route.ts`. |
| 28 | - Resolve Open Graph images from the route or canonical URL, with a fallback image if a route-specific asset is missing. |
| 29 | |
| 30 | ## Workflow |
| 31 | |
| 32 | 1. Read [references/implementation-checklist.md](references/implementation-checklist.md) first for the ordered setup. |
| 33 | 2. Read [references/source-map.md](references/source-map.md) when you need the recommended file layout and responsibility split. |
| 34 | 3. Read [references/content-contract.md](references/content-contract.md) when creating MDX collections, frontmatter, or editorial rules. |
| 35 | 4. Read [references/security-and-discovery.md](references/security-and-discovery.md) when wiring CSP, security headers, `llms.txt`, `robots.ts`, or `sitemap.ts`. |
| 36 | 5. Customize all project constants, route groups, supported embeds, discovery sections, and CTA variants for the target project. |
| 37 | 6. Keep one source of truth for site URLs and canonical generation. Do not hardcode the site origin across many files. |
| 38 | 7. Keep filtering, sorting, taxonomy, and related-content logic in query helpers instead of page components. |
| 39 | 8. Add or update tests around metadata helpers, schema validation, `llms.txt`, and sitemap coverage whenever you change the structure. |
| 40 | |
| 41 | ## Non-Negotiables |
| 42 | |
| 43 | - Use absolute canonical URLs in content frontmatter. |
| 44 | - Generate metadata through helpers instead of duplicating ad hoc metadata objects across content pages. |
| 45 | - Emit JSON-LD from shared helpers so article pages stay thin. |
| 46 | - Build content collections before typecheck, tests, or production builds. |
| 47 | - Keep MDX component registration centralized; do not import components directly inside MDX files. |
| 48 | - Keep SEO-facing titles in a dedicated `seoTitle` field and enforce a 50-70 character target there. |
| 49 | - Keep SEO descriptions in the 110-170 character range. |
| 50 | - For non-content pages, keep the metadata title between 50 and 70 characters and the metadata description between 110 and 170 characters, even if the visible page heading is longer. |
| 51 | - Keep the security header implementation centralized in `next.config.ts`; do not scatter CSP or header mutations across routes unless the user explicitly wants route-specific overrides. |
| 52 | - Keep `llms.txt`, `robots.ts`, and `sitemap.ts` driven from shared helpers and site constants rather than hardcoding disconnected values. |
| 53 | - Add these editorial rules and the full blog/SEO setup details to the target repository's `AGENTS.md` and/or `README.md` so future contributors keep following the same contract. |
| 54 | |
| 55 | ## Verification |
| 56 | |
| 57 | From the target app root, run the equivalent of: |
| 58 | |
| 59 | ```bash |
| 60 | npm run content:build |
| 61 | npm run typecheck |
| 62 | npm test |
| 63 | npm run build |
| 64 | ``` |
| 65 | |
| 66 | If the project uses `pnpm`, `yarn`, or `bun`, adapt the commands but keep the same order. |
| 67 | |
| 68 | ## References |
| 69 | |
| 70 | - [references/implementation-checklist.md](references/implementation-checklist.md): ordered setup steps and verification sequence |
| 71 | - [references/source-map.md](references/source-map.md): recommended file-by-file architecture map |
| 72 | - [references/content-contract.md](references/content-contract.md): frontmatter schema, editorial rules, and authoring constraints |
| 73 | - [references/security-and-discovery.md](references/security-and-discovery.md): CSP, headers, `llms.txt`, `robots.ts`, and `sitemap.ts` patterns |
| 74 | |