From 0cc2a3f721bf9aba338da5e27ce277244abe6645 Mon Sep 17 00:00:00 2001 From: Aidan Dona Date: Fri, 16 Oct 2026 18:01:02 -0500 Subject: [PATCH 01/15] Navigation in the admin: header and footer links, page titles, hidden pages, Shop Pages -> Navigation (migration 075) edits the header's pages and buttons and the footer's links; navConfig.ts is now only the defaults. Page titles and intros move there from Site settings. A hidden page answers Not found below viewer (server and app) and is out of the menus and sitemap; signed in, it shows with a bar. Adds a /shop page of sections, hidden, with its header button. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 +- docs/updating-data-in-code.md | 6 +- server/src/admin-schema.js | 4 + server/src/admin-schema/siteNav.js | 44 +++++++++ server/src/admin-schema/sitePages.js | 4 +- server/src/admin-schema/siteSettings.js | 12 +-- server/src/migrations/075_site_nav.sql | 122 ++++++++++++++++++++++++ server/src/pageMeta.js | 35 ++++--- server/src/routes/pages.js | 7 +- server/src/routes/sitePages.js | 22 ++++- server/src/siteNav.js | 65 +++++++++++++ site.json | 4 + src/App.tsx | 5 +- src/components/Footer.tsx | 96 ++++++++----------- src/components/Layout.tsx | 111 ++++++++++++--------- src/components/ReaderView.tsx | 5 +- src/components/SiteLink.tsx | 30 ++++++ src/lib/adminSchema.ts | 4 + src/lib/adminSchema/siteNav.ts | 104 ++++++++++++++++++++ src/lib/adminSchema/sitePages.ts | 4 +- src/lib/adminSchema/siteSettings.ts | 29 +----- src/lib/hrefs.ts | 2 +- src/lib/useSiteNav.ts | 56 +++++++++++ src/navConfig.ts | 74 ++++++++++---- src/pages/NotFound.tsx | 19 ++-- src/pages/QrCodes.tsx | 4 +- src/pages/admin/AdminLayout.tsx | 2 +- src/pages/admin/adminNav.ts | 13 ++- src/pages/sections/FeedbackForm.tsx | 17 ++-- src/pages/sections/QrCodeMaker.tsx | 30 +++--- 30 files changed, 716 insertions(+), 216 deletions(-) create mode 100644 server/src/admin-schema/siteNav.js create mode 100644 server/src/migrations/075_site_nav.sql create mode 100644 server/src/siteNav.js create mode 100644 src/components/SiteLink.tsx create mode 100644 src/lib/adminSchema/siteNav.ts create mode 100644 src/lib/useSiteNav.ts diff --git a/CLAUDE.md b/CLAUDE.md index 8aa38e5..b8b9a67 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -61,7 +61,7 @@ In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API mu - All pages use `PageShell.tsx` as the wrapper unless explicitly noted otherwise. - Pages live in `src/pages/`; section-level components go in `src/pages/sections/`. - `src/data/` holds only hardcoded data shared across multiple section files (e.g. `historyDecades.ts`, map grid). Everything else comes from SQLite, through hooks in `src/lib/`. -- `navConfig.ts` is the single source of truth for navigation, routes, and actions (header, footer, pages). +- Navigation (header and footer links, page titles and intros, hidden pages) is edited in Pages → Navigation (`site_nav*` tables, `server/src/siteNav.js`, read through `src/lib/useSiteNav.ts`). `navConfig.ts` only holds the defaults the app starts from before that loads. Routes are in `App.tsx`; a static page's default title and intro in `site.json`'s `pages`. A hidden page answers Not found below viewer (server and app both). - `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, in a folder by use: `/uploads/logos/`, `/uploads/images/`, `/uploads/thumbnails/` (saved previews), `/uploads/captions/` (videos' .vtt files); a logo or icon image field sets `folder: "logos"` (`docs/media-uploads.md`, Folders). 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/`. Logo images hide themselves on load error (`onError`). diff --git a/docs/updating-data-in-code.md b/docs/updating-data-in-code.md index a82a52c..23a1d96 100644 --- a/docs/updating-data-in-code.md +++ b/docs/updating-data-in-code.md @@ -247,8 +247,8 @@ const FRONT_PAGE_SECTIONS = [ The subnav links jump to each band by its anchor: the `id` passed in each band's `render` in `Home.tsx` (`#retreats`, `#calendar`, `#numbers`, `#connect`, and `#hero` for the hero). If you rename a -subnav label in `navConfig.ts`, leave its `hash` alone unless you also -change the band's `id`. +heading in Front page → Sections, its anchor stays: leave the band's +`id` alone unless you mean to break links to it. **Adding a new kind of band** (not just renaming one) is a feature, not a relabel: it needs a component, an entry in `SECTIONS` in @@ -278,7 +278,7 @@ The numbers band's "Number Source" dropdown works the same way: | What | File | Notes | | --- | --- | --- | -| Header and footer navigation, each page's sections (the header dropdowns, mobile menu and footer site map) | `src/navConfig.ts` | `PAGE_LINKS` (order), `NAV_ACTIONS`. Each page's sections aren't listed there: they follow the page itself, through `src/lib/navSections.ts` (the site pages' sections from Admin → Pages; the front page's bands it shows, with `src/lib/frontPageBands.ts` giving each band's anchor and default heading). A new page also needs a route in `src/App.tsx`. | +| Header and footer navigation, each page's sections (the header dropdowns, mobile menu and footer site map) | Admin → Pages → Navigation (the database, `075_site_nav.sql`); `src/navConfig.ts` is only the defaults the app starts from before it loads | Links: where each shows (header pages, header buttons, footer Get in Touch, footer bottom row), order, label, a header page set under another's menu, a filled button, new tab. Pages: title, intro and Hidden (Not found below viewer, out of the menus and the sitemap; `server/src/siteNav.js`). Each page's sections aren't listed there: they follow the page itself, through `src/lib/navSections.ts` (the site pages' sections from Admin → Pages; the front page's bands it shows, with `src/lib/frontPageBands.ts` giving each band's anchor and default heading). A new static page needs a route in `src/App.tsx` and an entry in `site.json`'s `pages` (its default title and intro, and what Navigation's Page select offers); a new page of sections also needs its id in `site_pages`' CHECK and a descriptor in both admin schemas, like Shop (075). | | Section titles, blurbs and colors on Feedback, Privacy, Terms | the page file in `src/pages/` | the `SECTIONS` array at the top. | | Site-wide announcement banner | `src/data/bannerConfig.ts` | `enabled: false` hides it. Bump `id` when the message changes, so people who dismissed the old one see the new one. | | History page decade headers | `src/data/historyDecades.ts` | Title, tagline and blurb per decade. | diff --git a/server/src/admin-schema.js b/server/src/admin-schema.js index 7294fa9..31039af 100644 --- a/server/src/admin-schema.js +++ b/server/src/admin-schema.js @@ -53,6 +53,7 @@ import { timeline } from "./admin-schema/timeline.js"; import { frontPage } from "./admin-schema/frontPage.js"; import { blogPosts } from "./admin-schema/blog.js"; import { siteSettings } from "./admin-schema/siteSettings.js"; +import { siteNav } from "./admin-schema/siteNav.js"; import { newsletters } from "./admin-schema/newsletters.js"; import { personTagTypes } from "./admin-schema/personTags.js"; import { tags } from "./admin-schema/tags.js"; @@ -64,6 +65,7 @@ import { resourcesPage, organizationPage, historyPage, + shopPage, } from "./admin-schema/sitePages.js"; export const ENTITIES = { @@ -84,6 +86,8 @@ export const ENTITIES = { resources_page: resourcesPage, organization_page: organizationPage, history_page: historyPage, + shop_page: shopPage, + navigation: siteNav, site_settings: siteSettings, newsletters, }; diff --git a/server/src/admin-schema/siteNav.js b/server/src/admin-schema/siteNav.js new file mode 100644 index 0000000..2ac245a --- /dev/null +++ b/server/src/admin-schema/siteNav.js @@ -0,0 +1,44 @@ +import { text, bool, enumeration } from "./columns.js"; + +/* ── Navigation (075_site_nav.sql) ─────────────────────────────── + Pages → Navigation: the header's and footer's links, in order, + and each static page's title, intro and whether it's hidden + (siteNav.js reads it for the site). Admins and up: it can take a + page off the site. */ +export const siteNav = { + key: "navigation", + table: "site_nav", + idColumn: "id", + idKind: "slug", + singleton: "site", + concurrency: "updated_at", + writeRole: "admin", + + list: { columns: ["id", "updated_at"], filters: [], search: [], order: "id" }, + + columns: [], + + children: [ + { + key: "links", + table: "site_nav_links", + owner: { column: "nav_id" }, + order: "sort_order", + columns: [ + enumeration("place", ["main", "action", "footer", "legal"], { required: true }), + text("label", { required: true }), + text("path", { required: true }), + text("parent_path"), + enumeration("style", ["filled"]), + bool("new_tab"), + ], + }, + { + key: "pages", + table: "site_nav_pages", + owner: { column: "nav_id" }, + order: "sort_order", + columns: [text("path", { required: true }), text("title"), text("description"), bool("is_hidden")], + }, + ], +}; diff --git a/server/src/admin-schema/sitePages.js b/server/src/admin-schema/sitePages.js index bee81c2..ddc1836 100644 --- a/server/src/admin-schema/sitePages.js +++ b/server/src/admin-schema/sitePages.js @@ -2,7 +2,8 @@ import { text, url, int, enumeration, featuredCardsChild, blocksChild } from "./ /* ── The site's own pages (056_site_pages.sql) ─────────────────── - Community, Retreats, Resources, Organization and History: one + Community, Retreats, Resources, Organization, History and Shop + (075): one site_pages row each, edited as its own singleton, with its sections nested under it and each section's blocks under that (the blocks' items under them, as on any record). A section is @@ -106,3 +107,4 @@ export const retreatsPage = sitePage("retreats"); export const resourcesPage = sitePage("resources"); export const organizationPage = sitePage("organization"); export const historyPage = sitePage("history"); +export const shopPage = sitePage("shop"); diff --git a/server/src/admin-schema/siteSettings.js b/server/src/admin-schema/siteSettings.js index 41c7f89..db5ef93 100644 --- a/server/src/admin-schema/siteSettings.js +++ b/server/src/admin-schema/siteSettings.js @@ -3,8 +3,9 @@ import { text, enumeration } from "./columns.js"; /* ── Site settings (035_site_settings.sql) ────────────────────── A singleton of overrides for what site.json says: name, - description, preview image, icons, search indexing, and static - pages' titles and intros. Superadmins only. pageMeta.js merges it + description, preview image, icons and search indexing (static + pages' titles and intros are Pages → Navigation's, siteNav.js). + Superadmins only. pageMeta.js merges it over site.json. */ export const siteSettings = { key: "site_settings", @@ -39,13 +40,6 @@ export const siteSettings = { ], children: [ - { - key: "pages", - table: "site_setting_pages", - owner: { column: "settings_id" }, - order: "sort_order", - columns: [text("path", { required: true }), text("title"), text("description")], - }, { key: "colors", table: "site_setting_colors", diff --git a/server/src/migrations/075_site_nav.sql b/server/src/migrations/075_site_nav.sql new file mode 100644 index 0000000..f23f683 --- /dev/null +++ b/server/src/migrations/075_site_nav.sql @@ -0,0 +1,122 @@ +-- ═══════════════════════════════════════════════════════════════ +-- 075 SITE NAVIGATION +-- +-- Pages → Navigation edits what navConfig.ts used to fix in code: +-- the header's links and buttons, the footer's, and each page's +-- title, intro and whether it is hidden. navConfig.ts stays as the +-- defaults the app starts from before this arrives. +-- +-- site_nav the editor's one row ('site') +-- site_nav_links every link, in order, by where it shows: +-- main the header's pages (sections drop +-- down under each); with a parent, in +-- that page's dropdown instead +-- action the header's buttons, right side +-- (and the phone menu's list under +-- the pages); a filled one also sits +-- beside the footer's logo +-- footer the footer's Get in Touch list +-- legal the footer's bottom row +-- site_nav_pages a static page's title and intro (the page's +-- heading and its search text) over site.json's, +-- and is_hidden: a hidden page is out of the nav +-- and the sitemap and answers Not found to anyone +-- below viewer (pageMeta.js, siteNav.js) +-- +-- site_setting_pages (Site settings → Page titles and intros) moves +-- into site_nav_pages and is dropped. +-- +-- The Shop page: site_pages takes 'shop' (a page of sections like +-- the others), rebuilt since its CHECK can't change in place. It +-- starts hidden, with its header button. +-- ═══════════════════════════════════════════════════════════════ + +CREATE TABLE site_nav ( + id TEXT PRIMARY KEY CHECK (id = 'site'), + updated_at TEXT NOT NULL DEFAULT (datetime('now')) +) STRICT; + +INSERT INTO site_nav (id) VALUES ('site'); + +CREATE TABLE site_nav_links ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + nav_id TEXT NOT NULL REFERENCES site_nav (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + place TEXT NOT NULL CHECK (place IN ('main', 'action', 'footer', 'legal')), + label TEXT NOT NULL, + -- '/retreats', '/organization#contact', or an https:// address + path TEXT NOT NULL, + -- main links only: the page whose dropdown it sits in + parent_path TEXT, + -- action links only: null is the outlined button + style TEXT CHECK (style IN ('filled')), + new_tab INTEGER NOT NULL DEFAULT 0 CHECK (new_tab IN (0, 1)) +) STRICT; +CREATE INDEX site_nav_links_order_idx ON site_nav_links (nav_id, sort_order); + +INSERT INTO site_nav_links (nav_id, sort_order, place, label, path, parent_path, style, new_tab) VALUES + ('site', 0, 'main', 'Home', '/', NULL, NULL, 0), + ('site', 1, 'main', 'Retreats', '/retreats', NULL, NULL, 0), + ('site', 2, 'main', 'Community', '/community', NULL, NULL, 0), + ('site', 3, 'main', 'Resources', '/resources', NULL, NULL, 0), + ('site', 4, 'main', 'Organization', '/organization', NULL, NULL, 0), + ('site', 5, 'main', 'History', '/history', NULL, NULL, 0), + ('site', 6, 'action', 'Shop', '/shop', NULL, NULL, 0), + ('site', 7, 'action', 'Contact Us', '/organization#contact', NULL, NULL, 0), + ('site', 8, 'action', 'Give', '/give', NULL, 'filled', 1), + ('site', 9, 'footer', 'Feedback', '/feedback', NULL, NULL, 0), + ('site', 10, 'footer', 'Request', '/request', NULL, NULL, 0), + ('site', 11, 'footer', 'Contact Us', '/organization#contact', NULL, NULL, 0), + ('site', 12, 'legal', 'Privacy Policy', '/privacy', NULL, NULL, 0), + ('site', 13, 'legal', 'Terms of Service', '/terms', NULL, NULL, 0); + +CREATE TABLE site_nav_pages ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + nav_id TEXT NOT NULL REFERENCES site_nav (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + path TEXT NOT NULL, -- '/retreats', a key of site.json's pages + title TEXT, -- null: site.json's + description TEXT, -- null: site.json's + is_hidden INTEGER NOT NULL DEFAULT 0 CHECK (is_hidden IN (0, 1)), + UNIQUE (nav_id, path) +) STRICT; + +INSERT INTO site_nav_pages (nav_id, sort_order, path, title, description) +SELECT 'site', sort_order, path, title, description + FROM site_setting_pages WHERE settings_id = 'site'; + +INSERT INTO site_nav_pages (nav_id, sort_order, path, is_hidden) +VALUES ('site', (SELECT coalesce(max(sort_order) + 1, 0) FROM site_nav_pages), '/shop', 1); + +DROP TABLE site_setting_pages; + +-- site_pages, with 'shop'. +CREATE TABLE site_pages_new ( + id TEXT PRIMARY KEY + CHECK (id IN ('community', 'retreats', 'resources', 'organization', 'history', 'shop')), + updated_at TEXT NOT NULL DEFAULT (datetime('now')) +) STRICT; + +INSERT INTO site_pages_new (id, updated_at) SELECT id, updated_at FROM site_pages; +INSERT INTO site_pages_new (id) VALUES ('shop'); + +-- page_sections names site_pages; legacy mode leaves it alone +-- through the rename. +PRAGMA legacy_alter_table = ON; +DROP TABLE site_pages; +ALTER TABLE site_pages_new RENAME TO site_pages; +PRAGMA legacy_alter_table = OFF; + +CREATE TRIGGER site_nav_touch +AFTER UPDATE ON site_nav +FOR EACH ROW WHEN new.updated_at = old.updated_at +BEGIN + UPDATE site_nav SET updated_at = datetime('now') WHERE id = new.id; +END; + +CREATE TRIGGER site_pages_touch +AFTER UPDATE ON site_pages +FOR EACH ROW WHEN new.updated_at = old.updated_at +BEGIN + UPDATE site_pages SET updated_at = datetime('now') WHERE id = new.id; +END; diff --git a/server/src/pageMeta.js b/server/src/pageMeta.js index 2d9bc72..5cc3139 100644 --- a/server/src/pageMeta.js +++ b/server/src/pageMeta.js @@ -15,7 +15,8 @@ /site.json (SITE_CONFIG): the site's name, address, default description and image, icons, and each static page's title and description. Laid over it: Panel → Site settings (the - site_settings table, 035), where anything set wins and anything + site_settings table, 035) and Pages → Navigation's page titles + (site_nav_pages, 075), where anything set wins and anything blank falls back to site.json. siteFor(db) does the merge. The pages read the same merged values (renderPage writes them into the HTML as window.__SITE__, see src/lib/site.ts), so a @@ -28,6 +29,8 @@ published, listed indexed, in the sitemap published, unlisted noindex: reachable by link, not by search unpublished, missing 404 and noindex, with the site defaults + a hidden static page 404 and noindex below viewer, out of the + sitemap (siteNav.js) /admin noindex Image paths resolve like src/lib/media.ts does: a bare filename @@ -44,6 +47,7 @@ import { fileURLToPath } from "node:url"; import { loadBlocks, paragraphs } from "./shape.js"; import { themeCss } from "./theme.js"; import { driveReady } from "./googleService.js"; +import { hiddenFrom, hiddenPaths, navFor } from "./siteNav.js"; const here = path.dirname(fileURLToPath(import.meta.url)); @@ -71,15 +75,15 @@ const origin = (site) => (site.url ?? "").replace(/\/$/, ""); /* site.json with the admin's Site settings laid over it: a value set there wins, a blank one falls back. indexing 'on' / 'off' overrides - robots.index for this database only. Page overrides apply only to - pages site.json knows. */ + robots.index for this database only. Page overrides (Pages → + Navigation) apply only to pages site.json knows. */ export function siteFor(db) { const base = loadSite(); const row = db.prepare(`SELECT * FROM site_settings WHERE id = 'site'`).get() ?? {}; const pages = { ...(base.pages ?? {}) }; const overrides = db - .prepare(`SELECT path, title, description FROM site_setting_pages WHERE settings_id = 'site'`) + .prepare(`SELECT path, title, description FROM site_nav_pages WHERE nav_id = 'site'`) .all(); for (const page of overrides) { const known = pages[page.path]; @@ -112,13 +116,15 @@ export function siteFor(db) { }; } -/* What the browser app reads for headings and titles. */ -// requestFiles: whether the Request form can take files (Drive set up). -const forBrowser = (site) => ({ +/* What the browser app reads for headings, titles and its menus. + requestFiles: whether the Request form can take files (Drive set + up). nav: this visitor's links and the hidden pages (siteNav.js). */ +const forBrowser = (site, nav) => ({ title: site.title, pages: site.pages, privacyEmail: site.privacyEmail, requestFiles: driveReady(), + nav, }); /* robots.txt for this database's setting, as the build writes it. */ @@ -358,12 +364,13 @@ function blogMeta(site, db, id, meta) { }; } -/* The metadata for one request path. */ -export function metaFor(db, rawPath) { +/* The metadata for one request path, for this visitor (the signed-in + user or null, who decides whether a hidden page is there). */ +export function metaFor(db, rawPath, user = null) { const site = siteFor(db); // Canonical form: no trailing slash (but "/" itself), no query. const pathname = rawPath.split(/[?#]/)[0].replace(/(.)\/+$/, "$1") || "/"; - const meta = defaults(site, db, pathname); + const meta = { ...defaults(site, db, pathname), nav: navFor(db, user) }; if (pathname === "/") { // The home page's data, and its first hero photo when the hero is @@ -396,6 +403,7 @@ export function metaFor(db, rawPath) { if (/^\/admin(\/|$)/.test(pathname)) return { ...meta, title: `Admin | ${site.title}`, noindex: true }; const page = site.pages?.[pathname]; + if (page && hiddenFrom(db, user, pathname)) return notFound(meta); if (page) { return { ...meta, title: titled(site, page.title), description: plainText(page.description) ?? meta.description }; } @@ -520,7 +528,7 @@ export function renderPage(html, meta) { ), // Read by src/lib/site.ts before the app's module runs (a plain // script in the head runs during parsing; modules wait). - ``, + ``, site.themeCss && ``, analyticsTag(site), ].filter(Boolean); @@ -542,10 +550,13 @@ export function sitemap(db) { const site = siteFor(db); const base = origin(site); const day = (value) => (value ? String(value).slice(0, 10) : null); + const hidden = hiddenPaths(db); const entries = [ { loc: "/" }, - ...Object.keys(site.pages ?? {}).map((loc) => ({ loc })), + ...Object.keys(site.pages ?? {}) + .filter((loc) => !hidden.has(loc)) + .map((loc) => ({ loc })), ...db .prepare(`SELECT id, updated_at FROM events WHERE is_published = 1 AND is_listed = 1`) .all() diff --git a/server/src/routes/pages.js b/server/src/routes/pages.js index 7a03596..d4f7fff 100644 --- a/server/src/routes/pages.js +++ b/server/src/routes/pages.js @@ -7,7 +7,8 @@ can say no while production says yes GET /anything the built index.html, its title, description, preview image, canonical link and structured - data filled in for that path (pageMeta.js) + data filled in for that path (pageMeta.js), + and this visitor's menus (siteNav.js) In production nginx serves files that exist (the JS, CSS, uploads) itself and sends everything else here, so a shared link @@ -35,6 +36,7 @@ import { fileURLToPath } from "node:url"; import { Hono } from "hono"; +import { currentUser } from "../auth.js"; import { metaFor, renderPage, robotsTxt, siteFor, sitemap } from "../pageMeta.js"; import { CACHE, NO_STORE } from "../shape.js"; @@ -109,7 +111,8 @@ pages.get("*", (c, next) => { let meta; let page; try { - meta = metaFor(c.get("db"), pathname); + // Who's asking decides whether a hidden page is there (siteNav.js). + meta = metaFor(c.get("db"), pathname, currentUser(c.get("db"), c)); page = renderPage(html, meta); } catch (err) { warnOnce( diff --git a/server/src/routes/sitePages.js b/server/src/routes/sitePages.js index 43e8f35..6101056 100644 --- a/server/src/routes/sitePages.js +++ b/server/src/routes/sitePages.js @@ -1,11 +1,15 @@ /* ═══════════════════════════════════════════════════════════════ SITE PAGE ROUTES: read-only, mounted under /api + GET /nav this visitor's header and footer links and + the hidden pages (siteNav.js); not cached, + since it depends on who's signed in GET /site-pages every site page's section headings, for the header's dropdowns and the side nav GET /site-pages/:id one page's sections, in order: heading, accent, preset (and an events preset's - filter and view), and its blocks + filter and view), and its blocks; Not + found for a hidden page, below viewer Edited in the admin as Pages → each page (admin-schema/sitePages.js). Blocks are shaped as on any record @@ -13,10 +17,17 @@ ═══════════════════════════════════════════════════════════════ */ import { Hono } from "hono"; -import { json, loadBlocks } from "../shape.js"; +import { currentUser } from "../auth.js"; +import { hiddenPaths, navFor, seesHidden } from "../siteNav.js"; +import { NO_STORE, json, loadBlocks } from "../shape.js"; const sitePages = new Hono(); +sitePages.get("/nav", (c) => { + const db = c.get("db"); + return c.json({ nav: navFor(db, currentUser(db, c)) }, 200, NO_STORE); +}); + sitePages.get("/site-pages", (c) => { const rows = c .get("db") @@ -31,7 +42,8 @@ sitePages.get("/site-pages", (c) => { sitePages.get("/site-pages/:id", (c) => { const db = c.get("db"); const id = c.req.param("id"); - if (!db.prepare(`SELECT 1 FROM site_pages WHERE id = ?`).get(id)) { + const hidden = hiddenPaths(db).has(`/${id}`); + if (!db.prepare(`SELECT 1 FROM site_pages WHERE id = ?`).get(id) || (hidden && !seesHidden(currentUser(db, c)))) { return c.json({ error: "No such page." }, 404); } @@ -53,7 +65,9 @@ sitePages.get("/site-pages/:id", (c) => { picked.set(section_id, [...(picked.get(section_id) ?? []), org_id]); } - return json(c, { + // A hidden page is only for those signed in: never kept. + const send = hidden ? (body) => c.json(body, 200, NO_STORE) : (body) => json(c, body); + return send({ page: { id, sections: rows.map(({ id: sectionId, ...section }) => ({ diff --git a/server/src/siteNav.js b/server/src/siteNav.js new file mode 100644 index 0000000..b06dbf6 --- /dev/null +++ b/server/src/siteNav.js @@ -0,0 +1,65 @@ +/* ═══════════════════════════════════════════════════════════════ + SITE NAVIGATION + + Pages → Navigation (075_site_nav.sql): the header's and footer's + links, and which static pages are hidden. Read by pageMeta.js + (window.__SITE__, the page's status, the sitemap) and served as + GET /api/nav for the app (routes/sitePages.js). + + A hidden page answers Not found to anyone below viewer, and its + links are left out of what they're sent; a viewer and up sees + both, and the page says it's hidden (Layout.tsx). Who's asking + is the session cookie, so the same page can be hidden from one + visitor and shown to the next: the HTML is no-cache already. + ═══════════════════════════════════════════════════════════════ */ + +import { hasRole } from "./auth.js"; + +/* Who sees hidden pages. */ +export const SEES_HIDDEN = "viewer"; + +export const seesHidden = (user) => hasRole(user, SEES_HIDDEN); + +/* The paths whose pages are hidden, eg. '/shop'. */ +export function hiddenPaths(db) { + return new Set( + db + .prepare(`SELECT path FROM site_nav_pages WHERE nav_id = 'site' AND is_hidden = 1`) + .all() + .map((row) => row.path), + ); +} + +/* A link's page: its path without the #section or ?query, or null + for an address off the site. */ +const pageOf = (href) => (/^\//.test(href) ? href.split(/[?#]/)[0].replace(/(.)\/+$/, "$1") : null); + +/* Whether this path's page is one the user can't see. */ +export function hiddenFrom(db, user, pathname) { + return !seesHidden(user) && hiddenPaths(db).has(pageOf(pathname)); +} + +/* What the app draws its menus from: every link this user may + follow, and the hidden pages' paths (so the app can answer Not + found, or say a page is hidden, without asking again). */ +export function navFor(db, user) { + const hidden = hiddenPaths(db); + const sees = seesHidden(user); + const links = db + .prepare( + `SELECT place, label, path, parent_path, style, new_tab + FROM site_nav_links WHERE nav_id = 'site' ORDER BY sort_order, id`, + ) + .all() + .filter((link) => sees || !hidden.has(pageOf(link.path))) + .map((link) => ({ + place: link.place, + label: link.label, + path: link.path, + parent: link.parent_path || null, + filled: link.style === "filled", + newTab: link.new_tab === 1, + })); + + return { links, hidden: [...hidden], seesHidden: sees }; +} diff --git a/site.json b/site.json index 4011a51..8a717b6 100644 --- a/site.json +++ b/site.json @@ -54,6 +54,10 @@ "title": "Privacy Policy", "description": "How Next Generation of Unity collects, uses, and protects your information." }, + "/shop": { + "title": "Shop", + "description": "Shirts, stickers and more from Next Generation of Unity. Every purchase supports our retreats and programs." + }, "/terms": { "title": "Terms of Service", "description": "The terms that apply when you use this site and our programs." diff --git a/src/App.tsx b/src/App.tsx index 2f66b03..3048d73 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -49,8 +49,8 @@ const lazyPage = (load) => throw err }), ) -// Community, Retreats, Resources, Organization and History: each -// built in the admin from sections. +// Community, Retreats, Resources, Organization, History and Shop: +// each built in the admin from sections. const SitePage = lazyPage(() => import("./pages/SitePage.tsx")) const Feedback = lazyPage(() => import("./pages/Feedback.tsx")) const Request = lazyPage(() => import("./pages/Request.tsx")) @@ -107,6 +107,7 @@ export default function App() { } /> } /> } /> + } /> } /> } /> } /> diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index 6b0797c..7ccbada 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -1,31 +1,16 @@ import { Link } from "react-router-dom"; -import { PAGE_LINKS, NAV_ACTIONS } from "../navConfig.ts"; import { useNavSections } from "../lib/navSections.ts"; +import { useSiteNav } from "../lib/useSiteNav.ts"; +import SiteLink from "./SiteLink.tsx"; import siteLogo from "../assets/logos/NGU_Logo.svg"; import PlatformIcon from "./PlatformIcon.tsx"; import { ORGANIZATION_DETAILS as Organization_Details } from "../data/organizationDetails.ts"; import { SOCIAL_LINKS } from "../data/socialLinks.ts"; -// Give's destination lives in navConfig so the footer and the nav can't drift. -// Only the label differs down here. -const giveAction = NAV_ACTIONS.find((a) => a.variant === "fancy"); - -/* An internal route, or an off-site address opened in a new tab. */ -type TouchLink = { label: string } & ( - | { external?: false; to: string } - | { external: true; href: string } -); - -const Get_In_Touch: TouchLink[] = [ - { label: "Feedback", to: "/feedback"}, - { label: "Request", to: "/request" }, - { label: "Contact Us", to: "/organization#contact" }, -]; - -const Footer_Links = [ - { label: "Privacy Policy", to: "/privacy" }, - { label: "Terms of Service", to: "/terms" }, -]; +/* Every link here is Pages → Navigation's (useSiteNav): the filled + header buttons (Give) beside the logo, Get in Touch, the site map + (the header's pages, their sections and the pages set under them) + and the bottom row. */ const footerLinkClass = "text-white/65 hover:text-[var(--pal-green-2)] text-sm transition-colors"; @@ -41,6 +26,7 @@ const headingClass = "text-white/90 text-sm font-semibold mb-4"; export default function Footer() { const sectionsOf = useNavSections(); + const nav = useSiteNav(); return (