Skip to content

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.

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.

  1. Run a build for your Astro project.

    Terminal window
    npm run build
  2. Start the preview server.

    Terminal window
    npm run preview
  3. Open http://localhost:4321/sitemap-0.xml in your browser to see the generated file.

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.

astro.config.mjs
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,
},
],
},
}),
],
});