import { HttpError } from "../admin-crud.js"; import { text, url, int, bool, enumeration, featuredCardsChild, blocksChild } from "./columns.js"; /* ── The site's pages (056_site_pages.sql, 080_page_registry.sql) ── 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). New pages are made here. A section type that needs more than its blocks keeps its settings in tables of its own (083_section_settings.sql), the section's extensions and collections here, each gated on its preset: a hero's words and slides, a countdown's event, a stats band's numbers, a pathfinder's paths, featured cards, a Community blog's slots, pinned posts and feeds. The front page is a page of sections like the rest. */ /* Gates on the section's preset. */ const is = (preset) => ({ column: "preset", value: preset }); const sectionsChild = { key: "sections", table: "page_sections", owner: { column: "page_id" }, order: "sort_order", columns: [ text("anchor", { required: true }), text("title", { required: true }), text("blurb"), enumeration("accent", ["teal", "deep", "green", "amber"]), enumeration("preset", [ "community_blog", "group_map", "region_list", "partner_list", "events", "timeline", "people_directory", // What used to be whole pages (081). "feedback_form", "request_form", "data_request_form", "giving", "qr_maker", // The front page's bands, on any page (083). "hero", "countdown", "calendar", "stats", "featured_cards", "connect", ]), text("scope_id"), enumeration("event_type", ["retreat", "class", "workshop", "meeting", "other"]), enumeration("view", ["carousel", "grid", "map"]), // Organization cards (067): the kinds listed by themselves. enumeration("org_kinds", ["partner", "ministry", "partner,ministry"]), bool("is_hidden"), ], extensions: [ { key: "hero", table: "section_hero", idColumn: "section_id", when: is("hero"), columns: [ text("eyebrow"), text("headline"), text("subhead"), text("primary_label"), url("primary_url"), text("secondary_label"), url("secondary_url"), enumeration("backdrop", ["brand", "photos"]), int("slide_seconds"), enumeration("feature", ["none", "livestream", "video", "event"]), url("livestream_url"), text("livestream_title"), url("video_url"), text("video_title"), text("video_captions"), text("video_still"), text("event_id"), // Its rotating words (084). enumeration("word_motion", ["slide", "flip", "fade", "type", "mirror"]), enumeration("word_direction", ["top", "bottom"]), int("word_seconds"), ], }, { key: "countdown", table: "section_countdown", idColumn: "section_id", when: is("countdown"), columns: [text("event_id"), text("scope_id"), enumeration("event_type", ["retreat", "class", "workshop", "meeting", "other"])], }, { key: "featured", table: "section_featured", idColumn: "section_id", when: is("featured_cards"), columns: [int("columns")], }, { key: "blog", table: "section_blog", idColumn: "section_id", when: is("community_blog"), columns: [ text("internal_title"), int("internal_slots"), text("external_title"), int("external_slots"), url("external_url"), text("external_label"), ], }, ], children: [ blocksChild("page_section"), { // A People directory's tags (078), a tab each, in order. key: "tags", table: "page_section_tags", owner: { column: "section_id" }, order: "sort_order", columns: [text("tag_id", { required: true })], }, { // Organization cards (067): a hand-picked list, shown instead. key: "orgs", table: "page_section_orgs", owner: { column: "section_id" }, order: "sort_order", columns: [text("org_id", { required: true })], }, { key: "slides", table: "section_slides", owner: { column: "section_id" }, order: "sort_order", when: is("hero"), columns: [text("media", { required: true }), text("alt"), text("caption"), url("link_url")], }, { key: "stats", table: "section_stats", owner: { column: "section_id" }, order: "sort_order", when: is("stats"), columns: [ text("label", { required: true }), enumeration("source", [ "manual", "years_since", "regions", "groups", "partners", "events_held", "retreats_held", "people", "awards_given", ]), text("value"), text("suffix"), text("note"), ], }, { key: "paths", table: "section_paths", owner: { column: "section_id" }, order: "sort_order", when: is("connect"), columns: [text("label", { required: true }), text("icon"), text("blurb")], children: [ { key: "actions", table: "section_path_actions", owner: { column: "path_id" }, order: "sort_order", columns: [text("label", { required: true }), text("description"), url("url", { required: true })], }, ], }, // Featured cards, and a Community blog's pinned community posts. { ...featuredCardsChild("page_section"), when: { column: "preset", value: ["featured_cards", "community_blog"] } }, { key: "blog_posts", table: "section_blog_posts", owner: { column: "section_id" }, order: "sort_order", when: is("community_blog"), columns: [text("post_id", { required: true })], }, { key: "feeds", table: "section_feeds", owner: { column: "section_id" }, order: "sort_order", when: is("community_blog"), columns: [url("url", { required: true }), text("label")], }, ], }; /* Pages the site's own code links to (the footer's defaults, the Request buttons, the privacy notice, Tools → QR codes): renamed, hidden or disabled, but never moved or deleted. */ export const CORE_PAGES = { home: "/", give: "/give", feedback: "/feedback", request: "/request", qr: "/qr", privacy: "/privacy", terms: "/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 (CORE_PAGES[id] && page.path !== CORE_PAGES[id]) { throw new HttpError(422, "Validation failed", { path: `The site links to this page at ${CORE_PAGES[id]}, so its address stays.` }); } if (id !== "home" && page.path === "/") throw new HttpError(422, "Validation failed", { path: "/ is the front page." }); } export const pages = { key: "pages", table: "site_pages", idColumn: "id", idKind: "slug", concurrency: "updated_at", undeletable: Object.keys(CORE_PAGES), list: { columns: ["id", "title", "path", "is_hidden", "is_disabled", "updated_at"], filters: [], search: ["title", "path"], order: "sort_order, title", }, columns: [ text("path", { required: true }), text("title", { required: true }), text("description"), bool("is_hidden"), bool("is_disabled"), int("sort_order"), ], children: [sectionsChild], check: checkPage, };