Tidy the structure the audit found

- The colour defaults have one source, server/src/themeDefaults.js,
  read by the server and the admin; the build stops if src/index.css
  disagrees with it
- server/src/admin-schema.js split into admin-schema/, one file per
  entity plus columns.js (the registry checked identical)
- loadOwned() in shape.js replaces the same three loads on four
  detail routes (every public route checked identical); one NO_STORE
- One OrgLogo component for the org lists and the chapter map; an
  organization's own page now shows the same initials as the lists
- One localISO() for the viewer's calendar day, in place of three
- Boot refuses a descriptor dropdown value the table's CHECK doesn't
  allow, instead of it failing on save
- Deleted the unused Other.tsx and white-background logo;
  chapters.ts is useCommunity.ts; isSuper() in the Panel; stale
  comments and docs corrected

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-29 03:02:21 -05:00
parent 048c7599ce
commit f934b1dd93
44 changed files with 1187 additions and 1170 deletions

View file

@ -67,14 +67,14 @@ In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API mu
- **Imports need explicit extensions** (`.ts`, `.tsx`, `.js`) everywhere. - **Imports need explicit extensions** (`.ts`, `.tsx`, `.js`) everywhere.
- **Vite resolves `.js` before `.ts`**, so a `.js` and `.ts` file with the same base name will import the wrong one. Give new hooks distinct names. - **Vite resolves `.js` before `.ts`**, so a `.js` and `.ts` file with the same base name will import the wrong one. Give new hooks distinct names.
- **Don't use `fallback: EMPTY` in api.ts hooks.** It silently returns empty arrays and hides server errors; let the error state surface. - **Don't use `fallback: EMPTY` in api.ts hooks.** It silently returns empty arrays and hides server errors; let the error state surface.
- **Colours are tokens, not hex.** Admins can override any token (Panel → Site settings → Colours); the defaults live in three places that must agree: `src/index.css`, `THEME_DEFAULTS` in `server/src/theme.js`, `THEME_COLORS` in `src/lib/adminSchema/siteSettings.ts`. Use the utilities from `src/index.css` (`text-ink`, `text-body`, `text-muted`, `text-link`, `bg-surface`, `bg-tint`, `bg-action`, `border-brand/20`...) so dark mode works; a literal only for something that must look the same in both modes (white on a dark band, a platform's colour). Data colours (accents, event and region colours) go through `withAlpha`, `accentText` and `readableOn` in `src/lib/color.ts`, never `${color}55`. - **Colours are tokens, not hex.** Admins can override any token (Panel → Site settings → Colours). The defaults are `server/src/themeDefaults.js` plus the same values as CSS in `src/index.css`; the build fails if they differ (`themeDefaultsCheck` in `vite.config.ts`), and migration 041's CHECK lists the token names. Use the utilities from `src/index.css` (`text-ink`, `text-body`, `text-muted`, `text-link`, `bg-surface`, `bg-tint`, `bg-action`, `border-brand/20`...) so dark mode works; a literal only for something that must look the same in both modes (white on a dark band, a platform's colour). Data colours (accents, event and region colours) go through `withAlpha`, `accentText` and `readableOn` in `src/lib/color.ts`, never `${color}55`.
- **Icons are Phosphor** (`@phosphor-icons/react`), weight `bold` (or `fill` for play/star). No hand-drawn `<svg>` icons and no Unicode glyphs as icons (× › ▶ →). Brand marks are the exception: `DoveMark`, `PlatformIcon`, the Google logo, the chapter map. - **Icons are Phosphor** (`@phosphor-icons/react`), weight `bold` (or `fill` for play/star). No hand-drawn `<svg>` icons and no Unicode glyphs as icons (× › ▶ →). Brand marks are the exception: `DoveMark`, `PlatformIcon`, the Google logo, the chapter map.
- **Accents come from `src/lib/color.ts`:** `BRAND` (the teal, via the button token so the admin palette reaches it) and `ACCENTS` (deep, green, mint). Not a new hex in a page. - **Accents come from `src/lib/color.ts`:** `BRAND` (the teal, via the button token so the admin palette reaches it) and `ACCENTS` (deep, green, mint). Not a new hex in a page.
- **No em-dashes** (U+2014) anywhere: UI text, help text, comments, docs, commit messages. Use a colon, comma or parentheses. An empty table cell shows `-`. - **No em-dashes** (U+2014) anywhere: UI text, help text, comments, docs, commit messages. Use a colon, comma or parentheses. An empty table cell shows `-`.
- **Admin editor text:** blank select options read `Default: …` (what blank means), examples in help text start with `eg.`, and record ids are called "URL ID". Cut-off preview text uses `preview()` from `src/lib/text.ts`, which ends it with an ellipsis. See `docs/updating-data-in-code.md`. - **Admin editor text:** blank select options read `Default: …` (what blank means), examples in help text start with `eg.`, and record ids are called "URL ID". Cut-off preview text uses `preview()` from `src/lib/text.ts`, which ends it with an ellipsis. See `docs/updating-data-in-code.md`.
## Admin CRUD engine ## Admin CRUD engine
Descriptor-driven: `server/src/admin-crud.js` and `server/src/admin-schema.js` (server) and `src/lib/adminSchema/` (client, one file per entity, registered in `adminSchema.ts`) generate SQL and form fields from declarative entity configs. Adding an entity should mean adding a descriptor, not new CRUD code. Descriptor-driven: `server/src/admin-crud.js` and `server/src/admin-schema/` (server, one file per entity, registered in `admin-schema.js`) and `src/lib/adminSchema/` (client, one file per entity, registered in `adminSchema.ts`) generate SQL and form fields from declarative entity configs. Adding an entity should mean adding a descriptor, not new CRUD code.
- Child collections are deleted and reinserted wholesale. Unsafe for entities referenced by foreign keys elsewhere. - Child collections are deleted and reinserted wholesale. Unsafe for entities referenced by foreign keys elsewhere.
- `reindex: false` prevents cross-entity sort order collisions. - `reindex: false` prevents cross-entity sort order collisions.
- `check: (db, id) => void` runs after a save has written everything, inside its transaction; throwing an `HttpError` refuses the save (Site settings uses it for the colour contrast check, `server/src/theme.js`). - `check: (db, id) => void` runs after a save has written everything, inside its transaction; throwing an `HttpError` refuses the save (Site settings uses it for the colour contrast check, `server/src/theme.js`).

View file

@ -50,7 +50,7 @@ each entity:
| File | What it holds | | File | What it holds |
| ----------------------------- | ----------------------------------------------------- | | ----------------------------- | ----------------------------------------------------- |
| `src/lib/adminSchema/` (one file per entity, `shared.ts` for common fields; `src/lib/adminSchema.ts` lists them) | The **form**: field labels, help text, dropdown labels, list columns and filters | | `src/lib/adminSchema/` (one file per entity, `shared.ts` for common fields; `src/lib/adminSchema.ts` lists them) | The **form**: field labels, help text, dropdown labels, list columns and filters |
| `server/src/admin-schema.js` | What the server **accepts**: columns, types, the allowed values of each `enumeration(...)` | | `server/src/admin-schema/` (one file per entity, `columns.js` for shared helpers; `server/src/admin-schema.js` lists them) | What the server **accepts**: columns, types, the allowed values of each `enumeration(...)` |
And the database itself holds the final word: most fixed lists are a And the database itself holds the final word: most fixed lists are a
`CHECK (... IN (...))` constraint on the column (read them in `CHECK (... IN (...))` constraint on the column (read them in
@ -145,7 +145,7 @@ together, in one branch:
**Renaming** a value also needs an `UPDATE` in the same migration so **Renaming** a value also needs an `UPDATE` in the same migration so
existing rows move to the new value. **Removing** one needs you to existing rows move to the new value. **Removing** one needs you to
decide what existing rows become first. decide what existing rows become first.
2. **`server/src/admin-schema.js`**: the `enumeration("column", [...])` 2. **`server/src/admin-schema/<entity>.js`**: the `enumeration("column", [...])`
list for that column. list for that column.
3. **`src/lib/adminSchema/<entity>.ts`**: the `options` on the form field, and on 3. **`src/lib/adminSchema/<entity>.ts`**: the `options` on the form field, and on
the list filter if there is one. the list filter if there is one.
@ -161,11 +161,11 @@ wrong rather than working around it.
### Every dropdown in the editor ### Every dropdown in the editor
**Fixed lists** (`options`: labels in `src/lib/adminSchema/`, values **Fixed lists** (`options`: labels in `src/lib/adminSchema/`, values
also in `admin-schema.js` and a CHECK): also in `server/src/admin-schema/` and a CHECK):
| Entity → field | Stored values | Labelled? | Also used on the public site by | | Entity → field | Stored values | Labelled? | Also used on the public site by |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| Organizations → Kind (+ list filter) | national, region, chapter, partner | no, shows values | `ORG_KIND_LABEL` in `src/lib/hrefs.ts`, and the route each kind uses | | Organizations → Kind (+ list filter) | national, region, chapter, partner | no, shows values | `ORG_BASE` in `src/lib/hrefs.ts` (the route each kind uses) and `orgListHref` there (its back link) |
| Organizations → Region → Scope | domestic, international, virtual | no | the Community page groups regions by it | | Organizations → Region → Scope | domestic, international, virtual | no | the Community page groups regions by it |
| Organizations → Region areas → Edge | top, bottom | no | the chapter map (`OrgList-Map.tsx`) | | Organizations → Region areas → Edge | top, bottom | no | the chapter map (`OrgList-Map.tsx`) |
| Events → Type (+ list filter) | retreat, class, workshop, meeting, other | no | `EVENT_TYPES` in `src/lib/eventTypes.ts` (public labels and plurals) | | Events → Type (+ list filter) | retreat, class, workshop, meeting, other | no | `EVENT_TYPES` in `src/lib/eventTypes.ts` (public labels and plurals) |
@ -206,7 +206,6 @@ code):
| Affiliations → Team | `teams` | teams, filtered to the chosen organization | | Affiliations → Team | `teams` | teams, filtered to the chosen organization |
| Person awards → Award | `awards` | awards, labelled "Award (Organization)" | | Person awards → Award | `awards` | awards, labelled "Award (Organization)" |
| Person awards → Presented at; Front page → Count down to; Front page → Featured event | `events` | events | | Person awards → Presented at; Front page → Count down to; Front page → Featured event | `events` | events |
| Timeline → Record | `timeline_refs` | all five kinds, filtered by "Points at" |
--- ---
@ -243,7 +242,7 @@ change the band's `id`.
**Adding a new kind of band** (not just renaming one) is a feature, **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 not a relabel: it needs a component, an entry in `SECTIONS` in
`Home.tsx`, the key added to `FRONT_PAGE_SECTIONS`, to the `Home.tsx`, the key added to `FRONT_PAGE_SECTIONS`, to the
`enumeration("section", …)` in `server/src/admin-schema.js`, to the `enumeration("section", …)` in `server/src/admin-schema/frontPage.js`, to the
`FrontPageSectionKey` type in `src/lib/useFrontPage.ts`, and to the `FrontPageSectionKey` type in `src/lib/useFrontPage.ts`, and to the
CHECK on `front_page_sections.section` via a migration. CHECK on `front_page_sections.section` via a migration.
@ -259,7 +258,7 @@ The numbers band's "Number Source" dropdown works the same way:
matching public page shows (published rows), or the number and the matching public page shows (published rows), or the number and the
page will disagree. page will disagree.
- **Add a source:** the CHECK on `front_page_stats.source` (migration), - **Add a source:** the CHECK on `front_page_stats.source` (migration),
the `enumeration("source", …)` in `server/src/admin-schema.js`, the `enumeration("source", …)` in `server/src/admin-schema/frontPage.js`,
`STAT_SOURCES`, and a query in `STAT_QUERIES`. `STAT_SOURCES`, and a query in `STAT_QUERIES`.
--- ---
@ -274,13 +273,13 @@ The numbers band's "Number Source" dropdown works the same way:
| History page decade headers | `src/data/historyDecades.ts` | Title, tagline and blurb per decade. | | History page decade headers | `src/data/historyDecades.ts` | Title, tagline and blurb per decade. |
| Chapter map tiles and area names | `src/data/mapGrid.ts` | `AREAS` (tile positions) and `AREA_NAMES`. Which region paints which tile is in the database (Admin → Data → Organizations → a region → Map areas). | | Chapter map tiles and area names | `src/data/mapGrid.ts` | `AREAS` (tile positions) and `AREA_NAMES`. Which region paints which tile is in the database (Admin → Data → Organizations → a region → Map areas). |
| Feedback form types | `src/data/feedbackTypes.ts` **and** `TYPES` in `server/src/routes/feedback.js` | Keep the ids identical in both; the server stores unknown ids as `general`. Labels and hints are client-only. `DATA_REQUEST` ('privacy') isn't a tile: the Privacy page's form sends it, and the server requires an email for it. | | Feedback form types | `src/data/feedbackTypes.ts` **and** `TYPES` in `server/src/routes/feedback.js` | Keep the ids identical in both; the server stores unknown ids as `general`. Labels and hints are client-only. `DATA_REQUEST` ('privacy') isn't a tile: the Privacy page's form sends it, and the server requires an email for it. |
| The site's colours, light and dark | the database over `src/index.css` | Admin → Panel → Site settings → Colours (superadmins): pick a colour, set its light and/or dark value; saving refuses anything that makes text hard to read. The defaults are the `@theme` tokens and dark block in `src/index.css`, and must stay the same in `THEME_DEFAULTS` (`server/src/theme.js`) and `THEME_COLORS` (`src/lib/adminSchema/siteSettings.ts`). Change a token's value in both modes and every use follows. Use the token utilities (`text-muted`, `bg-surface`, `border-brand/20`) or `var(--color-…)`, not hex. A colour that arrives as data (a page accent, an event's or region's colour) goes through `src/lib/color.ts`: `withAlpha` for tints, `accentText` for text in it, `readableOn` for text on it. | | The site's colours, light and dark | the database over `src/index.css` | Admin → Panel → Site settings → Colours (superadmins): pick a colour, set its light and/or dark value; saving refuses anything that makes text hard to read. The defaults are `THEME_DEFAULTS` in `server/src/themeDefaults.js` (the admin and the contrast check read it) and the same values as CSS in `src/index.css`; the build stops if the two differ. The admin's labels for them are `THEME_LABELS` in `src/lib/adminSchema/siteSettings.ts`. Change a token's value in both modes and every use follows. Use the token utilities (`text-muted`, `bg-surface`, `border-brand/20`) or `var(--color-…)`, not hex. A colour that arrives as data (a page accent, an event's or region's colour) goes through `src/lib/color.ts`: `withAlpha` for tints, `accentText` for text in it, `readableOn` for text on it. |
| The icons a Front page "Find your way in" path can pick | `src/data/pathIcons.ts` (keys and labels) **and** `ICONS` in `src/pages/sections/home/Pathfinder.tsx` (the Phosphor icon for each key) | Add a line to both. A path saved with an emoji from before the list shows it as it is. | | The icons a Front page "Find your way in" path can pick | `src/data/pathIcons.ts` (keys and labels) **and** `ICONS` in `src/pages/sections/home/Pathfinder.tsx` (the Phosphor icon for each key) | Add a line to both. A path saved with an emoji from before the list shows it as it is. |
| A page section's accent colour | `BRAND` and `ACCENTS` in `src/lib/color.ts` | Pages pick from these (`accent: ACCENTS.green`); add a colour there, not a hex in a page. Each is readable as text on white and the tints. | | A page section's accent colour | `BRAND` and `ACCENTS` in `src/lib/color.ts` | Pages pick from these (`accent: ACCENTS.green`); add a colour there, not a hex in a page. Each is readable as text on white and the tints. |
| Privacy Policy and Terms wording | `src/pages/Privacy.tsx`, `src/pages/Terms.tsx` | The `PARTS` list, and `LAST_UPDATED` whenever the wording changes. The Privacy page must stay true of the code: what the feedback form stores, what the browser keeps, which embeds wait for a click. | | Privacy Policy and Terms wording | `src/pages/Privacy.tsx`, `src/pages/Terms.tsx` | The `PARTS` list, and `LAST_UPDATED` whenever the wording changes. The Privacy page must stay true of the code: what the feedback form stores, what the browser keeps, which embeds wait for a click. |
| Event type labels and plurals (public site) | `src/lib/eventTypes.ts` | Also the order of the type filter chips. | | Event type labels and plurals (public site) | `src/lib/eventTypes.ts` | Also the order of the type filter chips. |
| Event and person role labels (public site) | `ROLE_LABEL` in `src/pages/EventDetail.tsx` and `src/pages/PersonDetail.tsx` | | | Event and person role labels (public site) | `ROLE_LABEL` in `src/pages/EventDetail.tsx` and `src/pages/PersonDetail.tsx` | |
| Organization kind labels ("Region", "Chapter") | `ORG_KIND_LABEL` in `src/lib/hrefs.ts` | | | Organization kind labels ("Region", "Chapter") | the Kind options in `src/lib/adminSchema/organizations.ts` (admin); `orgListHref` in `src/lib/hrefs.ts` (the public back link, "All regions") | |
| Admin account roles | `src/lib/roles.ts` (labels, notes) and `ROLES` in `server/src/auth.js` | Adding a role is also a CHECK change on `admin_users.role`. | | Admin account roles | `src/lib/roles.ts` (labels, notes) and `ROLES` in `server/src/auth.js` | Adding a role is also a CHECK change on `admin_users.role`. |
| Admin navigation | `src/pages/admin/adminNav.ts` | | | Admin navigation | `src/pages/admin/adminNav.ts` | |
| The live site's address (used by QR codes) | `SITE_ORIGIN` in `src/lib/site.ts` | | | The live site's address (used by QR codes) | `SITE_ORIGIN` in `src/lib/site.ts` | |

View file

@ -22,6 +22,15 @@
than waiting to surface one row at a time. than waiting to surface one row at a time.
═══════════════════════════════════════════════════════════════ */ ═══════════════════════════════════════════════════════════════ */
/* The values a CHECK (column IN (...)) on the table allows, read from
its CREATE TABLE, or null when there's no such CHECK. */
function checkValues(db, table, column) {
const sql = db.prepare(`SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = ?`).get(table)?.sql ?? "";
const match = new RegExp(`\\b${column}"?\\s+IN\\s*\\(([^)]*)\\)`, "i").exec(sql);
if (!match) return null;
return new Set([...match[1].matchAll(/'((?:[^']|'')*)'/g)].map((m) => m[1].replace(/''/g, "'")));
}
function tableMeta(db, table) { function tableMeta(db, table) {
const rows = db.prepare(`PRAGMA table_info(${table})`).all(); const rows = db.prepare(`PRAGMA table_info(${table})`).all();
if (!rows.length) return null; if (!rows.length) return null;
@ -114,6 +123,19 @@ export function syncDescriptorsWithSchema(db, entities) {
inferred.push(`${name}: ${group.table}.${column.name}`); inferred.push(`${name}: ${group.table}.${column.name}`);
} }
if (info.notNullable) column.notNullable = true; if (info.notNullable) column.notNullable = true;
// A dropdown value the table's CHECK refuses would only fail
// when someone saves it; say so at boot instead.
if (column.type === "enum") {
const allowed = checkValues(db, group.table, column.name);
const refused = allowed ? column.values.filter((value) => !allowed.has(value)) : [];
if (refused.length) {
problems.push(
`${name}: ${group.table}.${column.name} offers ${refused.join(", ")}, ` +
`which the table's CHECK doesn't allow.`,
);
}
}
} }
for (const [columnName, info] of meta) { for (const [columnName, info] of meta) {

View file

@ -1,6 +1,10 @@
/* ═══════════════════════════════════════════════════════════════ /* ═══════════════════════════════════════════════════════════════
ADMIN ENTITY DESCRIPTORS ADMIN ENTITY DESCRIPTORS
One object per editable entity, one file each in admin-schema/
(the shared column helpers and child collections are in
admin-schema/columns.js); this file lists them.
One object per editable entity. Everything the CRUD handlers do One object per editable entity. Everything the CRUD handlers do
(validation, SQL, nesting) is read from here, so adding a (validation, SQL, nesting) is read from here, so adding a
table later is a descriptor rather than another set of table later is a descriptor rather than another set of
@ -38,936 +42,15 @@
what the other side owns rather than blanking it. what the other side owns rather than blanking it.
═══════════════════════════════════════════════════════════════ */ ═══════════════════════════════════════════════════════════════ */
import { THEME_TOKENS, checkTheme } from "./theme.js"; import { organizations } from "./admin-schema/organizations.js";
import { events } from "./admin-schema/events.js";
/* ── Column helpers ──────────────────────────────────────────── */ import { people } from "./admin-schema/people.js";
import { teams } from "./admin-schema/teams.js";
const text = (name, opts = {}) => ({ name, type: "text", ...opts }); import { awards } from "./admin-schema/awards.js";
// Text that is a link: refuses javascript:, data: and other schemes. import { timeline } from "./admin-schema/timeline.js";
const url = (name, opts = {}) => ({ name, type: "url", ...opts }); import { frontPage } from "./admin-schema/frontPage.js";
const int = (name, opts = {}) => ({ name, type: "int", ...opts }); import { blogPosts, communityPage } from "./admin-schema/blog.js";
const real = (name, opts = {}) => ({ name, type: "real", ...opts }); import { siteSettings } from "./admin-schema/siteSettings.js";
const bool = (name, opts = {}) => ({ name, type: "bool", ...opts });
const date = (name, opts = {}) => ({ name, type: "date", ...opts });
const time = (name, opts = {}) => ({ name, type: "time", ...opts });
const enumeration = (name, values, opts = {}) => ({
name,
type: "enum",
values,
...opts,
});
/* Place columns shared by organizations and events, in schema order. */
const placeColumns = [
text("venue"),
text("address"),
text("locality"),
text("state_code"),
text("country"),
text("location_label"),
real("latitude"),
real("longitude"),
bool("is_online"),
];
/* The affiliation's own fields, minus whichever end owns the row.
Both editors write the same shape so neither loses the other's
values on save. */
const affiliationRole = [
text("title"),
enumeration("role", ["lead", "board", "staff", "volunteer", "member"], {
required: true,
}),
bool("is_owner"),
date("started_on"),
date("ended_on"),
bool("is_public"),
];
/* The editable half of a timeline entry, shared by the standalone
editor and by the in_timeline extension on events and organizations.
occurred_on is text, not date. "2012" and "2025-07" are legitimate
values (a backfilled entry often knows the year and nothing more),
and the date coercion would reject both. `precision` is what says how
much of it to believe. */
const timelineFields = [
text("occurred_on"),
enumeration("precision", ["year", "month", "day"]),
text("title"),
text("blurb"),
text("meta"),
url("link_url"),
bool("is_featured"),
bool("is_published"),
int("sort_order"),
];
/* The extension that the in_timeline checkbox drives. Ticked, the row
is upserted; unticked, writeExtensions deletes it. Both happen in the
parent's transaction, so the flag and the row cannot disagree.
The conflict target is the UNIQUE (ref_kind, ref_id) constraint
on timeline_entries, which is also what stops a second save creating a
duplicate instead of updating the first. */
const timelineExtension = (refKind) => ({
key: "timeline",
table: "timeline_entries",
owner: { column: "ref_id", kindColumn: "ref_kind", kindValue: refKind },
conflict: ["ref_kind", "ref_id"],
when: { column: "in_timeline", value: 1 },
columns: [
// Fixed for this end: an event's entry is always an event entry.
// Declared as a default rather than a form field so the column is
// written without asking.
enumeration(
"kind",
["milestone", "event", "organization", "award", "people"],
{ default: refKind === "organization" ? "organization" : refKind },
),
...timelineFields,
],
});
/* Featured cards (030_featured_cards.sql): polymorphic like links,
so the Community blog can own a set too. */
const featuredCardsChild = (ownerKind) => ({
key: "featured_cards",
table: "featured_cards",
owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind },
order: "sort_order",
columns: [
enumeration("kind", ["record", "link", "video"], { required: true }),
enumeration("ref_kind", ["event", "organization", "person", "team", "award"]),
text("ref_id"),
url("url"),
text("eyebrow"),
text("title"),
text("blurb"),
text("image"),
],
});
/* The two polymorphic collections, parameterised by owner_kind. */
const linksChild = (ownerKind) => ({
key: "links",
table: "links",
owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind },
order: "sort_order",
columns: [
enumeration("kind", ["action", "social", "website", "email"], {
required: true,
}),
text("platform"),
text("label", { required: true }),
url("url", { required: true }),
bool("is_primary"),
],
});
const blocksChild = (ownerKind) => ({
key: "content_blocks",
table: "content_blocks",
owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind },
order: "sort_order",
columns: [
enumeration("slot", ["card", "body"], { required: true }),
enumeration(
"type",
[
"heading",
"subheading",
"paragraph",
"list",
"links",
"quote",
"image",
"divider",
"video",
"button",
"callout",
"schedule",
],
{ required: true },
),
text("text"),
text("media"),
url("href"),
text("alt"),
text("cite"),
],
children: [
{
key: "items",
table: "content_block_items",
owner: { column: "block_id" },
order: "sort_order",
columns: [
text("text", { required: true }),
text("detail"),
url("url"),
// Schedule entries only (034_schedule_block.sql).
text("day"),
text("time"),
text("location"),
text("person_id"),
text("description"),
text("media"),
text("media_alt"),
text("map"),
],
},
],
});
/* Hosts. One row is one host, ordered, each either an organization
or a person. The CHECK on event_hosts rejects both and the blank
filter drops neither, so the only bad row that reaches SQLite is
one with both selects filled, and that comes back keyed to the
row like any other field error.
Not parameterised the way links and blocks are: this table is
events-only, and the owner column says so.
sort_order isn't declared. The engine writes it from the row's
position because `order` is "sort_order", which is what makes
the first row the one v_events takes the logo and colour from. */
const hostsChild = {
key: "event_hosts",
table: "event_hosts",
owner: { column: "event_id" },
order: "sort_order",
columns: [text("org_id"), text("person_id")],
};
/* ── Organizations ───────────────────────────────────────────── */
const organizations = {
key: "organizations",
table: "organizations",
idColumn: "id",
idKind: "slug",
concurrency: "updated_at",
list: {
columns: [
"id",
"kind",
"name",
"short_name",
"locality",
"state_code",
"is_published",
"is_listed",
"sort_order",
"updated_at",
],
filters: ["kind", "is_published", "is_listed"],
search: ["name", "id", "locality"],
order: "kind, sort_order, name",
},
columns: [
enumeration("kind", ["national", "region", "chapter", "partner"], {
required: true,
}),
text("name", { required: true }),
text("short_name"),
text("tagline"),
text("color"),
text("logo"),
...placeColumns,
bool("is_published"),
bool("is_listed"),
int("sort_order"),
bool("in_timeline"),
],
extensions: [
timelineExtension("organization"),
{
key: "region",
table: "regions",
idColumn: "id",
when: { column: "kind", value: "region" },
columns: [
enumeration("scope", ["domestic", "international", "virtual"], {
required: true,
}),
text("map_note"),
],
},
{
key: "chapter",
table: "chapters",
idColumn: "id",
when: { column: "kind", value: "chapter" },
columns: [text("region_id"), text("meets"), text("started")],
},
],
children: [
linksChild("organization"),
blocksChild("organization"),
{
key: "region_areas",
table: "region_areas",
owner: { column: "region_id" },
when: { column: "kind", value: "region" },
order: "area_code",
columns: [
text("area_code", { required: true }),
real("share"),
enumeration("edge", ["top", "bottom"]),
text("note"),
],
},
],
};
/* ── Events ──────────────────────────────────────────────────── */
/* Column suffixes for the series weekday flags, Sunday first to
match Date#getDay. */
const SERIES_WEEKDAYS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
const events = {
key: "events",
table: "events",
idColumn: "id",
idKind: "slug",
concurrency: "updated_at",
list: {
columns: [
"id",
"title",
"scope_id",
"event_type",
"date_label",
"starts_on",
"status",
"is_published",
"is_listed",
"updated_at",
],
// No host filter: hosts are rows in another table now, and the
// engine's filters are columns on this one. The events a host
// owns are on that host's own page.
filters: ["scope_id", "event_type", "status", "is_published", "is_listed"],
search: ["title", "id", "theme"],
order: "starts_on IS NULL, starts_on DESC, title",
},
columns: [
text("scope_id", { required: true }),
// What kind of gathering, as against scope_id's whose gathering
// it is. Declared required even though the column has a
// DEFAULT: every select renders a blank first option, so without
// it a new event files itself as a retreat while nobody is
// looking. An existing row always loads with its value set, so
// this only ever asks on create.
enumeration(
"event_type",
["retreat", "class", "workshop", "meeting", "other"],
{ required: true },
),
text("title", { required: true }),
text("theme"),
text("tagline"),
date("starts_on"),
date("ends_on"),
text("date_label"),
enumeration("status", ["upcoming", "past", "cancelled"]),
...placeColumns,
text("org_logo"),
text("event_logo"),
text("color"),
text("card_image"),
bool("is_published"),
bool("is_listed"),
bool("in_timeline"),
// A repeating schedule. Columns rather than a side table: the
// schedule is always exactly one per event, and the public view
// is SELECT e.*, so it reaches the site with no join. Ignored
// while is_series is 0. The events table in the schema says
// what each means.
bool("is_series"),
enumeration("series_frequency", ["weekly", "monthly_date", "monthly_weekday"]),
int("series_interval"),
...SERIES_WEEKDAYS.map((day) => bool(`series_${day}`)),
time("series_start_time"),
time("series_end_time"),
int("series_count"),
],
extensions: [timelineExtension("event")],
children: [
hostsChild,
linksChild("event"),
blocksChild("event"),
{
key: "event_people",
table: "event_people",
owner: { column: "event_id" },
order: "sort_order",
columns: [
text("person_id", { required: true }),
enumeration(
"role",
[
"speaker",
"leader",
"facilitator",
"host",
"musician",
"volunteer",
"attendee",
],
{ required: true },
),
text("title"),
bool("is_public"),
],
},
],
};
/* ── People ──────────────────────────────────────────────────── */
const people = {
key: "people",
table: "people",
idColumn: "id",
idKind: "slug",
concurrency: "updated_at",
list: {
columns: [
"id",
"display_name",
"sort_name",
"tagline",
"locality",
"is_published",
"is_listed",
"updated_at",
],
filters: ["is_published", "is_listed"],
search: ["display_name", "sort_name", "id"],
order: "sort_name, display_name",
},
columns: [
text("display_name", { required: true }),
text("sort_name"),
text("pronouns"),
text("tagline"),
text("photo"),
text("bio"),
text("primary_org_id"),
text("public_email"),
text("public_phone"),
text("locality"),
text("state_code"),
text("country"),
text("location_label"),
bool("is_published"),
bool("is_listed"),
],
extensions: [
{
key: "private",
table: "person_private",
idColumn: "person_id",
readRole: "editor", // viewers don't see birth dates, addresses, phones
touch: true, // has its own updated_at with no trigger behind it
columns: [
date("birth_date"),
text("private_email"),
text("private_phone"),
text("address"),
text("notes"),
],
},
],
children: [
linksChild("person"),
blocksChild("person"),
{
key: "affiliations",
table: "affiliations",
owner: { column: "person_id" },
// sort_order is where this person sits on that team, so it
// belongs to the team's editor. reindex: false stops this
// form renumbering by row position; declaring the column
// keeps the team's value intact across a save here.
reindex: false,
order: "org_id, team_id, sort_order",
columns: [
text("org_id", { required: true }),
text("team_id"),
...affiliationRole,
int("sort_order"),
],
},
{
key: "person_awards",
table: "person_awards",
owner: { column: "person_id" },
order: "awarded_on",
columns: [
text("award_id", { required: true }),
text("event_id"),
date("awarded_on"),
text("citation"),
bool("is_public"),
],
},
],
};
/* ── Teams ───────────────────────────────────────────────────── */
// A team belongs to exactly one organization, and affiliations
// point at the pair (team_id, org_id) rather than the team alone.
// Two consequences the form has to live with:
//
// · org_id cannot be changed once anyone is filed under the
// team. The composite foreign key has no ON UPDATE CASCADE, so
// SQLite aborts the UPDATE. That surfaces as a constraint
// error, which is the correct answer: reassign the members
// first.
//
// · deleting a team with members fails the same way, rather than
// quietly detaching them. Emptying the members list first is
// now something the form can do.
const teams = {
key: "teams",
table: "teams",
idColumn: "id",
idKind: "slug",
concurrency: "updated_at",
list: {
columns: ["id", "org_id", "name", "tagline", "is_published", "is_listed", "sort_order", "updated_at"],
filters: ["org_id", "is_published", "is_listed"],
search: ["name", "id", "tagline"],
order: "org_id, sort_order, name",
},
columns: [
text("org_id", { required: true }),
text("name", { required: true }),
text("tagline"),
text("color"),
text("logo"),
bool("is_published"),
bool("is_listed"),
int("sort_order"),
],
children: [
// 'team' is already a valid owner_kind in both polymorphic
// tables, and teams_cleanup drops the rows on delete, so a team
// page comes free.
linksChild("team"),
blocksChild("team"),
{
key: "members",
table: "affiliations",
// org_id is inherited from the team rather than asked for:
// the composite foreign key (team_id, org_id) means a member
// of this team can only belong to this team's organization,
// so a second dropdown could only ever be wrong.
owner: { column: "team_id", inherit: { org_id: "org_id" } },
// Row position is the order they appear on the public site.
// This is the only editor that writes it.
order: "sort_order",
columns: [text("person_id", { required: true }), ...affiliationRole],
},
],
};
/* ── Awards ──────────────────────────────────────────────────── */
// org_id is who gives the award. Nullable, because
// an award can predate any decision about which organization owns
// it, and because person_awards rows must survive the awarding
// org being deleted.
//
// No children: 'award' is not in the owner_kind CHECK on
// content_blocks or links. If awards ever need a page of their
// own, that CHECK is a table rebuild, so decide before adding one
// rather than after.
const awards = {
key: "awards",
table: "awards",
idColumn: "id",
idKind: "slug",
list: {
columns: ["id", "org_id", "name", "description", "is_published", "is_listed", "sort_order"],
filters: ["org_id", "is_published", "is_listed"],
search: ["name", "id", "description"],
order: "org_id, sort_order, name",
},
columns: [
text("org_id"),
text("name", { required: true }),
text("description"),
text("logo"),
bool("is_published"),
bool("is_listed"),
int("sort_order"),
],
};
/* ── Timeline ────────────────────────────────────────────────── */
// The history page's spine, and the only entity whose id the table
// assigns. There is nothing to slug: an entry referencing an event has
// no name of its own, and one gets created every time somebody ticks a
// checkbox. idKind "auto" is what lets createRow skip the id entirely.
//
// ref_kind and ref_id are writable here and only here. The extension on
// events and organizations owns those two columns for rows it created,
// which is why they aren't in timelineFields.
//
// Deleting an entry takes its people with it (ON DELETE CASCADE) and
// nothing points at an entry, so the delete-and-reinsert child engine
// is safe on this one.
const timeline = {
key: "timeline",
table: "timeline_entries",
idColumn: "id",
idKind: "auto",
concurrency: "updated_at",
list: {
columns: [
"id",
"kind",
"ref_kind",
"ref_id",
"occurred_on",
"title",
"is_featured",
"is_published",
"updated_at",
],
filters: ["kind", "ref_kind", "is_featured", "is_published"],
search: ["title", "blurb", "meta", "ref_id"],
// Undated entries sort last rather than first, so a missing date
// reads as something to fix instead of something to scroll past.
order: "occurred_on IS NULL, occurred_on DESC, sort_order",
},
columns: [
enumeration(
"kind",
["milestone", "event", "organization", "award", "people"],
{ required: true },
),
enumeration("ref_kind", ["event", "organization", "award", "person", "team"]),
text("ref_id"),
...timelineFields,
],
children: [
{
key: "people",
table: "timeline_entry_people",
owner: { column: "entry_id" },
order: "sort_order",
columns: [text("person_id", { required: true }), text("note")],
},
],
};
/* ── Front page ──────────────────────────────────────────────────
A singleton: one row, id 'home', seeded by the schema and never
created by the admin. `singleton` tells the engine to refuse create
and delete, and the CHECK on front_page.id is what makes a second
row impossible even without it.
Every collection here is owned by page_id and replaced wholesale.
That is safe for the same reason it is for links and blocks
(nothing has a foreign key into these tables), and paths carry
their actions as a nested collection, the shape content blocks
and their items already use. */
const frontPage = {
key: "front_page",
table: "front_page",
idColumn: "id",
idKind: "slug",
singleton: "home",
concurrency: "updated_at",
list: {
columns: ["id", "headline", "hero_backdrop", "hero_feature", "updated_at"],
filters: [],
search: [],
order: "id",
},
columns: [
enumeration("hero_backdrop", ["brand", "photos"]),
enumeration("hero_feature", ["none", "livestream", "video", "event"]),
text("hero_event_id"),
text("eyebrow"),
text("headline"),
text("subhead"),
text("primary_label"),
url("primary_url"),
text("secondary_label"),
url("secondary_url"),
int("slide_seconds"),
url("livestream_url"),
text("livestream_title"),
url("video_url"),
text("video_title"),
text("countdown_event_id"),
text("countdown_scope_id"),
enumeration("countdown_event_type", ["retreat", "class", "workshop", "meeting", "other"]),
],
children: [
{
key: "slides",
table: "front_page_slides",
owner: { column: "page_id" },
order: "sort_order",
columns: [
text("media", { required: true }),
text("alt"),
text("caption"),
url("link_url"),
],
},
{
key: "sections",
table: "front_page_sections",
owner: { column: "page_id" },
order: "sort_order",
columns: [
enumeration(
"section",
["countdown", "retreats", "calendar", "stats", "timeline", "connect", "featured"],
{ required: true },
),
text("title"),
text("blurb"),
bool("is_hidden"),
],
},
{
key: "stats",
table: "front_page_stats",
owner: { column: "page_id" },
order: "sort_order",
columns: [
text("label", { required: true }),
enumeration("source", [
"manual",
"years_since",
"regions",
"chapters",
"partners",
"events_held",
"retreats_held",
"people",
"awards_given",
]),
text("value"),
text("suffix"),
text("note"),
],
},
featuredCardsChild("front_page"),
{
key: "paths",
table: "front_page_paths",
owner: { column: "page_id" },
order: "sort_order",
columns: [text("label", { required: true }), text("icon"), text("blurb")],
children: [
{
key: "actions",
table: "front_page_path_actions",
owner: { column: "path_id" },
order: "sort_order",
columns: [
text("label", { required: true }),
text("description"),
url("url", { required: true }),
],
},
],
},
],
};
/* ── Blog (031_blog.sql) ─────────────────────────────────────────
Posts of our own, with a content-block body and people as
authors, and the Community page's blog section, a singleton like
the front page. The section's community posts are featured cards
owned by 'community_page'. ─────────────────────────────────── */
const blogPosts = {
key: "blog_posts",
table: "blog_posts",
idColumn: "id",
idKind: "slug",
concurrency: "updated_at",
list: {
columns: ["id", "title", "published_on", "tags", "is_published", "is_listed", "updated_at"],
filters: ["is_published", "is_listed"],
search: ["title", "id", "tags"],
order: "published_on IS NULL, published_on DESC, title",
},
columns: [
text("title", { required: true }),
text("excerpt"),
text("cover_image"),
text("cover_alt"),
date("published_on"),
text("tags"),
text("guest_author"),
text("guest_photo"),
bool("is_published"),
bool("is_listed"),
],
children: [
{
key: "authors",
table: "blog_post_authors",
owner: { column: "post_id" },
order: "sort_order",
columns: [text("person_id", { required: true })],
},
blocksChild("blog_post"),
],
};
const communityPage = {
key: "community_page",
table: "community_page",
idColumn: "id",
idKind: "slug",
singleton: "community",
concurrency: "updated_at",
list: {
columns: ["id", "blog_title", "updated_at"],
filters: [],
search: [],
order: "id",
},
columns: [
text("blog_title"),
text("blog_blurb"),
text("internal_title"),
int("internal_slots"),
text("external_title"),
int("external_slots"),
url("external_url"),
text("external_label"),
],
children: [
{
key: "pinned_posts",
table: "community_page_pinned_posts",
owner: { column: "page_id" },
order: "sort_order",
columns: [text("post_id", { required: true })],
},
featuredCardsChild("community_page"),
{
key: "feeds",
table: "community_page_feeds",
owner: { column: "page_id" },
order: "sort_order",
columns: [url("url", { required: true }), text("label")],
},
],
};
/* ── 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
over site.json. */
const siteSettings = {
key: "site_settings",
table: "site_settings",
idColumn: "id",
idKind: "slug",
singleton: "site",
concurrency: "updated_at",
writeRole: "superadmin",
list: {
columns: ["id", "site_name", "updated_at"],
filters: [],
search: [],
order: "id",
},
columns: [
text("site_name"),
text("description"),
text("preview_image"),
text("favicon"),
text("apple_touch_icon"),
enumeration("indexing", ["on", "off"]),
text("privacy_email"),
],
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",
owner: { column: "settings_id" },
order: "sort_order",
columns: [
enumeration("token", THEME_TOKENS, { required: true }),
text("light"),
text("dark"),
],
},
],
// Refuses a palette that would make text hard to read (theme.js).
check: checkTheme,
};
export const ENTITIES = { export const ENTITIES = {
organizations, organizations,

View file

@ -0,0 +1,36 @@
import { text, int, bool } from "./columns.js";
/* ── Awards ──────────────────────────────────────────────────── */
// org_id is who gives the award. Nullable, because
// an award can predate any decision about which organization owns
// it, and because person_awards rows must survive the awarding
// org being deleted.
//
// No children: 'award' is not in the owner_kind CHECK on
// content_blocks or links. If awards ever need a page of their
// own, that CHECK is a table rebuild, so decide before adding one
// rather than after.
export const awards = {
key: "awards",
table: "awards",
idColumn: "id",
idKind: "slug",
list: {
columns: ["id", "org_id", "name", "description", "is_published", "is_listed", "sort_order"],
filters: ["org_id", "is_published", "is_listed"],
search: ["name", "id", "description"],
order: "org_id, sort_order, name",
},
columns: [
text("org_id"),
text("name", { required: true }),
text("description"),
text("logo"),
bool("is_published"),
bool("is_listed"),
int("sort_order"),
],
};

View file

@ -0,0 +1,92 @@
import { text, url, int, bool, date, featuredCardsChild, blocksChild } from "./columns.js";
/* ── Blog (031_blog.sql) ─────────────────────────────────────────
Posts of our own, with a content-block body and people as
authors, and the Community page's blog section, a singleton like
the front page. The section's community posts are featured cards
owned by 'community_page'. ─────────────────────────────────── */
export const blogPosts = {
key: "blog_posts",
table: "blog_posts",
idColumn: "id",
idKind: "slug",
concurrency: "updated_at",
list: {
columns: ["id", "title", "published_on", "tags", "is_published", "is_listed", "updated_at"],
filters: ["is_published", "is_listed"],
search: ["title", "id", "tags"],
order: "published_on IS NULL, published_on DESC, title",
},
columns: [
text("title", { required: true }),
text("excerpt"),
text("cover_image"),
text("cover_alt"),
date("published_on"),
text("tags"),
text("guest_author"),
text("guest_photo"),
bool("is_published"),
bool("is_listed"),
],
children: [
{
key: "authors",
table: "blog_post_authors",
owner: { column: "post_id" },
order: "sort_order",
columns: [text("person_id", { required: true })],
},
blocksChild("blog_post"),
],
};
export const communityPage = {
key: "community_page",
table: "community_page",
idColumn: "id",
idKind: "slug",
singleton: "community",
concurrency: "updated_at",
list: {
columns: ["id", "blog_title", "updated_at"],
filters: [],
search: [],
order: "id",
},
columns: [
text("blog_title"),
text("blog_blurb"),
text("internal_title"),
int("internal_slots"),
text("external_title"),
int("external_slots"),
url("external_url"),
text("external_label"),
],
children: [
{
key: "pinned_posts",
table: "community_page_pinned_posts",
owner: { column: "page_id" },
order: "sort_order",
columns: [text("post_id", { required: true })],
},
featuredCardsChild("community_page"),
{
key: "feeds",
table: "community_page_feeds",
owner: { column: "page_id" },
order: "sort_order",
columns: [url("url", { required: true }), text("label")],
},
],
};

View file

@ -0,0 +1,202 @@
/* Column helpers, and the field sets and child collections several
entities share. The descriptor anatomy is in ../admin-schema.js. */
/* ── Column helpers ──────────────────────────────────────────── */
export const text = (name, opts = {}) => ({ name, type: "text", ...opts });
// Text that is a link: refuses javascript:, data: and other schemes.
export const url = (name, opts = {}) => ({ name, type: "url", ...opts });
export const int = (name, opts = {}) => ({ name, type: "int", ...opts });
export const real = (name, opts = {}) => ({ name, type: "real", ...opts });
export const bool = (name, opts = {}) => ({ name, type: "bool", ...opts });
export const date = (name, opts = {}) => ({ name, type: "date", ...opts });
export const time = (name, opts = {}) => ({ name, type: "time", ...opts });
export const enumeration = (name, values, opts = {}) => ({
name,
type: "enum",
values,
...opts,
});
/* Place columns shared by organizations and events, in schema order. */
export const placeColumns = [
text("venue"),
text("address"),
text("locality"),
text("state_code"),
text("country"),
text("location_label"),
real("latitude"),
real("longitude"),
bool("is_online"),
];
/* The affiliation's own fields, minus whichever end owns the row.
Both editors write the same shape so neither loses the other's
values on save. */
export const affiliationRole = [
text("title"),
enumeration("role", ["lead", "board", "staff", "volunteer", "member"], {
required: true,
}),
bool("is_owner"),
date("started_on"),
date("ended_on"),
bool("is_public"),
];
/* The editable half of a timeline entry, shared by the standalone
editor and by the in_timeline extension on events and organizations.
occurred_on is text, not date. "2012" and "2025-07" are legitimate
values (a backfilled entry often knows the year and nothing more),
and the date coercion would reject both. `precision` is what says how
much of it to believe. */
export const timelineFields = [
text("occurred_on"),
enumeration("precision", ["year", "month", "day"]),
text("title"),
text("blurb"),
text("meta"),
url("link_url"),
bool("is_featured"),
bool("is_published"),
int("sort_order"),
];
/* The extension that the in_timeline checkbox drives. Ticked, the row
is upserted; unticked, writeExtensions deletes it. Both happen in the
parent's transaction, so the flag and the row cannot disagree.
The conflict target is the UNIQUE (ref_kind, ref_id) constraint
on timeline_entries, which is also what stops a second save creating a
duplicate instead of updating the first. */
export const timelineExtension = (refKind) => ({
key: "timeline",
table: "timeline_entries",
owner: { column: "ref_id", kindColumn: "ref_kind", kindValue: refKind },
conflict: ["ref_kind", "ref_id"],
when: { column: "in_timeline", value: 1 },
columns: [
// Fixed for this end: an event's entry is always an event entry.
// Declared as a default rather than a form field so the column is
// written without asking.
enumeration(
"kind",
["milestone", "event", "organization", "award", "people"],
{ default: refKind === "organization" ? "organization" : refKind },
),
...timelineFields,
],
});
/* Featured cards (030_featured_cards.sql): polymorphic like links,
so the Community blog can own a set too. */
export const featuredCardsChild = (ownerKind) => ({
key: "featured_cards",
table: "featured_cards",
owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind },
order: "sort_order",
columns: [
enumeration("kind", ["record", "link", "video"], { required: true }),
enumeration("ref_kind", ["event", "organization", "person", "team", "award"]),
text("ref_id"),
url("url"),
text("eyebrow"),
text("title"),
text("blurb"),
text("image"),
],
});
/* The two polymorphic collections, parameterised by owner_kind. */
export const linksChild = (ownerKind) => ({
key: "links",
table: "links",
owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind },
order: "sort_order",
columns: [
enumeration("kind", ["action", "social", "website", "email"], {
required: true,
}),
text("platform"),
text("label", { required: true }),
url("url", { required: true }),
bool("is_primary"),
],
});
export const blocksChild = (ownerKind) => ({
key: "content_blocks",
table: "content_blocks",
owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind },
order: "sort_order",
columns: [
enumeration("slot", ["card", "body"], { required: true }),
enumeration(
"type",
[
"heading",
"subheading",
"paragraph",
"list",
"links",
"quote",
"image",
"divider",
"video",
"button",
"callout",
"schedule",
],
{ required: true },
),
text("text"),
text("media"),
url("href"),
text("alt"),
text("cite"),
],
children: [
{
key: "items",
table: "content_block_items",
owner: { column: "block_id" },
order: "sort_order",
columns: [
text("text", { required: true }),
text("detail"),
url("url"),
// Schedule entries only (034_schedule_block.sql).
text("day"),
text("time"),
text("location"),
text("person_id"),
text("description"),
text("media"),
text("media_alt"),
text("map"),
],
},
],
});
/* Hosts. One row is one host, ordered, each either an organization
or a person. The CHECK on event_hosts rejects both and the blank
filter drops neither, so the only bad row that reaches SQLite is
one with both selects filled, and that comes back keyed to the
row like any other field error.
Not parameterised the way links and blocks are: this table is
events-only, and the owner column says so.
sort_order isn't declared. The engine writes it from the row's
position because `order` is "sort_order", which is what makes
the first row the one v_events takes the logo and colour from. */
export const hostsChild = {
key: "event_hosts",
table: "event_hosts",
owner: { column: "event_id" },
order: "sort_order",
columns: [text("org_id"), text("person_id")],
};

View file

@ -0,0 +1,113 @@
import { text, int, bool, date, time, enumeration, placeColumns, timelineExtension, linksChild, blocksChild, hostsChild } from "./columns.js";
/* ── Events ──────────────────────────────────────────────────── */
/* Column suffixes for the series weekday flags, Sunday first to
match Date#getDay. */
const SERIES_WEEKDAYS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
export const events = {
key: "events",
table: "events",
idColumn: "id",
idKind: "slug",
concurrency: "updated_at",
list: {
columns: [
"id",
"title",
"scope_id",
"event_type",
"date_label",
"starts_on",
"status",
"is_published",
"is_listed",
"updated_at",
],
// No host filter: hosts are rows in another table now, and the
// engine's filters are columns on this one. The events a host
// owns are on that host's own page.
filters: ["scope_id", "event_type", "status", "is_published", "is_listed"],
search: ["title", "id", "theme"],
order: "starts_on IS NULL, starts_on DESC, title",
},
columns: [
text("scope_id", { required: true }),
// What kind of gathering, as against scope_id's whose gathering
// it is. Declared required even though the column has a
// DEFAULT: every select renders a blank first option, so without
// it a new event files itself as a retreat while nobody is
// looking. An existing row always loads with its value set, so
// this only ever asks on create.
enumeration(
"event_type",
["retreat", "class", "workshop", "meeting", "other"],
{ required: true },
),
text("title", { required: true }),
text("theme"),
text("tagline"),
date("starts_on"),
date("ends_on"),
text("date_label"),
enumeration("status", ["upcoming", "past", "cancelled"]),
...placeColumns,
text("org_logo"),
text("event_logo"),
text("color"),
text("card_image"),
bool("is_published"),
bool("is_listed"),
bool("in_timeline"),
// A repeating schedule. Columns rather than a side table: the
// schedule is always exactly one per event, and the public view
// is SELECT e.*, so it reaches the site with no join. Ignored
// while is_series is 0. The events table in the schema says
// what each means.
bool("is_series"),
enumeration("series_frequency", ["weekly", "monthly_date", "monthly_weekday"]),
int("series_interval"),
...SERIES_WEEKDAYS.map((day) => bool(`series_${day}`)),
time("series_start_time"),
time("series_end_time"),
int("series_count"),
],
extensions: [timelineExtension("event")],
children: [
hostsChild,
linksChild("event"),
blocksChild("event"),
{
key: "event_people",
table: "event_people",
owner: { column: "event_id" },
order: "sort_order",
columns: [
text("person_id", { required: true }),
enumeration(
"role",
[
"speaker",
"leader",
"facilitator",
"host",
"musician",
"volunteer",
"attendee",
],
{ required: true },
),
text("title"),
bool("is_public"),
],
},
],
};

View file

@ -0,0 +1,126 @@
import { text, url, int, bool, enumeration, featuredCardsChild } from "./columns.js";
/* ── Front page ──────────────────────────────────────────────────
A singleton: one row, id 'home', seeded by the schema and never
created by the admin. `singleton` tells the engine to refuse create
and delete, and the CHECK on front_page.id is what makes a second
row impossible even without it.
Every collection here is owned by page_id and replaced wholesale.
That is safe for the same reason it is for links and blocks
(nothing has a foreign key into these tables), and paths carry
their actions as a nested collection, the shape content blocks
and their items already use. */
export const frontPage = {
key: "front_page",
table: "front_page",
idColumn: "id",
idKind: "slug",
singleton: "home",
concurrency: "updated_at",
list: {
columns: ["id", "headline", "hero_backdrop", "hero_feature", "updated_at"],
filters: [],
search: [],
order: "id",
},
columns: [
enumeration("hero_backdrop", ["brand", "photos"]),
enumeration("hero_feature", ["none", "livestream", "video", "event"]),
text("hero_event_id"),
text("eyebrow"),
text("headline"),
text("subhead"),
text("primary_label"),
url("primary_url"),
text("secondary_label"),
url("secondary_url"),
int("slide_seconds"),
url("livestream_url"),
text("livestream_title"),
url("video_url"),
text("video_title"),
text("countdown_event_id"),
text("countdown_scope_id"),
enumeration("countdown_event_type", ["retreat", "class", "workshop", "meeting", "other"]),
],
children: [
{
key: "slides",
table: "front_page_slides",
owner: { column: "page_id" },
order: "sort_order",
columns: [
text("media", { required: true }),
text("alt"),
text("caption"),
url("link_url"),
],
},
{
key: "sections",
table: "front_page_sections",
owner: { column: "page_id" },
order: "sort_order",
columns: [
enumeration(
"section",
["countdown", "retreats", "calendar", "stats", "timeline", "connect", "featured"],
{ required: true },
),
text("title"),
text("blurb"),
bool("is_hidden"),
],
},
{
key: "stats",
table: "front_page_stats",
owner: { column: "page_id" },
order: "sort_order",
columns: [
text("label", { required: true }),
enumeration("source", [
"manual",
"years_since",
"regions",
"chapters",
"partners",
"events_held",
"retreats_held",
"people",
"awards_given",
]),
text("value"),
text("suffix"),
text("note"),
],
},
featuredCardsChild("front_page"),
{
key: "paths",
table: "front_page_paths",
owner: { column: "page_id" },
order: "sort_order",
columns: [text("label", { required: true }), text("icon"), text("blurb")],
children: [
{
key: "actions",
table: "front_page_path_actions",
owner: { column: "path_id" },
order: "sort_order",
columns: [
text("label", { required: true }),
text("description"),
url("url", { required: true }),
],
},
],
},
],
};

View file

@ -0,0 +1,86 @@
import { text, int, real, bool, enumeration, placeColumns, timelineExtension, linksChild, blocksChild } from "./columns.js";
/* ── Organizations ───────────────────────────────────────────── */
export const organizations = {
key: "organizations",
table: "organizations",
idColumn: "id",
idKind: "slug",
concurrency: "updated_at",
list: {
columns: [
"id",
"kind",
"name",
"short_name",
"locality",
"state_code",
"is_published",
"is_listed",
"sort_order",
"updated_at",
],
filters: ["kind", "is_published", "is_listed"],
search: ["name", "id", "locality"],
order: "kind, sort_order, name",
},
columns: [
enumeration("kind", ["national", "region", "chapter", "partner"], {
required: true,
}),
text("name", { required: true }),
text("short_name"),
text("tagline"),
text("color"),
text("logo"),
...placeColumns,
bool("is_published"),
bool("is_listed"),
int("sort_order"),
bool("in_timeline"),
],
extensions: [
timelineExtension("organization"),
{
key: "region",
table: "regions",
idColumn: "id",
when: { column: "kind", value: "region" },
columns: [
enumeration("scope", ["domestic", "international", "virtual"], {
required: true,
}),
text("map_note"),
],
},
{
key: "chapter",
table: "chapters",
idColumn: "id",
when: { column: "kind", value: "chapter" },
columns: [text("region_id"), text("meets"), text("started")],
},
],
children: [
linksChild("organization"),
blocksChild("organization"),
{
key: "region_areas",
table: "region_areas",
owner: { column: "region_id" },
when: { column: "kind", value: "region" },
order: "area_code",
columns: [
text("area_code", { required: true }),
real("share"),
enumeration("edge", ["top", "bottom"]),
text("note"),
],
},
],
};

View file

@ -0,0 +1,99 @@
import { text, int, bool, date, affiliationRole, linksChild, blocksChild } from "./columns.js";
/* ── People ──────────────────────────────────────────────────── */
export const people = {
key: "people",
table: "people",
idColumn: "id",
idKind: "slug",
concurrency: "updated_at",
list: {
columns: [
"id",
"display_name",
"sort_name",
"tagline",
"locality",
"is_published",
"is_listed",
"updated_at",
],
filters: ["is_published", "is_listed"],
search: ["display_name", "sort_name", "id"],
order: "sort_name, display_name",
},
columns: [
text("display_name", { required: true }),
text("sort_name"),
text("pronouns"),
text("tagline"),
text("photo"),
text("bio"),
text("primary_org_id"),
text("public_email"),
text("public_phone"),
text("locality"),
text("state_code"),
text("country"),
text("location_label"),
bool("is_published"),
bool("is_listed"),
],
extensions: [
{
key: "private",
table: "person_private",
idColumn: "person_id",
readRole: "editor", // viewers don't see birth dates, addresses, phones
touch: true, // has its own updated_at with no trigger behind it
columns: [
date("birth_date"),
text("private_email"),
text("private_phone"),
text("address"),
text("notes"),
],
},
],
children: [
linksChild("person"),
blocksChild("person"),
{
key: "affiliations",
table: "affiliations",
owner: { column: "person_id" },
// sort_order is where this person sits on that team, so it
// belongs to the team's editor. reindex: false stops this
// form renumbering by row position; declaring the column
// keeps the team's value intact across a save here.
reindex: false,
order: "org_id, team_id, sort_order",
columns: [
text("org_id", { required: true }),
text("team_id"),
...affiliationRole,
int("sort_order"),
],
},
{
key: "person_awards",
table: "person_awards",
owner: { column: "person_id" },
order: "awarded_on",
columns: [
text("award_id", { required: true }),
text("event_id"),
date("awarded_on"),
text("citation"),
bool("is_public"),
],
},
],
};

View file

@ -0,0 +1,58 @@
import { THEME_TOKENS, checkTheme } from "../theme.js";
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
over site.json. */
export const siteSettings = {
key: "site_settings",
table: "site_settings",
idColumn: "id",
idKind: "slug",
singleton: "site",
concurrency: "updated_at",
writeRole: "superadmin",
list: {
columns: ["id", "site_name", "updated_at"],
filters: [],
search: [],
order: "id",
},
columns: [
text("site_name"),
text("description"),
text("preview_image"),
text("favicon"),
text("apple_touch_icon"),
enumeration("indexing", ["on", "off"]),
text("privacy_email"),
],
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",
owner: { column: "settings_id" },
order: "sort_order",
columns: [
enumeration("token", THEME_TOKENS, { required: true }),
text("light"),
text("dark"),
],
},
],
// Refuses a palette that would make text hard to read (theme.js).
check: checkTheme,
};

View file

@ -0,0 +1,66 @@
import { text, int, bool, affiliationRole, linksChild, blocksChild } from "./columns.js";
/* ── Teams ───────────────────────────────────────────────────── */
// A team belongs to exactly one organization, and affiliations
// point at the pair (team_id, org_id) rather than the team alone.
// Two consequences the form has to live with:
//
// · org_id cannot be changed once anyone is filed under the
// team. The composite foreign key has no ON UPDATE CASCADE, so
// SQLite aborts the UPDATE. That surfaces as a constraint
// error, which is the correct answer: reassign the members
// first.
//
// · deleting a team with members fails the same way, rather than
// quietly detaching them. Emptying the members list first is
// now something the form can do.
export const teams = {
key: "teams",
table: "teams",
idColumn: "id",
idKind: "slug",
concurrency: "updated_at",
list: {
columns: ["id", "org_id", "name", "tagline", "is_published", "is_listed", "sort_order", "updated_at"],
filters: ["org_id", "is_published", "is_listed"],
search: ["name", "id", "tagline"],
order: "org_id, sort_order, name",
},
columns: [
text("org_id", { required: true }),
text("name", { required: true }),
text("tagline"),
text("color"),
text("logo"),
bool("is_published"),
bool("is_listed"),
int("sort_order"),
],
children: [
// 'team' is already a valid owner_kind in both polymorphic
// tables, and teams_cleanup drops the rows on delete, so a team
// page comes free.
linksChild("team"),
blocksChild("team"),
{
key: "members",
table: "affiliations",
// org_id is inherited from the team rather than asked for:
// the composite foreign key (team_id, org_id) means a member
// of this team can only belong to this team's organization,
// so a second dropdown could only ever be wrong.
owner: { column: "team_id", inherit: { org_id: "org_id" } },
// Row position is the order they appear on the public site.
// This is the only editor that writes it.
order: "sort_order",
columns: [text("person_id", { required: true }), ...affiliationRole],
},
],
};

View file

@ -0,0 +1,63 @@
import { text, date, time, enumeration, timelineFields } from "./columns.js";
/* ── Timeline ────────────────────────────────────────────────── */
// The history page's spine, and the only entity whose id the table
// assigns. There is nothing to slug: an entry referencing an event has
// no name of its own, and one gets created every time somebody ticks a
// checkbox. idKind "auto" is what lets createRow skip the id entirely.
//
// ref_kind and ref_id are writable here and only here. The extension on
// events and organizations owns those two columns for rows it created,
// which is why they aren't in timelineFields.
//
// Deleting an entry takes its people with it (ON DELETE CASCADE) and
// nothing points at an entry, so the delete-and-reinsert child engine
// is safe on this one.
export const timeline = {
key: "timeline",
table: "timeline_entries",
idColumn: "id",
idKind: "auto",
concurrency: "updated_at",
list: {
columns: [
"id",
"kind",
"ref_kind",
"ref_id",
"occurred_on",
"title",
"is_featured",
"is_published",
"updated_at",
],
filters: ["kind", "ref_kind", "is_featured", "is_published"],
search: ["title", "blurb", "meta", "ref_id"],
// Undated entries sort last rather than first, so a missing date
// reads as something to fix instead of something to scroll past.
order: "occurred_on IS NULL, occurred_on DESC, sort_order",
},
columns: [
enumeration(
"kind",
["milestone", "event", "organization", "award", "people"],
{ required: true },
),
enumeration("ref_kind", ["event", "organization", "award", "person", "team"]),
text("ref_id"),
...timelineFields,
],
children: [
{
key: "people",
table: "timeline_entry_people",
owner: { column: "entry_id" },
order: "sort_order",
columns: [text("person_id", { required: true }), text("note")],
},
],
};

View file

@ -28,12 +28,12 @@ import {
updateRow, updateRow,
deleteRow, deleteRow,
} from "../admin-crud.js"; } from "../admin-crud.js";
import { NO_STORE } from "../shape.js";
const entities = new Hono(); const entities = new Hono();
entities.use("*", requireAuth); entities.use("*", requireAuth);
const NO_STORE = { "Cache-Control": "no-store" };
function entityOr404(c) { function entityOr404(c) {
const name = c.req.param("entity"); const name = c.req.param("entity");

View file

@ -10,12 +10,12 @@
import { Hono } from "hono"; import { Hono } from "hono";
import { requireAuth, requireRole } from "../auth.js"; import { requireAuth, requireRole } from "../auth.js";
import { NO_STORE } from "../shape.js";
const admin = new Hono(); const admin = new Hono();
admin.use("*", requireAuth); admin.use("*", requireAuth);
const NO_STORE = { "Cache-Control": "no-store" };
const STATUSES = ["new", "read", "actioned", "archived", "spam"]; const STATUSES = ["new", "read", "actioned", "archived", "spam"];
const MAX_LIMIT = 200; const MAX_LIMIT = 200;

View file

@ -42,6 +42,7 @@ import {
} from "../auth.js"; } from "../auth.js";
import { GoogleLoginError, finishLogin, googleConfig, startLogin } from "../googleAuth.js"; import { GoogleLoginError, finishLogin, googleConfig, startLogin } from "../googleAuth.js";
import { failureLimit } from "../rateLimit.js"; import { failureLimit } from "../rateLimit.js";
import { NO_STORE } from "../shape.js";
// On top of the per-IP limit where /login is mounted: five wrong // On top of the per-IP limit where /login is mounted: five wrong
// passwords for one email in 15 minutes locks that email for the // passwords for one email in 15 minutes locks that email for the
@ -54,7 +55,6 @@ const auth = new Hono();
// so both paths cost the same. Computed once at import. // so both paths cost the same. Computed once at import.
const DUMMY_HASH = hashPassword("this password is never correct"); const DUMMY_HASH = hashPassword("this password is never correct");
const NO_STORE = { "Cache-Control": "no-store" };
auth.post("/login", async (c) => { auth.post("/login", async (c) => {
let body; let body;

View file

@ -39,13 +39,13 @@ import {
saveToLibrary, saveToLibrary,
toolVersions, toolVersions,
} from "../clips.js"; } from "../clips.js";
import { NO_STORE } from "../shape.js";
const clips = new Hono(); const clips = new Hono();
clips.use("/clips", requireAuth, requireRole("admin")); clips.use("/clips", requireAuth, requireRole("admin"));
clips.use("/clips/*", requireAuth, requireRole("admin")); clips.use("/clips/*", requireAuth, requireRole("admin"));
const NO_STORE = { "Cache-Control": "no-store" };
const RECENT = 50; const RECENT = 50;

View file

@ -57,6 +57,7 @@ import {
json, json,
loadBlocks, loadBlocks,
loadLinks, loadLinks,
loadOwned,
marks, marks,
paragraphs, paragraphs,
shapeSeries, shapeSeries,
@ -492,9 +493,7 @@ content.get("/events/:id", (c) => {
if (!row) return c.json({ error: "No such event" }, 404); if (!row) return c.json({ error: "No such event" }, 404);
const links = loadLinks(db, "event", [id]).get(id) ?? []; const { links, cards, body } = loadOwned(db, "event", id);
const cards = loadBlocks(db, "event", [id], "card").get(id) ?? [];
const body = loadBlocks(db, "event", [id], "body").get(id) ?? [];
const hosts = loadHosts(db, [id]).get(id) ?? []; const hosts = loadHosts(db, [id]).get(id) ?? [];
const people = db const people = db
@ -602,9 +601,7 @@ content.get("/organizations/:id", (c) => {
if (!row) return c.json({ error: "No such organization" }, 404); if (!row) return c.json({ error: "No such organization" }, 404);
const links = loadLinks(db, "organization", [id]).get(id) ?? []; const { links, cards, body } = loadOwned(db, "organization", id);
const cards = loadBlocks(db, "organization", [id], "card").get(id) ?? [];
const body = loadBlocks(db, "organization", [id], "body").get(id) ?? [];
const organization = shapeOrganization(row, links, cards, body); const organization = shapeOrganization(row, links, cards, body);
const one = [organization]; const one = [organization];
@ -684,9 +681,7 @@ content.get("/teams/:id", (c) => {
if (!row) return c.json({ error: "No such team" }, 404); if (!row) return c.json({ error: "No such team" }, 404);
const links = loadLinks(db, "team", [id]).get(id) ?? []; const { links, cards, body } = loadOwned(db, "team", id);
const cards = loadBlocks(db, "team", [id], "card").get(id) ?? [];
const body = loadBlocks(db, "team", [id], "body").get(id) ?? [];
return json(c, { team: { ...shapeTeam(row, links, cards), blocks: body } }); return json(c, { team: { ...shapeTeam(row, links, cards), blocks: body } });
}); });

View file

@ -37,12 +37,12 @@ import {
store, store,
} from "../media.js"; } from "../media.js";
import { fetchImage, previewLink } from "../linkPreview.js"; import { fetchImage, previewLink } from "../linkPreview.js";
import { NO_STORE } from "../shape.js";
const media = new Hono(); const media = new Hono();
media.use("*", requireAuth); media.use("*", requireAuth);
const NO_STORE = { "Cache-Control": "no-store" };
const MAX_LIST = 500; const MAX_LIST = 500;

View file

@ -36,7 +36,7 @@ import { fileURLToPath } from "node:url";
import { Hono } from "hono"; import { Hono } from "hono";
import { metaFor, renderPage, robotsTxt, siteFor, sitemap } from "../pageMeta.js"; import { metaFor, renderPage, robotsTxt, siteFor, sitemap } from "../pageMeta.js";
import { CACHE } from "../shape.js"; import { CACHE, NO_STORE } from "../shape.js";
const here = path.dirname(fileURLToPath(import.meta.url)); const here = path.dirname(fileURLToPath(import.meta.url));
@ -117,7 +117,7 @@ pages.get("*", (c, next) => {
`pages: serving ${pathname} without its metadata: ${err.message}` + `pages: serving ${pathname} without its metadata: ${err.message}` +
(err.code === "ENOENT" ? " (set SITE_CONFIG to the deployed site.json)" : ""), (err.code === "ENOENT" ? " (set SITE_CONFIG to the deployed site.json)" : ""),
); );
return c.html(html, 200, { "Cache-Control": "no-store" }); return c.html(html, 200, NO_STORE);
} }
// no-cache: a browser may keep the page but asks again each time. // no-cache: a browser may keep the page but asks again each time.

View file

@ -26,13 +26,13 @@
import { Hono } from "hono"; import { Hono } from "hono";
import { requireAuth, requireRole, ROLES } from "../auth.js"; import { requireAuth, requireRole, ROLES } from "../auth.js";
import { tx } from "../db.js"; import { tx } from "../db.js";
import { NO_STORE } from "../shape.js";
const panel = new Hono(); const panel = new Hono();
panel.use("*", requireAuth); panel.use("*", requireAuth);
panel.use("*", requireRole("superadmin")); panel.use("*", requireRole("superadmin"));
const NO_STORE = { "Cache-Control": "no-store" };
/* The counts on the overview. Table name is a literal from this /* The counts on the overview. Table name is a literal from this
list, never anything off the wire. */ list, never anything off the wire. */

View file

@ -21,7 +21,7 @@
import { Hono } from "hono"; import { Hono } from "hono";
import { asBool, json, loadBlocks, loadLinks, marks, paragraphs, splitLinks } from "../shape.js"; import { asBool, json, loadOwned, marks, paragraphs, splitLinks } from "../shape.js";
const people = new Hono(); const people = new Hono();
@ -175,9 +175,7 @@ people.get("/people/:id", (c) => {
if (!row) return c.json({ error: "No such person" }, 404); if (!row) return c.json({ error: "No such person" }, 404);
const links = loadLinks(db, "person", [id]).get(id) ?? []; const { links, cards, body } = loadOwned(db, "person", id);
const cards = loadBlocks(db, "person", [id], "card").get(id) ?? [];
const body = loadBlocks(db, "person", [id], "body").get(id) ?? [];
const { actions, socials, website, instagram } = splitLinks(links); const { actions, socials, website, instagram } = splitLinks(links);
// Current first, then most recently ended. Within each, the same // Current first, then most recently ended. Within each, the same

View file

@ -302,10 +302,23 @@ export function loadFeaturedCards(db, ownerKind, ownerId) {
export { asBool }; export { asBool };
/* One record's links, card blocks and body blocks: what every detail
page sends beside the record itself. */
export function loadOwned(db, ownerKind, id) {
return {
links: loadLinks(db, ownerKind, [id]).get(id) ?? [],
cards: loadBlocks(db, ownerKind, [id], "card").get(id) ?? [],
body: loadBlocks(db, ownerKind, [id], "body").get(id) ?? [],
};
}
/* Public reads may be cached a minute, and served a little stale /* Public reads may be cached a minute, and served a little stale
while a fresh copy is fetched. json() sends a body with it. */ while a fresh copy is fetched. json() sends a body with it. */
export const CACHE = "public, max-age=60, stale-while-revalidate=300"; export const CACHE = "public, max-age=60, stale-while-revalidate=300";
export const json = (c, body) => c.json(body, 200, { "Cache-Control": CACHE }); export const json = (c, body) => c.json(body, 200, { "Cache-Control": CACHE });
// Admin reads and anything personal: never kept by a browser or proxy.
export const NO_STORE = { "Cache-Control": "no-store" };
// "?,?,?" for an IN (...) list of n values. // "?,?,?" for an IN (...) list of n values.
export const marks = (n) => Array(n).fill("?").join(","); export const marks = (n) => Array(n).fill("?").join(",");

View file

@ -4,9 +4,9 @@
The admin's palette (Panel → Site settings → Colours, table The admin's palette (Panel → Site settings → Colours, table
site_setting_colors) over the site's own colour tokens. site_setting_colors) over the site's own colour tokens.
THEME_DEFAULTS must match @theme and the dark block in The defaults are THEME_DEFAULTS (themeDefaults.js), which the
src/index.css: the same tokens, the same light and dark values. build checks against src/index.css. A blank override keeps the
A blank override keeps the default. default.
themeCss() is written into every page's <head> (pageMeta.js). themeCss() is written into every page's <head> (pageMeta.js).
It goes into the same cascade layers as index.css (theme for It goes into the same cascade layers as index.css (theme for
@ -20,22 +20,9 @@
═══════════════════════════════════════════════════════════════ */ ═══════════════════════════════════════════════════════════════ */
import { HttpError } from "./admin-crud.js"; import { HttpError } from "./admin-crud.js";
import { THEME_DEFAULTS } from "./themeDefaults.js";
// light dark export { THEME_DEFAULTS };
export const THEME_DEFAULTS = {
ink: ["#073d4a", "#eaf6f8"],
body: ["#26454c", "#cde0e4"],
muted: ["#4a6b72", "#9fb9bf"],
link: ["#0f7183", "#5ccbdc"],
brand: ["#138ba0", "#2aa7bc"],
action: ["#0f7183", "#0f7183"],
"action-hover": ["#0b5c6a", "#0b5c6a"],
surface: ["#ffffff", "#0c1d21"],
tint: ["#eef9fb", "#11292e"],
"tint-soft": ["#f6fbfc", "#0f2428"],
danger: ["#b3261e", "#ff8a80"],
"danger-tint": ["#fdf3f2", "#3b1714"],
};
export const THEME_TOKENS = Object.keys(THEME_DEFAULTS); export const THEME_TOKENS = Object.keys(THEME_DEFAULTS);

View file

@ -0,0 +1,29 @@
/* ═══════════════════════════════════════════════════════════════
THEME DEFAULTS
The site's own colour tokens, light and dark: the one list both
the server (theme.js: contrast check, overrides) and the admin
(Site settings → Colours: defaults shown) read. No imports, so the
browser bundle can take it too.
src/index.css holds the same values as CSS (@theme and its dark
block), since CSS can't import this. The build checks the two
agree and stops if they don't (themeDefaultsCheck in
vite.config.ts). Change a colour here and there together.
═══════════════════════════════════════════════════════════════ */
// light dark
export const THEME_DEFAULTS = {
ink: ["#073d4a", "#eaf6f8"],
body: ["#26454c", "#cde0e4"],
muted: ["#4a6b72", "#9fb9bf"],
link: ["#0f7183", "#5ccbdc"],
brand: ["#138ba0", "#2aa7bc"],
action: ["#0f7183", "#0f7183"],
"action-hover": ["#0b5c6a", "#0b5c6a"],
surface: ["#ffffff", "#0c1d21"],
tint: ["#eef9fb", "#11292e"],
"tint-soft": ["#f6fbfc", "#0f2428"],
danger: ["#b3261e", "#ff8a80"],
"danger-tint": ["#fdf3f2", "#3b1714"],
};

View file

@ -1,82 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="403.64276mm"
height="86.755943mm"
viewBox="0 0 403.64273 86.755943"
version="1.1"
id="svg5"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs2" />
<g
id="layer10"
style="display:inline"
transform="translate(-344.28592,167.60401)">
<g
id="g3">
<circle
style="display:inline;fill:#008da9;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.634488;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path205602-8-3-1"
cx="403.82111"
cy="-121.75806"
r="40.889923" />
<path
id="path1887-1-3-7-7-6-2"
style="color:#000000;display:inline;fill:#008da9;fill-opacity:1;stroke:none;stroke-width:2.284;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 443.45159,-167.57122 c -8.63995,3.71591 -17.05927,7.97953 -25.85742,11.27148 -3.76442,1.391 -7.68514,2.52606 -11.12305,4.64648 -3.58916,2.42042 -5.95825,6.25942 -7.35135,10.29228 -1.23335,3.0863 -2.32136,6.17712 -3.84982,9.11983 -3.67393,-2.17848 -7.69746,-4.08371 -12.04108,-4.24843 -4.09333,-0.39358 -8.26381,0.55262 -11.85512,2.53592 -6.41916,3.13465 -11.92468,7.82515 -18.56868,10.51862 -2.73797,1.21486 -5.51687,2.3331 -8.27926,3.49077 -0.88252,2.47734 0.77854,5.31191 3.20508,6.10351 4.27199,1.7128 8.98018,1.56772 13.49433,1.35771 4.71612,-0.31488 9.32779,-1.47771 13.7933,-2.98449 4.28568,-1.20657 8.61172,-2.23873 13.00143,-3.03728 -2.64145,2.85774 -6.27041,4.39222 -9.272,6.78523 -0.9862,0.76271 -1.85771,1.89939 -1.64657,3.21845 0.1709,1.85512 1.7211,3.08775 2.9593,4.29677 2.6421,2.35246 5.95831,4.07918 9.49722,4.487017 1.35103,0.106385 2.71085,-0.642417 3.25697,-1.900747 1.43582,-2.68121 2.25426,-5.67671 4.35603,-7.93655 1.20099,-1.4152 3.08751,-1.77888 4.83141,-2.01081 3.79664,-0.62592 7.50391,-2.47133 9.93534,-5.50938 1.37471,-1.65305 2.10201,-3.71602 2.52235,-5.79656 0.1379,-0.6722 1.04486,-0.68506 1.58622,-0.85974 1.78218,-0.35339 3.91283,-0.77776 4.83392,-2.54366 0.89776,-1.84635 -0.0715,-4.04503 -1.61189,-5.21854 -2.41639,-1.86664 -5.65021,-3.01579 -8.63111,-2.61499 2.2258,-1.54005 4.74178,-2.58917 7.19752,-3.70372 6.31792,-2.71081 13.11161,-4.94567 18.40937,-9.54069 3.73885,-3.20962 6.79577,-7.24801 8.78271,-11.76096 0.80138,-2.0522 1.44232,-4.33553 0.95805,-6.5376 -0.3398,-1.04637 -1.34059,-2.15906 -2.5332,-1.91992 z" />
<path
id="path92116-3-2-7-1-4"
style="display:inline;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.222835;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 401.4397,-85.357733 -5.07733,3.7999 c 1.40469,0.28813 3.37038,0.49431 4.1477,0.56482 0,0 13.4726,-8.14749 21.27399,-14.00284 7.80139,-5.855347 13.28514,-13.045137 15.64699,-18.030857 4.23462,-8.93904 5.76755,-17.18121 4.93866,-21.94278 -2.3532,12.13055 -6.84548,20.1394 -8.91525,22.66728 -2.77658,3.39114 -7.3818,10.79482 -14.1263,15.035397 -8.02485,5.04559 -16.87157,10.25674 -17.88846,11.90908 z" />
<path
fill="#519259"
d="m 401.25566,-85.224563 c 2.11431,-7.90893 7.29014,-19.728807 13.53049,-25.077287 3.15174,-2.74769 6.75532,-5.34691 11.45401,-7.64618 4.36158,-2.05194 6.70709,-3.73973 9.19688,-6.81027 3.40267,-3.94053 5.90574,-7.35199 6.96383,-10.47421 0.22347,8.84634 -6.48806,19.37766 -9.02864,23.54668 -6.2265,9.41606 -10.0147,12.608287 -17.50625,17.196147 -4.38236,2.60687 -9.65678,5.68615 -14.61032,9.26512 z"
fill-opacity="1"
fill-rule="nonzero"
id="path184-6-7-6-9-3-2"
style="display:inline;fill:#358a0d;fill-opacity:1;stroke:none;stroke-width:0.625031;stroke-opacity:1" />
<path
style="color:#000000;display:inline;fill:#ffffff;stroke:none;stroke-width:2.284;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 358.52422,-123.11955 c 3.13369,-1.59928 7.04147,-4.49077 10.29591,-6.33595 3.25443,-1.84519 6.30899,-3.58417 9.61426,-4.20523 2.65302,-0.4889 6.37319,-0.18817 9.07211,0.58357 2.69896,0.77175 5.57299,2.70484 7.16593,3.40762 1.59295,0.70275 2.24655,0.19006 2.82855,-0.77494 0.582,-0.96504 2.81839,-6.05064 3.84362,-8.9293 1.02519,-2.87864 2.26409,-5.72337 4.14553,-7.76121 1.88144,-2.03782 2.31893,-2.07776 4.06202,-3.15865 1.74307,-1.08086 10.24244,-3.71628 14.53403,-5.61581 4.29158,-1.89953 8.11957,-3.58996 12.24067,-5.48028 4.12109,-1.89033 6.08861,-2.79441 7.30709,-3.29554 0.273,0.73801 -0.2034,3.06663 -1.16031,5.22317 -0.95691,2.15654 -2.9569,5.04357 -4.86279,7.26365 -1.90589,2.22009 -4.28775,4.10342 -6.82223,5.66812 -2.53448,1.56467 -4.53981,2.45823 -7.60439,3.71266 -3.06457,1.25446 -11.88915,4.7102 -14.64698,7.12005 -2.75786,2.40984 -4.18313,6.63212 -3.64772,7.60115 0.5354,0.96902 2.51391,-1.48598 3.81084,-2.34867 1.29694,-0.8627 1.95172,-1.05814 3.14897,-1.09198 1.17765,-0.0172 2.77532,0.40067 3.29849,0.63293 1.48441,0.659 3.97438,2.00122 3.54176,3.36038 -0.16368,0.51434 -0.19462,0.56904 -3.05611,1.25841 -2.86151,0.68935 -3.48508,1.29579 -3.81533,3.74861 -0.22097,1.47094 -1.44719,3.88743 -3.13317,5.28015 -1.68596,1.39274 -4.55099,2.93627 -8.41717,3.35482 -3.86617,0.41855 -6.17544,3.97192 -6.93256,5.37259 -0.75713,1.40064 -2.66104,5.90506 -2.99685,6.15238 -0.3358,0.24732 -2.76998,-0.36582 -3.79458,-0.82517 -1.02463,-0.45935 -2.612,-1.39111 -3.63624,-2.16132 -1.02425,-0.7702 -3.457,-2.975 -3.0018,-3.64018 0.45519,-0.66516 1.56543,-1.35445 2.73515,-2.12254 1.16972,-0.76811 3.86984,-2.33631 5.3456,-3.59002 1.47576,-1.25372 2.7334,-2.47754 3.4042,-3.48323 0.67079,-1.00567 0.9358,-2.14286 -0.28206,-2.7388 -1.21786,-0.59597 -1.84092,-0.39835 -4.4486,0.0225 -2.60769,0.42097 -4.8218,1.10142 -8.46858,1.9005 -3.64678,0.79905 -7.82786,2.49393 -10.97221,3.07304 -3.14439,0.5791 -4.3363,0.83756 -8.5197,0.95691 -4.1834,0.11935 -7.15938,-0.35864 -8.95468,-0.91763 -1.7953,-0.55899 -2.64147,-1.55556 -2.60415,-2.17667 3.90737,-1.58574 7.9469,-3.2841 11.38348,-5.04009 z"
id="path1887-1-3-7-7-6" />
<path
fill="#519259"
d="m 412.95849,-81.884143 c 4.58067,-1.05723 7.7275,-1.9948 13.67931,-5.91343 5.95181,-3.91863 10.62995,-9.54813 13.02992,-14.097387 2.39997,-4.54926 4.34384,-10.28218 4.83384,-15.81643 0.49,-5.53425 0.14775,-11.25197 -2.10696,-17.66367 0.15927,9.10203 -2.7414,15.06092 -4.17879,18.80503 -1.43739,3.74411 -4.80196,9.50687 -8.2717,13.57264 -3.46184,4.223207 -7.82036,7.647487 -12.67981,10.383567 -5.38026,3.05578 -13.21504,8.4585 -16.7484,11.61577 4.01135,0.4226 9.12694,-0.10316 12.44259,-0.88609 z"
fill-opacity="1"
fill-rule="nonzero"
id="path182-2-6-6-7-2-2"
style="display:inline;fill:#358a0d;fill-opacity:1;stroke:none;stroke-width:0.717458;stroke-opacity:1" />
</g>
<g
id="g40616-9"
transform="translate(13.096206,-216.39844)"
style="display:inline">
<g
id="g2-4">
<text
xml:space="preserve"
style="font-size:34.109px;line-height:1.25;font-family:Impact;-inkscape-font-specification:Impact;letter-spacing:0px;word-spacing:0px;display:inline;stroke-width:0.852729"
x="451.59149"
y="89.758339"
id="text156858-3-8"><tspan
id="tspan156856-8-82"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:34.109px;font-family:Poppins;-inkscape-font-specification:'Poppins, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#008da9;fill-opacity:1;stroke-width:0.852729"
x="451.59149"
y="89.758339">Next Generation</tspan></text>
<text
xml:space="preserve"
style="font-size:33.8136px;line-height:1.25;font-family:Impact;-inkscape-font-specification:Impact;letter-spacing:0px;word-spacing:0px;display:inline;stroke-width:0.845345"
x="469.26224"
y="119.08144"
id="text156858-3-1-4"><tspan
id="tspan156856-8-8-5"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:33.8136px;font-family:Poppins;-inkscape-font-specification:'Poppins, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#008da9;fill-opacity:1;stroke-width:0.845345"
x="469.26224"
y="119.08144">of Unity</tspan></text>
</g>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 8.4 KiB

View file

@ -0,0 +1,39 @@
/* ═══════════════════════════════════════════════════════════════
ORG LOGO
An organization's logo, or its initials in a square in its colour
when there's no file or it fails to load. Decorative: the name is
always right beside it. Used by the organization lists and the
chapter map.
═══════════════════════════════════════════════════════════════ */
import Logo from './Logo.tsx'
import { accentText } from '../lib/color.ts'
import { mediaUrl } from '../lib/media.ts'
import { initialsFor } from '../lib/organizations.ts'
export default function OrgLogo({
org,
color,
size = 'h-14 w-14',
}: {
org: { logo?: string | null; name: string }
color: string
size?: string
}) {
return (
<Logo
src={mediaUrl(org.logo)}
className={`${size} object-contain rounded-xl shrink-0`}
fallback={
<span
className={`${size} rounded-xl shrink-0 flex items-center justify-center font-extrabold`}
style={{ border: `1px solid ${color}`, color: accentText(color) }}
aria-hidden="true"
>
{initialsFor(org.name)}
</span>
}
/>
)
}

View file

@ -3,9 +3,8 @@
Used by the public form (to render the tiles) and the admin Used by the public form (to render the tiles) and the admin
triage view (to label them). The ids must match TYPES in triage view (to label them). The ids must match TYPES in
server/src/routes/feedback.js, that list stays separate because server/src/routes/feedback.js, which decides what's storable;
the server isn't in this workspace, and it's the thing that keep the two in step.
decides what's storable.
DATA_REQUEST is kept out of the tiles: the Privacy page's form DATA_REQUEST is kept out of the tiles: the Privacy page's form
sends it (FeedbackForm's fixedType), with an email required. sends it (FeedbackForm's fixedType), with an email required.

View file

@ -1,5 +1,6 @@
import siteConfiguration from "../../../site.json"; import siteConfiguration from "../../../site.json";
import { mediaUrl } from "../media.ts"; import { mediaUrl } from "../media.ts";
import { THEME_DEFAULTS } from "../../../server/src/themeDefaults.js";
/* ── Site settings (035_site_settings.sql) ─────────────────────── /* ── Site settings (035_site_settings.sql) ───────────────────────
Overrides for site.json, superadmins only: every blank falls back Overrides for site.json, superadmins only: every blank falls back
@ -8,24 +9,32 @@ const SITE_PAGES: [string, string][] = Object.entries(siteConfiguration.pages).m
([path, page]) => [path, `${page.title} (${path})`], ([path, page]) => [path, `${page.title} (${path})`],
); );
/* The palette an admin can change: token, label, light default, dark /* The palette an admin can change, in the order the dropdown lists
default. Keep in step with THEME_DEFAULTS in server/src/theme.js it: token and label. The defaults come from the server's list
and the tokens in src/index.css. */ (server/src/themeDefaults.js), which the build checks against
const THEME_COLORS: [string, string, string, string][] = [ src/index.css, so there's one copy of each colour to change. */
["ink", "Headings", "#073d4a", "#eaf6f8"], const THEME_LABELS: [string, string][] = [
["body", "Body text", "#26454c", "#cde0e4"], ["ink", "Headings"],
["muted", "Secondary text and quiet borders", "#4a6b72", "#9fb9bf"], ["body", "Body text"],
["link", "Links and teal text", "#0f7183", "#5ccbdc"], ["muted", "Secondary text and quiet borders"],
["brand", "Brand teal (borders, rules, rings)", "#138ba0", "#2aa7bc"], ["link", "Links and teal text"],
["action", "Buttons (under white text)", "#0f7183", "#0f7183"], ["brand", "Brand teal (borders, rules, rings)"],
["action-hover", "Buttons, hovered", "#0b5c6a", "#0b5c6a"], ["action", "Buttons (under white text)"],
["surface", "Page and card background", "#ffffff", "#0c1d21"], ["action-hover", "Buttons, hovered"],
["tint", "Tinted sections and panels", "#eef9fb", "#11292e"], ["surface", "Page and card background"],
["tint-soft", "Faint panels and hovered rows", "#f6fbfc", "#0f2428"], ["tint", "Tinted sections and panels"],
["danger", "Errors and warnings", "#b3261e", "#ff8a80"], ["tint-soft", "Faint panels and hovered rows"],
["danger-tint", "Error panel background", "#fdf3f2", "#3b1714"], ["danger", "Errors and warnings"],
["danger-tint", "Error panel background"],
]; ];
const THEME_COLORS: [string, string, string, string][] = THEME_LABELS.map(([token, label]) => [
token,
label,
THEME_DEFAULTS[token][0],
THEME_DEFAULTS[token][1],
]);
const defaultHelp = (row, column: 2 | 3) => { const defaultHelp = (row, column: 2 | 3) => {
const entry = THEME_COLORS.find(([token]) => token === row?.token); const entry = THEME_COLORS.find(([token]) => token === row?.token);
return entry ? `Default: ${entry[column]}` : undefined; return entry ? `Default: ${entry[column]}` : undefined;

View file

@ -17,6 +17,8 @@
not instants, nothing here converts timezones. not instants, nothing here converts timezones.
═══════════════════════════════════════════════════════════════ */ ═══════════════════════════════════════════════════════════════ */
import { localISO } from './timeline.ts'
export type SeriesFrequency = 'weekly' | 'monthly_date' | 'monthly_weekday' export type SeriesFrequency = 'weekly' | 'monthly_date' | 'monthly_weekday'
export type SeriesWeekday = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' export type SeriesWeekday = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat'
@ -66,11 +68,7 @@ function parseDate(value?: string | null): Date | null {
const isoDate = (date: Date) => date.toISOString().slice(0, 10) const isoDate = (date: Date) => date.toISOString().slice(0, 10)
/* The viewer's today, as a calendar date. */ /* The viewer's today, as a calendar date. */
function today(): string { const today = (): string => localISO()
const now = new Date()
const pad = (n: number) => String(n).padStart(2, '0')
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`
}
const daysInMonth = (year: number, month: number) => const daysInMonth = (year: number, month: number) =>
new Date(Date.UTC(year, month + 1, 0)).getUTCDate() new Date(Date.UTC(year, month + 1, 0)).getUTCDate()

View file

@ -27,7 +27,7 @@
Now the id is checked here. In dev that's a console.error with a Now the id is checked here. In dev that's a console.error with a
stack trace pointing at the caller; in production the path still stack trace pointing at the caller; in production the path still
comes out, because a broken link beats a crashed page, and comes out, because a broken link beats a crashed page, and
useResource refuses to fetch it. detailPath() returns null for it, so useRecord never fetches it.
═══════════════════════════════════════════════════════════════ */ ═══════════════════════════════════════════════════════════════ */
export type OrgKind = 'national' | 'region' | 'chapter' | 'partner' export type OrgKind = 'national' | 'region' | 'chapter' | 'partner'

View file

@ -72,10 +72,11 @@ export function areasSentence(areas: any[] = []) {
.join(", "); .join(", ");
} }
/* Initials for a card with no logo. "NGU Lynnwood" → "NL", dropping // Alphabetical by name, for sorting organizations.
the org prefix so every card doesn't read "NG". */
export const byName = (a, b) => a.name.localeCompare(b.name); export const byName = (a, b) => a.name.localeCompare(b.name);
/* Initials for an organization with no logo. "NGU Lynnwood" → "NL",
dropping the org prefix so every card doesn't read "NG". */
export function initialsFor(name = "") { export function initialsFor(name = "") {
return name return name
.replace(/^NGU\s+/i, "") .replace(/^NGU\s+/i, "")

View file

@ -185,8 +185,11 @@ export function windowStart(item: TimelineItem): string {
return `${year}-${pad(month ?? 1)}-${pad(day ?? 1)}` return `${year}-${pad(month ?? 1)}-${pad(day ?? 1)}`
} }
export function todayISO(now: Date = new Date()): string { /** A date as the viewer's own calendar day, YYYY-MM-DD (today when
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}` * given nothing). Local, not UTC: after 5pm in California, UTC is
* already tomorrow. The site's one copy of this. */
export function localISO(date: Date = new Date()): string {
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
} }
/** /**
@ -197,7 +200,7 @@ export function partitionByDate(
items: TimelineItem[], items: TimelineItem[],
now: Date = new Date(), now: Date = new Date(),
): { upcoming: TimelineItem[]; past: TimelineItem[] } { ): { upcoming: TimelineItem[]; past: TimelineItem[] } {
const today = todayISO(now) const today = localISO(now)
const upcoming: TimelineItem[] = [] const upcoming: TimelineItem[] = []
const past: TimelineItem[] = [] const past: TimelineItem[] = []
for (const item of items) { for (const item of items) {

View file

@ -1,13 +1,10 @@
/* ═══════════════════════════════════════════════════════════════ /* ═══════════════════════════════════════════════════════════════
LOCAL CHAPTER DATA useCommunity
The chapter map's view of the organization list. Regions and The chapter map's view of the organization list (OrgList-Map).
chapters are the same table and the same endpoint; this hook Regions and chapters are the same table and the same endpoint;
reshapes them into what a map needs, slices per tile, counts this hook reshapes them into what a map needs, slices per tile,
per tile, chapters grouped by region. counts per tile, chapters grouped by region.
Its return shape is unchanged from the version that called
/regions and /chapters, so LocalChapters didn't have to move.
Two things live elsewhere: Two things live elsewhere:

View file

@ -1,7 +1,7 @@
/** /**
* The four detail endpoints, typed. * The detail endpoints, typed.
* *
* Adding a fifth is a type and a one-line hook, useRecord owns * Adding one is a type and a one-line hook, useRecord owns
* the fetching, the caching and the 404. * the fetching, the caching and the 404.
* *
* An id that is missing, or the literal string "undefined", which * An id that is missing, or the literal string "undefined", which

View file

@ -11,8 +11,8 @@
* *
* Every detail route in content.js answers the same shape: 200 with * Every detail route in content.js answers the same shape: 200 with
* a single top-level key, or 404 with `{ error }`. So the hook takes * a single top-level key, or 404 with `{ error }`. So the hook takes
* the path and the key, and the four callers in useContent.ts are * the path and the key, and each caller (useContent.ts, useHistory,
* one line each rather than four copies of this file. * useBlog) is one line rather than a copy of this file.
* *
* `key` is a string rather than a selector function on purpose. A * `key` is a string rather than a selector function on purpose. A
* selector passed inline would be a new identity every render, and * selector passed inline would be a new identity every render, and

View file

@ -30,7 +30,8 @@ import {
type OrganizationRecord, type OrganizationRecord,
} from '../lib/useContent.ts' } from '../lib/useContent.ts'
import { orgHref, orgListHref, teamHref } from '../lib/hrefs.ts' import { orgHref, orgListHref, teamHref } from '../lib/hrefs.ts'
import { initials, mediaUrl } from '../lib/media.ts' import { mediaUrl } from '../lib/media.ts'
import { initialsFor } from '../lib/organizations.ts'
import Logo from '../components/Logo.tsx' import Logo from '../components/Logo.tsx'
import { withAlpha, accentText, readableOn, BRAND } from '../lib/color.ts' import { withAlpha, accentText, readableOn, BRAND } from '../lib/color.ts'
@ -370,7 +371,7 @@ function ChapterMark({ file, name, accent }: { file?: string | null; name: strin
className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full text-xs font-bold" className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full text-xs font-bold"
style={{ background: accent, color: readableOn(accent) }} style={{ background: accent, color: readableOn(accent) }}
> >
{initials(name)} {initialsFor(name)}
</span> </span>
} }
/> />

View file

@ -1,13 +0,0 @@
export default function Other() {
return (
<>
<section id="sectiona" className="scroll-mt-28 px-6 py-20">
<h1 className="text-4xl font-bold">Section A</h1>
</section>
<section id="sectionb" className="scroll-mt-28 px-6 py-20">
<h2 className="text-4xl font-bold">Section B</h2>
</section>
</>
);
}

View file

@ -28,7 +28,7 @@ import { useCallback, useEffect, useState } from "react";
import { del, get, patch } from "../../lib/api.ts"; import { del, get, patch } from "../../lib/api.ts";
import { isUnauthorized, useAuth } from "../../lib/auth.tsx"; import { isUnauthorized, useAuth } from "../../lib/auth.tsx";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { ROLES, ROLE_LABELS, ROLE_NOTES } from "../../lib/roles.ts"; import { ROLES, ROLE_LABELS, ROLE_NOTES, isSuper } from "../../lib/roles.ts";
/* SQLite hands back "2026-09-22 04:11:07": UTC, but without the /* SQLite hands back "2026-09-22 04:11:07": UTC, but without the
marker that says so. Left alone, browsers read it as local time marker that says so. Left alone, browsers read it as local time
@ -166,7 +166,7 @@ export default function AdminPanel() {
const { system, content, users } = data; const { system, content, users } = data;
const activeSupers = users.filter( const activeSupers = users.filter(
(u) => u.role === "superadmin" && u.is_active === 1, (u) => isSuper(u) && u.is_active === 1,
).length; ).length;
return ( return (
@ -225,7 +225,7 @@ export default function AdminPanel() {
{users.map((row) => { {users.map((row) => {
const isMe = row.id === me?.id; const isMe = row.id === me?.id;
const lastSuper = const lastSuper =
row.role === "superadmin" && row.is_active === 1 && activeSupers <= 1; isSuper(row) && row.is_active === 1 && activeSupers <= 1;
const locked = isMe || lastSuper; const locked = isMe || lastSuper;
const busy = busyId === row.id; const busy = busyId === row.id;

View file

@ -49,6 +49,7 @@ import { firstOccurrenceFrom, occurrencesBetween, seriesTimes } from '../../lib/
import { eventHref } from '../../lib/hrefs.ts' import { eventHref } from '../../lib/hrefs.ts'
import type { EventListItem } from '../../lib/useContent.ts' import type { EventListItem } from '../../lib/useContent.ts'
import { withAlpha, accentText, readableOn, BRAND } from '../../lib/color.ts' import { withAlpha, accentText, readableOn, BRAND } from '../../lib/color.ts'
import { localISO } from '../../lib/timeline.ts'
export type CalendarControl = 'scope' | 'type' | 'online' | 'search' export type CalendarControl = 'scope' | 'type' | 'online' | 'search'
export type CalendarView = 'month' | 'list' export type CalendarView = 'month' | 'list'
@ -94,8 +95,7 @@ type Segment = Occurrence & {
/* ── Dates ───────────────────────────────────────────────────── */ /* ── Dates ───────────────────────────────────────────────────── */
const pad = (n: number) => String(n).padStart(2, '0') const iso = (d: Date) => localISO(d)
const iso = (d: Date) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
function parse(date: string): Date { function parse(date: string): Date {
const [y, m, d] = date.split('-').map(Number) const [y, m, d] = date.split('-').map(Number)

View file

@ -1,9 +1,7 @@
import { ArrowUpRight } from '@phosphor-icons/react'; import { ArrowUpRight } from '@phosphor-icons/react';
import ArrowLink from "../../components/ArrowLink.tsx"; import ArrowLink from "../../components/ArrowLink.tsx";
import { mediaUrl } from "../../lib/media.ts"; import OrgLogo from "../../components/OrgLogo.tsx";
import Logo from "../../components/Logo.tsx";
import { import {
initialsFor,
orgPath, orgPath,
useOrganizations, useOrganizations,
byName, byName,
@ -35,24 +33,6 @@ const FALLBACK_COLOR = "#4a6b72";
const CARD_MIN = "20rem"; const CARD_MIN = "20rem";
const GRID_MAX = "88rem"; const GRID_MAX = "88rem";
function OrgMark({ org, color }) {
return (
<Logo
src={mediaUrl(org.logo)}
className="h-14 w-14 object-contain rounded-xl shrink-0"
fallback={
<span
className="h-14 w-14 rounded-xl shrink-0 flex items-center justify-center font-extrabold"
style={{ border: `1px solid ${color}`, color: accentText(color) }}
aria-hidden="true"
>
{initialsFor(org.name)}
</span>
}
/>
);
}
function OrgCard({ org, accent, pageLabel, siteLabel }) { function OrgCard({ org, accent, pageLabel, siteLabel }) {
const color = org.color || accent; const color = org.color || accent;
const path = orgPath(org); const path = orgPath(org);
@ -68,7 +48,7 @@ function OrgCard({ org, accent, pageLabel, siteLabel }) {
style={{ border: `1px solid ${color}`, background: "var(--color-surface)" }} style={{ border: `1px solid ${color}`, background: "var(--color-surface)" }}
> >
<div className="flex items-start gap-4"> <div className="flex items-start gap-4">
<OrgMark org={org} color={color} /> <OrgLogo org={org} color={color} />
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<h3 className="text-xl font-extrabold leading-tight" style={{ color }}> <h3 className="text-xl font-extrabold leading-tight" style={{ color }}>

View file

@ -1,11 +1,10 @@
import { CaretRight, X } from '@phosphor-icons/react'; import { CaretRight, X } from '@phosphor-icons/react';
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import { useCommunity } from "../../lib/chapters.ts"; import { useCommunity } from "../../lib/useCommunity.ts";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import ArrowLink from "../../components/ArrowLink.tsx"; import ArrowLink from "../../components/ArrowLink.tsx";
import { mediaUrl } from "../../lib/media.ts"; import OrgLogo from "../../components/OrgLogo.tsx";
import Logo from "../../components/Logo.tsx"; import { orgPath } from "../../lib/organizations.ts";
import { initialsFor, orgPath } from "../../lib/organizations.ts";
import { AREAS, AREA_NAMES } from "../../data/mapGrid.ts"; import { AREAS, AREA_NAMES } from "../../data/mapGrid.ts";
import { withAlpha, accentText, readableOn } from '../../lib/color.ts' import { withAlpha, accentText, readableOn } from '../../lib/color.ts'
import { scrollBehavior } from "../../lib/motion.ts"; import { scrollBehavior } from "../../lib/motion.ts";
@ -468,26 +467,6 @@ function RegionBlock({
color. Selecting another card swaps the panel's contents. color. Selecting another card swaps the panel's contents.
═══════════════════════════════════════════════════════════════ */ ═══════════════════════════════════════════════════════════════ */
/* Logo, or the organization's initials when there's no file or it
fails to load. Decorative: the name is right beside it. */
function OrgLogo({ org, color, size = "h-14 w-14" }) {
return (
<Logo
src={mediaUrl(org.logo)}
className={`${size} object-contain rounded-xl shrink-0`}
fallback={
<div
className={`${size} rounded-xl shrink-0 flex items-center justify-center font-extrabold`}
style={{ border: `1px solid ${color}`, color: accentText(color) }}
aria-hidden="true"
>
{initialsFor(org.name)}
</div>
}
/>
);
}
function ChapterCard({ chapter, color, open, onOpen }) { function ChapterCard({ chapter, color, open, onOpen }) {
return ( return (
<div <div

View file

@ -2,7 +2,10 @@ import { defineConfig, type HtmlTagDescriptor, type Plugin } from 'vite'
import react from '@vitejs/plugin-react' import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite' import tailwindcss from '@tailwindcss/vite'
import { readFileSync } from 'node:fs'
import siteConfiguration from './site.json' import siteConfiguration from './site.json'
import { THEME_DEFAULTS } from './server/src/themeDefaults.js'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
@ -10,6 +13,7 @@ export default defineConfig({
react(), react(),
tailwindcss(), tailwindcss(),
siteConfigurationPlugin(siteConfiguration), siteConfigurationPlugin(siteConfiguration),
themeDefaultsCheck(),
], ],
server: { server: {
proxy: { proxy: {
@ -198,3 +202,38 @@ function siteConfigurationPlugin(config: SiteConfiguration): Plugin {
}, },
} }
} }
/* The colour tokens exist twice: as data in server/src/themeDefaults.js
(the admin's defaults, the contrast check) and as CSS in
src/index.css (what pages draw with). This stops the build, and the
dev server, when the two disagree, naming each difference. */
function themeDefaultsCheck(): Plugin {
const read = (css: string, block: RegExp) => {
const body = block.exec(css)?.[1] ?? ''
return Object.fromEntries(
[...body.matchAll(/--color-([a-z-]+):\s*(#[0-9a-f]{6})/gi)].map((m) => [m[1], m[2].toLowerCase()]),
)
}
return {
name: 'theme-defaults-check',
buildStart() {
const css = readFileSync('src/index.css', 'utf8')
const light = read(css, /@theme\s*\{([\s\S]*?)\n\}/)
const dark = read(css, /:root\[data-theme="dark"\]\s*\{([\s\S]*?)\}/)
const problems: string[] = []
for (const [token, [lightHex, darkHex]] of Object.entries(THEME_DEFAULTS) as [string, string[]][]) {
if (light[token] !== lightHex.toLowerCase())
problems.push(`--color-${token} light: index.css ${light[token] ?? 'missing'}, themeDefaults.js ${lightHex}`)
// A token index.css doesn't redefine for dark keeps its light value.
const cssDark = dark[token] ?? light[token]
if (cssDark !== darkHex.toLowerCase())
problems.push(`--color-${token} dark: index.css ${cssDark ?? 'missing'}, themeDefaults.js ${darkHex}`)
}
if (problems.length) {
this.error(
`Colour tokens disagree between src/index.css and server/src/themeDefaults.js:\n ${problems.join('\n ')}`,
)
}
},
}
}