SEO
Sitemap
Publish a generated /sitemap.xml for a VitNode site with your own pages, Content Engine records and app-owned URL lists, kept fresh automatically.
With SEO set up and indexing: true, VitNode publishes /sitemap.xml: a sitemap index that lists your app's pages, every published Content Engine record and any other URL list you add. It refreshes itself when content changes.
What the sitemap lists
/sitemap.xml is a sitemap index. Each child file sits at the site root, so it may list any URL on the host:
| Child file | Source |
|---|---|
/sitemap-pages-1.xml | seo.sitemap.paths, once per language, with hreflang alternates |
/sitemap-blog-pl-1.xml | A content type with delivery.sitemap, one file per language and part |
/sitemap-docs-1.xml | A list source you pass to withSeo, such as your own docs |
The sitemap is off while indexing is false, and sitemap: { enabled: false } turns it off on an indexable site too. Then /sitemap.xml answers 404 and robots.txt has no Sitemap: line.
Add your own pages
List canonical, public, indexable pages in seo.sitemap.paths, without a language prefix:
seo: {
indexing: true,
sitemap: { paths: ['/', '/about', '/plugins'] },
},VitNode adds each language's URL through your locale routing: "/plugins" becomes /plugins and /pl/plugins, each with xhtml:link alternates and an x-default.
- A path starts with
/and has no query, hash,..segment or language prefix./adminand/apipaths are refused. - A trailing slash is dropped and duplicates are merged.
- App paths get no
lastmod, since VitNode has no real modification date for them.
An invalid path stops the server at startup with a SeoConfigError that names the entry.
Content Engine records
A plugin author only adds delivery.sitemap to a content type. At build time VitNode finds every such type in your configured plugins, writes it to src/sitemap-sources.gen.ts and lists its published records, one file per language. See Content SEO for what a record needs to appear.
VitNode reads each type's /delivery/sitemap route as a guest, sending no cookie or Authorization header, so the XML is the same when a signed-in admin opens it. Drafts, hidden and restricted records, unpublished translations and records marked noindex stay out.
App-owned lists
Pass any other bounded list of URLs as a source. vitnode.com publishes its documentation pages this way:
import '@tanstack/react-start/server-only'
import type { SeoSitemapListSource } from '@vitnode/core/tanstack/seo/server'
export const docsSitemapSource: SeoSitemapListSource = {
id: 'docs',
urls: async () => {
const { source } = await import('./source.server')
return source.getPages().map((page) => ({ path: page.url }))
},
}Then add it to withSeo in src/server.ts:
export default withSeo(entry, {
config: vitNodeServerConfig,
sitemap: sitemapManifest,
sources: [docsSitemapSource],
})The list is read once per server process. A URL may carry lastModified and alternates; one on a host you have not configured is dropped.
How the sitemap stays fresh
Generated XML is kept in the page cache's store, configured by pageCache.storage: one process's memory by default, or Redis shared by every instance. Nothing else needs setting up.
- A child file holds at most 1,000 URLs and stays under the protocol's 50 MB limit.
- A content file is cached for an hour. A publish, edit, slug change, delete, hide, or a change to a record's
noindexfield expires it at once. Removals are hard: XML that lists a removed URL is never served again. Additions may take one more request to appear. - The index lives for 10 minutes and is rebuilt as soon as any file it lists changes, so every child it links to exists.
- A large content type is built a few API pages per request and finished in the background. Until every part is ready, the previous complete sitemap is served. A crawler gets
503withRetry-Afteronly while there is no complete, valid copy, for example right after a deployment or a removal. Failures are never cached.
In a separate front end, list its origin in the API's content.revalidateOrigins. withSeo answers that POST /api/vitnode/content/revalidate itself, checks CRON_SECRET and expires the affected sitemap files. Give the front end the same CRON_SECRET as the API.
Check the result
Open the index and one child
curl -s https://example.com/sitemap.xml
curl -s https://example.com/sitemap-pages-1.xml | head -n 20Both answer application/xml; charset=utf-8. Every <loc> in the index opens a child file on the same host.
Publish and hide a record
Publish an article, then request its file again. Its URL appears. With the blog plugin:
curl -s https://example.com/sitemap-blog-en-1.xml | grep english-titleSet the record's noIndexField to true, or hide it, and the same command prints nothing.
Related
- Content SEO:
delivery.sitemapand the per-type sitemap route. - SEO reference:
sitemapoptions and the list source types.