Skip to main content

Sitemap

LitMDX automatically generates a sitemap.xml at build time from your docs folder, helping search engines like Google discover and index all your pages.

Sitemap

LitMDX can automatically generate a sitemap.xml file when you run litmdx build. The sitemap tells search engine crawlers (Google, Bing, etc.) which pages exist on your site, helping them index your documentation faster and more accurately.

Note

The sitemap is only generated during litmdx build. It is not available in dev mode.

Enabling the sitemap

Set the siteUrl field in litmdx.config.ts to the canonical base URL of your deployed site:

// litmdx.config.ts
import { defineConfig } from '@litmdx/core';

export default defineConfig({
  title: 'My Docs',
  siteUrl: 'https://docs.example.com',
});

That is all. After running litmdx build, a sitemap.xml file will appear at dist/sitemap.xml.

If siteUrl is not set, the build completes normally and no sitemap is written — there is no error.


Output format

The generated sitemap follows the Sitemaps 0.9 protocol:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://docs.example.com/</loc>
    <lastmod>2025-01-15</lastmod>
  </url>
  <url>
    <loc>https://docs.example.com/guide</loc>
    <lastmod>2025-01-14</lastmod>
  </url>
  <url>
    <loc>https://docs.example.com/reference/configuration</loc>
    <lastmod>2025-01-10</lastmod>
  </url>
</urlset>

Each entry contains:

FieldSource
<loc>siteUrl + route derived from the MDX file path
<lastmod>Last modification time (mtime) of the source file

URL derivation

Routes follow the same logic as the LitMDX router:

FileURL
docs/index.mdx/
docs/guide.mdx/guide
docs/guide/index.mdx/guide
docs/guide/install.mdx/guide/install
docs/reference/config.md/reference/config

Both .mdx and .md files are included.


Submitting to search engines

Once deployed, add your sitemap URL to:

  • Google Search Console → Sitemaps → https://docs.example.com/sitemap.xml
  • Bing Webmaster Tools → Sitemaps → same URL

robots.txt

litmdx build also writes a robots.txt file to dist/robots.txt automatically — no configuration required.

When siteUrl is set, the generated file includes a Sitemap: directive pointing to your sitemap:

User-agent: *
Allow: /

Sitemap: https://docs.example.com/sitemap.xml

When siteUrl is not set, the file is still written but without the Sitemap: line:

User-agent: *
Allow: /

Note

If you place a robots.txt in your public/ directory, Vite copies it to dist/ during the build. In that case your file takes precedence over the generated one, since Vite copies public/ before LitMDX writes the generated file.