feat: blacklists
This commit is contained in:
parent
4e1710539c
commit
0d33bd4833
3 changed files with 18 additions and 2 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1525,7 +1525,7 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
|
|||
|
||||
[[package]]
|
||||
name = "site_icons"
|
||||
version = "0.3.9"
|
||||
version = "0.3.10"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"clap",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "site_icons"
|
||||
version = "0.3.9"
|
||||
version = "0.3.10"
|
||||
authors = ["Sam Denty <sam@samdenty.com>"]
|
||||
edition = "2018"
|
||||
license = "GPL-3.0"
|
||||
|
|
16
src/icons.rs
16
src/icons.rs
|
@ -15,6 +15,7 @@ use std::{collections::HashMap, error::Error, pin::Pin, task::Context};
|
|||
use url::Url;
|
||||
|
||||
pub struct Icons {
|
||||
blacklist: Option<Box<dyn Fn(&Url) -> bool>>,
|
||||
entries: Vec<Icon>,
|
||||
pending_entries: HashMap<
|
||||
Url,
|
||||
|
@ -47,6 +48,15 @@ fn add_icon_entry(
|
|||
impl Icons {
|
||||
pub fn new() -> Self {
|
||||
Icons {
|
||||
blacklist: None,
|
||||
entries: Vec::new(),
|
||||
pending_entries: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_blacklist(blacklist: impl Fn(&Url) -> bool + 'static) -> Self {
|
||||
Icons {
|
||||
blacklist: Some(Box::new(blacklist)),
|
||||
entries: Vec::new(),
|
||||
pending_entries: HashMap::new(),
|
||||
}
|
||||
|
@ -116,6 +126,12 @@ impl Icons {
|
|||
|
||||
let url = res.url().clone();
|
||||
|
||||
if let Some(is_blacklisted) = &self.blacklist {
|
||||
if is_blacklisted(&url) {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
let mut body = res.bytes_stream();
|
||||
|
||||
let mut parser = driver::parse_document(Html::new_document(), Default::default());
|
||||
|
|
Reference in a new issue