Navigation in the admin: header and footer links, page titles, hidden pages, Shop

Pages -> Navigation (migration 075) edits the header's pages and buttons
and the footer's links; navConfig.ts is now only the defaults. Page titles
and intros move there from Site settings. A hidden page answers Not found
below viewer (server and app) and is out of the menus and sitemap; signed
in, it shows with a bar. Adds a /shop page of sections, hidden, with its
header button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aidan Dona 2026-10-16 18:01:02 -05:00
parent b49497cc59
commit 0cc2a3f721
30 changed files with 716 additions and 216 deletions

View file

@ -15,7 +15,8 @@
/site.json (SITE_CONFIG): the site's name, address, default
description and image, icons, and each static page's title and
description. Laid over it: Panel → Site settings (the
site_settings table, 035), where anything set wins and anything
site_settings table, 035) and Pages → Navigation's page titles
(site_nav_pages, 075), where anything set wins and anything
blank falls back to site.json. siteFor(db) does the merge. The
pages read the same merged values (renderPage writes them into
the HTML as window.__SITE__, see src/lib/site.ts), so a
@ -28,6 +29,8 @@
published, listed indexed, in the sitemap
published, unlisted noindex: reachable by link, not by search
unpublished, missing 404 and noindex, with the site defaults
a hidden static page 404 and noindex below viewer, out of the
sitemap (siteNav.js)
/admin noindex
Image paths resolve like src/lib/media.ts does: a bare filename
@ -44,6 +47,7 @@ import { fileURLToPath } from "node:url";
import { loadBlocks, paragraphs } from "./shape.js";
import { themeCss } from "./theme.js";
import { driveReady } from "./googleService.js";
import { hiddenFrom, hiddenPaths, navFor } from "./siteNav.js";
const here = path.dirname(fileURLToPath(import.meta.url));
@ -71,15 +75,15 @@ const origin = (site) => (site.url ?? "").replace(/\/$/, "");
/* site.json with the admin's Site settings laid over it: a value set
there wins, a blank one falls back. indexing 'on' / 'off' overrides
robots.index for this database only. Page overrides apply only to
pages site.json knows. */
robots.index for this database only. Page overrides (Pages →
Navigation) apply only to pages site.json knows. */
export function siteFor(db) {
const base = loadSite();
const row = db.prepare(`SELECT * FROM site_settings WHERE id = 'site'`).get() ?? {};
const pages = { ...(base.pages ?? {}) };
const overrides = db
.prepare(`SELECT path, title, description FROM site_setting_pages WHERE settings_id = 'site'`)
.prepare(`SELECT path, title, description FROM site_nav_pages WHERE nav_id = 'site'`)
.all();
for (const page of overrides) {
const known = pages[page.path];
@ -112,13 +116,15 @@ export function siteFor(db) {
};
}
/* What the browser app reads for headings and titles. */
// requestFiles: whether the Request form can take files (Drive set up).
const forBrowser = (site) => ({
/* What the browser app reads for headings, titles and its menus.
requestFiles: whether the Request form can take files (Drive set
up). nav: this visitor's links and the hidden pages (siteNav.js). */
const forBrowser = (site, nav) => ({
title: site.title,
pages: site.pages,
privacyEmail: site.privacyEmail,
requestFiles: driveReady(),
nav,
});
/* robots.txt for this database's setting, as the build writes it. */
@ -358,12 +364,13 @@ function blogMeta(site, db, id, meta) {
};
}
/* The metadata for one request path. */
export function metaFor(db, rawPath) {
/* The metadata for one request path, for this visitor (the signed-in
user or null, who decides whether a hidden page is there). */
export function metaFor(db, rawPath, user = null) {
const site = siteFor(db);
// Canonical form: no trailing slash (but "/" itself), no query.
const pathname = rawPath.split(/[?#]/)[0].replace(/(.)\/+$/, "$1") || "/";
const meta = defaults(site, db, pathname);
const meta = { ...defaults(site, db, pathname), nav: navFor(db, user) };
if (pathname === "/") {
// The home page's data, and its first hero photo when the hero is
@ -396,6 +403,7 @@ export function metaFor(db, rawPath) {
if (/^\/admin(\/|$)/.test(pathname)) return { ...meta, title: `Admin | ${site.title}`, noindex: true };
const page = site.pages?.[pathname];
if (page && hiddenFrom(db, user, pathname)) return notFound(meta);
if (page) {
return { ...meta, title: titled(site, page.title), description: plainText(page.description) ?? meta.description };
}
@ -520,7 +528,7 @@ export function renderPage(html, meta) {
),
// Read by src/lib/site.ts before the app's module runs (a plain
// script in the head runs during parsing; modules wait).
`<script>window.__SITE__ = ${scriptJson(forBrowser(site))}</script>`,
`<script>window.__SITE__ = ${scriptJson(forBrowser(site, meta.nav))}</script>`,
site.themeCss && `<style id="site-colors">${site.themeCss}</style>`,
analyticsTag(site),
].filter(Boolean);
@ -542,10 +550,13 @@ export function sitemap(db) {
const site = siteFor(db);
const base = origin(site);
const day = (value) => (value ? String(value).slice(0, 10) : null);
const hidden = hiddenPaths(db);
const entries = [
{ loc: "/" },
...Object.keys(site.pages ?? {}).map((loc) => ({ loc })),
...Object.keys(site.pages ?? {})
.filter((loc) => !hidden.has(loc))
.map((loc) => ({ loc })),
...db
.prepare(`SELECT id, updated_at FROM events WHERE is_published = 1 AND is_listed = 1`)
.all()