NGU-Web/src/lib/adminSchema/siteSettings.ts
Zaldimmar f934b1dd93 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>
2026-09-29 03:02:21 -05:00

183 lines
6.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import siteConfiguration from "../../../site.json";
import { mediaUrl } from "../media.ts";
import { THEME_DEFAULTS } from "../../../server/src/themeDefaults.js";
/* ── Site settings (035_site_settings.sql) ───────────────────────
Overrides for site.json, superadmins only: every blank falls back
to what site.json says, which is shown as the default. */
const SITE_PAGES: [string, string][] = Object.entries(siteConfiguration.pages).map(
([path, page]) => [path, `${page.title} (${path})`],
);
/* The palette an admin can change, in the order the dropdown lists
it: token and label. The defaults come from the server's list
(server/src/themeDefaults.js), which the build checks against
src/index.css, so there's one copy of each colour to change. */
const THEME_LABELS: [string, string][] = [
["ink", "Headings"],
["body", "Body text"],
["muted", "Secondary text and quiet borders"],
["link", "Links and teal text"],
["brand", "Brand teal (borders, rules, rings)"],
["action", "Buttons (under white text)"],
["action-hover", "Buttons, hovered"],
["surface", "Page and card background"],
["tint", "Tinted sections and panels"],
["tint-soft", "Faint panels and hovered rows"],
["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 entry = THEME_COLORS.find(([token]) => token === row?.token);
return entry ? `Default: ${entry[column]}` : undefined;
};
export const siteSettings = {
key: "site_settings",
label: "Site settings",
singular: "site settings",
idLabel: "Settings",
singleton: "site",
writeRole: "superadmin",
list: { columns: [], filters: [] },
groups: [
{
legend: "The site",
note: "Anything left blank uses site.json, so the build and these settings agree until you change one.",
fields: [
{ path: "site_name", label: "Site name", help: `Default: ${siteConfiguration.title}` },
{
path: "description",
label: "Description",
widget: "textarea",
full: true,
help: "Search engines and link previews show this for pages without their own. Default: site.json's, or the front page's subhead.",
},
{
path: "preview_image",
label: "Preview image",
widget: "image",
resolve: mediaUrl,
full: true,
help: "Shown when a page without its own image is shared. 1200 × 630 works everywhere.",
},
],
},
{
legend: "Icons",
fields: [
{
path: "favicon",
label: "Favicon",
widget: "image",
resolve: mediaUrl,
full: true,
help: "The browser-tab icon: a square PNG (512px) or an SVG. Keep original when uploading an SVG.",
},
{
path: "apple_touch_icon",
label: "Home-screen icon",
widget: "image",
resolve: mediaUrl,
full: true,
help: "For iPhones saving the site to their home screen: a square PNG, 180px, no transparency.",
},
],
},
{
legend: "Search engines",
fields: [
{
path: "indexing",
label: "Let search engines list this site",
widget: "select",
options: [
["on", "On: pages can appear in Google"],
["off", "Off: hidden from search (use on the dev server)"],
],
blankLabel: `Default: site.json (${siteConfiguration.robots?.index === false ? "off" : "on"})`,
help: "Applies to this server's database only, so dev can be off while production is on.",
},
],
},
{
legend: "Privacy",
fields: [
{
path: "privacy_email",
label: "Privacy contact email",
help: `The Privacy page gives this for privacy questions and data requests, eg. privacy@nextgenerationofunity.org. ${
siteConfiguration.privacyEmail ? `Default: ${siteConfiguration.privacyEmail}` : "Default: none, the page offers its request form only"
}.`,
},
],
},
],
children: [
{
key: "colors",
label: "Colours",
note: "Change any of the site's colours, for light mode, dark mode or both; a blank keeps the default. Saving refuses a palette that would make text hard to read (under 4.5:1). Changes show on the next page load.",
addLabel: "Change a colour",
title: (row) => THEME_COLORS.find(([token]) => token === row.token)?.[1] ?? "New colour",
blank: { token: "", light: "", dark: "" },
fields: [
{
path: "token",
label: "Colour",
widget: "select",
options: THEME_COLORS.map(([token, label]) => [token, label]),
required: true,
},
{
path: "light",
label: "Light mode",
widget: "color",
placeholder: (row) => THEME_COLORS.find(([token]) => token === row?.token)?.[2],
help: (row) => defaultHelp(row, 2),
},
{
path: "dark",
label: "Dark mode",
widget: "color",
placeholder: (row) => THEME_COLORS.find(([token]) => token === row?.token)?.[3],
help: (row) => defaultHelp(row, 3),
},
],
},
{
key: "pages",
label: "Page titles and intros",
note: "Change a static page's heading and intro, which are also its search title and description. Blank fields keep site.json's.",
addLabel: "Change a page",
title: (row) => SITE_PAGES.find(([path]) => path === row.path)?.[1] ?? "New page",
blank: { path: "", title: "", description: "" },
fields: [
{ path: "path", label: "Page", widget: "select", options: SITE_PAGES, required: true },
{
path: "title",
label: "Title",
help: (row) => (row?.path ? `Default: ${siteConfiguration.pages[row.path]?.title ?? ""}` : undefined),
},
{
path: "description",
label: "Intro",
widget: "textarea",
full: true,
help: (row) => (row?.path ? `Default: ${siteConfiguration.pages[row.path]?.description ?? ""}` : undefined),
},
],
},
],
};