Skip to content

Add SEO management: robots.txt and XML sitemaps - #933

Open
aXenDeveloper wants to merge 2 commits into
canaryfrom
claude/vitnode-seo-implementation-3848a1
Open

aXenDeveloper wants to merge 2 commits into
canaryfrom
claude/vitnode-seo-implementation-3848a1

Conversation

@aXenDeveloper

Copy link
Copy Markdown
Owner

Description

What?

Adds comprehensive SEO management to VitNode, enabling admins to control robots.txt generation and XML sitemaps through the AdminCP without code changes. This includes:

  • Dynamic robots.txt generation served at /robots.txt with configurable:

    • Site indexing toggle (allow/disallow all)
    • AI training crawler blocking (GPTBot, ClaudeBot, etc.)
    • Custom robots.txt rules
    • Automatic private area disallowing (/admin, /settings, /modcp, /notifications, /files)
  • XML sitemap infrastructure served at /sitemap.xml (index) and /sitemaps/{source}-{page}.xml (sub-sitemaps) with:

    • Per-content-type sitemaps (when delivery.sitemap is enabled)
    • Plugin/app-contributed static pages and custom sources
    • Per-source enable/disable toggle in AdminCP
    • Configurable URLs per file (100-50,000)
    • Support for hreflang alternates and image metadata
    • Proper cache headers and offline handling
  • AdminCP interface at System → SEO with tabs for:

    • Robots.txt preview and settings
    • Sitemap configuration and source management
    • Permission-based access control
  • Database schema (core_seo_settings table) to persist settings with audit logging

Why?

SEO is critical for discoverability. Previously, VitNode had a static sitemap and no robots.txt control. This implementation:

  • Lets admins manage crawling without code (e.g., hide staging sites from Google, block AI scrapers)
  • Automatically includes all published content in sitemaps
  • Provides extensibility for plugins and apps to contribute pages
  • Follows XML sitemap protocol standards (max 50k URLs per file, proper namespaces)
  • Integrates with VitNode's publication, localization, and access control systems

Test Plan

Added comprehensive test coverage:

  • sitemap.test.ts: Sitemap XML generation, file naming, pagination
  • robots.test.ts: robots.txt building, AI crawler blocking, custom rules normalization
  • static-source.test.ts: Static page sitemap entries with locale routing
  • sitemap-source.test.ts: Content type sitemap generation with publication/access filtering
  • config.test.ts: SEO config resolution and source ordering
  • settings.test.ts: Settings merging and validation
  • seo.route.test.ts: HTTP endpoints for robots.txt and sitemaps with caching and offline handling
  • seo.route.test.ts (admin): Admin API for reading/updating settings with permissions

Existing content delivery tests updated to support new sitemap conditions.

…ontrols

robots.txt
- /robots.txt is generated by the API: private areas (/admin, /settings,
  /modcp, /notifications, /files) disallowed in every language, an optional
  group blocking AI training crawlers, custom rules and the Sitemap line.
- "Allow search engines to index this site" off turns it into
  `Disallow: /` and makes every sitemap answer 404 (staging kill switch).
- While the site is offline it answers 503 with Retry-After, so crawlers
  pause instead of dropping pages.

Sitemaps
- /sitemap.xml is a sitemap index; /sitemaps/{source}-{page}.xml are its
  chunked files (URLs per file configurable, default 10,000), with
  xhtml:link hreflang alternates and image:image only when used, strict
  XML escaping and Cache-Control: public, max-age=3600, s-maxage=3600,
  stale-while-revalidate=86400.
- Sitemap registry: core `static` source (/, plugin and app paths,
  localized with x-default), one source per Content Engine type with
  delivery.sitemap, `buildApiPlugin({ sitemap })`,
  `buildApiConfig({ seo })`, `registerSitemapSource`,
  `defineSitemapSource` and `staticSitemapSource`. Ids are validated
  against /^[a-z0-9_-]+$/ and duplicates fail at boot.
- Content sources list only published, guest-readable, not-noIndex records
  at their current slug, one URL per published translation, ordered by id,
  selecting only id, slug, timestamps and the cover image id.
- Blog and forum add /blog and /forum; apps/web adds its marketing pages
  and a docs source, replacing the static public/robots.txt and
  public/sitemap.xml.
- robots.txt, sitemap.xml and /sitemaps are never locale-prefixed.

AdminCP
- System -> SEO with "General & robots.txt" (indexing, AI crawlers,
  custom rules, live preview) and "Sitemaps" (enable, URLs per file,
  sources table with URL counts, preview links and per-source switches).
- New `seo` staff permissions (can_view, can_manage), core_seo_settings
  table and migration, GET/PATCH /admin/seo/settings,
  GET /admin/seo/robots/preview, audit log entries and the
  seo.settings.updated event.

Web
- `@vitnode/core/tanstack/seo/server` handlers and root route files in
  apps/web and the create-vitnode-app template.

Docs
- New "Robots and sitemaps" and "Sitemap sources" pages, Content Engine
  SEO sitemap section rewritten, SEO events documented.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CnAiFZNJNobrZC6R2qu7sj
…routes

- Pure functions: buildRobotsTxt/normalizeCustomRobots, parseSitemapFileName,
  sitemapPageCount, sitemapUrlsetXml, defineSitemapSource, mergeSeoSettings,
  resolveSeoConfig and staticSitemapEntries on a real locale routing.
- Public routes on the in-memory database: headers, 404s when indexing or
  sitemaps are off, a source is disabled or a page is out of range, and 503
  with Retry-After while the site is offline.
- AdminCP routes: 403 without the seo permission, 400 for an unknown source,
  and a disabled source leaving the index and its file at once.
- contentSitemapSource: drafts, scheduled, hidden, noIndex (null included)
  and guest-restricted records are left out; localized types list each
  published translation with hreflang alternates and x-default.
- memory-db: evaluate IS [NOT] DISTINCT FROM, which the sitemap's noIndex
  condition uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CnAiFbAM6TCSyfasoERNUE
@github-actions

Copy link
Copy Markdown

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

No release type found in pull request title "Add SEO management: robots.txt and XML sitemaps". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T20:50:03.782491Z ef42bcb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit ef42bcb.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ef42bcbee2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +99 to +102
onToggle={async (source, enabled) => {
const disabled = new Set(
data.settings.sitemap.disabledSources,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Serialize source toggles or disable conflicting switches

If an administrator switches off two sources before the first save completes, both handlers build their replacement disabledSources array from the same stale data. Starting with no disabled sources, the requests send [A] and [B], so the last save silently re-enables the other source even though both actions report success. SourceSwitch only disables itself, leaving sibling switches active. Track pending state at the table/screen level and disable conflicting controls, or serialize updates against the latest saved state, as required by the action-loading guidance in AGENTS.md.

AGENTS.md reference: AGENTS.md:L46-L46

Useful? React with 👍 / 👎.

const admin = c.get("admin");
if (!admin) throw new HTTPException(403);

const next = mergeSeoSettings(await loadSeoSettings(c), body);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Merge partial settings updates under the database lock

When two administrators save different settings concurrently, both requests can load the same settings here and compute complete replacement objects before either transaction commits. Although saveSeoSettings subsequently locks the row, it writes every field from that already-computed object rather than merging with the locked row. For example, a sitemap-settings save can undo another administrator's concurrent allowIndexing: false update despite omitting that field from its PATCH. Read and merge the partial update inside the transaction against the locked database state, rather than using the cached pre-transaction settings.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants