Sitemap

Rspress provides an official @rspress/plugin-sitemap plugin that helps you generate sitemap.xml files for search engine optimization.

Installation

Add the sitemap plugin to your project:

pnpm add @rspress/plugin-sitemap
# or
npm install @rspress/plugin-sitemap
# or
yarn add @rspress/plugin-sitemap

Configuration

Add the sitemap plugin to rspress.config.ts:

import { defineConfig } from '@rspress/core';
import { pluginSitemap } from '@rspress/plugin-sitemap';

export default defineConfig({
  plugins: [
    pluginSitemap({
      siteUrl: 'https://your-domain.com',
    }),
  ],
});

Configuration Options

OptionDescriptionRequired
siteUrlYour website's base URL (e.g., https://your-domain.com)Yes
changefreqHow frequently the page is likely to change (e.g., daily, weekly)No
priorityPriority of this URL relative to other URLs on your site (0.0-1.0)No
excludeArray of paths to exclude from the sitemapNo

Example

import { defineConfig } from '@rspress/core';
import { pluginSitemap } from '@rspress/plugin-sitemap';

export default defineConfig({
  plugins: [
    pluginSitemap({
      siteUrl: 'https://xindi-technology.github.io/rspress-theme-aim/',
      changefreq: 'weekly',
      priority: 0.8,
      exclude: ['/404'],
    }),
  ],
});

How It Works

The sitemap plugin automatically generates a sitemap.xml file in the root of your build output directory. This file contains all the pages of your documentation site, which helps search engines crawl and index your content more efficiently.

Verification

After building your site, you can check if the sitemap.xml file has been generated by looking at the build output directory. The sitemap should be accessible at https://your-domain.com/sitemap.xml.

Benefits

  • Improved SEO: Helps search engines discover and index all pages of your site
  • Better crawl efficiency: Search engines can crawl your site more efficiently with a sitemap
  • Indexing control: You can control which pages are indexed and their priority

Notes

  • The siteUrl must be the full URL of your deployed site (including protocol)
  • For GitHub Pages, the siteUrl should be in the format: https://username.github.io/repository/
  • The sitemap is generated during the build process, so you need to rebuild your site whenever you add new pages