From 0d4c2e813f9c1531d304699f1ddf63de2decd554 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 12 Jul 2022 00:09:38 +0200 Subject: [PATCH] Fix some bugs + cargo fmt --- components/imageproc/src/lib.rs | 3 ++- components/markdown/src/markdown.rs | 2 +- components/markdown/tests/codeblocks.rs | 8 ++------ components/site/src/lib.rs | 5 ----- components/templates/src/global_fns/files.rs | 15 +++++++++++---- components/utils/src/anchors.rs | 5 ++--- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/components/imageproc/src/lib.rs b/components/imageproc/src/lib.rs index 09bf21f56..db56d4888 100644 --- a/components/imageproc/src/lib.rs +++ b/components/imageproc/src/lib.rs @@ -353,7 +353,8 @@ pub fn fix_orientation(img: &DynamicImage, path: &Path) -> Option let mut buf_reader = std::io::BufReader::new(&file); let exif_reader = exif::Reader::new(); let exif = exif_reader.read_from_container(&mut buf_reader).ok()?; - let orientation = exif.get_field(exif::Tag::Orientation, exif::In::PRIMARY)?.value.get_uint(0)?; + let orientation = + exif.get_field(exif::Tag::Orientation, exif::In::PRIMARY)?.value.get_uint(0)?; match orientation { // Values are taken from the page 30 of // https://www.cipa.jp/std/documents/e/DC-008-2012_E.pdf diff --git a/components/markdown/src/markdown.rs b/components/markdown/src/markdown.rs index 37cc224f9..63007e12b 100644 --- a/components/markdown/src/markdown.rs +++ b/components/markdown/src/markdown.rs @@ -520,7 +520,7 @@ pub fn markdown_to_html( let anchor_idx = match context.insert_anchor { InsertAnchor::Left => start_idx + 1, InsertAnchor::Right => end_idx, - InsertAnchor::Heading => 0, // modified later to the correct value + InsertAnchor::Heading => 0, // modified later to the correct value InsertAnchor::None => unreachable!(), }; let mut c = tera::Context::new(); diff --git a/components/markdown/tests/codeblocks.rs b/components/markdown/tests/codeblocks.rs index d12e0f32b..4b27d2966 100644 --- a/components/markdown/tests/codeblocks.rs +++ b/components/markdown/tests/codeblocks.rs @@ -241,13 +241,9 @@ bar #[test] fn can_add_line_numbers_windows_eol() { - let body = render_codeblock( - "```linenos\r\nfoo\r\nbar\r\n```\r\n", - true, - ); + let body = render_codeblock("```linenos\r\nfoo\r\nbar\r\n```\r\n", true); insta::assert_snapshot!(body); -} - +} #[test] fn can_add_line_numbers_with_lineno_start() { diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 4b3b94ba2..e647f4495 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -534,12 +534,7 @@ impl Site { /// Find all the tags and categories if it's asked in the config pub fn populate_taxonomies(&mut self) -> Result<()> { - if self.config.taxonomies.is_empty() { - return Ok(()); - } - self.taxonomies = self.library.read().unwrap().find_taxonomies(&self.config); - Ok(()) } diff --git a/components/templates/src/global_fns/files.rs b/components/templates/src/global_fns/files.rs index 94c761bc6..57c72f398 100644 --- a/components/templates/src/global_fns/files.rs +++ b/components/templates/src/global_fns/files.rs @@ -104,9 +104,11 @@ impl TeraFn for GetUrl { // anything else let mut segments = vec![]; - if lang != self.config.default_language && !path[1..].starts_with(&lang) { - segments.push(lang); - }; + if lang != self.config.default_language { + if path.is_empty() || !path[1..].starts_with(&lang) { + segments.push(lang); + } + } segments.push(path); @@ -366,7 +368,12 @@ title = "A title" ); let config = Config::parse(CONFIG_DATA).unwrap(); let dir = create_temp_dir(); - let static_fn = GetUrl::new(dir.path().to_path_buf(), config, permalinks, PathBuf::new()); + let static_fn = GetUrl::new( + dir.path().to_path_buf(), + config.clone(), + permalinks.clone(), + PathBuf::new(), + ); let mut args = HashMap::new(); args.insert("path".to_string(), to_value("@/a_section/a_page.md").unwrap()); args.insert("lang".to_string(), to_value("fr").unwrap()); diff --git a/components/utils/src/anchors.rs b/components/utils/src/anchors.rs index fe86e9608..a5706e79d 100644 --- a/components/utils/src/anchors.rs +++ b/components/utils/src/anchors.rs @@ -1,5 +1,5 @@ -use libs::regex::Regex; use libs::regex::escape; +use libs::regex::Regex; pub fn has_anchor_id(content: &str, anchor: &str) -> bool { let checks = anchor_id_checks(anchor); @@ -7,8 +7,7 @@ pub fn has_anchor_id(content: &str, anchor: &str) -> bool { } fn anchor_id_checks(anchor: &str) -> Regex { - Regex::new(&format!(r#"\s(?i)(id|name) *= *("|')*{}("|'| |>)+"#, - escape(anchor))).unwrap() + Regex::new(&format!(r#"\s(?i)(id|name) *= *("|')*{}("|'| |>)+"#, escape(anchor))).unwrap() } #[cfg(test)]