source: Klonkt/src/routes/og.js@ c06816e

main
Last change on this file since c06816e was d9c5eb8, checked in by roboburr <roboburr@…>, 2 months ago

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@…>

  • Property mode set to 100644
File size: 972 bytes
Line 
1/**
2 * GET /og/:slug.png — themed Open Graph card for a site (1200x630 PNG).
3 * Generated from the site's palette + accent (see OgImageService), cached.
4 * Used as the default og:image so every site has a branded social preview.
5 */
6import express from 'express';
7import db from '../config/database.js';
8import { ogImageFor } from '../services/OgImageService.js';
9
10const router = express.Router();
11
12router.get('/:slug.png', (req, res) => {
13 let site;
14 try {
15 site = db.prepare(
16 'SELECT slug, title, tagline, description, palette, accent, theme_override FROM sites WHERE slug = ?'
17 ).get(req.params.slug);
18 } catch { /* db error → 404 below */ }
19 if (!site) return res.status(404).end();
20
21 const png = ogImageFor(site);
22 if (!png) return res.status(404).end(); // resvg unavailable → no card (graceful)
23
24 res.set('Content-Type', 'image/png');
25 res.set('Cache-Control', 'public, max-age=86400');
26 return res.send(png);
27});
28
29export default router;
Note: See TracBrowser for help on using the repository browser.