Move toc to be a rendering page/section variable level
This commit is contained in:
parent
9bc675f2a7
commit
705a30aa8d
|
@ -5,6 +5,8 @@
|
|||
### Breaking
|
||||
- `earlier/later` and `lighter/heavier` are not set anymore on pages when rendering
|
||||
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
|
||||
- Add support for content in multiple languages
|
||||
|
|
|
@ -270,6 +270,7 @@ impl Page {
|
|||
context.insert("current_path", &self.path);
|
||||
context.insert("page", &self.to_serialized(library));
|
||||
context.insert("lang", &self.lang);
|
||||
context.insert("toc", &self.toc);
|
||||
|
||||
render_template(&tpl_name, tera, context, &config.theme).map_err(|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("section", &self.to_serialized(library));
|
||||
context.insert("lang", &self.lang);
|
||||
context.insert("toc", &self.toc);
|
||||
|
||||
render_template(tpl_name, tera, context, &config.theme).map_err(|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>,
|
||||
word_count: Option<usize>,
|
||||
reading_time: Option<usize>,
|
||||
toc: &'a [Header],
|
||||
assets: &'a [String],
|
||||
draft: bool,
|
||||
lang: &'a str,
|
||||
|
@ -129,7 +128,6 @@ impl<'a> SerializingPage<'a> {
|
|||
summary: &page.summary,
|
||||
word_count: page.word_count,
|
||||
reading_time: page.reading_time,
|
||||
toc: &page.toc,
|
||||
assets: &page.serialized_assets,
|
||||
draft: page.is_draft(),
|
||||
lang: &page.lang,
|
||||
|
@ -185,7 +183,6 @@ impl<'a> SerializingPage<'a> {
|
|||
summary: &page.summary,
|
||||
word_count: page.word_count,
|
||||
reading_time: page.reading_time,
|
||||
toc: &page.toc,
|
||||
assets: &page.serialized_assets,
|
||||
draft: page.is_draft(),
|
||||
lang: &page.lang,
|
||||
|
@ -212,7 +209,6 @@ pub struct SerializingSection<'a> {
|
|||
word_count: Option<usize>,
|
||||
reading_time: Option<usize>,
|
||||
lang: &'a str,
|
||||
toc: &'a [Header],
|
||||
assets: &'a [String],
|
||||
pages: Vec<SerializingPage<'a>>,
|
||||
subsections: Vec<&'a str>,
|
||||
|
@ -251,7 +247,6 @@ impl<'a> SerializingSection<'a> {
|
|||
components: §ion.components,
|
||||
word_count: section.word_count,
|
||||
reading_time: section.reading_time,
|
||||
toc: §ion.toc,
|
||||
assets: §ion.serialized_assets,
|
||||
lang: §ion.lang,
|
||||
pages,
|
||||
|
@ -290,7 +285,6 @@ impl<'a> SerializingSection<'a> {
|
|||
components: §ion.components,
|
||||
word_count: section.word_count,
|
||||
reading_time: section.reading_time,
|
||||
toc: §ion.toc,
|
||||
assets: §ion.serialized_assets,
|
||||
lang: §ion.lang,
|
||||
pages: vec![],
|
||||
|
|
|
@ -39,8 +39,6 @@ later: Page?;
|
|||
// and only set when rendering the page itself
|
||||
heavier: 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: Number?;
|
||||
month: Number?;
|
||||
|
@ -89,8 +87,6 @@ subsections: Array<String>;
|
|||
word_count: Number;
|
||||
// Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time
|
||||
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
|
||||
assets: Array<String>;
|
||||
// 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
|
||||
|
||||
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:
|
||||
|
||||
```ts
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
{% block content %}
|
||||
{{ page.content | safe }}
|
||||
{{ page.relative_path | safe }}
|
||||
{{ toc }}
|
||||
|
||||
{% if page.earlier %}Previous article: {{ page.earlier.permalink }}{% endif %}
|
||||
{% if page.later %}Next article: {{ page.later.permalink }}{% endif %}
|
||||
|
|
Loading…
Reference in a new issue