diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e700a2d..15da4c0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ a section - The table of content for a page/section is now only available as the `toc` variable when rendering it and not anymore on the `page`/`section` variable - Default directory for `load_data` is now the root of the site instead of the `content` directory +- Change variable sent to the sitemap template, see documentation for details ### Other - Add support for content in multiple languages @@ -17,6 +18,7 @@ rendering it and not anymore on the `page`/`section` variable - Add Dracula syntax highlighting theme - Fix using inline styles in headers - Fix sections with render=false being shown in sitemap +- Sitemap is now split when there are more than 30 000 links in it ## 0.5.1 (2018-12-14) diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index d8bada6a..f0a4d5ce 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -881,17 +881,17 @@ impl Site { if total_number < sitemap_limit { // Create single sitemap let mut context = Context::new(); - context.insert("sitemap_entries", &all_sitemap_entries); + context.insert("entries", &all_sitemap_entries); let sitemap = &render_template("sitemap.xml", &self.tera, context, &self.config.theme)?; create_file(&self.output_path.join("sitemap.xml"), sitemap)?; return Ok(()) } - + // Create multiple sitemaps (max 30000 urls each) let mut sitemap_index = Vec::new(); for (i, chunk) in all_sitemap_entries.chunks(sitemap_limit).enumerate() { let mut context = Context::new(); - context.insert("sitemap_entries", &chunk); + context.insert("entries", &chunk); let sitemap = &render_template("sitemap.xml", &self.tera, context, &self.config.theme)?; let file_name = format!("sitemap{}.xml", i+1); create_file(&self.output_path.join(&file_name), sitemap)?; @@ -903,8 +903,8 @@ impl Site { let mut main_context = Context::new(); main_context.insert("sitemaps", &sitemap_index); let sitemap = &render_template("split_sitemap_index.xml", &self.tera, main_context, &self.config.theme)?; - create_file(&self.output_path.join("sitemap.xml"), sitemap)?; - + create_file(&self.output_path.join("sitemap.xml"), sitemap)?; + Ok(()) } diff --git a/components/templates/src/builtins/sitemap.xml b/components/templates/src/builtins/sitemap.xml index 3e924543..6d55d37b 100644 --- a/components/templates/src/builtins/sitemap.xml +++ b/components/templates/src/builtins/sitemap.xml @@ -1,5 +1,5 @@ - {% for sitemap_entry in sitemap_entries %} + {% for sitemap_entry in entries %} {{ sitemap_entry.permalink | safe }} {% if sitemap_entry.date %} @@ -7,4 +7,4 @@ {% endif %} {% endfor %} - \ No newline at end of file + diff --git a/docs/content/documentation/templates/sitemap.md b/docs/content/documentation/templates/sitemap.md index 86f510ce..13119c8b 100644 --- a/docs/content/documentation/templates/sitemap.md +++ b/docs/content/documentation/templates/sitemap.md @@ -6,20 +6,27 @@ weight = 60 Zola will look for a `sitemap.xml` file in the `templates` directory or use the built-in one. +If your site has more than 30 000 pages, it will automatically split +the links into multiple sitemaps as recommended by [Google](https://support.google.com/webmasters/answer/183668?hl=en): -The sitemap template gets four variables in addition of the config: +> All formats limit a single sitemap to 50MB (uncompressed) and 50,000 URLs. +> If you have a larger file or more URLs, you will have to break your list into multiple sitemaps. +> You can optionally create a sitemap index file (a file that points to a list of sitemaps) and submit that single index file to Google. -- `pages`: all pages of the site -- `sections`: all sections of the site, including an index section -- `tags`: links the tags page and individual tag page, empty if no tags -- `categories`: links the categories page and individual category page, empty if no categories +In such a case, Zola will use a template called `split_sitemap_index.xml` to render the index sitemap. -As the sitemap only requires a link and an optional date for the `lastmod` field, -all the variables above are arrays of `SitemapEntry` with the following type: + +The `sitemap.xml` template gets a single variable: + +- `entries`: all pages of the site, as a list of `SitemapEntry` + +A `SitemapEntry` has the following fields: ```ts permalink: String; date: String?; ``` -All `SitemapEntry` are sorted in each variable by their permalink. +The `split_sitemap_index.xml` also gets a single variable: + +- `sitemaps`: a list of permalinks to the sitemaps