Do not clone pages in taxonomies

This commit is contained in:
Vincent Prouillet 2018-09-20 23:03:16 +02:00
parent 14560f224e
commit 69dce561c8
2 changed files with 5 additions and 7 deletions

View file

@ -417,9 +417,7 @@ impl Site {
self.pages self.pages
.values() .values()
.filter(|p| !p.is_draft()) .filter(|p| !p.is_draft())
.cloned() .collect::<Vec<_>>(),
.collect::<Vec<_>>()
.as_slice(),
)?; )?;
Ok(()) Ok(())

View file

@ -111,7 +111,7 @@ impl Taxonomy {
} }
} }
pub fn find_taxonomies(config: &Config, all_pages: &[Page]) -> Result<Vec<Taxonomy>> { pub fn find_taxonomies(config: &Config, all_pages: Vec<&Page>) -> Result<Vec<Taxonomy>> {
let taxonomies_def = { let taxonomies_def = {
let mut m = HashMap::new(); let mut m = HashMap::new();
for t in &config.taxonomies { for t in &config.taxonomies {
@ -183,9 +183,9 @@ mod tests {
taxo_page3.insert("tags".to_string(), vec!["js".to_string()]); taxo_page3.insert("tags".to_string(), vec!["js".to_string()]);
taxo_page3.insert("authors".to_string(), vec!["Vincent Prouillet".to_string()]); taxo_page3.insert("authors".to_string(), vec!["Vincent Prouillet".to_string()]);
page3.meta.taxonomies = taxo_page3; page3.meta.taxonomies = taxo_page3;
let pages = vec![page1, page2, page3]; let pages = vec![&page1, &page2, &page3];
let taxonomies = find_taxonomies(&config, &pages).unwrap(); let taxonomies = find_taxonomies(&config, pages).unwrap();
let (tags, categories, authors) = { let (tags, categories, authors) = {
let mut t = None; let mut t = None;
let mut c = None; let mut c = None;
@ -241,7 +241,7 @@ mod tests {
taxo_page1.insert("tags".to_string(), vec!["rust".to_string(), "db".to_string()]); taxo_page1.insert("tags".to_string(), vec!["rust".to_string(), "db".to_string()]);
page1.meta.taxonomies = taxo_page1; page1.meta.taxonomies = taxo_page1;
let taxonomies = find_taxonomies(&config, &vec![page1]); let taxonomies = find_taxonomies(&config, vec![&page1]);
assert!(taxonomies.is_err()); assert!(taxonomies.is_err());
let err = taxonomies.unwrap_err(); let err = taxonomies.unwrap_err();
// no path as this is created by Default // no path as this is created by Default