Skip to content

Commit 4d88ce4

Browse files
committed
fix(web): Fetch favicon from root domain before trying Google
1 parent 60cd2e7 commit 4d88ce4

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

plugins/src/web/mod.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,23 @@ impl App {
149149
|url: String| async move { fetch_favicon(&url, favicon_path, client).await };
150150

151151
// Searches for the favicon if it's not defined at the root of the domain.
152-
let mut result = fetch(
153-
favicon_url_from_page_source(&domain, client)
154-
.await
155-
.unwrap_or_else(|| {
156-
format!("https://www.google.com/s2/favicons?domain={}&sz=32", domain)
157-
}),
158-
)
159-
.await;
160-
161-
if result.is_none() {
162-
// Searches for the favicon from the root of the domain.
163-
result = fetch(["https://", &domain, "/favicon.ico"].concat()).await;
164-
}
152+
let result = match favicon_from_page(&domain, client).await {
153+
Some(url) => fetch(url).await,
154+
155+
// If not found, fetch from root domain.
156+
None => match fetch(["https://", &domain, "/favicon.ico"].concat()).await {
157+
Some(favicon) => Some(favicon),
158+
159+
// If all else fails, try Google.
160+
None => {
161+
fetch(format!(
162+
"https://www.google.com/s2/favicons?domain={}&sz=32",
163+
domain
164+
))
165+
.await
166+
}
167+
},
168+
};
165169

166170
match result {
167171
Some(icon) => {
@@ -229,7 +233,7 @@ async fn fetch_favicon(url: &str, favicon_path: &Path, client: &Client) -> Optio
229233

230234
// Try to extract a favicon url from html the icon path
231235
// returned can be either absolute or relative to the page domain
232-
async fn favicon_url_from_page_source(domain: &str, client: &Client) -> Option<String> {
236+
async fn favicon_from_page(domain: &str, client: &Client) -> Option<String> {
233237
let url = format!("https://{}", domain);
234238
match client.get(&url).send().await {
235239
Ok(html) => html

0 commit comments

Comments
 (0)