zola/components/rendering/src/context.rs

42 lines
1 KiB
Rust
Raw Normal View History

use std::collections::HashMap;
use tera::Tera;
use front_matter::InsertAnchor;
/// All the information from the gutenberg site that is needed to render HTML from markdown
#[derive(Debug)]
pub struct Context<'a> {
pub tera: &'a Tera,
pub highlight_code: bool,
pub highlight_theme: String,
2017-06-16 04:00:48 +00:00
pub current_page_permalink: String,
pub permalinks: &'a HashMap<String, String>,
pub insert_anchor: InsertAnchor,
}
impl<'a> Context<'a> {
2017-06-16 04:00:48 +00:00
pub fn new(
tera: &'a Tera,
2017-07-01 07:47:41 +00:00
highlight_code: bool,
highlight_theme: String,
2017-06-16 04:00:48 +00:00
current_page_permalink: &str,
permalinks: &'a HashMap<String, String>,
insert_anchor: InsertAnchor,
) -> Context<'a> {
Context {
tera,
2017-06-16 04:00:48 +00:00
current_page_permalink: current_page_permalink.to_string(),
permalinks,
insert_anchor,
2017-07-01 07:47:41 +00:00
highlight_code,
highlight_theme,
}
}
pub fn should_insert_anchor(&self) -> bool {
self.insert_anchor != InsertAnchor::None
}
}