Generate the sitemap.xml file for a site
seo-in-astro can generate the sitemap.xml file for your Astro site with automatic route detection.
Enabling sitemap.xml generation
Section titled “Enabling sitemap.xml generation”The sitemap is generated by default without any configuration needed. seo-in-astro automatically detects and includes all routes in your Astro site in the generated sitemap.xml file.
Viewing the sitemap.xml file
Section titled “Viewing the sitemap.xml file”-
Run a build for your Astro project.
Terminal window npm run buildTerminal window yarn buildTerminal window pnpm build -
Start the preview server.
Terminal window npm run previewTerminal window yarn previewTerminal window pnpm preview -
Open http://localhost:4321/sitemap-0.xml in your browser to see the generated file.
Advanced sitemap configuration
Section titled “Advanced sitemap configuration”By default, seo-in-astro generates a basic sitemap with all detected routes.
However, you can customize each route’s metadata by using the sitemapXml option in the integration configuration.
This option allows you to specify additional properties for each route, such as modification date, priority, change frequency, and more.
import { defineConfig } from "astro/config";import { seoInAstro } from "@dlcastillop/seo-in-astro";
export default defineConfig({ integrations: [ seoInAstro({ baseUrl: "https://example.com", siteName: "Example", defaultOgImg: "/default-og.png", sitemapXml: { sitemap: [ { route: "/", lastModified: new Date(), changeFrequency: "daily", priority: 1, }, { route: "/about", lastModified: new Date("2024-01-15"), changeFrequency: "monthly", priority: 0.8, }, ], }, }), ],});