Files
gsc-web-kit/src/chrome/brandIcons.ts
Claude a11353577d chrome: brandIcons() — derive Next.js favicon metadata from Brand
Every app that imports the kit was shipping a /favicon.ico 404
because none of them wired up Next.js's metadata.icons. This adds
a tiny helper so an app only has to:

  export const metadata: Metadata = {
    title: brand.product,
    icons: brandIcons(brand),
  };

brandIcons() returns icon/shortcut/apple entries pointing at
brand.faviconUrl (new optional field, defaults to brand.logoUrl).
MIME type inferred from the URL extension (svg/png/ico).

Brand gains the optional faviconUrl field. Existing apps that just
pass logoUrl keep working — they'll now render the logo as the
favicon by default. Apps that want a separate icon set
faviconUrl explicitly.

First consumer: gscSounds layout — verified /favicon.ico now
serves the proper icon and /icon.svg works too.
2026-05-23 13:39:49 +02:00

38 lines
1.2 KiB
TypeScript

// Returns a Next.js Metadata `icons` object derived from a Brand.
// Apps drop this into their root layout's `metadata` export to ship
// the brand logo as the favicon — fixes the "favicon 404" every
// consumer of the kit was shipping with.
//
// import type { Metadata } from "next";
// import { brandIcons } from "@gsc/web-kit/chrome";
// import { brand } from "@/config/brand";
//
// export const metadata: Metadata = {
// title: brand.product,
// icons: brandIcons(brand),
// };
import type { Brand } from "./types";
interface BrandMetaIcons {
icon: { url: string; type?: string }[];
shortcut?: { url: string; type?: string }[];
apple?: { url: string; type?: string }[];
}
export function brandIcons(brand: Brand): BrandMetaIcons {
const url = brand.faviconUrl ?? brand.logoUrl;
// Heuristic: trust the file extension to set the MIME type. Most
// brand logos in the GoSec assets bucket are SVG.
const type =
/\.svg(\?|$)/i.test(url) ? "image/svg+xml" :
/\.png(\?|$)/i.test(url) ? "image/png" :
/\.ico(\?|$)/i.test(url) ? "image/x-icon" :
undefined;
return {
icon: [{ url, ...(type ? { type } : {}) }],
shortcut: [{ url }],
apple: [{ url }],
};
}