diff --git a/.gitignore b/.gitignore index ea8c4bf..cb8c9e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.direnv \ No newline at end of file diff --git a/README.md b/README.md index abd4ece..206fdf8 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,11 @@ category "Spotify" { category "Campaign tracking (itm)" { params "itm_*" } +category "Campaign tracking (stm)" disabled=true { + params "stm_*" +} ``` -Categories do not have significance other than to make filter files better structured. +Categories are used to structure filter lists and allow disabling/enabling filters in groups. Each parameter applies to all URLs, unless a domain like `@example.com` is specified at the end. Both the parameter and the domain parts can contain wildcards. Use `*` to match 0 or more characters, and `?` to match exactly one character. The structure is based on [NeatURL's format](https://github.com/Smile4ever/Neat-URL/#default-blocked-parameters), with a few differences (aside from a different file format): diff --git a/src/main.rs b/src/main.rs index 0283438..2b7cb1d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,8 @@ use wildmatch::WildMatch; struct Category { #[knuffel(argument)] name: String, + #[knuffel(property, default)] + disabled: bool, #[knuffel(child, unwrap(arguments))] params: Vec, } @@ -24,12 +26,15 @@ fn main() -> Result<()> { .into_diagnostic() .map_err(|err| err.context(format!("Could not read file `{filters}`")))?; - let filters = knuffel::parse::>("config.kdl", &filters)?; + let filters = knuffel::parse::>("config.kdl", &filters)? + .into_iter() + .filter(|v| !v.disabled) + .collect::>(); println!("Loaded with categories:"); filters.iter().for_each(|v| println!("\t• {}", v.name)); - // Flatten all patterns into a single list, as categories do not matter + // Flatten filters into patterns let patterns: Vec = filters.iter().map(|v| v.params.clone()).flatten().collect(); // Initialize clipboard context