Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
This Astro integration generates a sitemap based on your pages when you build your Astro project.
Why Astro Sitemap
A Sitemap is an XML file that outlines all of the pages, videos, and files on your site. Search engines like Google read this file to crawl your site more efficiently. See Google’s own advice on sitemaps to learn more.
A sitemap file is recommended for large multi-page sites. If you don’t use a sitemap, most search engines will still be able to list your site’s pages, but a sitemap is a great way to ensure that your site is as search engine friendly as possible.
With Astro Sitemap, you don’t have to worry about creating this XML file yourself: the Astro Sitemap integration will crawl your statically-generated routes and create the sitemap file, including dynamic routes like
src/pages/[lang]/[version]/info.astro generated by
This integration cannot generate sitemap entries for dynamic routes in SSR mode.
astro add command-line tool automates the installation for you. Run one of the following commands in a new terminal window. (If you aren’t sure which package manager you’re using, run the first command.) Then, follow the prompts, and type “y” in the terminal (meaning “yes”) for each one.
If you run into any issues, feel free to report them to us on GitHub and try the manual installation steps below.
First, install the
@astrojs/sitemap package using your package manager. If you’re using npm or aren’t sure, run this in the terminal:
Then, apply this integration to your
astro.config.* file using the
@astrojs/sitemap requires a deployment / site URL for generation. Add your site’s URL under your
astro.config.* using the
site property. This must begin with
Note that unlike other configuration options,
site is set in the root
defineConfig object, rather than inside the
After verifying that the sitemaps are built, you can add them to your site’s
<head> and the
robots.txt file for crawlers to pick up.
Example of generated files for a two-page website
To configure this integration, pass an object to the
sitemap() function call in
All pages are included in your sitemap by default. By adding a custom
filter function, you can filter included pages by URL.
The function will be called for every page on your site. The
page function parameter is the full URL of the page currently under considering, including your
site domain. Return
true to include the page in your sitemap, and
false to leave it out.
To filter multiple pages, add arguments with target URLs.
In some cases, a page might be part of your deployed site but not part of your Astro project. If you’d like to include a page in your sitemap that isn’t created by Astro, you can use this option.
The maximum number entries per sitemap file. The default value is 45000. A sitemap index and multiple sitemaps are created if you have more entries. See this explanation of splitting up a large sitemap.
changefreq, lastmod, and priority
These options correspond to the
<priority> tags in the Sitemap XML specification.
priority are ignored by Google.
A function called for each sitemap entry just before writing to a disk. This function can be asynchronous.
It receives as its parameter a
SitemapItem object that can have these properties:
url(absolute page URL). This is the only property that is guaranteed to be on
lastmod(ISO formatted date,
links property contains a
LinkItem list of alternate pages including a parent page.
LinkItem type has two fields:
url (the fully-qualified URL for the version of this page for the specified language) and
lang (a supported language code targeted by this version of the page).
serialize function should return
SitemapItem, touched or not.
The example below shows the ability to add sitemap specific properties individually.
To localize a sitemap, pass an object to this
This object has two required properties:
String. Its value must exist as one of
Record<String, String>, key/value - pairs. The key is used to look for a locale part in a page path. The value is a language attribute, only English alphabet and hyphen allowed.
The resulting sitemap looks like this:
- The official Astro website uses Astro Sitemap to generate its sitemap.
- Browse projects with Astro Sitemap on GitHub for more examples!
For help, check out the
#support channel on Discord. Our friendly Support Squad members are here to help!
You can also check our Astro Integration Documentation for more on integrations.
This package is maintained by Astro’s Core team. You’re welcome to submit an issue or PR!
See CHANGELOG.md for a history of changes to this integration.