diff --git a/components/link_checker/src/lib.rs b/components/link_checker/src/lib.rs index 0aa55594..811c72d9 100644 --- a/components/link_checker/src/lib.rs +++ b/components/link_checker/src/lib.rs @@ -125,6 +125,7 @@ mod tests { check_page_for_anchor, check_url, has_anchor, is_valid, message, LinkChecker, LINKS, }; use mockito::mock; + use reqwest::StatusCode; // NOTE: HTTP mock paths below are randomly generated to avoid name // collisions. Mocks with the same path can sometimes bleed between tests @@ -189,9 +190,8 @@ mod tests { let url = format!("{}{}", mockito::server_url(), "/C4Szbfnvj6M0LoPk"); let res = check_url(&url, &LinkChecker::default()); - assert!(res.is_valid()); - assert!(res.code.is_some()); - assert!(res.error.is_none()); + assert!(is_valid(&res)); + assert_eq!(res.unwrap(), StatusCode::OK); } #[test] diff --git a/components/site/benches/site.rs b/components/site/benches/site.rs index f5eb7ccf..fd1514c0 100644 --- a/components/site/benches/site.rs +++ b/components/site/benches/site.rs @@ -46,7 +46,8 @@ fn bench_render_feed(b: &mut test::Bencher) { None, &site.config.default_language, None, - ).unwrap(); + ) + .unwrap(); }); } diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index bce4fadb..13c9e0fd 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -55,11 +55,7 @@ struct SerializedTaxonomyItem<'a> { impl<'a> SerializedTaxonomyItem<'a> { pub fn from_item(item: &'a TaxonomyItem) -> Self { - SerializedTaxonomyItem { - name: &item.name, - slug: &item.slug, - permalink: &item.permalink, - } + SerializedTaxonomyItem { name: &item.name, slug: &item.slug, permalink: &item.permalink } } } @@ -646,10 +642,8 @@ impl Site { /// Inject live reload script tag if in live reload mode fn inject_livereload(&self, mut html: String) -> String { if let Some(port) = self.live_reload { - let script = format!( - r#""#, - port, - ); + let script = + format!(r#""#, port,); if let Some(index) = html.rfind("") { html.insert_str(index, &script); } else { @@ -775,12 +769,7 @@ impl Site { } else { library.pages_values() }; - self.render_feed( - pages, - None, - &self.config.default_language, - None, - )?; + self.render_feed(pages, None, &self.config.default_language, None)?; } for lang in &self.config.languages { @@ -789,12 +778,7 @@ impl Site { } let pages = library.pages_values().iter().filter(|p| p.lang == lang.code).cloned().collect(); - self.render_feed( - pages, - Some(&PathBuf::from(lang.code.clone())), - &lang.code, - None, - )?; + self.render_feed(pages, Some(&PathBuf::from(lang.code.clone())), &lang.code, None)?; } self.render_404()?; @@ -1104,11 +1088,12 @@ impl Site { context.insert( "last_updated", - pages.iter() + pages + .iter() .filter_map(|page| page.meta.updated.as_ref()) .chain(pages[0].meta.date.as_ref()) - .max() // I love lexicographically sorted date strings - .unwrap(), // Guaranteed because of pages[0].meta.date + .max() // I love lexicographically sorted date strings + .unwrap(), // Guaranteed because of pages[0].meta.date ); let library = self.library.read().unwrap(); // limit to the last n elements if the limit is set; otherwise use all. @@ -1125,12 +1110,8 @@ impl Site { let feed_filename = &self.config.feed_filename; let feed_url = if let Some(ref base) = base_path { - self.config.make_permalink( - &base - .join(feed_filename) - .to_string_lossy() - .replace('\\', "/"), - ) + self.config + .make_permalink(&base.join(feed_filename).to_string_lossy().replace('\\', "/")) } else { self.config.make_permalink(feed_filename) }; diff --git a/components/site/tests/site_i18n.rs b/components/site/tests/site_i18n.rs index be666776..0d35bc0d 100644 --- a/components/site/tests/site_i18n.rs +++ b/components/site/tests/site_i18n.rs @@ -119,11 +119,19 @@ fn can_build_multilingual_site() { assert!(file_exists!(public, "atom.xml")); assert!(file_contains!(public, "atom.xml", "https://example.com/blog/something-else/")); assert!(!file_contains!(public, "atom.xml", "https://example.com/fr/blog/something-else/")); - assert!(file_contains!(public, "atom.xml", r#""#)); + assert!(file_contains!( + public, + "atom.xml", + r#""# + )); assert!(file_exists!(public, "fr/atom.xml")); assert!(!file_contains!(public, "fr/atom.xml", "https://example.com/blog/something-else/")); assert!(file_contains!(public, "fr/atom.xml", "https://example.com/fr/blog/something-else/")); - assert!(file_contains!(public, "fr/atom.xml", r#""#)); + assert!(file_contains!( + public, + "fr/atom.xml", + r#""# + )); // Italian doesn't have feed enabled assert!(!file_exists!(public, "it/atom.xml")); @@ -134,8 +142,16 @@ fn can_build_multilingual_site() { assert!(!file_contains!(public, "authors/index.html", "Vincent")); assert!(!file_exists!(public, "auteurs/index.html")); assert!(file_exists!(public, "authors/queen-elizabeth/atom.xml")); - assert!(file_contains!(public, "authors/queen-elizabeth/atom.xml", r#""#)); - assert!(file_contains!(public, "authors/queen-elizabeth/atom.xml", r#" - Queen Elizabeth"#)); + assert!(file_contains!( + public, + "authors/queen-elizabeth/atom.xml", + r#""# + )); + assert!(file_contains!( + public, + "authors/queen-elizabeth/atom.xml", + r#" - Queen Elizabeth"# + )); assert!(file_exists!(public, "tags/index.html")); assert!(file_contains!(public, "tags/index.html", "hello")); diff --git a/components/templates/src/builtins/atom.xml b/components/templates/src/builtins/atom.xml index ed6eef4a..b2c89443 100644 --- a/components/templates/src/builtins/atom.xml +++ b/components/templates/src/builtins/atom.xml @@ -19,7 +19,7 @@ {{ page.updated | default(value=page.date) | date(format="%+") }} {{ page.permalink | safe }} - {{ page.content }} - + {{ page.content }} + {%- endfor %} diff --git a/components/templates/src/global_fns/mod.rs b/components/templates/src/global_fns/mod.rs index 5b3c2298..89fd9054 100644 --- a/components/templates/src/global_fns/mod.rs +++ b/components/templates/src/global_fns/mod.rs @@ -60,7 +60,9 @@ fn make_path_with_lang(path: String, lang: &str, config: &Config) -> Result = path.split(".").map(String::from).collect(); @@ -90,13 +92,14 @@ impl TeraFn for GetUrl { if path.starts_with("@/") { let path_with_lang = match make_path_with_lang(path, &lang, &self.config) { Ok(x) => x, - Err(e) => return Err(e) + Err(e) => return Err(e), }; match resolve_internal_link(&path_with_lang, &self.permalinks) { Ok(resolved) => Ok(to_value(resolved.permalink).unwrap()), Err(_) => { - Err(format!("Could not resolve URL for link `{}` not found.", path_with_lang).into()) + Err(format!("Could not resolve URL for link `{}` not found.", path_with_lang) + .into()) } } } else { @@ -599,7 +602,10 @@ title = "A title" args.insert("path".to_string(), to_value("@/a_section/a_page.md").unwrap()); args.insert("lang".to_string(), to_value("it").unwrap()); let err = static_fn.call(&args).unwrap_err(); - assert_eq!("`it` is not an authorized language (check config.languages).", format!("{}", err)); + assert_eq!( + "`it` is not an authorized language (check config.languages).", + format!("{}", err) + ); } #[test] @@ -608,17 +614,20 @@ title = "A title" let mut permalinks = HashMap::new(); permalinks.insert( "a_section/a_page.md".to_string(), - "https://remplace-par-ton-url.fr/a_section/a_page/".to_string() + "https://remplace-par-ton-url.fr/a_section/a_page/".to_string(), ); permalinks.insert( "a_section/a_page.en.md".to_string(), - "https://remplace-par-ton-url.fr/en/a_section/a_page/".to_string() + "https://remplace-par-ton-url.fr/en/a_section/a_page/".to_string(), ); let static_fn = GetUrl::new(config, permalinks); 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()); - assert_eq!(static_fn.call(&args).unwrap(), "https://remplace-par-ton-url.fr/a_section/a_page/"); + assert_eq!( + static_fn.call(&args).unwrap(), + "https://remplace-par-ton-url.fr/a_section/a_page/" + ); } #[test] @@ -627,16 +636,19 @@ title = "A title" let mut permalinks = HashMap::new(); permalinks.insert( "a_section/a_page.md".to_string(), - "https://remplace-par-ton-url.fr/a_section/a_page/".to_string() + "https://remplace-par-ton-url.fr/a_section/a_page/".to_string(), ); permalinks.insert( "a_section/a_page.en.md".to_string(), - "https://remplace-par-ton-url.fr/en/a_section/a_page/".to_string() + "https://remplace-par-ton-url.fr/en/a_section/a_page/".to_string(), ); let static_fn = GetUrl::new(config, permalinks); 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("en").unwrap()); - assert_eq!(static_fn.call(&args).unwrap(), "https://remplace-par-ton-url.fr/en/a_section/a_page/"); + assert_eq!( + static_fn.call(&args).unwrap(), + "https://remplace-par-ton-url.fr/en/a_section/a_page/" + ); } }