From f3edef26407461492a4651e01822abf62a161b51 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 9 May 2017 21:12:10 +0900 Subject: [PATCH] Warn about ignored pages --- src/cmd/build.rs | 3 ++- src/cmd/mod.rs | 21 +++++++++++++++++++++ src/cmd/serve.rs | 3 ++- src/site.rs | 7 +++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 580439e4..6f65f672 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -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() } diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index e3c62b5e..33360fa5 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -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())); + } + } +} diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index fb16ee2f..115f65e6 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -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); diff --git a/src/site.rs b/src/site.rs index f5ffdaae..5cd91272 100644 --- a/src/site.rs +++ b/src/site.rs @@ -122,6 +122,13 @@ impl Site { self.live_reload = true; } + pub fn get_ignored_pages(&self) -> Vec { + 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>(&mut self, path: P) {