From 72373bea9b6ded9c28ae6cf22319838058281d08 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 6 Dec 2019 13:11:30 +0100 Subject: [PATCH] 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. --- components/library/src/content/ser.rs | 6 ++++++ docs/content/documentation/templates/pages-sections.md | 3 +++ test_site_i18n/templates/page.html | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/components/library/src/content/ser.rs b/components/library/src/content/ser.rs index e5177c50..b31e3c30 100644 --- a/components/library/src/content/ser.rs +++ b/components/library/src/content/ser.rs @@ -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, + /// 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, }); } diff --git a/docs/content/documentation/templates/pages-sections.md b/docs/content/documentation/templates/pages-sections.md index f827a7df..15751a1f 100644 --- a/docs/content/documentation/templates/pages-sections.md +++ b/docs/content/documentation/templates/pages-sections.md @@ -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; ``` diff --git a/test_site_i18n/templates/page.html b/test_site_i18n/templates/page.html index 7f7b9fb9..073f979e 100644 --- a/test_site_i18n/templates/page.html +++ b/test_site_i18n/templates/page.html @@ -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}} + +

+ +{% set translated_page = get_page(path = t.path) %} +{{ translated_page.content | safe }} + {% endfor %} {% for taxo_kind, items in page.taxonomies %}