@@ -35,13 +35,53 @@ export function getFavicon(
3535 } ,
3636) : Image . ImageLike {
3737 try {
38- const urlObj = typeof url === "string" ? new URL ( url ) : url ;
39- const hostname = urlObj . hostname ;
40- return {
41- source : `https://www.google.com/s2/favicons?sz=${ options ?. size ?? 64 } &domain=${ hostname } ` ,
42- fallback : options ?. fallback ?? Icon . Link ,
43- mask : options ?. mask ,
38+ const sanitize = ( url : string ) => {
39+ if ( ! url . startsWith ( "http" ) ) {
40+ return `https://${ url } ` ;
41+ }
42+ return url ;
4443 } ;
44+
45+ const urlObj = typeof url === "string" ? new URL ( sanitize ( url ) ) : url ;
46+ const hostname = urlObj . hostname ;
47+
48+ const faviconProvider : "none" | "raycast" | "apple" | "google" | "duckDuckGo" | "duckduckgo" | "legacy" =
49+ ( process . env . FAVICON_PROVIDER as any ) ?? "raycast" ;
50+
51+ switch ( faviconProvider ) {
52+ case "none" :
53+ return {
54+ source : options ?. fallback ?? Icon . Link ,
55+ mask : options ?. mask ,
56+ } ;
57+ case "apple" :
58+ // we can't support apple favicons as it's a native API
59+ return {
60+ source : options ?. fallback ?? Icon . Link ,
61+ mask : options ?. mask ,
62+ } ;
63+ case "duckduckgo" :
64+ case "duckDuckGo" :
65+ return {
66+ source : `https://icons.duckduckgo.com/ip3/${ hostname } .ico` ,
67+ fallback : options ?. fallback ?? Icon . Link ,
68+ mask : options ?. mask ,
69+ } ;
70+ case "google" :
71+ return {
72+ source : `https://www.google.com/s2/favicons?sz=${ options ?. size ?? 64 } &domain=${ hostname } ` ,
73+ fallback : options ?. fallback ?? Icon . Link ,
74+ mask : options ?. mask ,
75+ } ;
76+ case "legacy" :
77+ case "raycast" :
78+ default :
79+ return {
80+ source : `https://api.ray.so/favicon?url=${ hostname } &size=${ options ?. size } ` ,
81+ fallback : options ?. fallback ?? Icon . Link ,
82+ mask : options ?. mask ,
83+ } ;
84+ }
4585 } catch ( e ) {
4686 console . error ( e ) ;
4787 return Icon . Link ;
0 commit comments