On This Page
⏱ 1 min read
Sitemap Generator
What it does: Automatically generates a sitemap.xml file for search engines.
File types: Generates sitemap.xml
Events:
POST_RENDER(priority 100): Collects URLsPOST_LOOP(priority 100): Generates XML file
How it works:
- Listens as each page is rendered
- Collects the URL and last modification date
- Generates a standard XML sitemap at the end of the build process
- Saves the file to
output/sitemap.xml
Configuration
The Sitemap Generator uses the SITE_URL (or SITE_BASE_URL) from your .env file to generate absolute URLs.
# .env
SITE_URL="https://example.com"
Output Example
The generated sitemap.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://example.com/index.html</loc>
<lastmod>2023-11-25</lastmod>
</url>
<url>
<loc>https://example.com/about.html</loc>
<lastmod>2023-11-24</lastmod>
</url>
</urlset>
Customizing Last Modified Date
By default, the generator uses the file's modification time. You can override this by adding a date field to your content's frontmatter:
---
title: "My Page"
date: "2023-12-01"
---