Add a QR code page at /qr for any page on the site

Pick "Main navigation" or a kind of record (events, organizations,
teams, awards, people), then the page or record, and for a main page
optionally one of its #sections. The code, a copy-link button, and
PNG (1024px) and SVG downloads follow. An "NGU dove in the centre"
option puts the dove on a white badge over the code and raises error
correction to H so it still scans.

Codes always point at SITE_ORIGIN (https://nextgenerationofunity.org,
in src/lib/site.ts), so one made on localhost works on a poster.
Main pages come from navConfig.ts and record URLs from hrefs.ts, the
same sources the site links with.

GET /api/directory lists every published record with a page, as id,
name and (for organizations) kind, each filtered by the same rule as
that record's own page: a team also needs its organization
published. /api/people only answers for ids it's given, so there was
no public list to read.

The `qrcode` package does the encoding; QrCode.tsx draws the modules
as one SVG path, so the preview and both downloads are one picture.
The page is lazy-loaded so the encoder isn't in the main bundle.

The page is unlisted: not in navConfig, so not in the header or
footer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-26 18:24:08 -05:00
parent 8c26ec4906
commit 97c1827ca9
11 changed files with 892 additions and 0 deletions

View file

@ -0,0 +1,77 @@
/* ═══════════════════════════════════════════════════════════════
DIRECTORY ROUTE — read-only, mounted under /api
GET /directory every public record that has a page
One flat list per kind, each row just enough to name a record
and build its URL: id and name, plus the organization's kind,
which decides whether its page is /regions, /chapters or
/partners. The QR code page reads it to offer "any page on the
site" without five list requests carrying descriptions, links
and blocks it would throw away.
Each list applies the same visibility rule as that record's own
page, so nothing here leads to a 404:
events published
organizations published
teams published, and so is the organization
awards published
people published
The site already serves each of these at its own URL; this only
lists them in one place.
═══════════════════════════════════════════════════════════════ */
import { Hono } from "hono";
const directory = new Hono();
const CACHE = "public, max-age=60, stale-while-revalidate=300";
directory.get("/directory", (c) => {
const db = c.get("db");
const all = (sql) => db.prepare(sql).all();
return c.json(
{
directory: {
events: all(
`SELECT id, title AS name, starts_on
FROM events
WHERE is_published = 1
ORDER BY starts_on IS NULL, starts_on DESC, title`,
),
organizations: all(
`SELECT id, name, kind
FROM organizations
WHERE is_published = 1
ORDER BY kind, name`,
),
teams: all(
`SELECT t.id, t.name, o.name AS org_name
FROM teams t
JOIN organizations o ON o.id = t.org_id AND o.is_published = 1
WHERE t.is_published = 1
ORDER BY o.name, t.sort_order, t.name`,
),
awards: all(
`SELECT id, name
FROM awards
WHERE is_published = 1
ORDER BY name`,
),
people: all(
`SELECT id, display_name AS name
FROM people
WHERE is_published = 1
ORDER BY COALESCE(sort_name, display_name)`,
),
},
},
200,
{ "Cache-Control": CACHE },
);
});
export default directory;