Skip to content

Commit

Permalink
fix(content-loader): ignore paths containing hidden files or directories
Browse files Browse the repository at this point in the history
This shouldn't *really* be necessary, because I'm using `ignore::Walk`
to walk the content directory, and it claims to ignore hidden files
already, but I'm getting events for files in `.jj/` in the content dir.
  • Loading branch information
maddiemort committed Oct 7, 2024
1 parent 5045409 commit 2a60800
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use comrak::{
markdown_to_html_with_plugins, plugins::syntect::SyntectAdapter, ComrakOptions, ComrakPlugins,
};
use either::Either;
use ignore::Walk;
use ignore::{Walk, WalkBuilder};
use lazy_static::lazy_static;
use maud::{html, Markup, PreEscaped};
use notify::{RecommendedWatcher, RecursiveMode};
Expand Down Expand Up @@ -124,6 +124,7 @@ impl Config {

let runtime = runtime::Handle::current();
let content_1 = content.clone();
let content_path_1 = self.content_path.clone();

let loader_handle = runtime.spawn_blocking(move || {
let _guard = span!(Level::ERROR, "content_loader").entered();
Expand All @@ -139,6 +140,25 @@ impl Config {
return;
};

let Ok(relative) = path.strip_prefix(&content_path_1) else {
debug!(
%path,
"skipping entry for path that isn't relative to the content path"
);
return;
};

if relative
.components()
.any(|component| component.as_str().starts_with('.'))
{
debug!(
%path,
"skipping entry for a path containing a hidden file or directory"
);
return;
}

if path
.file_name()
.map_or(false, |name| name == "4913" || name.ends_with('~'))
Expand Down

0 comments on commit 2a60800

Please sign in to comment.