Fix config loading

Closes #1512
This commit is contained in:
Vincent Prouillet 2021-06-02 21:46:19 +02:00
parent 16c123aa20
commit 2289b2f55a
7 changed files with 110 additions and 98 deletions

View file

@ -151,6 +151,12 @@ impl Config {
Ok(config) Ok(config)
} }
pub fn default_for_test() -> Self {
let mut config = Config::default();
config.add_default_language();
config
}
/// Parses a config file from the given path /// Parses a config file from the given path
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Config> { pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Config> {
let path = path.as_ref(); let path = path.as_ref();
@ -184,7 +190,7 @@ impl Config {
} }
/// Adds the default language to the list of languages if not present /// Adds the default language to the list of languages if not present
fn add_default_language(&mut self) { pub fn add_default_language(&mut self) {
// We automatically insert a language option for the default language *if* it isn't present // We automatically insert a language option for the default language *if* it isn't present
// TODO: what to do if there is like an empty dict for the lang? merge it or use the language // TODO: what to do if there is like an empty dict for the lang? merge it or use the language
// TODO: as source of truth? // TODO: as source of truth?
@ -193,7 +199,7 @@ impl Config {
self.default_language.clone(), self.default_language.clone(),
languages::LanguageOptions { languages::LanguageOptions {
title: self.title.clone(), title: self.title.clone(),
description: self.title.clone(), description: self.description.clone(),
generate_feed: self.generate_feed, generate_feed: self.generate_feed,
build_search_index: self.build_search_index, build_search_index: self.build_search_index,
taxonomies: self.taxonomies.clone(), taxonomies: self.taxonomies.clone(),
@ -319,7 +325,7 @@ pub fn merge(into: &mut Toml, from: &Toml) -> Result<()> {
impl Default for Config { impl Default for Config {
fn default() -> Config { fn default() -> Config {
let mut config = Config { Config {
base_url: DEFAULT_BASE_URL.to_string(), base_url: DEFAULT_BASE_URL.to_string(),
title: None, title: None,
description: None, description: None,
@ -344,9 +350,7 @@ impl Default for Config {
search: search::Search::default(), search: search::Search::default(),
markdown: markup::Markdown::default(), markdown: markup::Markdown::default(),
extra: HashMap::new(), extra: HashMap::new(),
}; }
config.add_default_language();
config
} }
} }

View file

@ -353,7 +353,8 @@ mod tests {
use utils::slugs::SlugifyStrategy; use utils::slugs::SlugifyStrategy;
#[test] #[test]
fn test_can_parse_a_valid_page() { fn can_parse_a_valid_page() {
let config = Config::default_for_test();
let content = r#" let content = r#"
+++ +++
title = "Hello" title = "Hello"
@ -361,15 +362,10 @@ description = "hey there"
slug = "hello-world" slug = "hello-world"
+++ +++
Hello world"#; Hello world"#;
let res = Page::parse(Path::new("post.md"), content, &Config::default(), &PathBuf::new()); let res = Page::parse(Path::new("post.md"), content, &config, &PathBuf::new());
assert!(res.is_ok()); assert!(res.is_ok());
let mut page = res.unwrap(); let mut page = res.unwrap();
page.render_markdown( page.render_markdown(&HashMap::default(), &Tera::default(), &config, InsertAnchor::None)
&HashMap::default(),
&Tera::default(),
&Config::default(),
InsertAnchor::None,
)
.unwrap(); .unwrap();
assert_eq!(page.meta.title.unwrap(), "Hello".to_string()); assert_eq!(page.meta.title.unwrap(), "Hello".to_string());
@ -525,7 +521,7 @@ Hello world"#;
#[test] #[test]
fn can_specify_summary() { fn can_specify_summary() {
let config = Config::default(); let config = Config::default_for_test();
let content = r#" let content = r#"
+++ +++
+++ +++
@ -542,7 +538,7 @@ Hello world
#[test] #[test]
fn strips_footnotes_in_summary() { fn strips_footnotes_in_summary() {
let config = Config::default(); let config = Config::default_for_test();
let content = r#" let content = r#"
+++ +++
+++ +++

View file

@ -268,7 +268,7 @@ mod tests {
} }
fn render_shortcodes(code: &str, tera: &Tera) -> String { fn render_shortcodes(code: &str, tera: &Tera) -> String {
let config = Config::default(); let config = Config::default_for_test();
let permalinks = HashMap::new(); let permalinks = HashMap::new();
let context = RenderContext::new( let context = RenderContext::new(
&tera, &tera,

View file

@ -30,7 +30,7 @@ macro_rules! colored_html {
fn hide_lines_simple() { fn hide_lines_simple() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,

View file

@ -36,7 +36,7 @@ macro_rules! colored_html {
fn hl_lines_simple() { fn hl_lines_simple() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -72,7 +72,7 @@ baz
fn hl_lines_in_middle() { fn hl_lines_in_middle() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -108,7 +108,7 @@ baz
fn hl_lines_all() { fn hl_lines_all() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -142,7 +142,7 @@ baz
fn hl_lines_start_from_one() { fn hl_lines_start_from_one() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -177,7 +177,7 @@ baz
fn hl_lines_start_from_zero() { fn hl_lines_start_from_zero() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -212,7 +212,7 @@ baz
fn hl_lines_end() { fn hl_lines_end() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -247,7 +247,7 @@ baz
fn hl_lines_end_out_of_bounds() { fn hl_lines_end_out_of_bounds() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -282,7 +282,7 @@ baz
fn hl_lines_overlap() { fn hl_lines_overlap() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -316,7 +316,7 @@ baz
fn hl_lines_multiple() { fn hl_lines_multiple() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -351,7 +351,7 @@ baz
fn hl_lines_extra_spaces() { fn hl_lines_extra_spaces() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -386,7 +386,7 @@ baz
fn hl_lines_int_and_range() { fn hl_lines_int_and_range() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -422,7 +422,7 @@ baz
fn hl_lines_single_line_range() { fn hl_lines_single_line_range() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -458,7 +458,7 @@ baz
fn hl_lines_reverse_range() { fn hl_lines_reverse_range() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,

View file

@ -12,7 +12,7 @@ use utils::slugs::SlugifyStrategy;
fn can_do_render_content_simple() { fn can_do_render_content_simple() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
&config, &config,
@ -29,7 +29,7 @@ fn can_do_render_content_simple() {
fn doesnt_highlight_code_block_with_highlighting_off() { fn doesnt_highlight_code_block_with_highlighting_off() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = false; config.markdown.highlight_code = false;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -47,7 +47,7 @@ fn doesnt_highlight_code_block_with_highlighting_off() {
fn can_highlight_code_block_no_lang() { fn can_highlight_code_block_no_lang() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -68,7 +68,7 @@ fn can_highlight_code_block_no_lang() {
fn can_highlight_code_block_with_lang() { fn can_highlight_code_block_with_lang() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -89,7 +89,7 @@ fn can_highlight_code_block_with_lang() {
fn can_higlight_code_block_with_unknown_lang() { fn can_higlight_code_block_with_unknown_lang() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = true; config.markdown.highlight_code = true;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -110,7 +110,7 @@ fn can_higlight_code_block_with_unknown_lang() {
#[test] #[test]
fn can_render_shortcode() { fn can_render_shortcode() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -137,7 +137,7 @@ Hello
#[test] #[test]
fn can_render_shortcode_with_markdown_char_in_args_name() { fn can_render_shortcode_with_markdown_char_in_args_name() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -157,7 +157,7 @@ fn can_render_shortcode_with_markdown_char_in_args_name() {
#[test] #[test]
fn can_render_shortcode_with_markdown_char_in_args_value() { fn can_render_shortcode_with_markdown_char_in_args_value() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -187,7 +187,7 @@ fn can_render_body_shortcode_with_markdown_char_in_name() {
let mut tera = Tera::default(); let mut tera = Tera::default();
tera.extend(&ZOLA_TERA).unwrap(); tera.extend(&ZOLA_TERA).unwrap();
let input = vec!["quo_te", "qu_o_te"]; let input = vec!["quo_te", "qu_o_te"];
let config = Config::default(); let config = Config::default_for_test();
for i in input { for i in input {
tera.add_raw_template( tera.add_raw_template(
@ -232,7 +232,7 @@ Here is another paragraph.
"; ";
tera.add_raw_template("shortcodes/figure.html", shortcode).unwrap(); tera.add_raw_template("shortcodes/figure.html", shortcode).unwrap();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera, &tera,
&config, &config,
@ -272,7 +272,7 @@ Here is another paragraph.
"; ";
tera.add_raw_template("shortcodes/figure.html", shortcode).unwrap(); tera.add_raw_template("shortcodes/figure.html", shortcode).unwrap();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera, &tera,
&config, &config,
@ -290,7 +290,7 @@ Here is another paragraph.
#[test] #[test]
fn can_render_several_shortcode_in_row() { fn can_render_several_shortcode_in_row() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -331,7 +331,7 @@ Hello
#[test] #[test]
fn doesnt_render_ignored_shortcodes() { fn doesnt_render_ignored_shortcodes() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.highlight_code = false; config.markdown.highlight_code = false;
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
@ -355,7 +355,7 @@ fn can_render_shortcode_with_body() {
) )
.unwrap(); .unwrap();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera, &tera,
&config, &config,
@ -382,7 +382,7 @@ A quote
fn errors_rendering_unknown_shortcode() { fn errors_rendering_unknown_shortcode() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
&config, &config,
@ -400,7 +400,7 @@ fn can_make_valid_relative_link() {
let mut permalinks = HashMap::new(); let mut permalinks = HashMap::new();
permalinks.insert("pages/about.md".to_string(), "https://vincent.is/about".to_string()); permalinks.insert("pages/about.md".to_string(), "https://vincent.is/about".to_string());
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
&config, &config,
@ -425,7 +425,7 @@ fn can_make_relative_links_with_anchors() {
let mut permalinks = HashMap::new(); let mut permalinks = HashMap::new();
permalinks.insert("pages/about.md".to_string(), "https://vincent.is/about".to_string()); permalinks.insert("pages/about.md".to_string(), "https://vincent.is/about".to_string());
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
&config, &config,
@ -443,7 +443,7 @@ fn can_make_relative_links_with_anchors() {
fn errors_relative_link_inexistant() { fn errors_relative_link_inexistant() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
&config, &config,
@ -460,7 +460,7 @@ fn errors_relative_link_inexistant() {
fn can_add_id_to_headings() { fn can_add_id_to_headings() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
&config, &config,
@ -477,7 +477,7 @@ fn can_add_id_to_headings() {
fn can_add_id_to_headings_same_slug() { fn can_add_id_to_headings_same_slug() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
&config, &config,
@ -494,7 +494,7 @@ fn can_add_id_to_headings_same_slug() {
fn can_add_non_slug_id_to_headings() { fn can_add_non_slug_id_to_headings() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.slugify.anchors = SlugifyStrategy::Safe; config.slugify.anchors = SlugifyStrategy::Safe;
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
@ -512,7 +512,7 @@ fn can_add_non_slug_id_to_headings() {
fn can_handle_manual_ids_on_headings() { fn can_handle_manual_ids_on_headings() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
&config, &config,
@ -556,7 +556,7 @@ fn can_handle_manual_ids_on_headings() {
fn blank_headings() { fn blank_headings() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
&config, &config,
@ -575,7 +575,7 @@ fn blank_headings() {
#[test] #[test]
fn can_insert_anchor_left() { fn can_insert_anchor_left() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -594,7 +594,7 @@ fn can_insert_anchor_left() {
#[test] #[test]
fn can_insert_anchor_right() { fn can_insert_anchor_right() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -613,7 +613,7 @@ fn can_insert_anchor_right() {
#[test] #[test]
fn can_insert_anchor_for_multi_heading() { fn can_insert_anchor_for_multi_heading() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -634,7 +634,7 @@ fn can_insert_anchor_for_multi_heading() {
#[test] #[test]
fn can_insert_anchor_with_exclamation_mark() { fn can_insert_anchor_with_exclamation_mark() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -654,7 +654,7 @@ fn can_insert_anchor_with_exclamation_mark() {
#[test] #[test]
fn can_insert_anchor_with_link() { fn can_insert_anchor_with_link() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -673,7 +673,7 @@ fn can_insert_anchor_with_link() {
#[test] #[test]
fn can_insert_anchor_with_other_special_chars() { fn can_insert_anchor_with_other_special_chars() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -692,7 +692,7 @@ fn can_insert_anchor_with_other_special_chars() {
#[test] #[test]
fn can_make_toc() { fn can_make_toc() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -725,7 +725,7 @@ fn can_make_toc() {
#[test] #[test]
fn can_ignore_tags_in_toc() { fn can_ignore_tags_in_toc() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -762,7 +762,7 @@ fn can_ignore_tags_in_toc() {
#[test] #[test]
fn can_understand_backtick_in_titles() { fn can_understand_backtick_in_titles() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -778,7 +778,7 @@ fn can_understand_backtick_in_titles() {
#[test] #[test]
fn can_understand_backtick_in_paragraphs() { fn can_understand_backtick_in_paragraphs() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -795,7 +795,7 @@ fn can_understand_backtick_in_paragraphs() {
#[test] #[test]
fn can_understand_links_in_heading() { fn can_understand_links_in_heading() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -811,7 +811,7 @@ fn can_understand_links_in_heading() {
#[test] #[test]
fn can_understand_link_with_title_in_heading() { fn can_understand_link_with_title_in_heading() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -831,7 +831,7 @@ fn can_understand_link_with_title_in_heading() {
#[test] #[test]
fn can_understand_emphasis_in_heading() { fn can_understand_emphasis_in_heading() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -847,7 +847,7 @@ fn can_understand_emphasis_in_heading() {
#[test] #[test]
fn can_understand_strong_in_heading() { fn can_understand_strong_in_heading() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -863,7 +863,7 @@ fn can_understand_strong_in_heading() {
#[test] #[test]
fn can_understand_code_in_heading() { fn can_understand_code_in_heading() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -880,7 +880,7 @@ fn can_understand_code_in_heading() {
#[test] #[test]
fn can_understand_footnote_in_heading() { fn can_understand_footnote_in_heading() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -905,7 +905,7 @@ fn can_make_valid_relative_link_in_heading() {
let mut permalinks = HashMap::new(); let mut permalinks = HashMap::new();
permalinks.insert("pages/about.md".to_string(), "https://vincent.is/about/".to_string()); permalinks.insert("pages/about.md".to_string(), "https://vincent.is/about/".to_string());
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
&config, &config,
@ -925,7 +925,7 @@ fn can_make_valid_relative_link_in_heading() {
#[test] #[test]
fn can_make_permalinks_with_colocated_assets_for_link() { fn can_make_permalinks_with_colocated_assets_for_link() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -941,7 +941,7 @@ fn can_make_permalinks_with_colocated_assets_for_link() {
#[test] #[test]
fn can_make_permalinks_with_colocated_assets_for_image() { fn can_make_permalinks_with_colocated_assets_for_image() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -960,7 +960,7 @@ fn can_make_permalinks_with_colocated_assets_for_image() {
#[test] #[test]
fn markdown_doesnt_wrap_html_in_paragraph() { fn markdown_doesnt_wrap_html_in_paragraph() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -993,7 +993,7 @@ Some text
#[test] #[test]
fn correctly_captures_external_links() { fn correctly_captures_external_links() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -1019,7 +1019,7 @@ Email: <foo@bar.baz>
fn can_handle_summaries() { fn can_handle_summaries() {
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera_ctx, &tera_ctx,
&config, &config,
@ -1074,7 +1074,7 @@ fn doesnt_try_to_highlight_content_from_shortcode() {
let expected = "<figure>\n \n <img src=\"/images/spherecluster.png\" alt=\"Some spheres.\" />\n \n\n <figcaption>Some spheres.</figcaption>\n</figure>"; let expected = "<figure>\n \n <img src=\"/images/spherecluster.png\" alt=\"Some spheres.\" />\n \n\n <figcaption>Some spheres.</figcaption>\n</figure>";
tera.add_raw_template("shortcodes/figure.html", shortcode).unwrap(); tera.add_raw_template("shortcodes/figure.html", shortcode).unwrap();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera, &tera,
&config, &config,
@ -1103,7 +1103,7 @@ fn can_emit_newlines_and_whitespace_with_shortcode() {
let expected = "<pre>\nHello\n \n Zola\n \n !\n</pre>"; let expected = "<pre>\nHello\n \n Zola\n \n !\n</pre>";
tera.add_raw_template(&format!("shortcodes/{}.html", "preformatted"), shortcode).unwrap(); tera.add_raw_template(&format!("shortcodes/{}.html", "preformatted"), shortcode).unwrap();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera, &tera,
&config, &config,
@ -1138,7 +1138,7 @@ fn can_emit_newlines_and_whitespace_with_shortcode() {
// let expected = r#"<p>["multi", "ple", "lines"]</p>"#; // let expected = r#"<p>["multi", "ple", "lines"]</p>"#;
// //
// tera.add_raw_template(&format!("shortcodes/{}.html", "alert"), shortcode).unwrap(); // tera.add_raw_template(&format!("shortcodes/{}.html", "alert"), shortcode).unwrap();
// let config = Config::default(); // let config = Config::default_for_test();
// let context = RenderContext::new(&tera, &config, &config.default_language, "", &permalinks_ctx, InsertAnchor::None); // let context = RenderContext::new(&tera, &config, &config.default_language, "", &permalinks_ctx, InsertAnchor::None);
// //
// let res = render_content(markdown_string, &context).unwrap(); // let res = render_content(markdown_string, &context).unwrap();
@ -1157,7 +1157,7 @@ fn leaves_custom_url_scheme_untouched() {
"#; "#;
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let config = Config::default(); let config = Config::default_for_test();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let context = RenderContext::new( let context = RenderContext::new(
@ -1184,7 +1184,7 @@ fn stops_with_an_error_on_an_empty_link() {
let content = r#"[some link]()"#; let content = r#"[some link]()"#;
let tera_ctx = Tera::default(); let tera_ctx = Tera::default();
let config = Config::default(); let config = Config::default_for_test();
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let context = RenderContext::new( let context = RenderContext::new(
@ -1237,7 +1237,7 @@ Bla bla"#;
"#; "#;
tera.add_raw_template("shortcodes/quote.md", shortcode).unwrap(); tera.add_raw_template("shortcodes/quote.md", shortcode).unwrap();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera, &tera,
&config, &config,
@ -1274,7 +1274,7 @@ fn can_render_shortcode_body_with_no_invalid_escaping() {
let expected = "<a class=\"resize-image\" href=\"/tlera-corp-gnat/gnat-with-picoblade-cable.jpg\">\n <img\n src=\"https://placekitten.com/200/300\"\n alt=\"Some alt\">\n </img>\n <p>(click for full size)</p>\n</a>"; let expected = "<a class=\"resize-image\" href=\"/tlera-corp-gnat/gnat-with-picoblade-cable.jpg\">\n <img\n src=\"https://placekitten.com/200/300\"\n alt=\"Some alt\">\n </img>\n <p>(click for full size)</p>\n</a>";
tera.add_raw_template("shortcodes/resize_image.html", shortcode).unwrap(); tera.add_raw_template("shortcodes/resize_image.html", shortcode).unwrap();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera, &tera,
&config, &config,
@ -1310,7 +1310,7 @@ fn can_render_commented_out_shortcodes_fine() {
let expected = "<!--<a class=\"resize-image\" href=\"/tlera-corp-gnat/gnat-with-picoblade-cable.jpg\">\n <img\n src=\"https://placekitten.com/200/300\"\n alt=\"Some alt\">\n </img>\n <p>(click for full size)</p>\n</a>-->"; let expected = "<!--<a class=\"resize-image\" href=\"/tlera-corp-gnat/gnat-with-picoblade-cable.jpg\">\n <img\n src=\"https://placekitten.com/200/300\"\n alt=\"Some alt\">\n </img>\n <p>(click for full size)</p>\n</a>-->";
tera.add_raw_template("shortcodes/resize_image.html", shortcode).unwrap(); tera.add_raw_template("shortcodes/resize_image.html", shortcode).unwrap();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera, &tera,
&config, &config,
@ -1349,7 +1349,7 @@ Again more text"#;
"#; "#;
tera.add_raw_template("shortcodes/quote.md", shortcode).unwrap(); tera.add_raw_template("shortcodes/quote.md", shortcode).unwrap();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera, &tera,
&config, &config,
@ -1366,7 +1366,7 @@ Again more text"#;
#[test] #[test]
fn can_render_emoji_alias() { fn can_render_emoji_alias() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.render_emoji = true; config.markdown.render_emoji = true;
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
@ -1383,7 +1383,7 @@ fn can_render_emoji_alias() {
#[test] #[test]
fn emoji_aliases_are_ignored_when_disabled_in_config() { fn emoji_aliases_are_ignored_when_disabled_in_config() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -1419,7 +1419,7 @@ fn invocation_count_increments_in_shortcode() {
tera.add_raw_template("shortcodes/a.html", shortcode_template_a).unwrap(); tera.add_raw_template("shortcodes/a.html", shortcode_template_a).unwrap();
tera.add_raw_template("shortcodes/b.html", shortcode_template_b).unwrap(); tera.add_raw_template("shortcodes/b.html", shortcode_template_b).unwrap();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&tera, &tera,
&config, &config,
@ -1436,7 +1436,7 @@ fn invocation_count_increments_in_shortcode() {
#[test] #[test]
fn basic_external_links_unchanged() { fn basic_external_links_unchanged() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let config = Config::default(); let config = Config::default_for_test();
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
&config, &config,
@ -1452,7 +1452,7 @@ fn basic_external_links_unchanged() {
#[test] #[test]
fn can_set_target_blank_for_external_link() { fn can_set_target_blank_for_external_link() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.external_links_target_blank = true; config.markdown.external_links_target_blank = true;
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
@ -1469,7 +1469,7 @@ fn can_set_target_blank_for_external_link() {
#[test] #[test]
fn can_set_nofollow_for_external_link() { fn can_set_nofollow_for_external_link() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.external_links_no_follow = true; config.markdown.external_links_no_follow = true;
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
@ -1490,7 +1490,7 @@ fn can_set_nofollow_for_external_link() {
#[test] #[test]
fn can_set_noreferrer_for_external_link() { fn can_set_noreferrer_for_external_link() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.external_links_no_referrer = true; config.markdown.external_links_no_referrer = true;
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,
@ -1510,7 +1510,7 @@ fn can_set_noreferrer_for_external_link() {
#[test] #[test]
fn can_set_all_options_for_external_link() { fn can_set_all_options_for_external_link() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.external_links_target_blank = true; config.markdown.external_links_target_blank = true;
config.markdown.external_links_no_follow = true; config.markdown.external_links_no_follow = true;
config.markdown.external_links_no_referrer = true; config.markdown.external_links_no_referrer = true;
@ -1529,7 +1529,7 @@ fn can_set_all_options_for_external_link() {
#[test] #[test]
fn can_use_smart_punctuation() { fn can_use_smart_punctuation() {
let permalinks_ctx = HashMap::new(); let permalinks_ctx = HashMap::new();
let mut config = Config::default(); let mut config = Config::default_for_test();
config.markdown.smart_punctuation = true; config.markdown.smart_punctuation = true;
let context = RenderContext::new( let context = RenderContext::new(
&ZOLA_TERA, &ZOLA_TERA,

View file

@ -1,8 +1,8 @@
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use elasticlunr::{Index, Language};
use elasticlunr::pipeline; use elasticlunr::pipeline;
use elasticlunr::pipeline::TokenizerFn; use elasticlunr::pipeline::TokenizerFn;
use elasticlunr::{Index, Language};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use config::{Config, Search}; use config::{Config, Search};
@ -140,7 +140,13 @@ pub fn build_index(lang: &str, library: &Library, config: &Config) -> Result<Str
for section in library.sections_values() { for section in library.sections_values() {
if section.lang == lang { if section.lang == lang {
add_section_to_index(&mut index, section, library, &language_options.search, tokenizers.clone()); add_section_to_index(
&mut index,
section,
library,
&language_options.search,
tokenizers.clone(),
);
} }
} }
@ -181,7 +187,13 @@ fn add_section_to_index(
index.add_doc_with_tokenizers( index.add_doc_with_tokenizers(
&page.permalink, &page.permalink,
&fill_index(search_config, &page.meta.title, &page.meta.description, &page.path, &page.content), &fill_index(
search_config,
&page.meta.title,
&page.meta.description,
&page.path,
&page.content,
),
tokenizers.clone(), tokenizers.clone(),
); );
} }