cargo fmt

This commit is contained in:
Vincent Prouillet 2019-01-04 20:34:20 +01:00
parent 482a29b109
commit f45293ab25
4 changed files with 66 additions and 27 deletions

View file

@ -21,7 +21,11 @@ impl<'a> TranslatedContent<'a> {
for key in &section.translations { for key in &section.translations {
let other = library.get_section_by_key(*key); 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 translations
@ -32,7 +36,11 @@ impl<'a> TranslatedContent<'a> {
for key in &page.translations { for key in &page.translations {
let other = library.get_page_by_key(*key); 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 translations

View file

@ -316,7 +316,6 @@ impl Library {
} }
page.translations = translations.iter().filter(|k| **k != key).cloned().collect(); 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` /// Find all the orphan pages: pages that are in a folder without an `_index.md`

View file

@ -196,7 +196,8 @@ impl Site {
entry.as_path().file_name().unwrap().to_str().unwrap().starts_with("_index.") 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 sections = {
let config = &self.config; let config = &self.config;
@ -457,7 +458,8 @@ impl Site {
} }
pub fn process_images(&self) -> Result<()> { 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.prune()?;
imageproc.do_process() imageproc.do_process()
} }
@ -497,7 +499,11 @@ impl Site {
// Copy any asset we found previously into the same directory as the index.html // Copy any asset we found previously into the same directory as the index.html
for asset in &page.assets { for asset in &page.assets {
let asset_path = asset.as_path(); let asset_path = asset.as_path();
copy(&asset_path, &current_path.join(asset_path.file_name().expect("Couldn't get filename from page asset")))?; copy(
&asset_path,
&current_path
.join(asset_path.file_name().expect("Couldn't get filename from page asset")),
)?;
} }
Ok(()) Ok(())
@ -534,13 +540,7 @@ impl Site {
.library .library
.pages_values() .pages_values()
.iter() .iter()
.filter(|p| { .filter(|p| if let Some(ref l) = p.lang { l == &lang.code } else { false })
if let Some(ref l) = p.lang {
l == &lang.code
} else {
false
}
})
.map(|p| *p) .map(|p| *p)
.collect(); .collect();
self.render_rss_feed(pages, Some(&PathBuf::from(lang.code.clone())))?; 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 // Copy any asset we found previously into the same directory as the index.html
for asset in &section.assets { for asset in &section.assets {
let asset_path = asset.as_path(); 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 { if render_pages {
@ -957,7 +962,10 @@ impl Site {
/// Used only on reload /// Used only on reload
pub fn render_index(&self) -> Result<()> { pub fn render_index(&self) -> Result<()> {
self.render_section( 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, false,
) )
} }

View file

@ -72,19 +72,43 @@ fn can_build_multilingual_site() {
// Sections are there as well, with translations info // Sections are there as well, with translations info
assert!(file_exists!(public, "blog/index.html")); 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!(
assert!(file_contains!(public, "blog/index.html", "Translated in it: Il mio blog https://example.com/it/blog/")); 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_exists!(public, "fr/blog/index.html"));
assert!(file_contains!(public, "fr/blog/index.html", "Language: fr")); 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!(
assert!(file_contains!(public, "fr/blog/index.html", "Translated in it: Il mio blog https://example.com/it/blog/")); 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 // Normal pages are there with the translations
assert!(file_exists!(public, "blog/something/index.html")); 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_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", "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 // sitemap contains all languages
assert!(file_exists!(public, "sitemap.xml")); assert!(file_exists!(public, "sitemap.xml"));