normalize path to relative
This commit is contained in:
parent
3ab19f3295
commit
722c55f85f
|
@ -974,6 +974,7 @@ dependencies = [
|
||||||
"notify-debouncer-mini",
|
"notify-debouncer-mini",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"opener",
|
"opener",
|
||||||
|
"pathdiff",
|
||||||
"predicates",
|
"predicates",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"pulldown-cmark",
|
"pulldown-cmark",
|
||||||
|
@ -1151,6 +1152,12 @@ dependencies = [
|
||||||
"windows-targets 0.48.1",
|
"windows-targets 0.48.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pathdiff"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.3.0"
|
version = "2.3.0"
|
||||||
|
|
|
@ -28,6 +28,7 @@ log = "0.4.17"
|
||||||
memchr = "2.5.0"
|
memchr = "2.5.0"
|
||||||
opener = "0.6.1"
|
opener = "0.6.1"
|
||||||
pulldown-cmark = { version = "0.9.3", default-features = false }
|
pulldown-cmark = { version = "0.9.3", default-features = false }
|
||||||
|
pathdiff = "0.2.1"
|
||||||
regex = "1.8.1"
|
regex = "1.8.1"
|
||||||
serde = { version = "1.0.163", features = ["derive"] }
|
serde = { version = "1.0.163", features = ["derive"] }
|
||||||
serde_json = "1.0.96"
|
serde_json = "1.0.96"
|
||||||
|
|
|
@ -4,6 +4,7 @@ use ignore::gitignore::Gitignore;
|
||||||
use mdbook::errors::Result;
|
use mdbook::errors::Result;
|
||||||
use mdbook::utils;
|
use mdbook::utils;
|
||||||
use mdbook::MDBook;
|
use mdbook::MDBook;
|
||||||
|
use pathdiff::diff_paths;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
|
@ -93,11 +94,10 @@ fn filter_ignored_files(ignore: Gitignore, paths: &[PathBuf]) -> Vec<PathBuf> {
|
||||||
paths
|
paths
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|path| {
|
.filter(|path| {
|
||||||
let normalized_path = path
|
let relative_path =
|
||||||
.strip_prefix(¤t_dir)
|
diff_paths(¤t_dir, &path).expect("One of the paths should be an absolute");
|
||||||
.expect("Could not normalize path");
|
|
||||||
!ignore
|
!ignore
|
||||||
.matched_path_or_any_parents(normalized_path, normalized_path.is_dir())
|
.matched_path_or_any_parents(&relative_path, relative_path.is_dir())
|
||||||
.is_ignore()
|
.is_ignore()
|
||||||
})
|
})
|
||||||
.map(|path| path.to_path_buf())
|
.map(|path| path.to_path_buf())
|
||||||
|
|
Loading…
Reference in New Issue