Overview
The Sitemap generator creates an XML sitemap for search engine optimization (SEO). It includes all top-level API documentation pages with metadata for search engine crawlers.Metadata
Generator identifier
Generator version
Requires metadata generator output as input
Configuration
Base URL for the documentation site (e.g., “https://nodejs.org/”)
Output directory path for the generated sitemap.xml file
Output Format
The generator produces:- Single file:
sitemap.xml - Format: XML sitemap following the sitemaps.org protocol
- Entries: One URL entry per top-level API page plus main index
Usage
Dependency Chain
- ast - Parses Markdown to AST
- metadata - Extracts API metadata
- sitemap - Creates SEO sitemap
Implementation Details
The generator:- Reads the sitemap template (
template.xml) - Reads the entry template (
entry-template.xml) - Filters entries to depth-1 headings (top-level modules)
- Creates sitemap entries for each API page
- Adds a main index page entry
- Fills templates with generated data
- Writes
sitemap.xml
Sitemap Entry Format
Each entry includes:- loc: Full URL to the page
- lastmod: Last modification date (current date)
- changefreq: Update frequency (“weekly” for API pages)
- priority: Relative priority (“0.8” for API pages, “1.0” for main page)
Entry Creation
ThecreatePageSitemapEntry function:
- Constructs full URLs from baseURL and API slug
- Sets modification date to current date in ISO format
- Assigns appropriate change frequency
- Sets priority based on page importance
Template Structure
template.xml:Main Page Entry
A special entry is added for the main API index page:- URL:
{baseURL}/latest/api/ - Change frequency: “daily”
- Priority: “1.0” (highest)
src/generators/sitemap/