From b2eb00a374c71633e5a14c08732a58af253394c0 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Sun, 12 Apr 2020 19:17:29 +0200 Subject: [PATCH] Ensure lang is always set on default sections --- components/site/src/lib.rs | 2 +- docs/content/documentation/templates/overview.md | 2 +- test_site_i18n/templates/auteurs/list.html | 1 + test_site_i18n/templates/auteurs/single.html | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index eaba38e9..a095e3b7 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -458,13 +458,13 @@ impl Site { let filename = format!("_index.{}.md", l); index_section.file.path = self.content_path.join(&filename); index_section.file.relative = filename; - index_section.lang = index_section.file.find_language(&self.config)?; } else { index_section.file.name = "_index".to_string(); index_section.permalink = self.config.make_permalink(""); index_section.file.path = self.content_path.join("_index.md"); index_section.file.relative = "_index.md".to_string(); } + index_section.lang = index_section.file.find_language(&self.config)?; library.insert_section(index_section); } } diff --git a/docs/content/documentation/templates/overview.md b/docs/content/documentation/templates/overview.md index 6044d624..ed75db65 100644 --- a/docs/content/documentation/templates/overview.md +++ b/docs/content/documentation/templates/overview.md @@ -18,7 +18,7 @@ A few variables are available on all templates except RSS and the sitemap: - `config`: the [configuration](@/documentation/getting-started/configuration.md) without any modifications - `current_path`: the path (full URL without `base_url`) of the current page, never starting with a `/` - `current_url`: the full URL for the current page -- `lang`: the language for the current page; `null` if the page/section doesn't have a language set +- `lang`: the language for the current page Config variables can be accessed like `config.variable`, in HTML for example with `{{ config.base_url }}`. The 404 template does not get `current_path` and `current_url` (this information cannot be determined). diff --git a/test_site_i18n/templates/auteurs/list.html b/test_site_i18n/templates/auteurs/list.html index 5dfaaf87..0acbafe4 100644 --- a/test_site_i18n/templates/auteurs/list.html +++ b/test_site_i18n/templates/auteurs/list.html @@ -1,3 +1,4 @@ {% for author in terms %} {{ author.name }} {{ author.slug }} {{ author.pages | length }} {% endfor %} +{{lang}} \ No newline at end of file diff --git a/test_site_i18n/templates/auteurs/single.html b/test_site_i18n/templates/auteurs/single.html index 0c3f8fb8..cc1412bb 100644 --- a/test_site_i18n/templates/auteurs/single.html +++ b/test_site_i18n/templates/auteurs/single.html @@ -19,3 +19,4 @@ {% if paginator.previous %}has_prev{% endif%} {% if paginator.next %}has_next{% endif%} {% endif %} +{{lang}} \ No newline at end of file