Add Site settings: name, description, icons, page titles, indexing
Panel → Site settings (migration 035, superadmins only) edits the site's name, description, preview image, favicon and home-screen icon, each static page's title and intro, and whether search engines may list the site. Every value overrides site.json; a blank one falls back to it. The indexing switch is per database, so the dev server can be off while production is on from one build. The server merges the two (siteFor in pageMeta.js) for page metadata, the sitemap and a new /robots.txt route, and writes the merged wording into each page as window.__NGU_SITE__, which site.ts reads so headings match with no extra request. Entities can now require a higher role to save (writeRole), checked on both sides. Panel is a menu group with Accounts and server, and Site settings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8ec34ea185
commit
47df7b1fe0
15 changed files with 393 additions and 32 deletions
|
|
@ -18,6 +18,7 @@
|
|||
import { preview } from "./text.ts";
|
||||
import { PLATFORMS } from "./platforms.ts";
|
||||
import { FORMATTING_HELP } from "../components/InlineText.tsx";
|
||||
import siteConfiguration from "../../site.json";
|
||||
import {
|
||||
awardLogo,
|
||||
blockMedia,
|
||||
|
|
@ -1619,6 +1620,112 @@ const communityPage = {
|
|||
],
|
||||
};
|
||||
|
||||
/* ── Site settings (035_site_settings.sql) ───────────────────────
|
||||
Overrides for site.json, superadmins only: every blank falls back
|
||||
to what site.json says, which is shown as the default. */
|
||||
const SITE_PAGES: [string, string][] = Object.entries(siteConfiguration.pages).map(
|
||||
([path, page]) => [path, `${page.title} (${path})`],
|
||||
);
|
||||
|
||||
const siteSettings = {
|
||||
key: "site_settings",
|
||||
label: "Site settings",
|
||||
singular: "site settings",
|
||||
idLabel: "Settings",
|
||||
singleton: "site",
|
||||
writeRole: "superadmin",
|
||||
|
||||
list: { columns: [], filters: [] },
|
||||
|
||||
groups: [
|
||||
{
|
||||
legend: "The site",
|
||||
note: "Anything left blank uses site.json, so the build and these settings agree until you change one.",
|
||||
fields: [
|
||||
{ path: "site_name", label: "Site name", help: `Default: ${siteConfiguration.title}` },
|
||||
{
|
||||
path: "description",
|
||||
label: "Description",
|
||||
widget: "textarea",
|
||||
full: true,
|
||||
help: "Search engines and link previews show this for pages without their own. Default: site.json's, or the front page's subhead.",
|
||||
},
|
||||
{
|
||||
path: "preview_image",
|
||||
label: "Preview image",
|
||||
widget: "image",
|
||||
resolve: blogImage,
|
||||
full: true,
|
||||
help: "Shown when a page without its own image is shared. 1200 × 630 works everywhere.",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
legend: "Icons",
|
||||
fields: [
|
||||
{
|
||||
path: "favicon",
|
||||
label: "Favicon",
|
||||
widget: "image",
|
||||
resolve: blogImage,
|
||||
full: true,
|
||||
help: "The browser-tab icon: a square PNG (512px) or an SVG. Keep original when uploading an SVG.",
|
||||
},
|
||||
{
|
||||
path: "apple_touch_icon",
|
||||
label: "Home-screen icon",
|
||||
widget: "image",
|
||||
resolve: blogImage,
|
||||
full: true,
|
||||
help: "For iPhones saving the site to their home screen: a square PNG, 180px, no transparency.",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
legend: "Search engines",
|
||||
fields: [
|
||||
{
|
||||
path: "indexing",
|
||||
label: "Let search engines list this site",
|
||||
widget: "select",
|
||||
options: [
|
||||
["on", "On: pages can appear in Google"],
|
||||
["off", "Off: hidden from search (use on the dev server)"],
|
||||
],
|
||||
blankLabel: `Default: site.json (${siteConfiguration.robots?.index === false ? "off" : "on"})`,
|
||||
help: "Applies to this server's database only, so dev can be off while production is on.",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
children: [
|
||||
{
|
||||
key: "pages",
|
||||
label: "Page titles and intros",
|
||||
note: "Change a static page's heading and intro, which are also its search title and description. Blank fields keep site.json's.",
|
||||
addLabel: "Change a page",
|
||||
title: (row) => SITE_PAGES.find(([path]) => path === row.path)?.[1] ?? "New page",
|
||||
blank: { path: "", title: "", description: "" },
|
||||
fields: [
|
||||
{ path: "path", label: "Page", widget: "select", options: SITE_PAGES, required: true },
|
||||
{
|
||||
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),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const ADMIN_ENTITIES: Record<string, any> = {
|
||||
organizations,
|
||||
events,
|
||||
|
|
@ -1629,6 +1736,7 @@ export const ADMIN_ENTITIES: Record<string, any> = {
|
|||
front_page: frontPage,
|
||||
blog_posts: blogPosts,
|
||||
community_page: communityPage,
|
||||
site_settings: siteSettings,
|
||||
};
|
||||
|
||||
export function slugify(value) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,17 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
SITE
|
||||
|
||||
What /site.json says about the site, for the browser. The server
|
||||
reads the same file for the metadata it puts in each page's HTML
|
||||
(server/src/pageMeta.js), so a page's visible heading and intro
|
||||
and its search title and description come from one place.
|
||||
What the site says about itself, for the browser: /site.json, with
|
||||
the admin's Site settings (Panel) laid over it. The server merges
|
||||
the two and writes the result into each page's HTML as
|
||||
window.__NGU_SITE__ (server/src/pageMeta.js), which is read here
|
||||
before the app renders, so there's no request and no flash of the
|
||||
old wording. In development, or if the API is down and nginx
|
||||
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.
|
||||
|
||||
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
|
||||
|
|
@ -15,16 +22,25 @@
|
|||
|
||||
import siteConfiguration from '../../site.json'
|
||||
|
||||
export const SITE_NAME: string = siteConfiguration.title
|
||||
type PageText = { title: string; description: string }
|
||||
|
||||
type SiteText = { title?: string; pages?: Record<string, PageText> }
|
||||
|
||||
/* What the server wrote into the page, if it did. */
|
||||
const fromServer: SiteText =
|
||||
(typeof window !== 'undefined' && (window as unknown as { __NGU_SITE__?: SiteText }).__NGU_SITE__) || {}
|
||||
|
||||
export const SITE_NAME: string = fromServer.title || siteConfiguration.title
|
||||
|
||||
export const SITE_ORIGIN: string = siteConfiguration.url
|
||||
|
||||
/** A site path as a full URL on the live site. */
|
||||
export const siteUrl = (path: string): string => new URL(path, SITE_ORIGIN).href
|
||||
|
||||
type PageText = { title: string; description: string }
|
||||
const PAGES: Record<string, PageText> = { ...siteConfiguration.pages, ...fromServer.pages }
|
||||
|
||||
const PAGES: Record<string, PageText> = siteConfiguration.pages
|
||||
/** The static pages site.json knows, for the admin's page list. */
|
||||
export const SITE_PAGE_PATHS: string[] = Object.keys(siteConfiguration.pages)
|
||||
|
||||
/** A static page's title and intro, from site.json's "pages". */
|
||||
export function sitePage(path: string): PageText {
|
||||
|
|
|
|||
|
|
@ -128,8 +128,10 @@ export default function AdminHome() {
|
|||
))}
|
||||
|
||||
{isSuper(user) && (
|
||||
<CardBlock title="Superadmin" blurb="Only superadmins see this block.">
|
||||
<NavCard item={PANEL_NAV} />
|
||||
<CardBlock title={PANEL_NAV.label} blurb={PANEL_NAV.blurb}>
|
||||
{PANEL_NAV.children.map((item) => (
|
||||
<NavCard key={item.to} item={item} />
|
||||
))}
|
||||
</CardBlock>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -87,7 +87,9 @@ export default function EntityEdit() {
|
|||
useWideAdminPage();
|
||||
|
||||
const isNew = id === "new";
|
||||
const canWrite = atLeast(user, "editor");
|
||||
// Editor, unless the entity asks for more (site settings:
|
||||
// superadmin), matching the server's writeRole.
|
||||
const canWrite = atLeast(user, manifest?.writeRole ?? "editor");
|
||||
const canDelete = atLeast(user, "admin");
|
||||
|
||||
// Some entities have no slug: the table assigns an integer id, so
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ export default function EntityList() {
|
|||
// equality test this replaced hid the button from superadmins as
|
||||
// well as editors, which is the failure mode an == against a
|
||||
// ladder always produces once a rank is added above it.
|
||||
const canWrite = atLeast(user, "editor");
|
||||
const canWrite = atLeast(user, manifest?.writeRole ?? "editor");
|
||||
|
||||
const load = useCallback(async () => {
|
||||
if (!manifest || manifest.singleton) return;
|
||||
|
|
|
|||
|
|
@ -140,14 +140,27 @@ export const TOOLS_NAV = {
|
|||
],
|
||||
};
|
||||
|
||||
/* Accounts and server state, not content, which is why it's its
|
||||
own area rather than a group of CMS pages. */
|
||||
/* Accounts, server state and what the site says about itself: the
|
||||
superadmin's area, its own area rather than a group of CMS pages. */
|
||||
export const SITE_SETTINGS = "/admin/site_settings";
|
||||
|
||||
export const PANEL_NAV = {
|
||||
to: ADMIN_PANEL,
|
||||
label: "Panel",
|
||||
blurb: "Accounts, sessions and the state of the server.",
|
||||
blurb: "Only superadmins see this.",
|
||||
separated: true,
|
||||
superOnly: true,
|
||||
children: [
|
||||
{
|
||||
to: ADMIN_PANEL,
|
||||
label: "Accounts and server",
|
||||
blurb: "Accounts, sessions and the state of the server.",
|
||||
},
|
||||
{
|
||||
to: SITE_SETTINGS,
|
||||
label: "Site settings",
|
||||
blurb: "The site's name, description, preview image, icons, page titles and search indexing.",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const NAV: any[] = [DATA_NAV, PAGES_NAV, FORMS_NAV, TOOLS_NAV, PANEL_NAV];
|
||||
|
|
@ -167,6 +180,6 @@ export const target = (item) => item.to ?? item.children?.[0]?.to;
|
|||
|
||||
export function areaFor(pathname) {
|
||||
if (matches(pathname, ADMIN_HOME)) return "home";
|
||||
if (matches(pathname, ADMIN_PANEL)) return "panel";
|
||||
if (matches(pathname, ADMIN_PANEL) || matches(pathname, SITE_SETTINGS)) return "panel";
|
||||
return "cms";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue