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,16 +1,21 @@
/* ═══════════════════════════════════════════════════════════════
SITE NAVIGATION
SITE NAVIGATION AND PAGES
Pages → Navigation (075_site_nav.sql): the header's and footer's
links, and which static pages are hidden. Read by pageMeta.js
(window.__SITE__, the page's status, the sitemap) and served as
GET /api/nav for the app (routes/sitePages.js).
The site's pages (site_pages, 080_page_registry.sql: Pages →
Page management) and the header's and footer's links (Pages →
Navigation, 075). Read by pageMeta.js (window.__SITE__, each
page's status and title, the sitemap) and served as GET /api/nav
for the app (routes/sitePages.js).
A hidden page answers Not found to anyone below viewer, and its
links are left out of what they're sent; a viewer and up sees
both, and the page says it's hidden (Layout.tsx). Who's asking
is the session cookie, so the same page can be hidden from one
visitor and shown to the next: the HTML is no-cache already.
hidden Not found to anyone below viewer, and left out of
what they're sent, links included; a viewer and up
sees it, and the page says it's hidden (Layout.tsx)
disabled out of the menus, the sitemap and search, for
everyone; its address still works
Who's asking is the session cookie, so the same page can be
hidden from one visitor and shown to the next: the HTML is
no-cache already.
═══════════════════════════════════════════════════════════════ */
import { hasRole } from "./auth.js";
@ -20,38 +25,63 @@ export const SEES_HIDDEN = "viewer";
export const seesHidden = (user) => hasRole(user, SEES_HIDDEN);
/* A link's page: its path without the #section or ?query, or null
for an address off the site. */
export const pageOf = (href) =>
/^\//.test(href) ? href.split(/[?#]/)[0].replace(/(.)\/+$/, "$1") || "/" : null;
/* Every page, in the admin's order. */
export function allPages(db) {
return db
.prepare(
`SELECT id, path, title, description, is_hidden, is_disabled
FROM site_pages ORDER BY sort_order, title`,
)
.all();
}
/* The page at this path, or null. */
export function pageAt(db, path) {
return (
db
.prepare(`SELECT id, path, title, description, is_hidden, is_disabled FROM site_pages WHERE path = ?`)
.get(pageOf(path) ?? path) ?? null
);
}
/* The paths whose pages are hidden, eg. '/shop'. */
export function hiddenPaths(db) {
return new Set(
db
.prepare(`SELECT path FROM site_nav_pages WHERE nav_id = 'site' AND is_hidden = 1`)
.prepare(`SELECT path FROM site_pages WHERE is_hidden = 1`)
.all()
.map((row) => row.path),
);
}
/* A link's page: its path without the #section or ?query, or null
for an address off the site. */
const pageOf = (href) => (/^\//.test(href) ? href.split(/[?#]/)[0].replace(/(.)\/+$/, "$1") : null);
/* Whether this path's page is one the user can't see. */
export function hiddenFrom(db, user, pathname) {
return !seesHidden(user) && hiddenPaths(db).has(pageOf(pathname));
}
/* What the app draws its menus from: every link this user may
follow, and the hidden pages' paths (so the app can answer Not
found, or say a page is hidden, without asking again). */
/* What the app draws its menus and pages from: every page this user
may open, every link they may follow (none to a disabled page),
and which pages are hidden (so the app can say so). */
export function navFor(db, user) {
const hidden = hiddenPaths(db);
const sees = seesHidden(user);
const pages = allPages(db).filter((page) => sees || page.is_hidden !== 1);
const hidden = new Set(allPages(db).filter((p) => p.is_hidden === 1).map((p) => p.path));
const disabled = new Set(pages.filter((p) => p.is_disabled === 1).map((p) => p.path));
const links = db
.prepare(
`SELECT place, label, path, parent_path, style, new_tab
FROM site_nav_links WHERE nav_id = 'site' ORDER BY sort_order, id`,
)
.all()
.filter((link) => sees || !hidden.has(pageOf(link.path)))
.filter((link) => {
const page = pageOf(link.path);
return !disabled.has(page) && (sees || !hidden.has(page));
})
.map((link) => ({
place: link.place,
label: link.label,
@ -61,5 +91,17 @@ export function navFor(db, user) {
newTab: link.new_tab === 1,
}));
return { links, hidden: [...hidden], seesHidden: sees };
return {
links,
pages: pages.map((page) => ({
id: page.id,
path: page.path,
title: page.title,
description: page.description,
hidden: page.is_hidden === 1,
disabled: page.is_disabled === 1,
})),
hidden: sees ? [...hidden] : [],
seesHidden: sees,
};
}