eleventy-plugin-sitemap
Eleventy plugin to generate a sitemap using ekalinin/sitemap generator.
Installation
Install the package:
npm install --save eleventy-plugin-sitemap
Add the plugin to your Eleventy configuration
(usually .eleventy.js
):
const sitemap = ; module { eleventyConfig;};
Usage
Create a sitemap file and use the shortcode to generate the sitemap XML:
---permalink: /sitemap.xmllayout: nulleleventyExcludeFromCollections: true---{% sitemap collections.all %}
The above snippet does the following:
- Sets the permalink to
/sitemap.xml
. - Disables any layout.
- Excludes the sitemap file from Eleventy collections.
- Calls the
sitemap
shortcode.
As the first argument to the shortcode, you pass the collection of items that you want to use in the sitemap.
This shortcode is available for Liquid, Nunjucks, and Javascript templates.
You can also copy this sample from the examples and adapt it to your needs:
cp node_modules/eleventy-plugin-sitemap/examples/sitemap.njk sitemap.njk
After creating the sitemap, you should add the sitemap to robots.txt
:
Sitemap: https://example.com/sitemap.xml
Options
The following options are available:
eleventyConfig;
Advanced usage
Customizing sitemap properties
You can customize the values used for the sitemap links by adding front matter to your pages.
---sitemap: - changefreq: weekly - priority: 0.8---
For a full list of options, please refer to Sitemap Item Options.
Exclude pages from the sitemap
You have several options to exclude pages from the sitemap.
You can exclude them using the standard eleventyExcludeFromCollections
property, which will exclude them from all collections.
---eleventyExcludeFromCollections: true---
You can use the ignore
property on the sitemap
data, which will only
exclude it from the sitemap.
---sitemap: - ignore: true---
Or you can create a custom collection that excludes the items that you don't want in the sitemap and then pass that collection to the shortcode.
eleventyConfig;
Specify the collection in the shortcode:
{% sitemap collections.sitemap %}
Create a multilingual sitemap
For creating a multilingual sitemap you need to add alternate language child links for each link.
You could do this with front matter and the links property , but in most cases it's easier to do this with a custom collection.
eleventyConfig;
And then pass that collection to the sitemap shortcode:
{% sitemap collections.sitemap %}
Maintainers
License
MIT. See LICENSE.