feat: light icons on the dark cards
A link without an icon of its own gets the library's light version when there is one (github-light), instead of a dark logo on a dark card. The server keeps the library's list of names for a day.
This commit is contained in:
+15
-1
@@ -17,6 +17,15 @@ const slug = (name: string) =>
|
||||
|
||||
export const libraryIcon = (name: string) => `${LIBRARY}/png/${slug(name)}.png`
|
||||
|
||||
/**
|
||||
* The library has a light version of some icons (`github-light`), made for dark
|
||||
* backgrounds like the cards. Its name for a link that is called `name`, or null.
|
||||
*/
|
||||
export function lightVariant(libraryNames: Set<string>, name: string) {
|
||||
const light = `${slug(name)}-light`
|
||||
return libraryNames.has(light) ? light : null
|
||||
}
|
||||
|
||||
/** An image address or an upload, not a name in the library. */
|
||||
export const isImageAddress = (icon: string) =>
|
||||
/^https?:\/\//.test(icon) || icon.startsWith(UPLOADED_ICON)
|
||||
@@ -26,13 +35,18 @@ export function iconSources({
|
||||
name,
|
||||
url,
|
||||
icon,
|
||||
lightIcon,
|
||||
}: {
|
||||
name: string
|
||||
url: string
|
||||
icon: string | null
|
||||
/** see lightVariant; only used when the link has no icon of its own */
|
||||
lightIcon?: string | null
|
||||
}) {
|
||||
return [
|
||||
icon && isImageAddress(icon) ? icon : libraryIcon(icon || name),
|
||||
icon && isImageAddress(icon)
|
||||
? icon
|
||||
: libraryIcon(icon || lightIcon || name),
|
||||
`${new URL(url).origin}/favicon.ico`,
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user