Repository navigation
feat(seo): ✨ site indexing, robots.txt and sitemaps from server config - #937
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
72b3f6e to
6f3e37e
Compare
Add an optional `seo` block to `buildServerConfig` and a `withSeo` server handler (`@vitnode/core/tanstack/seo/server`) composed outside `withPageCache`: - `/robots.txt` from config alone, with the AdminCP and account-settings exclusions in every locale and per-bot groups for OAI-SearchBot, GPTBot, Claude-SearchBot, ClaudeBot and Google-Extended. - `indexing: false` adds `X-Robots-Tag: noindex` to HTML (cache hits too) and a robots meta to prerendered pages; sitemaps answer 404. - `/sitemap.xml` index with root-level child files from `seo.sitemap.paths`, app list sources and every content type with `delivery.sitemap`, read as a guest through the delivery routes. - Generated XML cached in the page cache store, built incrementally per content file and expired by content writes (hard on removals and noindex toggles) and by the content revalidation receiver. - The Vite plugin writes `src/sitemap-sources.gen.ts` and warns about static robots/sitemap files that would shadow the generated ones. - Regression tests for robots, indexing, sitemaps, revalidation and sitemap sources. - Migrate vitnode.com and the starter, remove legacy static files, and document SEO and social images.
6f3e37e to
a751f91
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a751f91a69
ℹ️ 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".
| // write, so a record that left the public site leaves its sitemap too. | ||
| const sitemapMode = noIndexChanged(definition, payload) ? "hard" : mode; | ||
| const sitemapTags = [definition, ...dependents].flatMap(target => | ||
| contentSitemapPageCacheTags(target), |
There was a problem hiding this comment.
Relay sitemap invalidations for ordinary API writes
In a split API/web deployment using separate memory stores, these tag invalidations affect only the API process, even when content.revalidateOrigins is configured. Ordinary edits, deletes and manual publication changes reach invalidateContentPages through emitContentEvent, but the only callers of dispatchContentRevalidation are schedule-effects.ts and visibility-effects.ts. Consequently, deleting a record or setting its noindex field leaves its URL in the frontend's cached sitemap until the periodic refresh; the new revalidation receiver never hears about the change. Relay these mutations to the configured frontend origins as well, preserving hard invalidation for removals.
AGENTS.md reference: AGENTS.md:L103-L103
Useful? React with 👍 / 👎.
Improving Documentation
pnpm lint:fix-equivalent checks (oxlint --type-awareper package, rootoxfmt --check) before opening the PR.Description
What?
Core (
@vitnode/core,@vitnode/api)buildServerConfig({ seo }), an optional, typed contract documented in JSDoc. Leavingseoout keeps the current behavior: requests pass through untouched, so apps that serve their own robots or sitemap files keep them. Onceseois set,indexingis required. The sitemap defaults toindexing,indexing: falseturns the sitemap off whatever else is set, and any crawler left out followsUser-agent: *. Static paths are validated as canonical, unlocalized paths, normalized and deduplicated.withSeo/createSeoHandlerin@vitnode/core/tanstack/seo/server, composed outsidewithPageCache:/robots.txtis built from config only: no API, session or database. It has aUser-agent: *group with/adminand the account settings path excluded for every locale (translatedroutePathsincluded). It adds a group for each configured bot:OAI-SearchBot/GPTBot,Claude-SearchBot/ClaudeBotandGoogle-Extended. A bot set tofalsegetsDisallow: /; a bot set totruegets the baseline exclusions repeated. There is exactly one absoluteSitemap:line, andHEADreturns the same headers with no body.indexing: falseaddsX-Robots-Tag: noindexto HTML responses, including page-cache HITs, and keeps any directive already on the response. Prerendered documents also get<meta name="robots" content="noindex"/>. Sitemap routes return404./sitemap.xmlis an index of root-level child files,/sitemap-{file}-{n}.xml. They come from three sources:seo.sitemap.paths(each locale withhreflangalternates andx-default), app list sources, and every content type withdelivery.sitemap. Content records are read from the existing/delivery/sitemaproutes through a newguestRawFetcher, which sends no cookies, authorization or forwarded visitor headers. It calls the API in process for single-app deployments (falling back to the app's own server entry until the/apiroute module has loaded) and over the network for a separate API.nextCursoris treated as opaque.VITNODE_WEB_URLor a configuredi18n.domainsorigin. Each host's sitemap lists only that host's URLs. A request'sHostor forwarding headers only choose among the configured origins.waitUntilrun continues an unfinished build. A generation's part list is published only after every part is stored.503withRetry-Afterand is not cached.cache-control: no-cachewith an ETag, so removals reach the public at once.invalidateContentPagesnow also expirescontentDeliverySitemapTagfor the content type and its dependents. Toggling a record'snoIndexFieldis escalated to a hard invalidation. There was no revalidation receiver anywhere, sowithSeonow answersPOST /api/vitnode/content/revalidate. It checks the bearerCRON_SECRETin constant time, rejects stale timestamps, and expires only the sitemap tags.plugin-routes.tsnow also writessrc/sitemap-sources.gen.ts. It reuses the content definitions the public-URL check already loaded, keeps types with public API +delivery+delivery.sitemap, records plugin id, type id, endpoint and localization, and fails the build on file-name collisions. The build warns whenpublic/robots.txtorpublic/sitemap*.xmlwould shadow the generated files.contentSitemapXmlaccepts entries withoutlastModified(the newContentSitemapXmlEntrytype). TheContentSitemapEntryAPI contract is unchanged.Starter:
server.tscomposeswithSeo.vitnode.server.config.tssetsseo: { indexing: process.env.VITNODE_SEO_INDEXING === "true", sitemap: { paths: ["/"] } }, so new sites are not indexable until opted in.VITNODE_SEO_INDEXINGis added to the env examples, the monorepoturbo.jsonbuild env, and Docker compose.vitnode.com (
apps/web):VITNODE_WEB_URLishttps://vitnode.com, so previews answernoindex.sitemap.pathsreusesPRERENDERED_PATHS.src/docs/sitemap.server.ts).public/robots.txtandpublic/sitemap.xmlare removed./adminand/settingsexclusions, plus/pl/settings. Maintainers can opt in toseo.crawlersexplicitly./docs/dev/content-enginenow 301-redirects to/docs/content-engine, which is listed. Polish variants of the marketing pages are added because they are canonical.Docs:
dev/seo.mdx, registered indev/meta.json. It covers the smallest config, options and defaults, the robots output, bot controls, production vs preview, sitemap sources, freshness, and migration/verification with curl, prerendered HTML and Cloudflare's managed robots.txt.dev/configuration.mdxlistsseoand the new generated file.content-engine/seo.mdxnow leads with automatic discovery throughdelivery.sitemapand shows how to check that a published record appears and a noindex record disappears. Manual XML assembly is kept as the advanced path.Why?
Maintainers need deployment-time control over search indexing, sitemap publication and AI crawlers without hand-maintained static files. Plugin authors now only declare
delivery.sitemap.Checks run
packages/vitnode:tsc --noEmit,oxlint --type-awareandpnpm test:unitall pass: 359 files, 4,668 tests, including 150 new SEO/sitemap tests.packages/api:oxlint --type-awareandpnpm test:unitpass: 336 files, 6,143 tests, including newsitemapandpage-cachecases. A test-only mutation pass (6 deliberate engine breakages, then reverted) confirmed at least one test fails for each.apps/web:tsc --noEmit,oxlintandnode --testpass. The Node build and the Cloudflare build (pnpm build:cloudflare) both succeed.create-vitnode-appvitest: 135 tests pass. Rootoxfmt --checkpasses.Host/X-Forwarded-Host.noIndex: truerecord are not.X-Robots-Tag: noindex, prerendered files carry the robots meta, and sitemaps return 404.wrangler devon the built Worker):/has the meta tag. SSR MISS and HIT responses both carryX-Robots-Tag.process.envis populated at module load in workerd, theSitemap:line is present, and the sitemap is built in process inside the Worker.Not run: the 50 MB byte-split path has no test, because reaching it needs very large data. GitHub CI has not been inspected yet. Turbo-driven
pnpm lint/pnpm testcould not spawn tasks in this sandbox, so each package's scripts were run directly instead.Generated by Claude Code