From 0d33bd4833b7f654755d744e2f8058674b7a77ea Mon Sep 17 00:00:00 2001 From: Sam Denty Date: Fri, 23 Dec 2022 21:51:34 +0000 Subject: [PATCH] feat: blacklists --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/icons.rs | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3fc73fb..82a98e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1525,7 +1525,7 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" [[package]] name = "site_icons" -version = "0.3.9" +version = "0.3.10" dependencies = [ "byteorder", "clap", diff --git a/Cargo.toml b/Cargo.toml index 18f77e7..28154c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "site_icons" -version = "0.3.9" +version = "0.3.10" authors = ["Sam Denty "] edition = "2018" license = "GPL-3.0" diff --git a/src/icons.rs b/src/icons.rs index e50cc1d..2f7c8fb 100644 --- a/src/icons.rs +++ b/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 bool>>, entries: Vec, 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());