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.
This commit is contained in:
parent
73ea4b3b16
commit
72373bea9b
|
@ -1,5 +1,6 @@
|
||||||
//! What we are sending to the templates when rendering them
|
//! What we are sending to the templates when rendering them
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use tera::{Map, Value};
|
use tera::{Map, Value};
|
||||||
|
|
||||||
|
@ -12,6 +13,9 @@ pub struct TranslatedContent<'a> {
|
||||||
lang: &'a str,
|
lang: &'a str,
|
||||||
permalink: &'a str,
|
permalink: &'a str,
|
||||||
title: &'a Option<String>,
|
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> {
|
impl<'a> TranslatedContent<'a> {
|
||||||
|
@ -25,6 +29,7 @@ impl<'a> TranslatedContent<'a> {
|
||||||
lang: &other.lang,
|
lang: &other.lang,
|
||||||
permalink: &other.permalink,
|
permalink: &other.permalink,
|
||||||
title: &other.meta.title,
|
title: &other.meta.title,
|
||||||
|
path: &other.file.path,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +45,7 @@ impl<'a> TranslatedContent<'a> {
|
||||||
lang: &other.lang,
|
lang: &other.lang,
|
||||||
permalink: &other.permalink,
|
permalink: &other.permalink,
|
||||||
title: &other.meta.title,
|
title: &other.meta.title,
|
||||||
|
path: &other.file.path,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,5 +132,8 @@ lang: String?;
|
||||||
title: String?;
|
title: String?;
|
||||||
// A permalink to that content
|
// A permalink to that content
|
||||||
permalink: String;
|
permalink: String;
|
||||||
|
// The path to the markdown file; useful for retrieving the full page through
|
||||||
|
// the `get_page` function.
|
||||||
|
path: String;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,12 @@ Language: {{lang}}
|
||||||
|
|
||||||
{% for t in page.translations %}
|
{% for t in page.translations %}
|
||||||
Translated in {{t.lang|default(value=config.default_language)}}: {{t.title}} {{t.permalink|safe}}
|
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 %}
|
{% endfor %}
|
||||||
|
|
||||||
{% for taxo_kind, items in page.taxonomies %}
|
{% for taxo_kind, items in page.taxonomies %}
|
||||||
|
|
Loading…
Reference in a new issue