diff --git a/CLAUDE.md b/CLAUDE.md index acb20d0..375dde6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -57,7 +57,7 @@ In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API mu - `navConfig.ts` is the single source of truth for navigation, routes, and actions (header, footer, pages). - `api.ts` is the shared caching client used by frontend data hooks. - `docs/updating-data-in-code.md`: where content that isn't in the database lives (admin dropdown labels, fixed value lists, nav, banner, decades, map grid) and how to change it. Keep it current when adding a dropdown or code-owned content. -- Logos: org logos in `public/org-logos/` (served at `/org-logos/`), event logos in `public/event-logos/`. The `` component hides itself on load error. +- Images: every record image (logos, photos, backgrounds, block images) is an upload. A bare filename resolves to `/uploads/` (`src/lib/media.ts`, and `server/src/pageMeta.js` for previews). Only the site's own chosen assets, the NGU logos in the nav, footer and admin, are bundled from `src/assets/logos/`. The `` component hides itself on load error. ## Rules and gotchas - **Role checks must use ladder comparisons, never equality.** Roles rank viewer → editor → admin → superadmin. Use the minimum-rank helpers from `src/lib/roles.ts` (`canWrite`, `canDelete`, `isSuper`, `atLeast`). Where a local variable shadows the name, import with an alias, e.g. `canWrite as roleCanWrite`. `role === "admin"` silently excludes higher roles and has caused repeated bugs. diff --git a/server/src/pageMeta.js b/server/src/pageMeta.js index 69555fb..c76dc45 100644 --- a/server/src/pageMeta.js +++ b/server/src/pageMeta.js @@ -27,8 +27,8 @@ /admin noindex Image paths resolve like src/lib/media.ts does: a bare filename - lives in that record kind's public/ directory, anything starting - with / or a scheme is used as it is. Keep DIRS in step with it. + is in the uploads directory, anything starting with / or a scheme + is used as it is. An SVG isn't used as a preview image (the big sites won't show one), so it falls back to the site default. ═══════════════════════════════════════════════════════════════ */ @@ -45,16 +45,9 @@ export const SITE_CONFIG = path.resolve(process.env.SITE_CONFIG ?? path.join(her const DESCRIPTION_CHARS = 160; -/* Where a bare filename lives, per kind. Mirrors src/lib/media.ts. */ -const DIRS = { - person: "/people", - eventLogo: "/event-logos", - eventBackground: "/event-backgrounds", - organization: "/org-logos", - team: "/team-logos", - award: "/award-logos", - blog: "/blog", -}; +/* Where a bare filename lives: record images are uploads, whatever + kind they are. Mirrors src/lib/media.ts. */ +const UPLOADS = "/uploads"; /* ── site.json, reread when it changes ─────────────────────── */ @@ -94,9 +87,9 @@ const first = (...values) => values.find((v) => v != null && String(v).trim() != function imageUrl(site, file, kind) { if (!file || /\.svg(\?|#|$)/i.test(file)) return null; - // A bare filename is in that kind's directory, or at the site's - // root for the site's own default (kind null). - const pathOrUrl = /^(https?:|\/)/.test(file) ? file : kind ? `${DIRS[kind]}/${file}` : `/${file}`; + // A record's bare filename is an upload; the site's own default + // image (kind null) is a path from the site's root. + const pathOrUrl = /^(https?:|\/)/.test(file) ? file : kind ? `${UPLOADS}/${file}` : `/${file}`; return /^https?:/.test(pathOrUrl) ? pathOrUrl : `${origin(site)}${pathOrUrl}`; } diff --git a/site.json b/site.json index a0fc0c3..786515f 100644 --- a/site.json +++ b/site.json @@ -39,7 +39,7 @@ }, "/qr": { "title": "QR Codes", - "description": "Codes for flyers, slides and signs, pointing at any page on the site." + "description": "Codes for flyers, slides and signs, pointing at any page on the site or any link, in your choice of colours." }, "/give": { "title": "Giving", diff --git a/src/assets/Fall Logo.svg b/src/assets/Fall Logo.svg deleted file mode 100644 index 33f133f..0000000 --- a/src/assets/Fall Logo.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/assets/event-logos/fall-retreat-logo.svg b/src/assets/event-logos/fall-retreat-logo.svg deleted file mode 100644 index 33f133f..0000000 --- a/src/assets/event-logos/fall-retreat-logo.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/assets/event-logos/ngu-logo-white-bg.svg b/src/assets/event-logos/ngu-logo-white-bg.svg deleted file mode 100644 index 3202fa3..0000000 --- a/src/assets/event-logos/ngu-logo-white-bg.svg +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - - - - - - - - - - Next Generation - of Unity - - - - diff --git a/src/assets/NGU_Logo.svg b/src/assets/logos/NGU_Logo.svg similarity index 100% rename from src/assets/NGU_Logo.svg rename to src/assets/logos/NGU_Logo.svg diff --git a/src/assets/NGU_Logo_WhiteBG.svg b/src/assets/logos/NGU_Logo_WhiteBG.svg similarity index 100% rename from src/assets/NGU_Logo_WhiteBG.svg rename to src/assets/logos/NGU_Logo_WhiteBG.svg diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index 21974ea..d06455e 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -1,6 +1,6 @@ import { Link } from "react-router-dom"; import { PAGE_LINKS, PAGE_SECTIONS, NAV_ACTIONS } from "../navConfig.ts"; -import nguLogo from "../assets/NGU_Logo.svg"; +import nguLogo from "../assets/logos/NGU_Logo.svg"; import PlatformIcon from "./PlatformIcon.tsx"; const Social_Links = [ diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index 6b999a7..d04bf59 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -2,7 +2,7 @@ import { useState, useEffect, useRef } from "react"; import { NavLink, Link, Outlet, useLocation } from "react-router-dom"; import { PAGE_LINKS, PAGE_SECTIONS, NAV_ACTIONS } from "../navConfig.ts"; import Banner from "./Banner.jsx"; -import nguLogo from "../assets/NGU_Logo.svg"; +import nguLogo from "../assets/logos/NGU_Logo.svg"; import Footer from "./Footer.tsx"; /* ── Right-side nav actions ──────────────────────────────── */ diff --git a/src/components/QrCode.tsx b/src/components/QrCode.tsx index e5f92d1..8ae64bf 100644 --- a/src/components/QrCode.tsx +++ b/src/components/QrCode.tsx @@ -1,16 +1,25 @@ /* ═══════════════════════════════════════════════════════════════ QR CODE - A QR code as an , sized by its container. With `dove`, the - NGU dove sits on a white badge over the centre; the code switches - to high error correction so the modules under the badge are - recovered when it's scanned (see lib/qr.ts). The badge covers - under 6% of the code, well inside what 'H' repairs, and never - reaches the three corner finder patterns. + A QR code as an , sized by its container. - Everything is drawn in the SVG itself (no CSS, no external - references), so the element serialises to a file that looks the - same outside the page. `ref` reaches the for exactly that. + `centre` puts something on a badge over the middle: the NGU dove, + or an image (an SVG from src/assets/qr, passed as a data: URL). + With anything there, the code switches to high error correction + so the modules under the badge are recovered when it's scanned + (see lib/qr.ts). The badge covers under 6% of the code, well + inside what 'H' repairs, and never reaches the three corner + finder patterns. + + `ink` is the modules and the badge's outline, `paper` the + background and the badge. A code should stay dark on light with + strong contrast to scan reliably; QrCodeMaker warns when it + doesn't, this just draws what it's given. + + Everything is drawn in the SVG itself (no CSS, and an image is + embedded rather than linked), so the element serialises to a + file that looks the same outside the page. `ref` reaches the + for exactly that. ═══════════════════════════════════════════════════════════════ */ import { useMemo, type Ref } from 'react' @@ -23,8 +32,9 @@ import { qrMatrix, qrPath } from '../lib/qr.ts' const MARGIN = 4 /* Dark enough to scan as black; the site's deep teal. */ -const INK = '#04262e' -const TEAL = '#138ba0' +export const QR_INK = '#04262e' +export const QR_PAPER = '#ffffff' +export const QR_DOVE = '#138ba0' /* Badge side as a share of the code's width. */ const BADGE = 0.24 @@ -32,21 +42,28 @@ const BADGE = 0.24 /* DoveMark's own viewBox is 72.87 × 48.57. */ const DOVE_ASPECT = 72.867699 / 48.568241 +export type QrCentre = { kind: 'dove'; color?: string } | { kind: 'image'; src: string } | null + export default function QrCode({ value, - dove = false, + centre = null, + ink = QR_INK, + paper = QR_PAPER, label, ref, className, }: { value: string - dove?: boolean + centre?: QrCentre + ink?: string + paper?: string /** Accessible name for the image, e.g. "QR code for /retreats". */ label: string ref?: Ref className?: string }) { - const matrix = useMemo(() => qrMatrix(value, dove ? 'H' : 'M'), [value, dove]) + const level = centre ? 'H' : 'M' + const matrix = useMemo(() => qrMatrix(value, level), [value, level]) const path = useMemo(() => qrPath(matrix, MARGIN), [matrix]) const total = matrix.size + MARGIN * 2 @@ -54,6 +71,7 @@ export default function QrCode({ const badgeAt = (total - badge) / 2 const doveWidth = badge * 0.78 const doveHeight = doveWidth / DOVE_ASPECT + const imageSize = badge * 0.8 return ( - - + + - {dove && ( + {centre && ( - + {centre.kind === 'dove' ? ( + + ) : ( + + )} )} diff --git a/src/components/ScheduleBlock.tsx b/src/components/ScheduleBlock.tsx index 05b6b10..d15e2d0 100644 --- a/src/components/ScheduleBlock.tsx +++ b/src/components/ScheduleBlock.tsx @@ -59,7 +59,7 @@ function todayIndex(days: Day[]): number { } const mapEmbed = (place: string) => - `https://maps.google.com/maps?q=${encodeURIComponent(place)}&output=embed` + `https://maps.google.com/maps?q=${encodeURIComponent(place)}&output=embed&maptype=satellite` const mapLink = (place: string) => `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(place)}` diff --git a/src/lib/adminSchema.ts b/src/lib/adminSchema.ts index 94d227b..224dbd9 100644 --- a/src/lib/adminSchema.ts +++ b/src/lib/adminSchema.ts @@ -1305,7 +1305,7 @@ const frontPage = { full: true, help: "A YouTube, Vimeo or Facebook link, or a video file: a filename in " + - "/front-page/ or a link ending in .mp4 or .webm", + "the uploads folder, or a link ending in .mp4 or .webm", }, { path: "video_title", label: "Video title", full: true, help: "Shown after \"Featured video\" above the headline" }, { diff --git a/src/lib/embeds.ts b/src/lib/embeds.ts index afc68c1..435560c 100644 --- a/src/lib/embeds.ts +++ b/src/lib/embeds.ts @@ -15,7 +15,7 @@ so the visitor presses play. A featured video can also be a file rather than a link: a - filename in public/front-page/, a /path, or an https URL ending + filename in the uploads directory, a /path, or an https URL ending in a video extension. videoSource() says which, so the hero can hand a file to that removes itself if the file 404s. */ -function Logo({ file, alt = "", className }) { +/* An that removes itself if the file 404s. `src` is already + resolved by media.ts: a bare filename from the uploads directory, + anything with a path or URL as it is. */ +function Logo({ src, alt = "", className }) { const [failed, setFailed] = useState(false); - const src = logoSrc(file); if (!src || failed) return null; return ( - +
{typeBadge}

@@ -234,7 +223,7 @@ export function Card({ )}

@@ -245,7 +234,7 @@ export function Card({ <>
- + {typeBadge}

@@ -263,7 +252,7 @@ export function Card({

diff --git a/src/pages/sections/QrCodeMaker.tsx b/src/pages/sections/QrCodeMaker.tsx index 4db3dcb..1db9613 100644 --- a/src/pages/sections/QrCodeMaker.tsx +++ b/src/pages/sections/QrCodeMaker.tsx @@ -1,12 +1,23 @@ /* ═══════════════════════════════════════════════════════════════ QR CODE MAKER - Pick a page, get a QR code for it on the live site. + Pick a page, or type a link, and get a QR code for it. - What main navigation, or one kind of record + What main navigation, one kind of record, or a link + typed in Which the page or record itself Section for a main page with a subnav, optionally one of its #sections + Centre nothing, the NGU dove, or any SVG in + src/assets/qr (drop a file there and it's offered; + it's embedded in the code, so downloads carry it) + Colours the code, its background, and the dove. A warning + appears when the pair is unlikely to scan: too + little contrast, or a light code on a dark ground + + A typed link can be a site path (/retreats, which goes to the live + site like every other choice), a full http(s) address, or a bare + domain, which gets https:// in front. The main pages come from navConfig.ts, the same list the header draws; records come from GET /directory, which lists only what's @@ -22,7 +33,7 @@ import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react' -import QrCode from '../../components/QrCode.tsx' +import QrCode, { QR_DOVE, QR_INK, QR_PAPER, type QrCentre } from '../../components/QrCode.tsx' import { NAV_ACTIONS, PAGE_LINKS, PAGE_SECTIONS } from '../../navConfig.ts' import { awardHref, blogHref, eventHref, orgHref, personHref, teamHref } from '../../lib/hrefs.ts' import { siteUrl } from '../../lib/site.ts' @@ -35,7 +46,7 @@ const MUTED = '#4a6b72' anything bigger should use the SVG. */ const PNG_SIZE = 1024 -type Kind = 'pages' | 'events' | 'organizations' | 'teams' | 'awards' | 'people' | 'blog_posts' +type Kind = 'pages' | 'events' | 'organizations' | 'teams' | 'awards' | 'people' | 'blog_posts' | 'custom' const KINDS: Array<[Kind, string]> = [ ['pages', 'Main navigation'], @@ -45,8 +56,81 @@ const KINDS: Array<[Kind, string]> = [ ['awards', 'Awards'], ['people', 'People'], ['blog_posts', 'Blog posts'], + ['custom', 'A link I type'], ] +/* The centres on offer: the dove, then every SVG in src/assets/qr, + named after its file ("ngu-circle.svg" → "Ngu circle"). Read as + text and turned into data: URLs so they sit inside the code's own + SVG. */ +const CENTRE_FILES = import.meta.glob('../../assets/qr/*.svg', { + eager: true, + query: '?raw', + import: 'default', +}) + +type CentreOption = { id: string; label: string; centre: (dove: string) => QrCentre } + +const toDataUrl = (svg: string) => + `data:image/svg+xml;base64,${btoa(String.fromCharCode(...new TextEncoder().encode(svg)))}` + +const CENTRES: CentreOption[] = [ + { id: 'none', label: 'Nothing', centre: () => null }, + { id: 'dove', label: 'NGU dove', centre: (color) => ({ kind: 'dove', color }) }, + ...Object.entries(CENTRE_FILES) + .sort(([a], [b]) => a.localeCompare(b)) + .map(([path, svg]) => { + const name = path.split('/').pop()!.replace(/\.svg$/i, '') + const label = name.replace(/[-_]+/g, ' ').replace(/^./, (c) => c.toUpperCase()) + const src = toDataUrl(svg) + return { id: `file:${name}`, label, centre: () => ({ kind: 'image', src }) as QrCentre } + }), +] + +/* ── Contrast ────────────────────────────────────────────────── + WCAG relative luminance and contrast ratio. Below MIN_CONTRAST + some phone cameras struggle; a code lighter than its background + is "inverted", which many scanners don't read at all. */ +const MIN_CONTRAST = 4 + +function luminance(hex: string): number { + const m = hex.replace('#', '').match(/^([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i) + if (!m) return 0 + const [r, g, b] = m.slice(1).map((h) => { + const c = parseInt(h, 16) / 255 + return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4 + }) + return 0.2126 * r + 0.7152 * g + 0.0722 * b +} + +function scanWarning(ink: string, paper: string): string | null { + const a = luminance(ink) + const b = luminance(paper) + if (a > b) return 'The code is lighter than its background. Many scanners can’t read an inverted code.' + const ratio = (b + 0.05) / (a + 0.05) + if (ratio < MIN_CONTRAST) { + return `Low contrast (${ratio.toFixed(1)}:1). Use a darker code or a lighter background so it scans reliably.` + } + return null +} + +/* What a typed link means: a site path goes to the live site, a + full address is used as it is, a bare domain gets https://. + Anything else isn't a link. */ +function typedUrl(raw: string): string | null { + const value = raw.trim() + if (!value) return null + if (value.startsWith('/') && !value.startsWith('//')) return siteUrl(value) + const withScheme = /^[a-z][a-z0-9+.-]*:/i.test(value) ? value : /^[^\s/]+\.[^\s/]+/.test(value) ? `https://${value}` : null + if (!withScheme) return null + try { + const url = new URL(withScheme) + return url.protocol === 'http:' || url.protocol === 'https:' ? url.href : null + } catch { + return null + } +} + /* Organizations are grouped by kind in the dropdown, in this order. */ const ORG_GROUPS: Array<[string, string]> = [ ['national', 'NGU'], @@ -109,12 +193,22 @@ function groupsFor(kind: Kind, directory: Directory | null): Group[] { return [{ choices: directory.people.map((p) => ({ path: personHref(p.id), label: p.name })) }] case 'blog_posts': return [{ choices: directory.blog_posts.map((b) => ({ path: blogHref(b.id), label: b.name })) }] + case 'custom': + return [] } } -/* "/regions/northwest#events" → "regions-northwest-events". */ -function fileStem(path: string): string { - const stem = path.replace(/^\//, '').replace(/[^a-z0-9]+/gi, '-').replace(/^-|-$/g, '') +/* "/regions/northwest#events" → "regions-northwest-events"; a typed + link keeps its host too: "example-org-page". */ +function fileStem(target: string): string { + let name = target + try { + const url = new URL(target) + name = `${url.hostname.replace(/^www\./, '')}${url.pathname}${url.hash}` + } catch { + /* a site path */ + } + const stem = name.replace(/^\//, '').replace(/[^a-z0-9]+/gi, '-').replace(/^-|-$/g, '') return `ngu-qr-${stem || 'home'}` } @@ -163,7 +257,11 @@ export default function QrCodeMaker() { const [kind, setKind] = useState('pages') const [path, setPath] = useState('/') const [section, setSection] = useState('') - const [dove, setDove] = useState(true) + const [custom, setCustom] = useState('') + const [centreId, setCentreId] = useState('dove') + const [ink, setInk] = useState(QR_INK) + const [paper, setPaper] = useState(QR_PAPER) + const [doveColor, setDoveColor] = useState(QR_DOVE) const [copied, setCopied] = useState(false) const svgRef = useRef(null) @@ -181,8 +279,13 @@ export default function QrCodeMaker() { const sections = kind === 'pages' ? (PAGE_SECTIONS[path] ?? []) : [] const selected = choices.find((c) => c.path === path) ?? null - const target = selected ? `${selected.path}${section}` : null - const url = target ? siteUrl(target) : null + const typed = kind === 'custom' ? typedUrl(custom) : null + const target = kind === 'custom' ? typed : selected ? `${selected.path}${section}` : null + const url = kind === 'custom' ? typed : target ? siteUrl(target) : null + + const centreOption = CENTRES.find((c) => c.id === centreId) ?? CENTRES[0] + const centre = centreOption.centre(doveColor) + const warning = scanWarning(ink, paper) useEffect(() => setCopied(false), [url]) @@ -198,7 +301,7 @@ export default function QrCodeMaker() { } } - const needsDirectory = kind !== 'pages' + const needsDirectory = kind !== 'pages' && kind !== 'custom' return (
@@ -211,7 +314,27 @@ export default function QrCodeMaker() { ))} - {needsDirectory && loading && !directory ? ( + {kind === 'custom' ? ( +
+ + setCustom(e.target.value)} + placeholder="https://… or /retreats" + className={`mt-2 ${inputClass}`} + /> +

+ {custom.trim() && !typed + ? 'That isn’t a web address. Use https://…, a domain, or a site path like /retreats.' + : 'A full address, a domain (example.org), or a path on this site (/retreats).'} +

+
+ ) : needsDirectory && loading && !directory ? (

Loading the list…

) : needsDirectory && error ? (

Couldn't load the list of pages. {error}

@@ -258,15 +381,43 @@ export default function QrCodeMaker() { )} - + + +
+ Colours +
+ + + {centreOption.id === 'dove' && ( + + )} + {(ink !== QR_INK || paper !== QR_PAPER || doveColor !== QR_DOVE) && ( + + )} +
+ {warning && ( +

+ {warning} +

+ )} +
{url && (
@@ -295,7 +446,9 @@ export default function QrCodeMaker() { @@ -333,6 +486,52 @@ function DownloadButton({ onClick, children }: { onClick: () => void; children: ) } +const inputClass = + 'w-full rounded-xl border border-[#4a6b72]/25 bg-white px-4 py-3 text-[#26454c] ' + + 'outline-none transition-colors focus:border-[#138ba0] focus:ring-2 focus:ring-[#138ba0]/25' + +/* A colour well with its hex beside it, both editable. */ +function ColourInput({ + id, + label, + value, + onChange, +}: { + id: string + label: string + value: string + onChange: (value: string) => void +}) { + const [text, setText] = useState(value) + useEffect(() => setText(value), [value]) + return ( +
+ +
+ onChange(e.target.value)} + className="h-9 w-11 cursor-pointer rounded border border-[#4a6b72]/25 bg-white" + /> + { + setText(e.target.value) + if (/^#[0-9a-f]{6}$/i.test(e.target.value)) onChange(e.target.value.toLowerCase()) + }} + className="w-24 rounded-lg border border-[#4a6b72]/25 bg-white px-2 py-1.5 font-mono text-sm text-[#26454c] outline-none focus:border-[#138ba0]" + /> +
+
+ ) +} + const selectClass = 'w-full appearance-none rounded-xl border border-[#4a6b72]/25 bg-white px-4 py-3 pr-10 text-[#26454c] ' + 'outline-none transition-colors focus:border-[#138ba0] focus:ring-2 focus:ring-[#138ba0]/25'