Browse Source

Allow ignored_content to support markdown files (#759)

* Allow ignored_content to support markdown files

* Add test for markdown supported ignored_content
index-subcmd
Pyry Kovanen Vincent Prouillet 5 years ago
parent
commit
4b43b75d22
7 changed files with 46 additions and 1 deletions
  1. +1
    -0
      Cargo.toml
  2. +11
    -1
      components/rebuild/src/lib.rs
  3. +6
    -0
      components/site/src/lib.rs
  4. +6
    -0
      components/site/tests/site.rs
  5. +14
    -0
      src/cmd/serve.rs
  6. +2
    -0
      test_site/config.toml
  7. +6
    -0
      test_site/content/posts/ignored.md

+ 1
- 0
Cargo.toml View File

@@ -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" }


+ 11
- 1
components/rebuild/src/lib.rs View File

@@ -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


+ 6
- 0
components/site/src/lib.rs View File

@@ -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)


+ 6
- 0
components/site/tests/site.rs View File

@@ -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"));
}

+ 14
- 0
src/cmd/serve.rs View File

@@ -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<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
/// by an editor or the OS
fn is_temp_file(path: &Path) -> bool {


+ 2
- 0
test_site/config.toml View File

@@ -11,5 +11,7 @@ taxonomies = [

extra_syntaxes = ["syntaxes"]

ignored_content = ["*/ignored.md"]

[extra.author]
name = "Vincent Prouillet"

+ 6
- 0
test_site/content/posts/ignored.md View File

@@ -0,0 +1,6 @@
+++
title = "This should not be picked up"
date = 2019-07-23
+++

Don't pick me up.

Loading…
Cancel
Save