@@ -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 | |||
@@ -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` | |||
@@ -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, | |||
) | |||
} | |||
@@ -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")); | |||