This repository has been archived on 2025-01-30. You can view files and clone it, but cannot push or open issues or pull requests.
site_icons/README.md

60 lines
1.8 KiB
Markdown
Raw Normal View History

2021-01-29 12:23:15 +00:00
# site_icons
2021-01-29 16:26:04 +00:00
[![Crates.io](https://img.shields.io/crates/v/site_icons.svg)](https://crates.io/crates/site_icons)
[![Documentation](https://docs.rs/site_icons/badge.svg)](https://docs.rs/site_icons/)
![GitHub Sponsors](https://img.shields.io/github/sponsors/samdenty?style=social)
An efficient website icon scraper for rust or command line usage.
## Features
2021-01-29 16:35:42 +00:00
- Super fast!
- Gives you the size for each image (partially downloads them)
- Can extract a site logo `<img>` using a weighing system
2021-01-29 16:37:33 +00:00
- Works with inline-data URIs (and automatically converts `<svg>` to them)
2021-01-29 16:26:04 +00:00
- Supports WASM (and cloudflare workers)
### Command line usage
```bash
cargo install site_icons
site-icons https://google.com
# https://github.githubassets.com/favicons/favicon.svg site_favicon svg
# https://github.githubassets.com/app-icon-512.png app_icon png 512x512
# https://github.githubassets.com/app-icon-192.png app_icon png 192x192
# https://github.githubassets.com/apple-touch-icon-180x180.png app_icon png 180x180
```
### API usage
2021-01-29 12:23:15 +00:00
2021-01-29 12:24:05 +00:00
```rust
2021-01-29 12:23:15 +00:00
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;
2021-01-29 16:26:04 +00:00
// entries are sorted from highest to lowest resolution
2021-01-29 12:23:15 +00:00
for icon in entries {
println("{:?}", icon)
}
```
### Sources
- HTML favicon tag (or looking for default `/favicon.ico`)
- [Web app manifest](https://developer.mozilla.org/en-US/docs/Web/Manifest) [`icons`](https://developer.mozilla.org/en-US/docs/Web/Manifest/icons) field
- `<img>` tags on the page, directly inside the header OR with a `src|alt|class` containing the text "logo"
## Running locally
Install [cargo make](https://github.com/sagiegurari/cargo-make) and then:
```bash
cargo make run https://github.com
```