Browse Source

Add path to `TranslatedContent` (#863)

* Add path to `TranslatedContent`

This makes it possible to retrieve the translated page through the `get_page` function.

* Use TranslatedContent::path field in test_site_i18n

Use it with the `get_page` function to get a reference to the page object.
index-subcmd
Philipp Oppermann Vincent Prouillet 5 years ago
parent
commit
72373bea9b
3 changed files with 15 additions and 0 deletions
  1. +6
    -0
      components/library/src/content/ser.rs
  2. +3
    -0
      docs/content/documentation/templates/pages-sections.md
  3. +6
    -0
      test_site_i18n/templates/page.html

+ 6
- 0
components/library/src/content/ser.rs View File

@@ -1,5 +1,6 @@
//! What we are sending to the templates when rendering them
use std::collections::HashMap;
use std::path::Path;

use tera::{Map, Value};

@@ -12,6 +13,9 @@ pub struct TranslatedContent<'a> {
lang: &'a str,
permalink: &'a str,
title: &'a Option<String>,
/// The path to the markdown file; useful for retrieving the full page through
/// the `get_page` function.
path: &'a Path,
}

impl<'a> TranslatedContent<'a> {
@@ -25,6 +29,7 @@ impl<'a> TranslatedContent<'a> {
lang: &other.lang,
permalink: &other.permalink,
title: &other.meta.title,
path: &other.file.path,
});
}

@@ -40,6 +45,7 @@ impl<'a> TranslatedContent<'a> {
lang: &other.lang,
permalink: &other.permalink,
title: &other.meta.title,
path: &other.file.path,
});
}



+ 3
- 0
docs/content/documentation/templates/pages-sections.md View File

@@ -132,5 +132,8 @@ lang: String?;
title: String?;
// A permalink to that content
permalink: String;
// The path to the markdown file; useful for retrieving the full page through
// the `get_page` function.
path: String;
```


+ 6
- 0
test_site_i18n/templates/page.html View File

@@ -4,6 +4,12 @@ Language: {{lang}}

{% for t in page.translations %}
Translated in {{t.lang|default(value=config.default_language)}}: {{t.title}} {{t.permalink|safe}}

<br><br>

{% set translated_page = get_page(path = t.path) %}
{{ translated_page.content | safe }}

{% endfor %}

{% for taxo_kind, items in page.taxonomies %}


Loading…
Cancel
Save