Page management, step 1: every page in a registry, new pages, hidden and disabled

Migration 080 makes site_pages the list of every page: address, title,
intro, Hidden, Disabled (out of menus, sitemap and search) and card order.
site.json's pages and Navigation's page list move into it. Pages ->
Page management (one editor in place of six) makes new pages of sections
at any free address; the admin home opens Pages with a banner and a card
per page. A catch-all route draws whatever page is at an address; the
fixed pages take their words from the registry and can't be deleted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aidan Dona 2026-10-16 23:19:54 -05:00
parent 56acedf926
commit 1342691f49
36 changed files with 584 additions and 405 deletions

View file

@ -1,18 +1,19 @@
import { text, url, int, enumeration, featuredCardsChild, blocksChild } from "./columns.js";
import { HttpError } from "../admin-crud.js";
import { text, url, int, bool, enumeration, featuredCardsChild, blocksChild } from "./columns.js";
/* ── The site's own pages (056_site_pages.sql) ───────────────────
/* ── The site's pages (056_site_pages.sql, 080_page_registry.sql) ──
Community, Retreats, Resources, Organization, History and Shop
(075): one
site_pages row each, edited as its own singleton, with its
sections nested under it and each section's blocks under that
Pages → Page management: every page of the site, one site_pages
row each (its address, title, intro, Hidden and Disabled), with
its sections nested under it and each section's blocks under that
(the blocks' items under them, as on any record). A section is
either its blocks or a preset, a prebuilt part of the site
(SitePage.tsx draws both).
(SitePage.tsx draws both). New pages are made here.
Community also carries the blog section's settings: the
community_page row (same id) as an extension, and its pinned
posts, cards and feeds, all owned by that id. */
posts, cards and feeds, all owned by that id; only for the page
whose id is community. */
const sectionsChild = {
key: "sections",
@ -60,27 +61,62 @@ const sectionsChild = {
],
};
const sitePage = (id, more = {}) => ({
key: `${id}_page`,
/* Pages the site draws in code (src/pages/fixedPages.ts): they can be
renamed, moved, hidden or disabled, never deleted. */
export const FIXED_PAGES = ["home", "give", "feedback", "request", "qr", "privacy", "terms"];
/* Addresses a page can't take: the admin, the API, the uploads, the
records' own pages and the account pages. */
const RESERVED = [
"admin", "api", "uploads", "assets", "pa", "go",
"events", "regions", "groups", "partners", "organizations", "teams", "awards", "people", "blog", "directory",
"sign-in", "account", "sitemap.xml", "robots.txt",
];
/* After a save: the address is one a page may have. */
function checkPage(db, id) {
const page = db.prepare(`SELECT path FROM site_pages WHERE id = ?`).get(id);
const first = page?.path.split("/")[1];
if (first && RESERVED.includes(first)) {
throw new HttpError(422, "Validation failed", { path: `/${first} belongs to another part of the site. Pick another address.` });
}
if (id === "home" && page.path !== "/") throw new HttpError(422, "Validation failed", { path: "The front page stays at /." });
if (id !== "home" && page.path === "/") throw new HttpError(422, "Validation failed", { path: "/ is the front page." });
}
const isCommunity = { column: "id", value: "community" };
export const pages = {
key: "pages",
table: "site_pages",
idColumn: "id",
idKind: "slug",
singleton: id,
concurrency: "updated_at",
undeletable: FIXED_PAGES,
list: { columns: ["id", "updated_at"], filters: [], search: [], order: "id" },
list: {
columns: ["title", "path", "is_hidden", "is_disabled", "updated_at"],
filters: [],
search: ["title", "path"],
order: "sort_order, title",
},
columns: [],
...more,
children: [sectionsChild, ...(more.children ?? [])],
});
columns: [
text("path", { required: true }),
text("title", { required: true }),
text("description"),
bool("is_hidden"),
bool("is_disabled"),
int("sort_order"),
],
export const communityPage = sitePage("community", {
extensions: [
{
key: "blog",
table: "community_page",
idColumn: "id",
when: isCommunity,
columns: [
text("internal_title"),
int("internal_slots"),
@ -91,27 +127,27 @@ export const communityPage = sitePage("community", {
],
},
],
children: [
sectionsChild,
{
key: "pinned_posts",
table: "community_page_pinned_posts",
owner: { column: "page_id" },
order: "sort_order",
when: isCommunity,
columns: [text("post_id", { required: true })],
},
featuredCardsChild("community_page"),
{ ...featuredCardsChild("community_page"), when: isCommunity },
{
key: "feeds",
table: "community_page_feeds",
owner: { column: "page_id" },
order: "sort_order",
when: isCommunity,
columns: [url("url", { required: true }), text("label")],
},
],
});
export const retreatsPage = sitePage("retreats");
export const resourcesPage = sitePage("resources");
export const organizationPage = sitePage("organization");
export const historyPage = sitePage("history");
export const shopPage = sitePage("shop");
check: checkPage,
};