@@ -5,6 +5,8 @@ | |||||
### Breaking | ### Breaking | ||||
- `earlier/later` and `lighter/heavier` are not set anymore on pages when rendering | - `earlier/later` and `lighter/heavier` are not set anymore on pages when rendering | ||||
a section | 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 | |||||
### Other | ### Other | ||||
- Add support for content in multiple languages | - Add support for content in multiple languages | ||||
@@ -270,6 +270,7 @@ impl Page { | |||||
context.insert("current_path", &self.path); | context.insert("current_path", &self.path); | ||||
context.insert("page", &self.to_serialized(library)); | context.insert("page", &self.to_serialized(library)); | ||||
context.insert("lang", &self.lang); | context.insert("lang", &self.lang); | ||||
context.insert("toc", &self.toc); | |||||
render_template(&tpl_name, tera, context, &config.theme).map_err(|e| { | render_template(&tpl_name, tera, context, &config.theme).map_err(|e| { | ||||
Error::chain(format!("Failed to render page '{}'", self.file.path.display()), e) | Error::chain(format!("Failed to render page '{}'", self.file.path.display()), e) | ||||
@@ -189,6 +189,7 @@ impl Section { | |||||
context.insert("current_path", &self.path); | context.insert("current_path", &self.path); | ||||
context.insert("section", &self.to_serialized(library)); | context.insert("section", &self.to_serialized(library)); | ||||
context.insert("lang", &self.lang); | context.insert("lang", &self.lang); | ||||
context.insert("toc", &self.toc); | |||||
render_template(tpl_name, tera, context, &config.theme).map_err(|e| { | render_template(tpl_name, tera, context, &config.theme).map_err(|e| { | ||||
Error::chain(format!("Failed to render section '{}'", self.file.path.display()), e) | Error::chain(format!("Failed to render section '{}'", self.file.path.display()), e) | ||||
@@ -67,7 +67,6 @@ pub struct SerializingPage<'a> { | |||||
summary: &'a Option<String>, | summary: &'a Option<String>, | ||||
word_count: Option<usize>, | word_count: Option<usize>, | ||||
reading_time: Option<usize>, | reading_time: Option<usize>, | ||||
toc: &'a [Header], | |||||
assets: &'a [String], | assets: &'a [String], | ||||
draft: bool, | draft: bool, | ||||
lang: &'a str, | lang: &'a str, | ||||
@@ -129,7 +128,6 @@ impl<'a> SerializingPage<'a> { | |||||
summary: &page.summary, | summary: &page.summary, | ||||
word_count: page.word_count, | word_count: page.word_count, | ||||
reading_time: page.reading_time, | reading_time: page.reading_time, | ||||
toc: &page.toc, | |||||
assets: &page.serialized_assets, | assets: &page.serialized_assets, | ||||
draft: page.is_draft(), | draft: page.is_draft(), | ||||
lang: &page.lang, | lang: &page.lang, | ||||
@@ -185,7 +183,6 @@ impl<'a> SerializingPage<'a> { | |||||
summary: &page.summary, | summary: &page.summary, | ||||
word_count: page.word_count, | word_count: page.word_count, | ||||
reading_time: page.reading_time, | reading_time: page.reading_time, | ||||
toc: &page.toc, | |||||
assets: &page.serialized_assets, | assets: &page.serialized_assets, | ||||
draft: page.is_draft(), | draft: page.is_draft(), | ||||
lang: &page.lang, | lang: &page.lang, | ||||
@@ -212,7 +209,6 @@ pub struct SerializingSection<'a> { | |||||
word_count: Option<usize>, | word_count: Option<usize>, | ||||
reading_time: Option<usize>, | reading_time: Option<usize>, | ||||
lang: &'a str, | lang: &'a str, | ||||
toc: &'a [Header], | |||||
assets: &'a [String], | assets: &'a [String], | ||||
pages: Vec<SerializingPage<'a>>, | pages: Vec<SerializingPage<'a>>, | ||||
subsections: Vec<&'a str>, | subsections: Vec<&'a str>, | ||||
@@ -251,7 +247,6 @@ impl<'a> SerializingSection<'a> { | |||||
components: §ion.components, | components: §ion.components, | ||||
word_count: section.word_count, | word_count: section.word_count, | ||||
reading_time: section.reading_time, | reading_time: section.reading_time, | ||||
toc: §ion.toc, | |||||
assets: §ion.serialized_assets, | assets: §ion.serialized_assets, | ||||
lang: §ion.lang, | lang: §ion.lang, | ||||
pages, | pages, | ||||
@@ -290,7 +285,6 @@ impl<'a> SerializingSection<'a> { | |||||
components: §ion.components, | components: §ion.components, | ||||
word_count: section.word_count, | word_count: section.word_count, | ||||
reading_time: section.reading_time, | reading_time: section.reading_time, | ||||
toc: §ion.toc, | |||||
assets: §ion.serialized_assets, | assets: §ion.serialized_assets, | ||||
lang: §ion.lang, | lang: §ion.lang, | ||||
pages: vec![], | pages: vec![], | ||||
@@ -39,8 +39,6 @@ later: Page?; | |||||
// and only set when rendering the page itself | // and only set when rendering the page itself | ||||
heavier: Page?; | heavier: Page?; | ||||
lighter: Page?; | lighter: Page?; | ||||
// See the Table of contents section below for more details | |||||
toc: Array<Header>; | |||||
// Year/month/day is only set if the page has a date and month/day are 1-indexed | // Year/month/day is only set if the page has a date and month/day are 1-indexed | ||||
year: Number?; | year: Number?; | ||||
month: Number?; | month: Number?; | ||||
@@ -89,8 +87,6 @@ subsections: Array<String>; | |||||
word_count: Number; | word_count: Number; | ||||
// Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time | // Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time | ||||
reading_time: Number; | reading_time: Number; | ||||
// See the Table of contents section below for more details | |||||
toc: Array<Header>; | |||||
// Paths of colocated assets, relative to the content directory | // Paths of colocated assets, relative to the content directory | ||||
assets: Array<String>; | assets: Array<String>; | ||||
// The relative paths of the parent sections until the index onef for use with the `get_section` Tera function | // The relative paths of the parent sections until the index onef for use with the `get_section` Tera function | ||||
@@ -107,7 +103,7 @@ translations: Array<TranslatedContent>; | |||||
## Table of contents | ## Table of contents | ||||
Both page and section have a `toc` field which corresponds to an array of `Header`. | |||||
Both page and section templates have a `toc` variable which corresponds to an array of `Header`. | |||||
A `Header` has the following fields: | A `Header` has the following fields: | ||||
```ts | ```ts | ||||
@@ -3,6 +3,7 @@ | |||||
{% block content %} | {% block content %} | ||||
{{ page.content | safe }} | {{ page.content | safe }} | ||||
{{ page.relative_path | safe }} | {{ page.relative_path | safe }} | ||||
{{ toc }} | |||||
{% if page.earlier %}Previous article: {{ page.earlier.permalink }}{% endif %} | {% if page.earlier %}Previous article: {{ page.earlier.permalink }}{% endif %} | ||||
{% if page.later %}Next article: {{ page.later.permalink }}{% endif %} | {% if page.later %}Next article: {{ page.later.permalink }}{% endif %} | ||||