diff --git a/Cargo.toml b/Cargo.toml index 871ae757..ef25d830 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ notify = "4" ws = "0.8" ctrlc = "3" open = "1.2" +globset = "0.4" site = { path = "components/site" } errors = { path = "components/errors" } diff --git a/components/rebuild/src/lib.rs b/components/rebuild/src/lib.rs index 41b4fc44..f14ac5d6 100644 --- a/components/rebuild/src/lib.rs +++ b/components/rebuild/src/lib.rs @@ -306,7 +306,17 @@ pub fn after_content_rename(site: &mut Site, old: &Path, new: &Path) -> Result<( old.to_path_buf() }; site.library.write().unwrap().remove_page(&old_path); - handle_page_editing(site, &new_path) + + let ignored_content_globset = site.config.ignored_content_globset.clone(); + let is_ignored_file = match ignored_content_globset { + Some(gs) => gs.is_match(new), + None => false + }; + + if !is_ignored_file { + return handle_page_editing(site, &new_path) + } + return Ok(()) } /// What happens when a section or a page is created/edited diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index cd393e91..910f892b 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -210,6 +210,12 @@ impl Site { page_entries .into_par_iter() + .filter(|entry| { + match &config.ignored_content_globset { + Some(gs) => !gs.is_match(entry.as_path()), + None => true + } + }) .map(|entry| { let path = entry.as_path(); Page::from_file(path, config, &self.base_path) diff --git a/components/site/tests/site.rs b/components/site/tests/site.rs index bb5f8d4a..c5288be6 100644 --- a/components/site/tests/site.rs +++ b/components/site/tests/site.rs @@ -653,3 +653,9 @@ fn can_build_site_custom_builtins_from_theme() { assert!(file_exists!(public, "404.html")); assert!(file_contains!(public, "404.html", "Oops")); } + +#[test] +fn can_ignore_markdown_content() { + let (_, _tmp_dir, public) = build_site("test_site"); + assert!(!file_exists!(public, "posts/ignored/index.html")); +} diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 97685479..01d07676 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -21,6 +21,8 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +extern crate globset; + use std::env; use std::fs::{read_dir, remove_dir_all, File}; use std::io::Read; @@ -40,6 +42,7 @@ use ws::{Message, Sender, WebSocket}; use errors::{Error as ZolaError, Result}; use site::Site; use utils::fs::copy_file; +use cmd::serve::globset::GlobSet; use console; use open; @@ -345,6 +348,7 @@ pub fn serve( ); let start = Instant::now(); + match change_kind { ChangeKind::Content => { console::info(&format!("-> Content renamed {}", path.display())); @@ -376,6 +380,9 @@ pub fn serve( // Intellij does weird things on edit, chmod is there to count those changes // https://github.com/passcod/notify/issues/150#issuecomment-494912080 Create(path) | Write(path) | Remove(path) | Chmod(path) => { + if is_ignored_file(&site.config.ignored_content_globset, &path) { + continue; + } if is_temp_file(&path) || path.is_dir() { continue; } @@ -422,6 +429,13 @@ pub fn serve( } } +fn is_ignored_file(ignored_content_globset: &Option, path: &Path) -> bool { + match ignored_content_globset { + Some(gs) => gs.is_match(path), + None => false + } +} + /// Returns whether the path we received corresponds to a temp file created /// by an editor or the OS fn is_temp_file(path: &Path) -> bool { diff --git a/test_site/config.toml b/test_site/config.toml index 31cd7b1c..08f32ab1 100644 --- a/test_site/config.toml +++ b/test_site/config.toml @@ -11,5 +11,7 @@ taxonomies = [ extra_syntaxes = ["syntaxes"] +ignored_content = ["*/ignored.md"] + [extra.author] name = "Vincent Prouillet" diff --git a/test_site/content/posts/ignored.md b/test_site/content/posts/ignored.md new file mode 100644 index 00000000..54e0556a --- /dev/null +++ b/test_site/content/posts/ignored.md @@ -0,0 +1,6 @@ ++++ +title = "This should not be picked up" +date = 2019-07-23 ++++ + +Don't pick me up.