From 97c1827ca99cbe6576b351c9fcb1299cf43363c0 Mon Sep 17 00:00:00 2001 From: Zaldimmar Date: Sat, 26 Sep 2026 18:24:08 -0500 Subject: [PATCH] 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 --- package.json | 2 + pnpm-lock.yaml | 226 ++++++++++++++++++ server/src/index.js | 2 + server/src/routes/directory.js | 77 ++++++ src/App.tsx | 5 + src/components/QrCode.tsx | 94 ++++++++ src/lib/qr.ts | 48 ++++ src/lib/site.ts | 13 + src/lib/useContent.ts | 17 ++ src/pages/QrCodes.tsx | 37 +++ src/pages/sections/QrCodeMaker.tsx | 371 +++++++++++++++++++++++++++++ 11 files changed, 892 insertions(+) create mode 100644 server/src/routes/directory.js create mode 100644 src/components/QrCode.tsx create mode 100644 src/lib/qr.ts create mode 100644 src/lib/site.ts create mode 100644 src/pages/QrCodes.tsx create mode 100644 src/pages/sections/QrCodeMaker.tsx diff --git a/package.json b/package.json index 16ec736..16df0d3 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dependencies": { "@fontsource/montserrat": "^5.3.0", "@fontsource/poppins": "^5.3.0", + "qrcode": "^1.5.4", "react": "^19.0.0", "react-dom": "^19.0.0", "react-router-dom": "^7.18.4" @@ -19,6 +20,7 @@ "devDependencies": { "@tailwindcss/vite": "^4.0.0", "@types/node": "^22.0.0", + "@types/qrcode": "^1.5.6", "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0", "@vitejs/plugin-react": "^6.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d5e8552..70bbb7b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: '@fontsource/poppins': specifier: ^5.3.0 version: 5.3.0 + qrcode: + specifier: ^1.5.4 + version: 1.5.4 react: specifier: ^19.0.0 version: 19.3.0 @@ -30,6 +33,9 @@ importers: '@types/node': specifier: ^22.0.0 version: 22.20.3 + '@types/qrcode': + specifier: ^1.5.6 + version: 1.5.6 '@types/react': specifier: ^19.0.0 version: 19.3.0 @@ -319,6 +325,9 @@ packages: '@types/node@22.20.3': resolution: {integrity: sha512-DZmzkmwHzXrLPAXPyKNDzlIwMMUZCVacoD25ywdy5YTKGbOx/2ld+Q38Im2zJ0vBuZP5Prd3VZutKZyXwkOS8A==} + '@types/qrcode@1.5.6': + resolution: {integrity: sha512-te7NQcV2BOvdj2b1hCAHzAoMNuj65kNBMz0KBaxM6c3VGBOhU0dURQKOtH8CFNI/dsKkwlv32p26qYQTWoB5bw==} + '@types/react-dom@19.3.0': resolution: {integrity: sha512-ZI7bU42mZXXKHn/qNLEw2IrbiINU7X5+vfgdixBHkCNpYWXjKgfQ/P+uyGb5CjOLB9UcnTeg3rylQtV2hym44Q==} peerDependencies: @@ -343,6 +352,28 @@ packages: oxc-transform-react: optional: true + ansi-regex@5.0.1: + resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} + engines: {node: '>=8'} + + ansi-styles@4.3.0: + resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} + engines: {node: '>=8'} + + camelcase@5.3.1: + resolution: {integrity: sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==} + engines: {node: '>=6'} + + cliui@6.0.0: + resolution: {integrity: sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==} + + color-convert@2.0.1: + resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} + engines: {node: '>=7.0.0'} + + color-name@1.1.4: + resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} + cookie@1.1.1: resolution: {integrity: sha512-ei8Aos7ja0weRpFzJnEA9UHJ/7XQmqglbRwnf2ATjcB9Wq874VKH9kfjjirM6UhU2/E5fFYadylyhFldcqSidQ==} engines: {node: '>=18'} @@ -350,10 +381,20 @@ packages: csstype@3.2.3: resolution: {integrity: sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==} + decamelize@1.2.0: + resolution: {integrity: sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==} + engines: {node: '>=0.10.0'} + detect-libc@2.1.2: resolution: {integrity: sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==} engines: {node: '>=8'} + dijkstrajs@1.0.3: + resolution: {integrity: sha512-qiSlmBq9+BCdCA/L46dw8Uy93mloxsPSbwnm5yrKn2vMPiy8KyAskTF6zuV/j5BMsmOGZDPs7KjU+mjb670kfA==} + + emoji-regex@8.0.0: + resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} + enhanced-resolve@5.25.1: resolution: {integrity: sha512-nGXts5znJzmWPu+mIE9izCOzdg63oJca2mDzGWWTth7sr4aCToKcoyFVBQwN75Ij5Pf6p510EwkTqViTRzDV+w==} engines: {node: '>=10.13.0'} @@ -367,14 +408,26 @@ packages: picomatch: optional: true + find-up@4.1.0: + resolution: {integrity: sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==} + engines: {node: '>=8'} + fsevents@2.3.3: resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} os: [darwin] + get-caller-file@2.0.5: + resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} + engines: {node: 6.* || 8.* || >= 10.*} + graceful-fs@4.2.11: resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} + is-fullwidth-code-point@3.0.0: + resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} + engines: {node: '>=8'} + jiti@2.7.0: resolution: {integrity: sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ==} hasBin: true @@ -527,6 +580,10 @@ packages: resolution: {integrity: sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==} engines: {node: '>= 12.0.0'} + locate-path@5.0.0: + resolution: {integrity: sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==} + engines: {node: '>=8'} + magic-string@0.30.21: resolution: {integrity: sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==} @@ -540,6 +597,22 @@ packages: engines: {node: '>=8.*'} hasBin: true + p-limit@2.3.0: + resolution: {integrity: sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==} + engines: {node: '>=6'} + + p-locate@4.1.0: + resolution: {integrity: sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==} + engines: {node: '>=8'} + + p-try@2.2.0: + resolution: {integrity: sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==} + engines: {node: '>=6'} + + path-exists@4.0.0: + resolution: {integrity: sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==} + engines: {node: '>=8'} + picocolors@1.1.1: resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==} @@ -547,10 +620,19 @@ packages: resolution: {integrity: sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==} engines: {node: '>=12'} + pngjs@5.0.0: + resolution: {integrity: sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw==} + engines: {node: '>=10.13.0'} + postcss@8.5.28: resolution: {integrity: sha512-RRuzqDtt5Y9h3quz5hWhK+TPnsmVs6WwSU6LkJMeY4HstUEDuYTG8UJSdawMRzmzAtV+KEoG8N3Qg2qLy5vM/A==} engines: {node: ^10 || ^12 || >=14} + qrcode@1.5.4: + resolution: {integrity: sha512-1ca71Zgiu6ORjHqFBDpnSMTR2ReToX4l1Au1VFLyVeBTFavzQnv5JxMFr3ukHVKpSrSA2MCk0lNJSykjUfz7Zg==} + engines: {node: '>=10.13.0'} + hasBin: true + react-dom@19.3.0: resolution: {integrity: sha512-JDk8dgif51OjFoDE70+OT9ICyYr+69HlmihNwp1+Nsfbna3t5sIiCa9ZJktDmQ4/1b/rn26hIAR2uYXDMr5r0Q==} peerDependencies: @@ -577,6 +659,13 @@ packages: resolution: {integrity: sha512-E8LUcbtBWt20bbl2YoHfx4ZDBdxVTfOKtCZn9cDSJ4l6/nuoApcpIBcj47t2wZoVX8g2ZHuMHbiShgCR1T5Sog==} engines: {node: '>=0.10.0'} + require-directory@2.1.1: + resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} + engines: {node: '>=0.10.0'} + + require-main-filename@2.0.0: + resolution: {integrity: sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==} + rolldown@1.2.9: resolution: {integrity: sha512-hx/Pv0N1haXRb11qkfnK5MXB/iqr7i0yjWQqmO9uHqZpBgQSqzc8UsSnEpalsh+j1I8qQ2CkXAkJC8Br3dKSlg==} engines: {node: ^20.19.0 || >=22.12.0} @@ -585,6 +674,9 @@ packages: scheduler@0.28.0: resolution: {integrity: sha512-juorfCmIkIw8tT+p5BXSm6PJjQF/ycEYmKyzURCIt/RaZIhL+PulbQ9Yu2z1HdOJDdqDTlxA1+xKBmHXJsczAw==} + set-blocking@2.0.0: + resolution: {integrity: sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==} + set-cookie-parser@2.7.2: resolution: {integrity: sha512-oeM1lpU/UvhTxw+g3cIfxXHyJRc/uidd3yK1P242gzHds0udQBYzs3y8j4gCCW+ZJ7ad0yctld8RYO+bdurlvw==} @@ -592,6 +684,14 @@ packages: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} + string-width@4.2.3: + resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} + engines: {node: '>=8'} + + strip-ansi@6.0.1: + resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==} + engines: {node: '>=8'} + tailwindcss@4.3.3: resolution: {integrity: sha512-gOhV3P7ufE62QDGg1zVaTgCR+EtPv92k2nIhVcVKcLmxT1sUBsQGhnZj175j+MqRt4zLF7ic+sCYjfhxMxj7YQ==} @@ -654,6 +754,24 @@ packages: yaml: optional: true + which-module@2.0.1: + resolution: {integrity: sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==} + + wrap-ansi@6.2.0: + resolution: {integrity: sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==} + engines: {node: '>=8'} + + y18n@4.0.3: + resolution: {integrity: sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==} + + yargs-parser@18.1.3: + resolution: {integrity: sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==} + engines: {node: '>=6'} + + yargs@15.4.1: + resolution: {integrity: sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==} + engines: {node: '>=8'} + snapshots: '@fontsource/montserrat@5.3.0': {} @@ -824,6 +942,10 @@ snapshots: dependencies: undici-types: 6.21.0 + '@types/qrcode@1.5.6': + dependencies: + '@types/node': 22.20.3 + '@types/react-dom@19.3.0(@types/react@19.3.0)': dependencies: '@types/react': 19.3.0 @@ -837,12 +959,38 @@ snapshots: '@rolldown/pluginutils': 1.0.1 vite: 8.3.0(@types/node@22.20.3)(jiti@2.7.0) + ansi-regex@5.0.1: {} + + ansi-styles@4.3.0: + dependencies: + color-convert: 2.0.1 + + camelcase@5.3.1: {} + + cliui@6.0.0: + dependencies: + string-width: 4.2.3 + strip-ansi: 6.0.1 + wrap-ansi: 6.2.0 + + color-convert@2.0.1: + dependencies: + color-name: 1.1.4 + + color-name@1.1.4: {} + cookie@1.1.1: {} csstype@3.2.3: {} + decamelize@1.2.0: {} + detect-libc@2.1.2: {} + dijkstrajs@1.0.3: {} + + emoji-regex@8.0.0: {} + enhanced-resolve@5.25.1: dependencies: graceful-fs: 4.2.11 @@ -852,11 +1000,20 @@ snapshots: optionalDependencies: picomatch: 4.0.7 + find-up@4.1.0: + dependencies: + locate-path: 5.0.0 + path-exists: 4.0.0 + fsevents@2.3.3: optional: true + get-caller-file@2.0.5: {} + graceful-fs@4.2.11: {} + is-fullwidth-code-point@3.0.0: {} + jiti@2.7.0: {} lightningcss-android-arm64@1.32.0: @@ -957,6 +1114,10 @@ snapshots: lightningcss-win32-arm64-msvc: 1.33.0 lightningcss-win32-x64-msvc: 1.33.0 + locate-path@5.0.0: + dependencies: + p-locate: 4.1.0 + magic-string@0.30.21: dependencies: '@jridgewell/sourcemap-codec': 1.6.0 @@ -974,16 +1135,36 @@ snapshots: '@oxfmt/win32-arm64': 0.2.0 '@oxfmt/win32-x64': 0.2.0 + p-limit@2.3.0: + dependencies: + p-try: 2.2.0 + + p-locate@4.1.0: + dependencies: + p-limit: 2.3.0 + + p-try@2.2.0: {} + + path-exists@4.0.0: {} + picocolors@1.1.1: {} picomatch@4.0.7: {} + pngjs@5.0.0: {} + postcss@8.5.28: dependencies: nanoid: 3.3.19 picocolors: 1.1.1 source-map-js: 1.2.1 + qrcode@1.5.4: + dependencies: + dijkstrajs: 1.0.3 + pngjs: 5.0.0 + yargs: 15.4.1 + react-dom@19.3.0(react@19.3.0): dependencies: react: 19.3.0 @@ -1005,6 +1186,10 @@ snapshots: react@19.3.0: {} + require-directory@2.1.1: {} + + require-main-filename@2.0.0: {} + rolldown@1.2.9: dependencies: '@oxc-project/types': 0.150.0 @@ -1028,10 +1213,22 @@ snapshots: scheduler@0.28.0: {} + set-blocking@2.0.0: {} + set-cookie-parser@2.7.2: {} source-map-js@1.2.1: {} + string-width@4.2.3: + dependencies: + emoji-regex: 8.0.0 + is-fullwidth-code-point: 3.0.0 + strip-ansi: 6.0.1 + + strip-ansi@6.0.1: + dependencies: + ansi-regex: 5.0.1 + tailwindcss@4.3.3: {} tapable@2.3.3: {} @@ -1056,3 +1253,32 @@ snapshots: '@types/node': 22.20.3 fsevents: 2.3.3 jiti: 2.7.0 + + which-module@2.0.1: {} + + wrap-ansi@6.2.0: + dependencies: + ansi-styles: 4.3.0 + string-width: 4.2.3 + strip-ansi: 6.0.1 + + y18n@4.0.3: {} + + yargs-parser@18.1.3: + dependencies: + camelcase: 5.3.1 + decamelize: 1.2.0 + + yargs@15.4.1: + dependencies: + cliui: 6.0.0 + decamelize: 1.2.0 + find-up: 4.1.0 + get-caller-file: 2.0.5 + require-directory: 2.1.1 + require-main-filename: 2.0.0 + set-blocking: 2.0.0 + string-width: 4.2.3 + which-module: 2.0.1 + y18n: 4.0.3 + yargs-parser: 18.1.3 diff --git a/server/src/index.js b/server/src/index.js index 6eab6ca..2be4ef8 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -18,6 +18,7 @@ import content from "./routes/content.js"; import people from "./routes/people.js"; import history from "./routes/history.js"; import home from "./routes/home.js"; +import directory from "./routes/directory.js"; import feedback from "./routes/feedback.js"; import auth from "./routes/auth.js"; import admin from "./routes/admin.js"; @@ -58,6 +59,7 @@ app.route("/api", content); app.route("/api", people); app.route("/api", history); app.route("/api", home); +app.route("/api", directory); // Tighter limit on the write path than anything else gets. app.use("/api/feedback", rateLimit({ windowMs: 60_000, max: 5 })); diff --git a/server/src/routes/directory.js b/server/src/routes/directory.js new file mode 100644 index 0000000..1d55a93 --- /dev/null +++ b/server/src/routes/directory.js @@ -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; diff --git a/src/App.tsx b/src/App.tsx index ff85789..c72c0f2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,5 @@ import { BrowserRouter, Routes, Route, Outlet, Navigate } from "react-router-dom"; +import { lazy, Suspense } from "react"; /*Components*/ import Layout from "./components/Layout.tsx"; @@ -39,6 +40,9 @@ import Privacy from "./pages/Privacy.tsx"; import Terms from "./pages/Terms.tsx"; import NotFound from "./pages/NotFound.tsx"; +// Loaded on demand: it brings the QR encoder, which no other page needs. +const QrCodes = lazy(() => import("./pages/QrCodes.tsx")); + export default function App() { return ( @@ -60,6 +64,7 @@ export default function App() { } /> } /> } /> + } /> } /> } /> } /> diff --git a/src/components/QrCode.tsx b/src/components/QrCode.tsx new file mode 100644 index 0000000..80a7da2 --- /dev/null +++ b/src/components/QrCode.tsx @@ -0,0 +1,94 @@ +/* ═══════════════════════════════════════════════════════════════ + 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. + + 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' + +import DoveMark from './DoveMark.tsx' +import { qrMatrix, qrPath } from '../lib/qr.ts' + +/* The spec's minimum quiet zone, in modules. Less and some + scanners can't find the edge of the code. */ +const MARGIN = 4 + +/* Dark enough to scan as black; the site's deep teal. */ +const INK = '#04262e' +const TEAL = '#138ba0' + +/* Badge side as a share of the code's width. */ +const BADGE = 0.24 + +/* DoveMark's own viewBox is 72.87 × 48.57. */ +const DOVE_ASPECT = 72.867699 / 48.568241 + +export default function QrCode({ + value, + dove = false, + label, + ref, + className, +}: { + value: string + dove?: boolean + /** 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 path = useMemo(() => qrPath(matrix, MARGIN), [matrix]) + + const total = matrix.size + MARGIN * 2 + const badge = matrix.size * BADGE + const badgeAt = (total - badge) / 2 + const doveWidth = badge * 0.78 + const doveHeight = doveWidth / DOVE_ASPECT + + return ( + + + + + {dove && ( + + + + + )} + + ) +} diff --git a/src/lib/qr.ts b/src/lib/qr.ts new file mode 100644 index 0000000..06a3ad2 --- /dev/null +++ b/src/lib/qr.ts @@ -0,0 +1,48 @@ +/* ═══════════════════════════════════════════════════════════════ + QR CODES + + The encoding comes from the `qrcode` package: which modules are + dark, at which error-correction level. Drawing is QrCode.tsx's + job, so the on-screen code, the SVG download and the PNG download + are one picture rather than three renderers that could disagree. + + Error correction is the share of the code that can be damaged and + still scan. A logo over the middle is damage, so a code carrying + the dove uses 'H' (about 30% recoverable); a plain one uses 'M', + which keeps it less dense and easier to scan from a distance. + ═══════════════════════════════════════════════════════════════ */ + +import { create } from 'qrcode' + +export type QrLevel = 'L' | 'M' | 'Q' | 'H' + +export type QrMatrix = { + /** Modules per side, not counting the quiet zone. */ + size: number + dark: (row: number, col: number) => boolean +} + +export function qrMatrix(text: string, level: QrLevel): QrMatrix { + const { modules } = create(text, { errorCorrectionLevel: level }) + return { size: modules.size, dark: (row, col) => modules.get(row, col) === 1 } +} + +/* The dark modules as one SVG path, a run of horizontal neighbours + per subpath, offset by the quiet zone. One element instead of a + rect per module keeps the markup (and the SVG download) small. */ +export function qrPath(matrix: QrMatrix, margin: number): string { + const parts: string[] = [] + for (let row = 0; row < matrix.size; row++) { + let col = 0 + while (col < matrix.size) { + if (!matrix.dark(row, col)) { + col++ + continue + } + const start = col + while (col < matrix.size && matrix.dark(row, col)) col++ + parts.push(`M${start + margin} ${row + margin}h${col - start}v1h-${col - start}z`) + } + } + return parts.join('') +} diff --git a/src/lib/site.ts b/src/lib/site.ts new file mode 100644 index 0000000..a7668e3 --- /dev/null +++ b/src/lib/site.ts @@ -0,0 +1,13 @@ +/* ═══════════════════════════════════════════════════════════════ + SITE + + The public address of the live site. Used where a URL has to + leave the browser and still work — a printed QR code made on + localhost or a preview has to point here, not at wherever it was + generated. Everything inside the site links by path, not this. + ═══════════════════════════════════════════════════════════════ */ + +export const SITE_ORIGIN = 'https://nextgenerationofunity.org' + +/** A site path as a full URL on the live site. */ +export const siteUrl = (path: string): string => new URL(path, SITE_ORIGIN).href diff --git a/src/lib/useContent.ts b/src/lib/useContent.ts index df27c41..86feaa1 100644 --- a/src/lib/useContent.ts +++ b/src/lib/useContent.ts @@ -336,3 +336,20 @@ export type PersonRecord = { export const usePerson = (id?: string): Resource => useRecord(detailPath('/people', id), 'person') + +/* ── Directory ───────────────────────────────────────────────── + GET /directory: every public record that has a page, one list + per kind, each row just enough to build its URL with hrefs.ts. */ + +export type DirectoryEntry = { id: string; name: string } + +export type Directory = { + events: Array + organizations: Array + teams: Array + awards: DirectoryEntry[] + people: DirectoryEntry[] +} + +export const useDirectory = (): Resource => + useRecord('/directory', 'directory') diff --git a/src/pages/QrCodes.tsx b/src/pages/QrCodes.tsx new file mode 100644 index 0000000..1341b5d --- /dev/null +++ b/src/pages/QrCodes.tsx @@ -0,0 +1,37 @@ +import PageShell from '../components/PageShell.tsx' +import QrCodeMaker from './sections/QrCodeMaker.tsx' + +/* ═══════════════════════════════════════════════════════════════ + QR CODES PAGE — /qr + + A QR code for any page on the site, for flyers, slides and + signs. Unlisted: not in navConfig, so neither the header nor the + footer links here. It lists only published records, so there is + nothing on it a visitor couldn't already reach. + ═══════════════════════════════════════════════════════════════ */ + +const SECTIONS = [ + { + id: 'make', + title: 'Make a QR code', + blurb: + 'Pick a page from the main navigation, or any event, organization, team, award or person on the site. The code always points at the live site.', + accent: '#138ba0', + background: '#eef9fb', + content: ( +
+ +
+ ), + }, +] + +export default function QrCodes() { + return ( + + ) +} diff --git a/src/pages/sections/QrCodeMaker.tsx b/src/pages/sections/QrCodeMaker.tsx new file mode 100644 index 0000000..25b53e1 --- /dev/null +++ b/src/pages/sections/QrCodeMaker.tsx @@ -0,0 +1,371 @@ +/* ═══════════════════════════════════════════════════════════════ + QR CODE MAKER + + Pick a page, get a QR code for it on the live site. + + 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 + + The main pages come from navConfig.ts, the same list the header + draws; records come from GET /directory, which lists only what's + published, and their URLs from hrefs.ts, the same builders the + site links with. So a code can only point at a page that exists. + + Codes point at SITE_ORIGIN, never at wherever this page is open, + so one made on localhost still works on a poster. + + Downloads are the on-screen itself: serialised for the SVG, + drawn onto a canvas for the PNG. Neither needs a server. + ═══════════════════════════════════════════════════════════════ */ + +import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react' + +import QrCode from '../../components/QrCode.tsx' +import { NAV_ACTIONS, PAGE_LINKS, PAGE_SECTIONS } from '../../navConfig.ts' +import { awardHref, eventHref, orgHref, personHref, teamHref } from '../../lib/hrefs.ts' +import { siteUrl } from '../../lib/site.ts' +import { useDirectory, type Directory } from '../../lib/useContent.ts' + +const TEAL = '#138ba0' +const MUTED = '#4a6b72' + +/* PNG download size in pixels. Plenty for print at a few inches; + anything bigger should use the SVG. */ +const PNG_SIZE = 1024 + +type Kind = 'pages' | 'events' | 'organizations' | 'teams' | 'awards' | 'people' + +const KINDS: Array<[Kind, string]> = [ + ['pages', 'Main navigation'], + ['events', 'Events'], + ['organizations', 'Organizations'], + ['teams', 'Teams'], + ['awards', 'Awards'], + ['people', 'People'], +] + +/* Organizations are grouped by kind in the dropdown, in this order. */ +const ORG_GROUPS: Array<[string, string]> = [ + ['national', 'NGU'], + ['region', 'Regions'], + ['chapter', 'Chapters'], + ['partner', 'Partner organizations'], +] + +type Choice = { path: string; label: string } +type Group = { label?: string; choices: Choice[] } + +/* The header's pages, then any nav action that is a page of its own + rather than an anchor on one of them (Give, not Contact Us). */ +function mainPages(): Choice[] { + const pages = PAGE_LINKS.map((p) => ({ path: p.path, label: p.label })) + const known = new Set(pages.map((p) => p.path)) + for (const action of NAV_ACTIONS) { + const path = action.to.split('#')[0] + if (!action.to.includes('#') && !known.has(path)) { + pages.push({ path, label: action.label }) + known.add(path) + } + } + return pages +} + +function groupsFor(kind: Kind, directory: Directory | null): Group[] { + if (kind === 'pages') return [{ choices: mainPages() }] + if (!directory) return [] + + switch (kind) { + case 'events': + return [ + { + choices: directory.events.map((e) => ({ + path: eventHref(e.id), + label: e.starts_on ? `${e.name} (${e.starts_on.slice(0, 4)})` : e.name, + })), + }, + ] + case 'organizations': + return ORG_GROUPS.map(([orgKind, label]) => ({ + label, + choices: directory.organizations + .filter((o) => o.kind === orgKind) + .map((o) => ({ path: orgHref(o.id, o.kind), label: o.name })), + })).filter((group) => group.choices.length > 0) + case 'teams': + return [ + { + choices: directory.teams.map((t) => ({ + path: teamHref(t.id), + label: `${t.name} — ${t.org_name}`, + })), + }, + ] + case 'awards': + return [{ choices: directory.awards.map((a) => ({ path: awardHref(a.id), label: a.name })) }] + case 'people': + return [{ choices: directory.people.map((p) => ({ path: personHref(p.id), label: p.name })) }] + } +} + +/* "/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'}` +} + +function download(href: string, filename: string) { + const a = document.createElement('a') + a.href = href + a.download = filename + document.body.appendChild(a) + a.click() + a.remove() +} + +function svgMarkup(svg: SVGSVGElement): string { + return new XMLSerializer().serializeToString(svg) +} + +function downloadSvg(svg: SVGSVGElement, stem: string) { + const url = URL.createObjectURL(new Blob([svgMarkup(svg)], { type: 'image/svg+xml' })) + download(url, `${stem}.svg`) + URL.revokeObjectURL(url) +} + +function downloadPng(svg: SVGSVGElement, stem: string) { + const image = new Image() + image.onload = () => { + const canvas = document.createElement('canvas') + canvas.width = PNG_SIZE + canvas.height = PNG_SIZE + const context = canvas.getContext('2d') + if (!context) return + context.imageSmoothingEnabled = false + context.drawImage(image, 0, 0, PNG_SIZE, PNG_SIZE) + canvas.toBlob((blob) => { + if (!blob) return + const url = URL.createObjectURL(blob) + download(url, `${stem}.png`) + URL.revokeObjectURL(url) + }, 'image/png') + } + image.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgMarkup(svg))}` +} + +export default function QrCodeMaker() { + const { data: directory, loading, error } = useDirectory() + + const [kind, setKind] = useState('pages') + const [path, setPath] = useState('/') + const [section, setSection] = useState('') + const [dove, setDove] = useState(true) + const [copied, setCopied] = useState(false) + const svgRef = useRef(null) + + const groups = useMemo(() => groupsFor(kind, directory), [kind, directory]) + const choices = useMemo(() => groups.flatMap((group) => group.choices), [groups]) + + // A new kind, or the directory arriving, can leave the current + // path outside the list; fall back to its first entry. + useEffect(() => { + if (choices.length > 0 && !choices.some((c) => c.path === path)) { + setPath(choices[0].path) + setSection('') + } + }, [choices, path]) + + 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 + + useEffect(() => setCopied(false), [url]) + + async function copy() { + if (!url) return + try { + await navigator.clipboard.writeText(url) + setCopied(true) + } catch { + // Clipboard refused (an insecure origin, or a denied + // permission). The link is on screen to copy by hand. + setCopied(false) + } + } + + const needsDirectory = kind !== 'pages' + + return ( +
+
+ + + {needsDirectory && loading && !directory ? ( +

Loading the list…

+ ) : needsDirectory && error ? ( +

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

+ ) : choices.length === 0 ? ( +

Nothing published here yet.

+ ) : ( + + )} + + {sections.length > 0 && ( + + )} + + + + {url && ( +
+

Links to

+
+ + {url} + + +
+
+ )} +
+ +
+ {url ? ( + <> +
+ +
+
+ svgRef.current && downloadPng(svgRef.current, fileStem(target!))}> + Download PNG + + svgRef.current && downloadSvg(svgRef.current, fileStem(target!))}> + Download SVG + +
+

+ PNG for documents and slides, {PNG_SIZE}px square. SVG for print: it stays sharp at + any size. +

+ + ) : ( +
+ )} +
+
+ ) +} + +function DownloadButton({ onClick, children }: { onClick: () => void; children: ReactNode }) { + return ( + + ) +} + +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' + +function Select({ + id, + label, + value, + onChange, + children, +}: { + id: string + label: string + value: string + onChange: (value: string) => void + children: ReactNode +}) { + return ( +
+ +
+ + +
+
+ ) +}