diff --git a/CLAUDE.md b/CLAUDE.md index 375dde6..acb20d0 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. -- 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. +- Logos: org logos in `public/org-logos/` (served at `/org-logos/`), event logos in `public/event-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 c76dc45..69555fb 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 - is in the uploads directory, anything starting with / or a scheme - is used as it is. + 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. 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,9 +45,16 @@ export const SITE_CONFIG = path.resolve(process.env.SITE_CONFIG ?? path.join(her const DESCRIPTION_CHARS = 160; -/* Where a bare filename lives: record images are uploads, whatever - kind they are. Mirrors src/lib/media.ts. */ -const UPLOADS = "/uploads"; +/* 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", +}; /* ── site.json, reread when it changes ─────────────────────── */ @@ -87,9 +94,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 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}`; + // 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}`; return /^https?:/.test(pathOrUrl) ? pathOrUrl : `${origin(site)}${pathOrUrl}`; } diff --git a/site.json b/site.json index 786515f..a0fc0c3 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 or any link, in your choice of colours." + "description": "Codes for flyers, slides and signs, pointing at any page on the site." }, "/give": { "title": "Giving", diff --git a/src/assets/Fall Logo.svg b/src/assets/Fall Logo.svg new file mode 100644 index 0000000..33f133f --- /dev/null +++ b/src/assets/Fall Logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/assets/logos/NGU_Logo.svg b/src/assets/NGU_Logo.svg similarity index 100% rename from src/assets/logos/NGU_Logo.svg rename to src/assets/NGU_Logo.svg diff --git a/src/assets/logos/NGU_Logo_WhiteBG.svg b/src/assets/NGU_Logo_WhiteBG.svg similarity index 100% rename from src/assets/logos/NGU_Logo_WhiteBG.svg rename to src/assets/NGU_Logo_WhiteBG.svg diff --git a/src/assets/event-logos/fall-retreat-logo.svg b/src/assets/event-logos/fall-retreat-logo.svg new file mode 100644 index 0000000..33f133f --- /dev/null +++ b/src/assets/event-logos/fall-retreat-logo.svg @@ -0,0 +1 @@ + \ 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 new file mode 100644 index 0000000..3202fa3 --- /dev/null +++ b/src/assets/event-logos/ngu-logo-white-bg.svg @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + Next Generation + of Unity + + + + diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index d06455e..21974ea 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/logos/NGU_Logo.svg"; +import nguLogo from "../assets/NGU_Logo.svg"; import PlatformIcon from "./PlatformIcon.tsx"; const Social_Links = [ diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index d04bf59..6b999a7 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/logos/NGU_Logo.svg"; +import nguLogo from "../assets/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 8ae64bf..e5f92d1 100644 --- a/src/components/QrCode.tsx +++ b/src/components/QrCode.tsx @@ -1,25 +1,16 @@ /* ═══════════════════════════════════════════════════════════════ QR CODE - A QR code as an , sized by its container. + 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. - `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. + 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. ═══════════════════════════════════════════════════════════════ */ import { useMemo, type Ref } from 'react' @@ -32,9 +23,8 @@ import { qrMatrix, qrPath } from '../lib/qr.ts' const MARGIN = 4 /* Dark enough to scan as black; the site's deep teal. */ -export const QR_INK = '#04262e' -export const QR_PAPER = '#ffffff' -export const QR_DOVE = '#138ba0' +const INK = '#04262e' +const TEAL = '#138ba0' /* Badge side as a share of the code's width. */ const BADGE = 0.24 @@ -42,28 +32,21 @@ 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, - centre = null, - ink = QR_INK, - paper = QR_PAPER, + dove = false, label, ref, className, }: { value: string - centre?: QrCentre - ink?: string - paper?: string + dove?: boolean /** Accessible name for the image, e.g. "QR code for /retreats". */ label: string ref?: Ref className?: string }) { - const level = centre ? 'H' : 'M' - const matrix = useMemo(() => qrMatrix(value, level), [value, level]) + const matrix = useMemo(() => qrMatrix(value, dove ? 'H' : 'M'), [value, dove]) const path = useMemo(() => qrPath(matrix, MARGIN), [matrix]) const total = matrix.size + MARGIN * 2 @@ -71,7 +54,6 @@ 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 ( - - + + - {centre && ( + {dove && ( - {centre.kind === 'dove' ? ( - - ) : ( - - )} + )} diff --git a/src/components/ScheduleBlock.tsx b/src/components/ScheduleBlock.tsx index d15e2d0..05b6b10 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&maptype=satellite` + `https://maps.google.com/maps?q=${encodeURIComponent(place)}&output=embed` 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 224dbd9..94d227b 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 " + - "the uploads folder, or a link ending in .mp4 or .webm", + "/front-page/ 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 435560c..afc68c1 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 the uploads directory, a /path, or an https URL ending + filename in public/front-page/, 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. `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 }) { +/* An that removes itself if the file 404s. */ +function Logo({ file, alt = "", className }) { const [failed, setFailed] = useState(false); + const src = logoSrc(file); if (!src || failed) return null; return ( - +
{typeBadge}

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

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

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

diff --git a/src/pages/sections/QrCodeMaker.tsx b/src/pages/sections/QrCodeMaker.tsx index 1db9613..4db3dcb 100644 --- a/src/pages/sections/QrCodeMaker.tsx +++ b/src/pages/sections/QrCodeMaker.tsx @@ -1,23 +1,12 @@ /* ═══════════════════════════════════════════════════════════════ QR CODE MAKER - Pick a page, or type a link, and get a QR code for it. + Pick a page, get a QR code for it on the live site. - What main navigation, one kind of record, or a link - typed in + What main navigation, or one kind of record 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 @@ -33,7 +22,7 @@ import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react' -import QrCode, { QR_DOVE, QR_INK, QR_PAPER, type QrCentre } from '../../components/QrCode.tsx' +import QrCode 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' @@ -46,7 +35,7 @@ const MUTED = '#4a6b72' anything bigger should use the SVG. */ const PNG_SIZE = 1024 -type Kind = 'pages' | 'events' | 'organizations' | 'teams' | 'awards' | 'people' | 'blog_posts' | 'custom' +type Kind = 'pages' | 'events' | 'organizations' | 'teams' | 'awards' | 'people' | 'blog_posts' const KINDS: Array<[Kind, string]> = [ ['pages', 'Main navigation'], @@ -56,81 +45,8 @@ 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'], @@ -193,22 +109,12 @@ 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"; 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, '') +/* "/regions/northwest#events" → "regions-northwest-events". */ +function fileStem(path: string): string { + const stem = path.replace(/^\//, '').replace(/[^a-z0-9]+/gi, '-').replace(/^-|-$/g, '') return `ngu-qr-${stem || 'home'}` } @@ -257,11 +163,7 @@ export default function QrCodeMaker() { const [kind, setKind] = useState('pages') const [path, setPath] = useState('/') const [section, setSection] = useState('') - 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 [dove, setDove] = useState(true) const [copied, setCopied] = useState(false) const svgRef = useRef(null) @@ -279,13 +181,8 @@ export default function QrCodeMaker() { const sections = kind === 'pages' ? (PAGE_SECTIONS[path] ?? []) : [] const selected = choices.find((c) => c.path === path) ?? 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) + const target = selected ? `${selected.path}${section}` : null + const url = target ? siteUrl(target) : null useEffect(() => setCopied(false), [url]) @@ -301,7 +198,7 @@ export default function QrCodeMaker() { } } - const needsDirectory = kind !== 'pages' && kind !== 'custom' + const needsDirectory = kind !== 'pages' return (
@@ -314,27 +211,7 @@ export default function QrCodeMaker() { ))} - {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 ? ( + {needsDirectory && loading && !directory ? (

Loading the list…

) : needsDirectory && error ? (

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

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

- {warning} -

- )} -
+ {url && (
@@ -446,9 +295,7 @@ export default function QrCodeMaker() { @@ -486,52 +333,6 @@ 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'