Warn about ignored pages

This commit is contained in:
Vincent Prouillet 2017-05-09 21:12:10 +09:00
parent 7099fc8ac2
commit f3edef2640
4 changed files with 32 additions and 2 deletions

View file

@ -7,6 +7,7 @@ use gutenberg::Site;
pub fn build(config_file: &str) -> Result<()> {
let mut site = Site::new(env::current_dir().unwrap(), config_file)?;
site.load()?;
println!("-> Creating {} pages and {} sections", site.pages.len(), site.sections.len());
super::notify_site_size(&site);
super::warn_about_ignored_pages(&site);
site.build()
}

View file

@ -5,3 +5,24 @@ mod serve;
pub use self::init::create_new_project;
pub use self::build::build;
pub use self::serve::serve;
use gutenberg::Site;
use console::warn;
fn notify_site_size(site: &Site) {
println!("-> Creating {} pages and {} sections", site.pages.len(), site.sections.len());
}
fn warn_about_ignored_pages(site: &Site) {
let ignored_pages = site.get_ignored_pages();
if !ignored_pages.is_empty() {
warn(&format!(
"{} page(s) ignored (missing date or order in a sorted section):",
ignored_pages.len()
));
for path in site.get_ignored_pages() {
warn(&format!("- {}", path.display()));
}
}
}

View file

@ -67,7 +67,8 @@ pub fn serve(interface: &str, port: &str, config_file: &str) -> Result<()> {
site.load()?;
site.enable_live_reload();
println!("-> Creating {} pages and {} sections", site.pages.len(), site.sections.len());
super::notify_site_size(&site);
super::warn_about_ignored_pages(&site);
site.build()?;
report_elapsed_time(start);

View file

@ -122,6 +122,13 @@ impl Site {
self.live_reload = true;
}
pub fn get_ignored_pages(&self) -> Vec<PathBuf> {
self.sections
.values()
.flat_map(|s| s.ignored_pages.iter().map(|p| p.file_path.clone()))
.collect()
}
/// Used by tests to change the output path to a tmp dir
#[doc(hidden)]
pub fn set_output_path<P: AsRef<Path>>(&mut self, path: P) {