* Let toc is visable through Page & Section variables in templates * Removed the current toc variable from page & sectionindex-subcmd
@@ -290,7 +290,6 @@ 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) | ||||
@@ -219,7 +219,6 @@ 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) | ||||
@@ -5,6 +5,7 @@ use tera::{Map, Value}; | |||||
use content::{Page, Section}; | use content::{Page, Section}; | ||||
use library::Library; | use library::Library; | ||||
use rendering::Heading; | |||||
#[derive(Clone, Debug, PartialEq, Serialize)] | #[derive(Clone, Debug, PartialEq, Serialize)] | ||||
pub struct TranslatedContent<'a> { | pub struct TranslatedContent<'a> { | ||||
@@ -64,6 +65,7 @@ pub struct SerializingPage<'a> { | |||||
path: &'a str, | path: &'a str, | ||||
components: &'a [String], | components: &'a [String], | ||||
summary: &'a Option<String>, | summary: &'a Option<String>, | ||||
toc: &'a [Heading], | |||||
word_count: Option<usize>, | word_count: Option<usize>, | ||||
reading_time: Option<usize>, | reading_time: Option<usize>, | ||||
assets: &'a [String], | assets: &'a [String], | ||||
@@ -125,6 +127,7 @@ impl<'a> SerializingPage<'a> { | |||||
path: &page.path, | path: &page.path, | ||||
components: &page.components, | components: &page.components, | ||||
summary: &page.summary, | summary: &page.summary, | ||||
toc: &page.toc, | |||||
word_count: page.word_count, | word_count: page.word_count, | ||||
reading_time: page.reading_time, | reading_time: page.reading_time, | ||||
assets: &page.serialized_assets, | assets: &page.serialized_assets, | ||||
@@ -180,6 +183,7 @@ impl<'a> SerializingPage<'a> { | |||||
path: &page.path, | path: &page.path, | ||||
components: &page.components, | components: &page.components, | ||||
summary: &page.summary, | summary: &page.summary, | ||||
toc: &page.toc, | |||||
word_count: page.word_count, | word_count: page.word_count, | ||||
reading_time: page.reading_time, | reading_time: page.reading_time, | ||||
assets: &page.serialized_assets, | assets: &page.serialized_assets, | ||||
@@ -205,6 +209,7 @@ pub struct SerializingSection<'a> { | |||||
extra: &'a HashMap<String, Value>, | extra: &'a HashMap<String, Value>, | ||||
path: &'a str, | path: &'a str, | ||||
components: &'a [String], | components: &'a [String], | ||||
toc: &'a [Heading], | |||||
word_count: Option<usize>, | word_count: Option<usize>, | ||||
reading_time: Option<usize>, | reading_time: Option<usize>, | ||||
lang: &'a str, | lang: &'a str, | ||||
@@ -244,6 +249,7 @@ impl<'a> SerializingSection<'a> { | |||||
extra: §ion.meta.extra, | extra: §ion.meta.extra, | ||||
path: §ion.path, | path: §ion.path, | ||||
components: §ion.components, | components: §ion.components, | ||||
toc: §ion.toc, | |||||
word_count: section.word_count, | word_count: section.word_count, | ||||
reading_time: section.reading_time, | reading_time: section.reading_time, | ||||
assets: §ion.serialized_assets, | assets: §ion.serialized_assets, | ||||
@@ -280,6 +286,7 @@ impl<'a> SerializingSection<'a> { | |||||
extra: §ion.meta.extra, | extra: §ion.meta.extra, | ||||
path: §ion.path, | path: §ion.path, | ||||
components: §ion.components, | components: §ion.components, | ||||
toc: §ion.toc, | |||||
word_count: section.word_count, | word_count: section.word_count, | ||||
reading_time: section.reading_time, | reading_time: section.reading_time, | ||||
assets: §ion.serialized_assets, | assets: §ion.serialized_assets, | ||||
@@ -5,7 +5,7 @@ weight = 60 | |||||
Each page/section will automatically generate a table of contents for itself based on the headers present. | Each page/section will automatically generate a table of contents for itself based on the headers present. | ||||
It is available in the template through the `toc` variable. | |||||
It is available in the template through the `page.toc` or `section.toc` variable. | |||||
You can view the [template variables](@/documentation/templates/pages-sections.md#table-of-contents) | You can view the [template variables](@/documentation/templates/pages-sections.md#table-of-contents) | ||||
documentation for information on its structure. | documentation for information on its structure. | ||||
@@ -13,7 +13,7 @@ Here is an example of using that field to render a 2-level table of contents: | |||||
```jinja2 | ```jinja2 | ||||
<ul> | <ul> | ||||
{% for h1 in toc %} | |||||
{% for h1 in page.toc %} | |||||
<li> | <li> | ||||
<a href="{{h1.permalink | safe}}">{{ h1.title }}</a> | <a href="{{h1.permalink | safe}}">{{ h1.title }}</a> | ||||
{% if h1.children %} | {% if h1.children %} | ||||
@@ -27,6 +27,7 @@ permalink: String; | |||||
summary: String?; | summary: String?; | ||||
taxonomies: HashMap<String, Array<String>>; | taxonomies: HashMap<String, Array<String>>; | ||||
extra: HashMap<String, Any>; | extra: HashMap<String, Any>; | ||||
toc: Array<Header>, | |||||
// Naive word count, will not work for languages without whitespace | // Naive word count, will not work for languages without whitespace | ||||
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 | ||||
@@ -81,6 +82,7 @@ pages: Array<Page>; | |||||
// This only contains the path to use in the `get_section` Tera function to get | // This only contains the path to use in the `get_section` Tera function to get | ||||
// the actual section object if you need it | // the actual section object if you need it | ||||
subsections: Array<String>; | subsections: Array<String>; | ||||
toc: Array<Header>, | |||||
// Unicode word count | // Unicode word count | ||||
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 | ||||
@@ -3,7 +3,7 @@ | |||||
{% block content %} | {% block content %} | ||||
{{ page.content | safe }} | {{ page.content | safe }} | ||||
{{ page.relative_path | safe }} | {{ page.relative_path | safe }} | ||||
{{ toc }} | |||||
{{ page.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 %} | ||||