crawlnicle/src/utils.rs

15 lines
375 B
Rust
Raw Normal View History

2023-06-27 18:03:52 +00:00
use url::Url;
pub fn get_domain(url: &str) -> Option<String> {
Url::parse(url)
.ok()
.and_then(|url| url.host_str().map(|s| s.to_string()))
.map(|domain| {
if domain.starts_with("www.") && domain.matches('.').count() > 1 {
domain[4..].to_string()
} else {
domain
}
})
}