@@ -31,6 +31,7 @@ Tera function | |||||
- Add `ancestors` to pages and sections pointing to the relative path of all ancestor | - Add `ancestors` to pages and sections pointing to the relative path of all ancestor | ||||
sections up to the index to be used with the `get_section` Tera function | sections up to the index to be used with the `get_section` Tera function | ||||
- Add a `load_data` Tera function to load local CSV/TOML/JSON files | - Add a `load_data` Tera function to load local CSV/TOML/JSON files | ||||
- Add `relative_path` to pages and sections in templates | |||||
## 0.4.2 (2018-09-03) | ## 0.4.2 (2018-09-03) | ||||
@@ -20,6 +20,7 @@ use content::file_info::FileInfo; | |||||
/// What we are sending to the templates when rendering them | /// What we are sending to the templates when rendering them | ||||
#[derive(Clone, Debug, PartialEq, Serialize)] | #[derive(Clone, Debug, PartialEq, Serialize)] | ||||
pub struct SerializingPage<'a> { | pub struct SerializingPage<'a> { | ||||
relative_path: &'a str, | |||||
content: &'a str, | content: &'a str, | ||||
permalink: &'a str, | permalink: &'a str, | ||||
slug: &'a str, | slug: &'a str, | ||||
@@ -65,6 +66,7 @@ impl<'a> SerializingPage<'a> { | |||||
let ancestors = page.ancestors.iter().map(|k| library.get_section_by_key(*k).file.relative.clone()).collect(); | let ancestors = page.ancestors.iter().map(|k| library.get_section_by_key(*k).file.relative.clone()).collect(); | ||||
SerializingPage { | SerializingPage { | ||||
relative_path: &page.file.relative, | |||||
ancestors, | ancestors, | ||||
content: &page.content, | content: &page.content, | ||||
permalink: &page.permalink, | permalink: &page.permalink, | ||||
@@ -109,6 +111,7 @@ impl<'a> SerializingPage<'a> { | |||||
}; | }; | ||||
SerializingPage { | SerializingPage { | ||||
relative_path: &page.file.relative, | |||||
ancestors, | ancestors, | ||||
content: &page.content, | content: &page.content, | ||||
permalink: &page.permalink, | permalink: &page.permalink, | ||||
@@ -19,6 +19,7 @@ use library::Library; | |||||
#[derive(Clone, Debug, PartialEq, Serialize)] | #[derive(Clone, Debug, PartialEq, Serialize)] | ||||
pub struct SerializingSection<'a> { | pub struct SerializingSection<'a> { | ||||
relative_path: &'a str, | |||||
content: &'a str, | content: &'a str, | ||||
permalink: &'a str, | permalink: &'a str, | ||||
ancestors: Vec<String>, | ancestors: Vec<String>, | ||||
@@ -51,6 +52,7 @@ impl<'a> SerializingSection<'a> { | |||||
let ancestors = section.ancestors.iter().map(|k| library.get_section_by_key(*k).file.relative.clone()).collect(); | let ancestors = section.ancestors.iter().map(|k| library.get_section_by_key(*k).file.relative.clone()).collect(); | ||||
SerializingSection { | SerializingSection { | ||||
relative_path: §ion.file.relative, | |||||
ancestors, | ancestors, | ||||
content: §ion.content, | content: §ion.content, | ||||
permalink: §ion.permalink, | permalink: §ion.permalink, | ||||
@@ -77,6 +79,7 @@ impl<'a> SerializingSection<'a> { | |||||
}; | }; | ||||
SerializingSection { | SerializingSection { | ||||
relative_path: §ion.file.relative, | |||||
ancestors, | ancestors, | ||||
content: §ion.content, | content: §ion.content, | ||||
permalink: §ion.permalink, | permalink: §ion.permalink, | ||||
@@ -142,7 +142,10 @@ fn can_build_site_without_live_reload() { | |||||
assert!(file_exists!(public, "posts/tutorials/programming/index.html")); | assert!(file_exists!(public, "posts/tutorials/programming/index.html")); | ||||
// Ensure subsection pages are correctly filled | // Ensure subsection pages are correctly filled | ||||
assert!(file_contains!(public, "posts/tutorials/index.html", "Sub-pages: 2")); | assert!(file_contains!(public, "posts/tutorials/index.html", "Sub-pages: 2")); | ||||
// TODO: add assertion for syntax highlighting | |||||
// Pages and section get their relative path | |||||
assert!(file_contains!(public, "posts/tutorials/index.html", "posts/tutorials/_index.md")); | |||||
assert!(file_contains!(public, "posts/tutorials/devops/nix/index.html", "posts/tutorials/devops/nix.md")); | |||||
// aliases work | // aliases work | ||||
assert!(file_exists!(public, "an-old-url/old-page/index.html")); | assert!(file_exists!(public, "an-old-url/old-page/index.html")); | ||||
@@ -3,10 +3,10 @@ title = "Table of Contents" | |||||
weight = 60 | weight = 60 | ||||
+++ | +++ | ||||
Each page/section will automatically generate a table of content for itself based on the headers present. | |||||
Each page/section will automatically generate a table of content for itself based on the headers present. | |||||
It is available in the template through `section.toc` and `page.toc`. | |||||
You can view the [template variables](./documentation/templates/pages-sections.md#table-of-contents) | |||||
It is available in the template through `section.toc` and `page.toc`. | |||||
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. | ||||
Here is an example of using that field to render a 2-level table of content: | Here is an example of using that field to render a 2-level table of content: | ||||
@@ -31,3 +31,6 @@ Here is an example of using that field to render a 2-level table of content: | |||||
``` | ``` | ||||
While headers are neatly ordered in that example, it will work just as well with disjoint headers. | While headers are neatly ordered in that example, it will work just as well with disjoint headers. | ||||
Note that all existing HTML tags from the title will NOT be present in the table of contents to | |||||
avoid various issues. |
@@ -49,6 +49,8 @@ assets: Array<String>; | |||||
// The first item is the index section and the last one is the parent section | // The first item is the index section and the last one is the parent section | ||||
// This is filled after rendering a page content so it will be empty in shortcodes | // This is filled after rendering a page content so it will be empty in shortcodes | ||||
ancestors: Array<String>; | ancestors: Array<String>; | ||||
// The relative path from the `content` directory to the markdown file | |||||
relative_path: String; | |||||
``` | ``` | ||||
## Section variables | ## Section variables | ||||
@@ -89,6 +91,8 @@ assets: Array<String>; | |||||
// The first item is the index section and the last one is the parent section | // The first item is the index section and the last one is the parent section | ||||
// This is filled after rendering a page content so it will be empty in shortcodes | // This is filled after rendering a page content so it will be empty in shortcodes | ||||
ancestors: Array<String>; | ancestors: Array<String>; | ||||
// The relative path from the `content` directory to the markdown file | |||||
relative_path: String; | |||||
``` | ``` | ||||
## Table of contents | ## Table of contents | ||||
@@ -2,6 +2,7 @@ | |||||
{% block content %} | {% block content %} | ||||
{{ page.content | safe }} | {{ page.content | safe }} | ||||
{{ page.relative_path | safe }} | |||||
{% 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 %} | ||||
@@ -4,6 +4,7 @@ | |||||
{% for page in section.pages %} | {% for page in section.pages %} | ||||
{{page.title}} | {{page.title}} | ||||
{% endfor %} | {% endfor %} | ||||
{{ section.relative_path | safe }} | |||||
{% for sub in section.subsections %} | {% for sub in section.subsections %} | ||||
{% set subsection = get_section(path=sub) %} | {% set subsection = get_section(path=sub) %} | ||||
{{subsection.title}} | {{subsection.title}} | ||||