@@ -149,19 +149,23 @@ impl App {
149
149
|url : String | async move { fetch_favicon ( & url, favicon_path, client) . await } ;
150
150
151
151
// 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
+ } ;
165
169
166
170
match result {
167
171
Some ( icon) => {
@@ -229,7 +233,7 @@ async fn fetch_favicon(url: &str, favicon_path: &Path, client: &Client) -> Optio
229
233
230
234
// Try to extract a favicon url from html the icon path
231
235
// 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 > {
233
237
let url = format ! ( "https://{}" , domain) ;
234
238
match client. get ( & url) . send ( ) . await {
235
239
Ok ( html) => html
0 commit comments