Add draft to section variable in templates

Closes #1592
This commit is contained in:
Vincent Prouillet 2021-08-20 19:47:04 +02:00
parent 5ca2b29c49
commit f7a4ef2617
4 changed files with 8 additions and 8 deletions

View File

@ -7,6 +7,7 @@
- `zola serve` now properly returns a 404
- Fix `zola serve` having issues with config files in separate dir
- Fix code blocks content not being escaped when not using syntax highlighting
- Add missing `draft` attribute to the `section` variable in templates
## 0.14.0 (2021-07-19)

View File

@ -103,10 +103,6 @@ impl Page {
Page { file: FileInfo::new_page(file_path, base_path), meta, ..Self::default() }
}
pub fn is_draft(&self) -> bool {
self.meta.draft
}
/// Parse a page given the content of the .md file
/// Files without front matter or with invalid front matter are considered
/// erroneous

View File

@ -167,7 +167,7 @@ impl<'a> SerializingPage<'a> {
word_count: page.word_count,
reading_time: page.reading_time,
assets: &page.serialized_assets,
draft: page.is_draft(),
draft: page.meta.draft,
lang: &page.lang,
lighter,
heavier,
@ -233,7 +233,7 @@ impl<'a> SerializingPage<'a> {
word_count: page.word_count,
reading_time: page.reading_time,
assets: &page.serialized_assets,
draft: page.is_draft(),
draft: page.meta.draft,
lang: &page.lang,
lighter: None,
heavier: None,
@ -253,6 +253,7 @@ pub struct SerializingSection<'a> {
relative_path: &'a str,
content: &'a str,
permalink: &'a str,
draft: bool,
ancestors: Vec<&'a str>,
title: &'a Option<String>,
description: &'a Option<String>,
@ -292,6 +293,7 @@ impl<'a> SerializingSection<'a> {
SerializingSection {
relative_path: &section.file.relative,
ancestors,
draft: section.meta.draft,
content: &section.content,
permalink: &section.permalink,
title: &section.meta.title,
@ -329,6 +331,7 @@ impl<'a> SerializingSection<'a> {
SerializingSection {
relative_path: &section.file.relative,
ancestors,
draft: section.meta.draft,
content: &section.content,
permalink: &section.permalink,
title: &section.meta.title,

View File

@ -1,13 +1,13 @@
use std::fmt::Write;
use config::highlighting::{SyntaxAndTheme, CLASS_STYLE};
use tera::escape_html;
use syntect::easy::HighlightLines;
use syntect::highlighting::{Color, Theme};
use syntect::html::{
styled_line_to_highlighted_html, line_tokens_to_classed_spans, ClassStyle, IncludeBackground,
line_tokens_to_classed_spans, styled_line_to_highlighted_html, ClassStyle, IncludeBackground,
};
use syntect::parsing::{ParseState, ScopeStack, SyntaxReference, SyntaxSet};
use tera::escape_html;
/// Not public, but from syntect::html
fn write_css_color(s: &mut String, c: Color) {