Merge pull request #424 from Freaky/hash-orphans
Use a HashSet for detecting orphan pages
This commit is contained in:
commit
5e6458aa61
|
@ -21,7 +21,7 @@ extern crate imageproc;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
extern crate tempfile;
|
extern crate tempfile;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::fs::{create_dir_all, remove_dir_all, copy};
|
use std::fs::{create_dir_all, remove_dir_all, copy};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
@ -149,20 +149,15 @@ impl Site {
|
||||||
|
|
||||||
/// Get all the orphan (== without section) pages in the site
|
/// Get all the orphan (== without section) pages in the site
|
||||||
pub fn get_all_orphan_pages(&self) -> Vec<&Page> {
|
pub fn get_all_orphan_pages(&self) -> Vec<&Page> {
|
||||||
let mut pages_in_sections = vec![];
|
let pages_in_sections = self.sections
|
||||||
let mut orphans = vec![];
|
.values()
|
||||||
|
.flat_map(|s| s.all_pages_path())
|
||||||
|
.collect::<HashSet<_>>();
|
||||||
|
|
||||||
for s in self.sections.values() {
|
self.pages
|
||||||
pages_in_sections.extend(s.all_pages_path());
|
.values()
|
||||||
}
|
.filter(|page| !pages_in_sections.contains(&page.file.path))
|
||||||
|
.collect()
|
||||||
for page in self.pages.values() {
|
|
||||||
if !pages_in_sections.contains(&page.file.path) {
|
|
||||||
orphans.push(page);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
orphans
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_base_url(&mut self, base_url: String) {
|
pub fn set_base_url(&mut self, base_url: String) {
|
||||||
|
|
Loading…
Reference in a new issue