Compare commits

...

5 commits
v0.3.0 ... main

Author SHA1 Message Date
81dbf946e9 Add CI
All checks were successful
Build & Test / build-run (push) Successful in 30s
2025-02-04 00:17:26 +01:00
61619ac660 Bump version 2025-02-02 23:20:20 +01:00
314bc347de Add an example to the readme and test it 2025-02-02 23:19:30 +01:00
f1a4e2e819 Pub use icon stuff for convenience 2025-02-02 23:19:15 +01:00
108eb427b8 Fix relative URLs in manifests not being handled 2025-02-02 23:06:24 +01:00
6 changed files with 50 additions and 7 deletions

View file

@ -0,0 +1,20 @@
name: Build & Test
on: [push]
jobs:
build-run:
runs-on: docker
container:
image: rust
steps:
- name: Update package repos
run: apt update
- name: Install Node using apt
run: apt install nodejs -y
- name: Checkout repo
uses: actions/checkout@v4
- name: Build using Cargo
run: cargo build --verbose
- name: Run unit tests
run: cargo test --verbose

2
Cargo.lock generated
View file

@ -226,7 +226,7 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]] [[package]]
name = "favicon-scraper" name = "favicon-scraper"
version = "0.3.0" version = "0.3.1"
dependencies = [ dependencies = [
"futures", "futures",
"imagesize", "imagesize",

View file

@ -1,12 +1,13 @@
[package] [package]
name = "favicon-scraper" name = "favicon-scraper"
version = "0.3.0" version = "0.3.1"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"
description = "A favicon scraper that just works" description = "A favicon scraper that just works"
homepage = "https://kitsunes.dev/Nekomata/favicon-scraper" homepage = "https://kitsunes.dev/Nekomata/favicon-scraper"
repository = "https://kitsunes.dev/Nekomata/favicon-scraper" repository = "https://kitsunes.dev/Nekomata/favicon-scraper"
readme = "README.md" readme = "README.md"
exclude = ["/.forgejo"]
[dependencies] [dependencies]
futures = { version = "0.3.31", default-features = false, features = ["std"] } futures = { version = "0.3.31", default-features = false, features = ["std"] }

View file

@ -1,5 +1,15 @@
# favicon-scraper # favicon-scraper
Scrapes favicons from websites. Scrapes favicons from websites. Does not particularly care for 100% optimal
performance, it just needs to work.
Does not particularly care for 100% optimal performance, it just needs to work To get started, try the `scrape` function:
```rust
use favicon_scraper::{scrape, Icon};
let icons: Vec<Icon> = scrape("https://google.com").await.unwrap();
// Should find something like "https://www.google.com/favicon.ico"
println!("Google's icon can be found at {}", icons[0].url);
```

View file

@ -12,7 +12,7 @@ pub mod manifest;
pub use error::Error; pub use error::Error;
use futures::future::{join, join_all}; use futures::future::{join, join_all};
use html::HTML; use html::HTML;
use icon::{Icon, IconKind}; pub use icon::{Icon, IconKind};
use manifest::scan_manifest; use manifest::scan_manifest;
use reqwest::{Client, IntoUrl}; use reqwest::{Client, IntoUrl};
use url::Url; use url::Url;
@ -92,4 +92,14 @@ mod tests {
println!("Kind of icon: {:?}\n", icon.kind); println!("Kind of icon: {:?}\n", icon.kind);
} }
} }
#[tokio::test]
async fn test_readme_example() {
use crate::{scrape, Icon};
let icons: Vec<Icon> = scrape("https://google.com").await.unwrap();
// Should find something like "https://www.google.com/favicon.ico"
println!("Google's icon can be found at {}", icons[0].url);
}
} }

View file

@ -20,12 +20,14 @@ struct ManifestIcon {
/// Scans a Web App Manifest for icons. /// Scans a Web App Manifest for icons.
pub async fn scan_manifest(client: &Client, url: impl IntoUrl) -> Result<Vec<Icon>, Error> { pub async fn scan_manifest(client: &Client, url: impl IntoUrl) -> Result<Vec<Icon>, Error> {
let manifest: Manifest = client.get(url).send().await?.json().await?; let url = url.into_url()?;
let manifest: Manifest = client.get(url.clone()).send().await?.json().await?;
Ok(join_all( Ok(join_all(
manifest manifest
.icons .icons
.into_iter() .into_iter()
.map(|i| Icon::from_url(client, i.src, IconKind::LinkedInManifest)), .filter_map(|i| url.join(&i.src).ok())
.map(|u| Icon::from_url(client, u, IconKind::LinkedInManifest)),
) )
.await .await
.into_iter() .into_iter()