Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/utils-reference/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ npm install --save @raycast/utils

## Changelog

### v2.1.0

- `getFavicon` will now respect the user's setting for the favicon provider. Note that the `Apple` provider isn't supported since it relies on a native API.

### v2.0.1

- Fix types for ESM extensions
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@raycast/utils",
"version": "2.0.1",
"version": "2.1.0",
"description": "Set of utilities to streamline building Raycast extensions",
"author": "Raycast Technologies Ltd.",
"homepage": "https://developers.raycast.com/utils-reference",
Expand Down
52 changes: 46 additions & 6 deletions src/icon/favicon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,53 @@
},
): Image.ImageLike {
try {
const urlObj = typeof url === "string" ? new URL(url) : url;
const hostname = urlObj.hostname;
return {
source: `https://www.google.com/s2/favicons?sz=${options?.size ?? 64}&domain=${hostname}`,
fallback: options?.fallback ?? Icon.Link,
mask: options?.mask,
const sanitize = (url: string) => {
if (!url.startsWith("http")) {
return `https://${url}`;
}
return url;
};

const urlObj = typeof url === "string" ? new URL(sanitize(url)) : url;
const hostname = urlObj.hostname;

const faviconProvider: "none" | "raycast" | "apple" | "google" | "duckDuckGo" | "duckduckgo" | "legacy" =
(process.env.FAVICON_PROVIDER as any) ?? "raycast";

Check warning on line 49 in src/icon/favicon.ts

View workflow job for this annotation

GitHub Actions / tests

Unexpected any. Specify a different type

switch (faviconProvider) {
case "none":
return {
source: options?.fallback ?? Icon.Link,
mask: options?.mask,
};
case "apple":
// we can't support apple favicons as it's a native API
return {
source: options?.fallback ?? Icon.Link,
mask: options?.mask,
};
case "duckduckgo":
case "duckDuckGo":
return {
source: `https://icons.duckduckgo.com/ip3/${hostname}.ico`,
fallback: options?.fallback ?? Icon.Link,
mask: options?.mask,
};
case "google":
return {
source: `https://www.google.com/s2/favicons?sz=${options?.size ?? 64}&domain=${hostname}`,
fallback: options?.fallback ?? Icon.Link,
mask: options?.mask,
};
case "legacy":
case "raycast":
default:
return {
source: `https://api.ray.so/favicon?url=${hostname}&size=${options?.size}`,
fallback: options?.fallback ?? Icon.Link,
mask: options?.mask,
};
}
} catch (e) {
console.error(e);
return Icon.Link;
Expand Down
Loading