What is @astrojs/sitemap?
@astrojs/sitemap is an npm package designed to generate sitemaps for Astro projects. It helps in creating XML sitemaps that are essential for SEO, allowing search engines to crawl and index your website more effectively.
What are @astrojs/sitemap's main functionalities?
Basic Sitemap Generation
This feature allows you to generate a basic sitemap for your Astro project. By specifying the site URL and integrating the sitemap plugin, you can automatically create a sitemap.xml file.
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
export default defineConfig({
site: 'https://example.com',
integrations: [sitemap()]
});
Customizing Sitemap Options
This feature allows you to customize various options for your sitemap, such as change frequency, priority, excluding specific pages, and adding custom pages.
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
export default defineConfig({
site: 'https://example.com',
integrations: [
sitemap({
changefreq: 'daily',
priority: 0.8,
exclude: ['/exclude-this-page'],
customPages: ['/custom-page-1', '/custom-page-2']
})
]
});
Dynamic Sitemap Generation
This feature allows for dynamic generation of the sitemap by filtering and serializing pages. You can exclude certain pages and customize the sitemap entries dynamically.
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
export default defineConfig({
site: 'https://example.com',
integrations: [
sitemap({
filter: (page) => !page.includes('/exclude-this-page'),
serialize: (page) => ({
url: page,
lastmod: new Date().toISOString(),
changefreq: 'weekly',
priority: 0.5
})
})
]
});
Other packages similar to @astrojs/sitemap
sitemap
The 'sitemap' package is a general-purpose sitemap generator for Node.js. It offers a wide range of customization options and can be used with various frameworks. Compared to @astrojs/sitemap, it is more versatile but requires more manual setup.
next-sitemap
The 'next-sitemap' package is specifically designed for Next.js projects. It provides an easy way to generate sitemaps with minimal configuration. While it offers similar functionalities to @astrojs/sitemap, it is tailored for Next.js rather than Astro.
gatsby-plugin-sitemap
The 'gatsby-plugin-sitemap' package is a plugin for Gatsby projects that generates sitemaps automatically. It is similar to @astrojs/sitemap in terms of ease of use and integration but is specific to Gatsby.
@astrojs/sitemap 🗺
This Astro integration generates a sitemap based on your pages when you build your Astro project.
Documentation
Read the @astrojs/sitemap
docs
Support
Contributing
This package is maintained by Astro's Core team. You're welcome to submit an issue or PR! These links will help you get started:
License
MIT
Copyright (c) 2023–present Astro