Browse Source

Update docs for sitemap

index-subcmd
Vincent Prouillet 5 years ago
parent
commit
7baf08cef2
4 changed files with 24 additions and 15 deletions
  1. +2
    -0
      CHANGELOG.md
  2. +5
    -5
      components/site/src/lib.rs
  3. +2
    -2
      components/templates/src/builtins/sitemap.xml
  4. +15
    -8
      docs/content/documentation/templates/sitemap.md

+ 2
- 0
CHANGELOG.md View File

@@ -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)


+ 5
- 5
components/site/src/lib.rs View File

@@ -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(())
}



+ 2
- 2
components/templates/src/builtins/sitemap.xml View File

@@ -1,5 +1,5 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for sitemap_entry in sitemap_entries %}
{% for sitemap_entry in entries %}
<url>
<loc>{{ sitemap_entry.permalink | safe }}</loc>
{% if sitemap_entry.date %}
@@ -7,4 +7,4 @@
{% endif %}
</url>
{% endfor %}
</urlset>
</urlset>

+ 15
- 8
docs/content/documentation/templates/sitemap.md View File

@@ -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

Loading…
Cancel
Save