feat: Implement basic general folder support (#2051)

- Related: #1748
This commit is contained in:
Dermot Duffy
2025-05-21 19:59:21 -07:00
committed by GitHub
parent 2eb0d9e35e
commit c6a4c8aea2
350 changed files with 12837 additions and 4509 deletions
+24
View File
@@ -0,0 +1,24 @@
// Small set of utility functions to transform brand URLs. This is a fairly
// hacky approach used by the HA frontend to transform logos (which may be wide
// and not fit well in thumbnails, or may not respect the users themes) into
// icons. In order to ensure consistency of iconography across the card and Home
// Assistant, this is mirrored here.
//
// See: https://github.com/home-assistant/frontend/blob/dev/src/util/brands-url.ts
interface BrandsOptions {
domain: string;
type: 'icon' | 'logo' | 'icon@2x' | 'logo@2x';
useFallback?: boolean;
darkOptimized?: boolean;
brand?: boolean;
}
export const brandsUrl = (options: BrandsOptions): string =>
`https://brands.home-assistant.io/${options.brand ? 'brands/' : ''}${
options.useFallback ? '_/' : ''
}${options.domain}/${options.darkOptimized ? 'dark_' : ''}${options.type}.png`;
export const extractDomainFromBrandUrl = (url: string) => url.split('/')[4];
export const isBrandUrl = (thumbnail?: string | null): boolean =>
!!thumbnail?.startsWith('https://brands.home-assistant.io/');