Allow ignored_content to support markdown files (#759)

* Allow ignored_content to support markdown files

* Add test for markdown supported ignored_content
This commit is contained in:
Pyry Kovanen 2019-08-01 11:18:42 +03:00 committed by Vincent Prouillet
parent 0cd9e58a86
commit 4b43b75d22
7 changed files with 46 additions and 1 deletions

View file

@ -32,6 +32,7 @@ notify = "4"
ws = "0.8" ws = "0.8"
ctrlc = "3" ctrlc = "3"
open = "1.2" open = "1.2"
globset = "0.4"
site = { path = "components/site" } site = { path = "components/site" }
errors = { path = "components/errors" } errors = { path = "components/errors" }

View file

@ -306,7 +306,17 @@ pub fn after_content_rename(site: &mut Site, old: &Path, new: &Path) -> Result<(
old.to_path_buf() old.to_path_buf()
}; };
site.library.write().unwrap().remove_page(&old_path); 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 /// What happens when a section or a page is created/edited

View file

@ -210,6 +210,12 @@ impl Site {
page_entries page_entries
.into_par_iter() .into_par_iter()
.filter(|entry| {
match &config.ignored_content_globset {
Some(gs) => !gs.is_match(entry.as_path()),
None => true
}
})
.map(|entry| { .map(|entry| {
let path = entry.as_path(); let path = entry.as_path();
Page::from_file(path, config, &self.base_path) Page::from_file(path, config, &self.base_path)

View file

@ -653,3 +653,9 @@ fn can_build_site_custom_builtins_from_theme() {
assert!(file_exists!(public, "404.html")); assert!(file_exists!(public, "404.html"));
assert!(file_contains!(public, "404.html", "Oops")); 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"));
}

View file

@ -21,6 +21,8 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
extern crate globset;
use std::env; use std::env;
use std::fs::{read_dir, remove_dir_all, File}; use std::fs::{read_dir, remove_dir_all, File};
use std::io::Read; use std::io::Read;
@ -40,6 +42,7 @@ use ws::{Message, Sender, WebSocket};
use errors::{Error as ZolaError, Result}; use errors::{Error as ZolaError, Result};
use site::Site; use site::Site;
use utils::fs::copy_file; use utils::fs::copy_file;
use cmd::serve::globset::GlobSet;
use console; use console;
use open; use open;
@ -345,6 +348,7 @@ pub fn serve(
); );
let start = Instant::now(); let start = Instant::now();
match change_kind { match change_kind {
ChangeKind::Content => { ChangeKind::Content => {
console::info(&format!("-> Content renamed {}", path.display())); 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 // Intellij does weird things on edit, chmod is there to count those changes
// https://github.com/passcod/notify/issues/150#issuecomment-494912080 // https://github.com/passcod/notify/issues/150#issuecomment-494912080
Create(path) | Write(path) | Remove(path) | Chmod(path) => { 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() { if is_temp_file(&path) || path.is_dir() {
continue; continue;
} }
@ -422,6 +429,13 @@ pub fn serve(
} }
} }
fn is_ignored_file(ignored_content_globset: &Option<GlobSet>, 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 /// Returns whether the path we received corresponds to a temp file created
/// by an editor or the OS /// by an editor or the OS
fn is_temp_file(path: &Path) -> bool { fn is_temp_file(path: &Path) -> bool {

View file

@ -11,5 +11,7 @@ taxonomies = [
extra_syntaxes = ["syntaxes"] extra_syntaxes = ["syntaxes"]
ignored_content = ["*/ignored.md"]
[extra.author] [extra.author]
name = "Vincent Prouillet" name = "Vincent Prouillet"

View file

@ -0,0 +1,6 @@
+++
title = "This should not be picked up"
date = 2019-07-23
+++
Don't pick me up.