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:
parent
56acedf926
commit
1342691f49
36 changed files with 584 additions and 405 deletions
|
|
@ -33,14 +33,7 @@ import { personTagTypes } from "./adminSchema/personTags.ts";
|
|||
import { tags } from "./adminSchema/tags.ts";
|
||||
import { contactTypes } from "./adminSchema/contactTypes.ts";
|
||||
import { redirects } from "./adminSchema/redirects.ts";
|
||||
import {
|
||||
communityPage,
|
||||
retreatsPage,
|
||||
resourcesPage,
|
||||
organizationPage,
|
||||
historyPage,
|
||||
shopPage,
|
||||
} from "./adminSchema/sitePages.ts";
|
||||
import { pages } from "./adminSchema/sitePages.ts";
|
||||
|
||||
export const ADMIN_ENTITIES: Record<string, any> = {
|
||||
organizations,
|
||||
|
|
@ -55,12 +48,7 @@ export const ADMIN_ENTITIES: Record<string, any> = {
|
|||
timeline,
|
||||
front_page: frontPage,
|
||||
blog_posts: blogPosts,
|
||||
community_page: communityPage,
|
||||
retreats_page: retreatsPage,
|
||||
resources_page: resourcesPage,
|
||||
organization_page: organizationPage,
|
||||
history_page: historyPage,
|
||||
shop_page: shopPage,
|
||||
pages,
|
||||
navigation: siteNav,
|
||||
site_settings: siteSettings,
|
||||
};
|
||||
|
|
@ -79,12 +67,7 @@ export const PREVIEW_PATHS: Record<string, (row: any) => string | null> = {
|
|||
timeline: () => "/history",
|
||||
front_page: () => "/",
|
||||
blog_posts: (row) => blogHref(row.id),
|
||||
community_page: () => "/community",
|
||||
retreats_page: () => "/retreats",
|
||||
resources_page: () => "/resources",
|
||||
organization_page: () => "/organization",
|
||||
history_page: () => "/history",
|
||||
shop_page: () => "/shop",
|
||||
pages: (row) => row.path || null,
|
||||
// The menus are on every page.
|
||||
navigation: () => "/",
|
||||
site_settings: () => "/",
|
||||
|
|
|
|||
|
|
@ -1,16 +1,10 @@
|
|||
import siteConfiguration from "../../../site.json";
|
||||
|
||||
/* ── Navigation (075_site_nav.sql) ───────────────────────────────
|
||||
Pages → Navigation: the header's and footer's links, and each
|
||||
static page's title, intro and whether it's hidden. Admins and up
|
||||
save it, since hiding takes a page off the site. Server side:
|
||||
Pages → Navigation: the header's and footer's links. The pages
|
||||
themselves (titles, intros, Hidden, Disabled) are Page
|
||||
management's (sitePages.ts). Admins and up. Server side:
|
||||
server/src/admin-schema/siteNav.js; the site reads it through
|
||||
server/src/siteNav.js and src/lib/useSiteNav.ts. */
|
||||
|
||||
const SITE_PAGES: [string, string][] = Object.entries(siteConfiguration.pages).map(
|
||||
([path, page]) => [path, `${page.title} (${path})`],
|
||||
);
|
||||
|
||||
const PLACES: [string, string][] = [
|
||||
["main", "Header: pages"],
|
||||
["action", "Header: buttons"],
|
||||
|
|
@ -36,7 +30,7 @@ export const siteNav = {
|
|||
{
|
||||
key: "links",
|
||||
label: "Links",
|
||||
note: "Top to bottom, in the order each place shows them. A link to a hidden page is only shown to signed-in admin accounts. A header page lists its sections under it by itself (Pages → the page).",
|
||||
note: "Top to bottom, in the order each place shows them. A link to a hidden page is only shown to signed-in admin accounts, and one to a disabled page to no one. A header page lists its sections under it by itself (Pages → the page).",
|
||||
addLabel: "Add link",
|
||||
title: (row) => (row.label ? `${row.label} · ${placeLabel(row.place) ?? "No place"}` : "New link"),
|
||||
blank: { place: "", label: "", path: "", parent_path: "", style: "", new_tab: 0 },
|
||||
|
|
@ -54,7 +48,7 @@ export const siteNav = {
|
|||
path: "parent_path",
|
||||
label: "Under page",
|
||||
widget: "select",
|
||||
options: [["/", "Home (/)"], ...SITE_PAGES],
|
||||
optionsFrom: "site_pages",
|
||||
blankLabel: "Default: its own place in the header",
|
||||
help: "Lists it in that page's menu, after its sections, instead of in the header's row",
|
||||
when: { path: "place", value: "main" },
|
||||
|
|
@ -70,35 +64,5 @@ export const siteNav = {
|
|||
{ path: "new_tab", label: "Opens in a new tab", widget: "checkbox" },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "pages",
|
||||
label: "Pages",
|
||||
note: "A page's heading and intro (also its search title and description), and whether it's hidden. A hidden page is out of the menus and the sitemap and says Not found to everyone but signed-in admin accounts, who see it with a bar saying it's hidden. Blank fields keep site.json's. A page not listed here shows as site.json has it.",
|
||||
addLabel: "Add page",
|
||||
title: (row) =>
|
||||
`${SITE_PAGES.find(([path]) => path === row.path)?.[1] ?? "New page"}${row.is_hidden ? " · Hidden" : ""}`,
|
||||
blank: { path: "", title: "", description: "", is_hidden: 0 },
|
||||
fields: [
|
||||
{ path: "path", label: "Page", widget: "select", options: SITE_PAGES, required: true },
|
||||
{
|
||||
path: "is_hidden",
|
||||
label: "Hidden",
|
||||
widget: "checkbox",
|
||||
help: "Not found to everyone but signed-in admin accounts, eg. a page that isn't done",
|
||||
},
|
||||
{
|
||||
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),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* ── The site's own pages (056_site_pages.sql) ───────────────────
|
||||
Pages → Community, Retreats, Resources, Organization, History,
|
||||
Shop (075):
|
||||
/* ── The site's pages (056_site_pages.sql, 080_page_registry.sql) ──
|
||||
Pages → Page management: every page, its address, title, intro,
|
||||
Hidden and Disabled, and new pages made here.
|
||||
each page is its sections, in order, and each section is its
|
||||
heading and its own content blocks, then a preset if it has one
|
||||
(a prebuilt part of the site, drawn under the blocks). Server
|
||||
|
|
@ -8,7 +8,8 @@
|
|||
src/pages/SitePage.tsx.
|
||||
|
||||
The preset values are the CHECK list on page_sections.preset;
|
||||
each page offers the ones that belong on it. */
|
||||
every page offers them all. The Community blog's settings show on
|
||||
the Community page only (its id), for now. */
|
||||
|
||||
import { FEATURED_KINDS, featuredCardsChild, blocksChild } from "./shared.ts";
|
||||
|
||||
|
|
@ -162,26 +163,77 @@ const sectionsChild = (presets: string[]) => ({
|
|||
],
|
||||
});
|
||||
|
||||
const sitePage = (id: string, label: string, presets: string[], more: Record<string, any> = {}) => ({
|
||||
key: `${id}_page`,
|
||||
label,
|
||||
singular: label.toLowerCase(),
|
||||
idLabel: "Page",
|
||||
singleton: id,
|
||||
const COMMUNITY = { path: "id", value: "community" };
|
||||
const ALL_PRESETS = Object.keys(PRESETS);
|
||||
|
||||
list: { columns: [], filters: [] },
|
||||
/* The pages the site draws in code (src/pages/fixedPages.ts, and the
|
||||
front page): no sections of their own yet. */
|
||||
export const FIXED_PAGE_IDS = ["home", "give", "feedback", "request", "qr", "privacy", "terms"];
|
||||
const isFixed = (row) => FIXED_PAGE_IDS.includes(row?.id);
|
||||
|
||||
groups: [],
|
||||
...more,
|
||||
children: [sectionsChild(presets), ...(more.children ?? [])],
|
||||
});
|
||||
const communityGroups = (groups) => groups.map((group) => ({ ...group, when: COMMUNITY }));
|
||||
const communityChildren = (children) => children.map((child) => ({ ...child, when: COMMUNITY }));
|
||||
|
||||
export const communityPage = sitePage(
|
||||
"community",
|
||||
"Community page",
|
||||
["community_blog", "group_map", "region_list", "partner_list", "people_directory"],
|
||||
{
|
||||
groups: [
|
||||
export const pages = {
|
||||
key: "pages",
|
||||
label: "Page management",
|
||||
singular: "page",
|
||||
idLabel: "URL ID",
|
||||
slugFrom: "title",
|
||||
// Every page's address, title, intro and switches, then its own
|
||||
// sections. The fixed pages (and the front page, edited in Front
|
||||
// page) have no sections here.
|
||||
list: {
|
||||
columns: [
|
||||
{ key: "title", label: "Page", primary: true },
|
||||
{ key: "path", label: "Address" },
|
||||
{ key: "is_hidden", label: "Hidden", widget: "bool" },
|
||||
{ key: "is_disabled", label: "Disabled", widget: "bool" },
|
||||
],
|
||||
filters: [],
|
||||
},
|
||||
|
||||
groups: [
|
||||
{
|
||||
legend: "The page",
|
||||
fields: [
|
||||
{ path: "title", label: "Title", required: true, help: "The page's heading, and its title in search and the browser tab, eg. Library" },
|
||||
{
|
||||
path: "path",
|
||||
label: "Address",
|
||||
required: true,
|
||||
help: "Where it lives on the site, eg. /library. Lowercase letters, numbers, hyphens and /. Changing it breaks old links: update Navigation's too.",
|
||||
},
|
||||
{ path: "description", label: "Intro", widget: "textarea", full: true, help: "The line under the title, and its description in search." },
|
||||
{
|
||||
path: "is_hidden",
|
||||
label: "Hidden",
|
||||
widget: "checkbox",
|
||||
help: "Not found to everyone but signed-in admin accounts, eg. a page that isn't done. Out of the menus and the sitemap.",
|
||||
},
|
||||
{
|
||||
path: "is_disabled",
|
||||
label: "Disabled",
|
||||
widget: "checkbox",
|
||||
help: "Out of the menus, the sitemap and search; its address still works for anyone with the link.",
|
||||
},
|
||||
{ path: "sort_order", label: "Order", widget: "number", help: "Where its card sits on the admin home, lowest first. Default: 0" },
|
||||
],
|
||||
},
|
||||
{
|
||||
legend: "Its content",
|
||||
note: "The front page's content is edited in Pages → Front page: its hero, and the bands it shows.",
|
||||
when: { test: (row) => row?.id === "home" },
|
||||
fields: [],
|
||||
},
|
||||
{
|
||||
legend: "Its content",
|
||||
note: "This page's content is built into the site (a form, an embed or set text), so it has no sections to edit here yet. Its title, intro, address and switches above are yours.",
|
||||
when: { test: (row) => isFixed(row) && row?.id !== "home" },
|
||||
fields: [],
|
||||
},
|
||||
...communityGroups(
|
||||
[
|
||||
{
|
||||
legend: "Community blog: our posts",
|
||||
note: "For the Community blog preset. Pinned posts first, then the newest published, listed posts, up to the number of slots.",
|
||||
|
|
@ -200,8 +252,14 @@ export const communityPage = sitePage(
|
|||
{ path: "blog.external_label", label: "Button text", help: "Default: Read more on Substack" },
|
||||
],
|
||||
},
|
||||
],
|
||||
children: [
|
||||
]
|
||||
),
|
||||
],
|
||||
|
||||
children: [
|
||||
{ ...sectionsChild(ALL_PRESETS), when: { test: (row) => !isFixed(row) } },
|
||||
...communityChildren(
|
||||
[
|
||||
{
|
||||
key: "pinned_posts",
|
||||
label: "Community blog: pinned posts (ours)",
|
||||
|
|
@ -244,12 +302,7 @@ export const communityPage = sitePage(
|
|||
{ path: "label", label: "Source name", help: "Shown on its cards. Default: the feed's own title" },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
export const retreatsPage = sitePage("retreats", "Retreats page", ["events"]);
|
||||
export const resourcesPage = sitePage("resources", "Resources page", ["people_directory"]);
|
||||
export const organizationPage = sitePage("organization", "Organization page", ["people_directory"]);
|
||||
export const historyPage = sitePage("history", "History page", ["timeline"]);
|
||||
export const shopPage = sitePage("shop", "Shop page", []);
|
||||
]
|
||||
),
|
||||
],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export function useNavSections(): (path: string) => NavSection[] {
|
|||
return useCallback(
|
||||
(path: string) => {
|
||||
if (path !== '/') {
|
||||
return (sitePages?.[path.slice(1)] ?? []).map((section) => ({
|
||||
return (sitePages?.[path] ?? []).map((section) => ({
|
||||
label: section.title,
|
||||
hash: `#${section.anchor}`,
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -10,8 +10,9 @@
|
|||
serves the plain index.html, it isn't there and site.json alone
|
||||
applies.
|
||||
|
||||
A page's visible heading and intro and its search title and
|
||||
description come from the same values, so they can't drift.
|
||||
A page's heading and intro are its site_pages row's (Pages → Page
|
||||
management), which also give its search title and description, so
|
||||
they can't drift: useSiteNav and the page's own data carry them.
|
||||
|
||||
SITE_ORIGIN is the public address of the live site. It's used
|
||||
where a URL has to leave the browser and still work: a printed QR
|
||||
|
|
@ -22,9 +23,7 @@
|
|||
|
||||
import siteConfiguration from '../../site.json'
|
||||
|
||||
type PageText = { title: string; description: string }
|
||||
|
||||
type SiteText = { title?: string; pages?: Record<string, PageText>; privacyEmail?: string; requestFiles?: boolean }
|
||||
type SiteText = { title?: string; privacyEmail?: string; requestFiles?: boolean }
|
||||
|
||||
/* What the server wrote into the page, if it did. */
|
||||
const fromServer: SiteText =
|
||||
|
|
@ -46,18 +45,6 @@ export const REQUEST_FILES: boolean = fromServer.requestFiles ?? true
|
|||
/** A site path as a full URL on the live site. */
|
||||
export const siteUrl = (path: string): string => new URL(path, SITE_ORIGIN).href
|
||||
|
||||
const PAGES: Record<string, PageText> = { ...siteConfiguration.pages, ...fromServer.pages }
|
||||
|
||||
/* Every static page's path and text, for the not-found page's suggestions. */
|
||||
export const SITE_PAGES: Readonly<Record<string, PageText>> = PAGES
|
||||
|
||||
/** A static page's title and intro, from site.json's "pages". */
|
||||
export function sitePage(path: string): PageText {
|
||||
const page = PAGES[path]
|
||||
if (!page) throw new Error(`site.json has no "pages" entry for ${path}`)
|
||||
return page
|
||||
}
|
||||
|
||||
/** The browser tab's title for a page: "Retreats | Next Generation
|
||||
* of Unity", or the site name alone for the home page. */
|
||||
export const documentTitle = (title?: string | null): string =>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
SITE NAV: the header's and footer's links, and the hidden pages
|
||||
SITE NAV: the site's pages, the header's and footer's links, and
|
||||
the hidden pages
|
||||
|
||||
Pages → Navigation, for this visitor (server/src/siteNav.js): a
|
||||
link to a hidden page is only sent to a viewer and up. The page
|
||||
HTML carries it (window.__SITE__.nav), so the menus draw on the
|
||||
first paint; GET /api/nav asks again, which is also how the dev
|
||||
server (no page metadata) and a sign-in in another tab get it.
|
||||
Until either answers, navConfig.ts's defaults.
|
||||
Pages → Page management and Pages → Navigation, for this visitor
|
||||
(server/src/siteNav.js): a hidden page, and links to it, are only
|
||||
sent to a viewer and up; a disabled page's links to no one. The
|
||||
page HTML carries it (window.__SITE__.nav), so the menus draw on
|
||||
the first paint; GET /api/nav asks again, which is also how the
|
||||
dev server (no page metadata) and a sign-in in another tab get it.
|
||||
Until either answers, navConfig.ts's links, and no pages yet
|
||||
(`ready` false).
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useMemo } from 'react'
|
||||
|
|
@ -14,9 +17,20 @@ import { useMemo } from 'react'
|
|||
import { NAV_DEFAULTS, type NavLink } from '../navConfig.ts'
|
||||
import { useRecord } from './useRecord.ts'
|
||||
|
||||
/** A page of the site (site_pages). */
|
||||
export type SitePageInfo = {
|
||||
id: string
|
||||
path: string
|
||||
title: string
|
||||
description: string | null
|
||||
hidden: boolean
|
||||
disabled: boolean
|
||||
}
|
||||
|
||||
export type SiteNav = {
|
||||
links: NavLink[]
|
||||
/** Paths of hidden pages, eg. '/shop'. */
|
||||
pages: SitePageInfo[]
|
||||
/** Paths of hidden pages, eg. '/shop' (sent to a viewer and up only). */
|
||||
hidden: string[]
|
||||
/** This visitor sees hidden pages (signed in, viewer and up). */
|
||||
seesHidden: boolean
|
||||
|
|
@ -25,7 +39,7 @@ export type SiteNav = {
|
|||
const fromPage: SiteNav | undefined =
|
||||
typeof window !== 'undefined' ? (window as unknown as { __SITE__?: { nav?: SiteNav } }).__SITE__?.nav : undefined
|
||||
|
||||
const DEFAULTS: SiteNav = { links: NAV_DEFAULTS, hidden: [], seesHidden: false }
|
||||
const DEFAULTS: SiteNav = { links: NAV_DEFAULTS, pages: [], hidden: [], seesHidden: false }
|
||||
|
||||
/** A path's page: no #section or ?query, no trailing slash. */
|
||||
export const pageOf = (path: string): string => path.split(/[?#]/)[0].replace(/(.)\/+$/, '$1') || '/'
|
||||
|
|
@ -38,19 +52,24 @@ export function useSiteNav() {
|
|||
const main = nav.links.filter((l) => l.place === 'main')
|
||||
const top = main.filter((l) => !l.parent)
|
||||
const tops = new Set(top.map((l) => pageOf(l.path)))
|
||||
const byPath = new Map(nav.pages.map((page) => [page.path, page]))
|
||||
return {
|
||||
...nav,
|
||||
/** Whether the pages have arrived (else a page can't be told from a missing one). */
|
||||
ready: Boolean(data ?? fromPage),
|
||||
/** The header's pages, each with the links set under it. */
|
||||
main: top.map((page) => ({
|
||||
...page,
|
||||
children: main.filter((l) => l.parent && l.parent === pageOf(page.path)),
|
||||
})),
|
||||
/** Every main link, children included, for lists of the site's pages. */
|
||||
pages: main.filter((l) => !l.parent || tops.has(l.parent)),
|
||||
pageLinks: main.filter((l) => !l.parent || tops.has(l.parent)),
|
||||
actions: nav.links.filter((l) => l.place === 'action'),
|
||||
footer: nav.links.filter((l) => l.place === 'footer'),
|
||||
legal: nav.links.filter((l) => l.place === 'legal'),
|
||||
isHidden: (path: string) => nav.hidden.includes(pageOf(path)),
|
||||
/** The page at this path, or null. */
|
||||
pageAt: (path: string): SitePageInfo | null => byPath.get(pageOf(path)) ?? null,
|
||||
}
|
||||
}, [nav])
|
||||
}, [nav, data])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/* The site's own pages (Community, Retreats, Resources, Organization,
|
||||
History), built in the admin from sections: GET /site-pages/:id
|
||||
for one page's sections, GET /site-pages for every page's section
|
||||
headings (the header's dropdowns, the footer, the side nav). */
|
||||
/* The site's pages of sections (Pages → Page management): GET
|
||||
/site-pages/:id for one page's title, intro and sections, GET
|
||||
/site-pages for every page's section headings by the page's path
|
||||
(the header's dropdowns, the footer, the side nav). */
|
||||
|
||||
import { useRecord, type Resource } from './useRecord.ts'
|
||||
import type { ContentBlock } from './useContent.ts'
|
||||
|
|
@ -24,7 +24,7 @@ export type SitePageSection = {
|
|||
blocks: ContentBlock[]
|
||||
}
|
||||
|
||||
export const useSitePage = (id: string): Resource<{ id: string; sections: SitePageSection[] }> =>
|
||||
export const useSitePage = (id: string): Resource<{ id: string; title: string; description: string | null; sections: SitePageSection[] }> =>
|
||||
useRecord(`/site-pages/${id}`, 'page')
|
||||
|
||||
export const useSitePageHeadings = (): Resource<Record<string, Array<{ anchor: string; title: string }>>> =>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue