Allow disabling categories of filters
This commit is contained in:
parent
1ee90d2293
commit
5bd65faa55
|
@ -1 +1,2 @@
|
||||||
/target
|
/target
|
||||||
|
.direnv
|
|
@ -14,8 +14,11 @@ category "Spotify" {
|
||||||
category "Campaign tracking (itm)" {
|
category "Campaign tracking (itm)" {
|
||||||
params "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.
|
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.
|
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):
|
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):
|
||||||
|
|
|
@ -9,6 +9,8 @@ use wildmatch::WildMatch;
|
||||||
struct Category {
|
struct Category {
|
||||||
#[knuffel(argument)]
|
#[knuffel(argument)]
|
||||||
name: String,
|
name: String,
|
||||||
|
#[knuffel(property, default)]
|
||||||
|
disabled: bool,
|
||||||
#[knuffel(child, unwrap(arguments))]
|
#[knuffel(child, unwrap(arguments))]
|
||||||
params: Vec<String>,
|
params: Vec<String>,
|
||||||
}
|
}
|
||||||
|
@ -24,12 +26,15 @@ fn main() -> Result<()> {
|
||||||
.into_diagnostic()
|
.into_diagnostic()
|
||||||
.map_err(|err| err.context(format!("Could not read file `{filters}`")))?;
|
.map_err(|err| err.context(format!("Could not read file `{filters}`")))?;
|
||||||
|
|
||||||
let filters = knuffel::parse::<Vec<Category>>("config.kdl", &filters)?;
|
let filters = knuffel::parse::<Vec<Category>>("config.kdl", &filters)?
|
||||||
|
.into_iter()
|
||||||
|
.filter(|v| !v.disabled)
|
||||||
|
.collect::<Vec<Category>>();
|
||||||
|
|
||||||
println!("Loaded with categories:");
|
println!("Loaded with categories:");
|
||||||
filters.iter().for_each(|v| println!("\t• {}", v.name));
|
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<String> = filters.iter().map(|v| v.params.clone()).flatten().collect();
|
let patterns: Vec<String> = filters.iter().map(|v| v.params.clone()).flatten().collect();
|
||||||
|
|
||||||
// Initialize clipboard context
|
// Initialize clipboard context
|
||||||
|
|
Loading…
Reference in New Issue