From f45293ab25f792fab1449fa9a9b86f049e175e13 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Fri, 4 Jan 2019 20:34:20 +0100 Subject: [PATCH] cargo fmt --- components/library/src/content/ser.rs | 12 +++++++-- components/library/src/library.rs | 13 +++++----- components/site/src/lib.rs | 32 +++++++++++++++--------- components/site/tests/site_i18n.rs | 36 ++++++++++++++++++++++----- 4 files changed, 66 insertions(+), 27 deletions(-) diff --git a/components/library/src/content/ser.rs b/components/library/src/content/ser.rs index 56a2768..5008c80 100644 --- a/components/library/src/content/ser.rs +++ b/components/library/src/content/ser.rs @@ -21,7 +21,11 @@ impl<'a> TranslatedContent<'a> { for key in §ion.translations { let other = library.get_section_by_key(*key); - translations.push(TranslatedContent { lang: &other.lang, permalink: &other.permalink, title: &other.meta.title }); + translations.push(TranslatedContent { + lang: &other.lang, + permalink: &other.permalink, + title: &other.meta.title, + }); } translations @@ -32,7 +36,11 @@ impl<'a> TranslatedContent<'a> { for key in &page.translations { let other = library.get_page_by_key(*key); - translations.push(TranslatedContent { lang: &other.lang, permalink: &other.permalink, title: &other.meta.title }); + translations.push(TranslatedContent { + lang: &other.lang, + permalink: &other.permalink, + title: &other.meta.title, + }); } translations diff --git a/components/library/src/library.rs b/components/library/src/library.rs index 558958f..5552ee9 100644 --- a/components/library/src/library.rs +++ b/components/library/src/library.rs @@ -119,10 +119,10 @@ impl Library { continue; } if let Some(section_key) = - self.paths_to_sections.get(&path.join(§ion.file.filename)) - { - parents.push(*section_key); - } + self.paths_to_sections.get(&path.join(§ion.file.filename)) + { + parents.push(*section_key); + } } ancestors.insert(section.file.path.clone(), parents); } @@ -285,7 +285,7 @@ impl Library { let mut sections_translations = HashMap::new(); for (key, section) in &self.sections { sections_translations - .entry(section.file.canonical.clone()) // TODO: avoid this clone + .entry(section.file.canonical.clone()) // TODO: avoid this clone .or_insert_with(Vec::new) .push(key); } @@ -303,7 +303,7 @@ impl Library { let mut pages_translations = HashMap::new(); for (key, page) in &self.pages { pages_translations - .entry(page.file.canonical.clone()) // TODO: avoid this clone + .entry(page.file.canonical.clone()) // TODO: avoid this clone .or_insert_with(Vec::new) .push(key); } @@ -316,7 +316,6 @@ impl Library { } page.translations = translations.iter().filter(|k| **k != key).cloned().collect(); } - } /// Find all the orphan pages: pages that are in a folder without an `_index.md` diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 402c04e..e115880 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -196,7 +196,8 @@ impl Site { entry.as_path().file_name().unwrap().to_str().unwrap().starts_with("_index.") }); - self.library = Library::new(page_entries.len(), section_entries.len(), self.config.is_multilingual()); + self.library = + Library::new(page_entries.len(), section_entries.len(), self.config.is_multilingual()); let sections = { let config = &self.config; @@ -457,7 +458,8 @@ impl Site { } pub fn process_images(&self) -> Result<()> { - let mut imageproc = self.imageproc.lock().expect("Couldn't lock imageproc (process_images)"); + let mut imageproc = + self.imageproc.lock().expect("Couldn't lock imageproc (process_images)"); imageproc.prune()?; imageproc.do_process() } @@ -497,7 +499,11 @@ impl Site { // Copy any asset we found previously into the same directory as the index.html for asset in &page.assets { let asset_path = asset.as_path(); - copy(&asset_path, ¤t_path.join(asset_path.file_name().expect("Couldn't get filename from page asset")))?; + copy( + &asset_path, + ¤t_path + .join(asset_path.file_name().expect("Couldn't get filename from page asset")), + )?; } Ok(()) @@ -534,13 +540,7 @@ impl Site { .library .pages_values() .iter() - .filter(|p| { - if let Some(ref l) = p.lang { - l == &lang.code - } else { - false - } - }) + .filter(|p| if let Some(ref l) = p.lang { l == &lang.code } else { false }) .map(|p| *p) .collect(); self.render_rss_feed(pages, Some(&PathBuf::from(lang.code.clone())))?; @@ -920,7 +920,12 @@ impl Site { // Copy any asset we found previously into the same directory as the index.html for asset in §ion.assets { let asset_path = asset.as_path(); - copy(&asset_path, &output_path.join(asset_path.file_name().expect("Failed to get asset filename for section")))?; + copy( + &asset_path, + &output_path.join( + asset_path.file_name().expect("Failed to get asset filename for section"), + ), + )?; } if render_pages { @@ -957,7 +962,10 @@ impl Site { /// Used only on reload pub fn render_index(&self) -> Result<()> { self.render_section( - &self.library.get_section(&self.content_path.join("_index.md")).expect("Failed to get index section"), + &self + .library + .get_section(&self.content_path.join("_index.md")) + .expect("Failed to get index section"), false, ) } diff --git a/components/site/tests/site_i18n.rs b/components/site/tests/site_i18n.rs index e0518c5..cba0002 100644 --- a/components/site/tests/site_i18n.rs +++ b/components/site/tests/site_i18n.rs @@ -72,19 +72,43 @@ fn can_build_multilingual_site() { // Sections are there as well, with translations info assert!(file_exists!(public, "blog/index.html")); - assert!(file_contains!(public, "blog/index.html", "Translated in fr: Mon blog https://example.com/fr/blog/")); - assert!(file_contains!(public, "blog/index.html", "Translated in it: Il mio blog https://example.com/it/blog/")); + assert!(file_contains!( + public, + "blog/index.html", + "Translated in fr: Mon blog https://example.com/fr/blog/" + )); + assert!(file_contains!( + public, + "blog/index.html", + "Translated in it: Il mio blog https://example.com/it/blog/" + )); assert!(file_exists!(public, "fr/blog/index.html")); assert!(file_contains!(public, "fr/blog/index.html", "Language: fr")); - assert!(file_contains!(public, "fr/blog/index.html", "Translated in : My blog https://example.com/blog/")); - assert!(file_contains!(public, "fr/blog/index.html", "Translated in it: Il mio blog https://example.com/it/blog/")); + assert!(file_contains!( + public, + "fr/blog/index.html", + "Translated in : My blog https://example.com/blog/" + )); + assert!(file_contains!( + public, + "fr/blog/index.html", + "Translated in it: Il mio blog https://example.com/it/blog/" + )); // Normal pages are there with the translations assert!(file_exists!(public, "blog/something/index.html")); - assert!(file_contains!(public, "blog/something/index.html", "Translated in fr: Quelque chose https://example.com/fr/blog/something/")); + assert!(file_contains!( + public, + "blog/something/index.html", + "Translated in fr: Quelque chose https://example.com/fr/blog/something/" + )); assert!(file_exists!(public, "fr/blog/something/index.html")); assert!(file_contains!(public, "fr/blog/something/index.html", "Language: fr")); - assert!(file_contains!(public, "fr/blog/something/index.html", "Translated in : Something https://example.com/blog/something/")); + assert!(file_contains!( + public, + "fr/blog/something/index.html", + "Translated in : Something https://example.com/blog/something/" + )); // sitemap contains all languages assert!(file_exists!(public, "sitemap.xml"));