2017-05-22 11:28:43 +00:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
2018-05-06 20:58:39 +00:00
|
|
|
use config::Config;
|
2018-10-31 07:18:57 +00:00
|
|
|
use front_matter::InsertAnchor;
|
|
|
|
use tera::{Context, Tera};
|
2017-05-22 11:28:43 +00:00
|
|
|
|
2018-10-18 20:50:06 +00:00
|
|
|
/// All the information from the zola site that is needed to render HTML from markdown
|
2017-05-22 11:28:43 +00:00
|
|
|
#[derive(Debug)]
|
2018-05-06 20:58:39 +00:00
|
|
|
pub struct RenderContext<'a> {
|
2017-05-22 11:28:43 +00:00
|
|
|
pub tera: &'a Tera,
|
2018-05-06 20:58:39 +00:00
|
|
|
pub config: &'a Config,
|
2018-06-25 17:13:21 +00:00
|
|
|
pub tera_context: Context,
|
2018-05-06 20:58:39 +00:00
|
|
|
pub current_page_permalink: &'a str,
|
2017-05-22 11:28:43 +00:00
|
|
|
pub permalinks: &'a HashMap<String, String>,
|
|
|
|
pub insert_anchor: InsertAnchor,
|
|
|
|
}
|
|
|
|
|
2018-05-06 20:58:39 +00:00
|
|
|
impl<'a> RenderContext<'a> {
|
2017-06-16 04:00:48 +00:00
|
|
|
pub fn new(
|
|
|
|
tera: &'a Tera,
|
2018-05-06 20:58:39 +00:00
|
|
|
config: &'a Config,
|
|
|
|
current_page_permalink: &'a str,
|
2017-06-16 04:00:48 +00:00
|
|
|
permalinks: &'a HashMap<String, String>,
|
|
|
|
insert_anchor: InsertAnchor,
|
2018-05-06 20:58:39 +00:00
|
|
|
) -> RenderContext<'a> {
|
2018-06-25 17:13:21 +00:00
|
|
|
let mut tera_context = Context::new();
|
|
|
|
tera_context.insert("config", config);
|
2018-05-06 20:58:39 +00:00
|
|
|
RenderContext {
|
2017-05-22 11:28:43 +00:00
|
|
|
tera,
|
2018-06-25 17:13:21 +00:00
|
|
|
tera_context,
|
2018-05-06 20:58:39 +00:00
|
|
|
current_page_permalink,
|
2017-05-22 11:28:43 +00:00
|
|
|
permalinks,
|
|
|
|
insert_anchor,
|
2018-05-06 20:58:39 +00:00
|
|
|
config,
|
2017-05-22 11:28:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|