diff --git a/Cargo.lock b/Cargo.lock index e18f6c1..aa94a0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1539,7 +1539,7 @@ checksum = "fa8f3741c7372e75519bd9346068370c9cdaabcc1f9599cbcf2a2719352286b7" [[package]] name = "site_icons" -version = "0.1.0" +version = "0.1.1" dependencies = [ "byteorder", "clap", diff --git a/Cargo.toml b/Cargo.toml index 95b4d02..43314b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "site_icons" -version = "0.1.0" +version = "0.1.1" authors = ["Sam Denty "] edition = "2018" license = "GPL-3.0" diff --git a/Makefile.toml b/Makefile.toml index f2d247f..9f4ea83 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -1,4 +1,4 @@ [tasks.run] -env = { "RUST_LOG" = "site_icons" } +env = { "RUST_LOG" = "info" } command = "cargo" args = ["run", "--", "${@}"] diff --git a/src/bin/site-icons.rs b/src/bin/site-icons.rs index 771c471..7a200e5 100644 --- a/src/bin/site-icons.rs +++ b/src/bin/site-icons.rs @@ -21,7 +21,7 @@ async fn main() -> Result<(), Box> { if opts.debug { let mut builder = Builder::new(); - builder.filter_module("site_icons", LevelFilter::Info); + builder.filter_module("info", LevelFilter::Info); builder.init(); } diff --git a/src/icons.rs b/src/icons.rs index 8104718..3ee1ffe 100644 --- a/src/icons.rs +++ b/src/icons.rs @@ -1,4 +1,4 @@ -use crate::{selector, utils::encode_svg, warn_err, Icon, IconInfo, IconKind, CLIENT}; +use crate::{utils::encode_svg, Icon, IconInfo, IconKind, CLIENT}; use future::join_all; use futures::StreamExt; use futures::{prelude::*, task::noop_waker}; diff --git a/src/lib.rs b/src/lib.rs index 240ce72..e9e66a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,35 @@ #![feature(async_closure, map_into_keys_values, bool_to_option)] +//! # site_icons +//! An efficient website icon scraper. +//! +//! ## Usage +//! ```rust +//! use site_icons::Icons; +//! +//! let icons = Icons::new(); +//! // scrape the icons from a url +//! icons.load_website("https://github.com").await?; +//! +//! // fetch all icons, ensuring they exist & determining size +//! let entries = icons.entries().await; +//! +//! // entries are sorted from highest to lowest resolution +//! for icon in entries { +//! println("{:?}", icon) +//! } +//! ``` + #[macro_use] extern crate serde_with; #[macro_use] extern crate log; +#[macro_use] +mod macros; mod icon; mod icon_info; mod icon_size; mod icons; -mod macros; mod utils; pub use icon::*; diff --git a/src/macros.rs b/src/macros.rs index 696f622..10608b9 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,19 +1,16 @@ -#[macro_export] macro_rules! selector { ($($selector:expr),+ $(,)?) => {{ static RE: once_cell::sync::OnceCell = once_cell::sync::OnceCell::new(); - RE.get_or_init(|| scraper::Selector::parse(crate::join!(",", $($selector),+)).unwrap()) + RE.get_or_init(|| scraper::Selector::parse(join!(",", $($selector),+)).unwrap()) }}; } -#[macro_export] macro_rules! join { ($pattern:literal,$first:expr$(, $($rest:expr),*)? $(,)?) => { concat!($first$(, $($pattern, $rest),*)?) }; } -#[macro_export] macro_rules! regex { ($re:literal $(,)?) => {{ static RE: once_cell::sync::OnceCell = once_cell::sync::OnceCell::new(); @@ -21,7 +18,6 @@ macro_rules! regex { }}; } -#[macro_export] macro_rules! warn_err { ($result:expr, $($arg:tt)*) => {{ if let Err(err) = $result { diff --git a/src/utils.rs b/src/utils.rs index 91d5ebb..7c408d1 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,3 @@ -use crate::regex; use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS}; const DATA_URI: &AsciiSet = &CONTROLS