Use default rust formatting
This commit is contained in:
parent
ed163b9a42
commit
a1c38dbc9a
20 changed files with 1104 additions and 1102 deletions
|
@ -1,3 +0,0 @@
|
|||
indent_style = "Block"
|
||||
reorder_imports = true
|
||||
tab_spaces = 2
|
|
@ -46,7 +46,9 @@ pub async fn parse_head(
|
|||
.and_then(|href| url.join(&href).ok())
|
||||
{
|
||||
new_icons.borrow_mut().push(
|
||||
async { SiteIcons::load_manifest(href).await.unwrap_or(Vec::new()) }
|
||||
async {
|
||||
SiteIcons::load_manifest(href).await.unwrap_or(Vec::new())
|
||||
}
|
||||
.boxed_local()
|
||||
.shared(),
|
||||
)
|
||||
|
|
|
@ -24,7 +24,8 @@ pub async fn parse_site_logo(
|
|||
|
||||
let document = parser.finish();
|
||||
|
||||
let mut logos: Vec<_> = document
|
||||
let mut logos: Vec<_> =
|
||||
document
|
||||
.select(selector!(
|
||||
"a[href='/'] img, a[href='/'] svg",
|
||||
"header img, header svg",
|
||||
|
@ -108,11 +109,9 @@ pub async fn parse_site_logo(
|
|||
.and_then(|domain| TldOption::default().build().extract(domain).unwrap().domain)
|
||||
{
|
||||
// if the alt contains the site_name then highest priority
|
||||
if site_name
|
||||
.to_lowercase()
|
||||
.split('-')
|
||||
.any(|segment| mentions("alt", Box::new(move |attr| attr.contains(segment))))
|
||||
{
|
||||
if site_name.to_lowercase().split('-').any(|segment| {
|
||||
mentions("alt", Box::new(move |attr| attr.contains(segment)))
|
||||
}) {
|
||||
weight += 10;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,8 +84,7 @@ impl IconInfo {
|
|||
let mime = url.mime_type().to_string().parse::<MediaType>()?;
|
||||
|
||||
let body = Cursor::new(
|
||||
url
|
||||
.decode_to_vec()
|
||||
url.decode_to_vec()
|
||||
.map_err(|_| "failed to decode data uri body")?
|
||||
.0,
|
||||
);
|
||||
|
@ -115,7 +114,9 @@ impl IconInfo {
|
|||
let body = res
|
||||
.bytes_stream()
|
||||
.map(|result| {
|
||||
result.map_err(|error| io::Error::new(io::ErrorKind::Other, error.to_string()))
|
||||
result.map_err(|error| {
|
||||
io::Error::new(io::ErrorKind::Other, error.to_string())
|
||||
})
|
||||
})
|
||||
.into_async_read();
|
||||
|
||||
|
@ -230,12 +231,14 @@ impl Display for IconInfo {
|
|||
impl Ord for IconInfo {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
match (self, other) {
|
||||
(IconInfo::SVG { size }, IconInfo::SVG { size: other_size }) => match (size, other_size) {
|
||||
(IconInfo::SVG { size }, IconInfo::SVG { size: other_size }) => {
|
||||
match (size, other_size) {
|
||||
(Some(_), None) => Ordering::Less,
|
||||
(None, Some(_)) => Ordering::Greater,
|
||||
(Some(size), Some(other_size)) => size.cmp(other_size),
|
||||
(None, None) => Ordering::Equal,
|
||||
},
|
||||
}
|
||||
}
|
||||
(IconInfo::SVG { .. }, _) => Ordering::Less,
|
||||
(_, IconInfo::SVG { .. }) => Ordering::Greater,
|
||||
|
||||
|
|
|
@ -4,8 +4,7 @@ use lol_html::{element, HtmlRewriter, Settings};
|
|||
use std::{cell::RefCell, error::Error};
|
||||
|
||||
fn parse_size<S: ToString>(size: S) -> Option<u32> {
|
||||
size
|
||||
.to_string()
|
||||
size.to_string()
|
||||
.parse::<f64>()
|
||||
.ok()
|
||||
.map(|size| size.round() as u32)
|
||||
|
@ -27,14 +26,17 @@ pub async fn get_svg_size<R: AsyncRead + Unpin>(
|
|||
let width = el.get_attribute("width").and_then(parse_size);
|
||||
let height = el.get_attribute("height").and_then(parse_size);
|
||||
|
||||
*size.borrow_mut() = Some(if let (Some(width), Some(height)) = (width, height) {
|
||||
*size.borrow_mut() =
|
||||
Some(if let (Some(width), Some(height)) = (width, height) {
|
||||
Some(IconSize::new(width, height))
|
||||
} else if let Some(viewbox) = viewbox {
|
||||
regex!(r"^-?\d+\s+-?\d+\s+(\d+\.?[\d]?)\s+(\d+\.?[\d]?)")
|
||||
.captures(&viewbox)
|
||||
.map(|captures| {
|
||||
let width = parse_size(captures.get(1).unwrap().as_str()).unwrap();
|
||||
let height = parse_size(captures.get(2).unwrap().as_str()).unwrap();
|
||||
let width =
|
||||
parse_size(captures.get(1).unwrap().as_str()).unwrap();
|
||||
let height =
|
||||
parse_size(captures.get(2).unwrap().as_str()).unwrap();
|
||||
IconSize::new(width, height)
|
||||
})
|
||||
} else {
|
||||
|
|
|
@ -61,8 +61,7 @@ impl Hash for Icon {
|
|||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
(
|
||||
&self.url,
|
||||
self
|
||||
.headers
|
||||
self.headers
|
||||
.iter()
|
||||
.sorted_by_key(|(key, _)| *key)
|
||||
.collect::<Vec<_>>(),
|
||||
|
|
14
src/icons.rs
14
src/icons.rs
|
@ -82,8 +82,7 @@ impl SiteIcons {
|
|||
None
|
||||
} else {
|
||||
let body = res.bytes_stream().map(|res| {
|
||||
res
|
||||
.map(|bytes| bytes.to_vec())
|
||||
res.map(|bytes| bytes.to_vec())
|
||||
.map_err(|err| err.to_string())
|
||||
});
|
||||
|
||||
|
@ -118,7 +117,8 @@ impl SiteIcons {
|
|||
LoadedKind::SiteLogo(match html_response {
|
||||
Some((url, complete, body)) => {
|
||||
let (icons, _) = join!(
|
||||
html_parser::parse_site_logo(&url, body, |url| self.is_blacklisted(url)),
|
||||
html_parser::parse_site_logo(&url, body, |url| self
|
||||
.is_blacklisted(url)),
|
||||
complete
|
||||
);
|
||||
|
||||
|
@ -129,7 +129,8 @@ impl SiteIcons {
|
|||
}
|
||||
.boxed_local(),
|
||||
async {
|
||||
let manifests = join_all(manifest_urls.map(|url| SiteIcons::load_manifest(url))).await;
|
||||
let manifests =
|
||||
join_all(manifest_urls.map(|url| SiteIcons::load_manifest(url))).await;
|
||||
|
||||
LoadedKind::DefaultManifest(
|
||||
manifests
|
||||
|
@ -139,8 +140,9 @@ impl SiteIcons {
|
|||
}
|
||||
.boxed_local(),
|
||||
async {
|
||||
let favicons =
|
||||
join_all(favicon_urls.map(|url| Icon::load(url.clone(), IconKind::SiteFavicon, None)))
|
||||
let favicons = join_all(
|
||||
favicon_urls.map(|url| Icon::load(url.clone(), IconKind::SiteFavicon, None)),
|
||||
)
|
||||
.await;
|
||||
|
||||
LoadedKind::DefaultFavicon(favicons.into_iter().find_map(|favicon| favicon.ok()))
|
||||
|
|
|
@ -40,8 +40,7 @@ async fn load_manifest_cached(url: Url) -> Result<Vec<Icon>, String> {
|
|||
.await
|
||||
.map_err(|e| format!("{}: {:?}", url, e))?;
|
||||
|
||||
Ok(
|
||||
join_all(manifest.icons.into_iter().map(|icon| async move {
|
||||
Ok(join_all(manifest.icons.into_iter().map(|icon| async move {
|
||||
if let Ok(src) = url.join(&icon.src) {
|
||||
Icon::load(src, IconKind::AppIcon, icon.sizes).await.ok()
|
||||
} else {
|
||||
|
@ -51,6 +50,5 @@ async fn load_manifest_cached(url: Url) -> Result<Vec<Icon>, String> {
|
|||
.await
|
||||
.into_iter()
|
||||
.filter_map(|icon| icon)
|
||||
.collect(),
|
||||
)
|
||||
.collect())
|
||||
}
|
||||
|
|
Reference in a new issue