Browse Source

Move toc to be a rendering page/section variable level

index-subcmd
Vincent Prouillet 5 years ago
parent
commit
705a30aa8d
6 changed files with 6 additions and 11 deletions
  1. +2
    -0
      CHANGELOG.md
  2. +1
    -0
      components/library/src/content/page.rs
  3. +1
    -0
      components/library/src/content/section.rs
  4. +0
    -6
      components/library/src/content/ser.rs
  5. +1
    -5
      docs/content/documentation/templates/pages-sections.md
  6. +1
    -0
      test_site/templates/page.html

+ 2
- 0
CHANGELOG.md View File

@@ -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


+ 1
- 0
components/library/src/content/page.rs View File

@@ -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)


+ 1
- 0
components/library/src/content/section.rs View File

@@ -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)


+ 0
- 6
components/library/src/content/ser.rs View File

@@ -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: &section.components,
word_count: section.word_count,
reading_time: section.reading_time,
toc: &section.toc,
assets: &section.serialized_assets,
lang: &section.lang,
pages,
@@ -290,7 +285,6 @@ impl<'a> SerializingSection<'a> {
components: &section.components,
word_count: section.word_count,
reading_time: section.reading_time,
toc: &section.toc,
assets: &section.serialized_assets,
lang: &section.lang,
pages: vec![],


+ 1
- 5
docs/content/documentation/templates/pages-sections.md View File

@@ -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


+ 1
- 0
test_site/templates/page.html View File

@@ -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…
Cancel
Save