Changeset d9c5eb8 in Klonkt for src/services/OgImageService.js


Ignore:
Timestamp:
06/30/2026 10:17:48 PM (2 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
f3663e5
Parents:
e3a5aed
Message:

feat(og): light OG card when the site's default theme is Light

OgImageService always rendered a dark card. It now follows the site's "default theme for new
visitors" (theme_override): a light card (the palette's light paper/ink/accent) when set to Light,
otherwise dark (Auto/Dark -> dark, since an OG image is static). og.js selects theme_override and the
theme is part of the cache key so light + dark cache separately.

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/services/OgImageService.js

    re3a5aed rd9c5eb8  
    4343function esc(s) { return String(s == null ? '' : s).replace(/[<>&]/g, (c) => ({ '<': '&lt;', '>': '&gt;', '&': '&amp;' }[c])); }
    4444
    45 function buildSvg(site, palette, accent) {
    46   const pal = (ThemeService.PALETTES[palette] || ThemeService.PALETTES.klonkt).dark;
     45function buildSvg(site, palette, accent, theme) {
     46  const _p = ThemeService.PALETTES[palette] || ThemeService.PALETTES.klonkt;
     47  const pal = _p[theme] || _p.dark;
    4748  const paper = pal.paper, ink = pal.ink;
    4849  const paper2 = mix(paper, ink, 0.08);
     
    8990
    9091  const palette = ThemeService.PALETTES[site.palette] ? site.palette : 'klonkt';
    91   const accent = site.accent || (ThemeService.PALETTES[palette] || ThemeService.PALETTES.klonkt).dark.accent;
     92  // Follow the site's "default theme for new visitors" (theme_override): a light card when the site
     93  // is set to Light, otherwise dark (an OG image is static, so Auto/Dark → dark).
     94  const theme = site.theme_override === 'light' ? 'light' : 'dark';
     95  const accent = site.accent || ((ThemeService.PALETTES[palette] || ThemeService.PALETTES.klonkt)[theme] || ThemeService.PALETTES.klonkt.dark).accent;
    9296  const key = crypto.createHash('sha1')
    93     .update([TEMPLATE_VERSION, site.slug, palette, accent, site.title || '', site.tagline || site.description || ''].join('\x1f'))
     97    .update([TEMPLATE_VERSION, site.slug, palette, accent, theme, site.title || '', site.tagline || site.description || ''].join('\x1f'))
    9498    .digest('hex').slice(0, 16);
    9599  const file = path.join(CACHE_DIR, key + '.png');
     
    98102
    99103  try {
    100     const svg = buildSvg(site, palette, accent);
     104    const svg = buildSvg(site, palette, accent, theme);
    101105    const png = new Resvg(svg, {
    102106      font: { fontFiles: [FONT], loadSystemFonts: false },
Note: See TracChangeset for help on using the changeset viewer.