Files
such.software/apps/web/src/components/dynamic-favicon.tsx
T
jwinterm ca5f555918 Rework home hero and portfolio, invert favicon theme mapping
- Home hero subhead rewritten to name commerce/websites/apps/consulting
  plus in-house mobile apps and games; primary CTA points to /products
- Portfolio page (/products) title renamed and each product card now shows
  a 56px icon beside the title
- Favicon served inverse to the browser color scheme so the tile contrasts
  with the chrome instead of blending into it
2026-04-20 13:04:27 -04:00

28 lines
876 B
TypeScript

'use client';
import { useTheme } from 'next-themes';
import { useEffect } from 'react';
export function DynamicFavicon() {
const { resolvedTheme } = useTheme();
useEffect(() => {
if (!resolvedTheme) return;
// Favicons contrast with browser chrome, so we serve the opposite-tone tile:
// dark mode → light tile, light mode → dark tile.
const variant = resolvedTheme === 'dark' ? 'light' : 'dark';
// Update all favicon link elements
const links = document.querySelectorAll<HTMLLinkElement>('link[rel="icon"], link[rel="shortcut icon"], link[rel="apple-touch-icon"]');
links.forEach((link) => {
const href = link.getAttribute('href');
if (href?.includes('/images/branding/favicon_')) {
link.href = href.replace(/favicon_(dark|light)/, `favicon_${variant}`);
}
});
}, [resolvedTheme]);
return null;
}