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
|
|
@ -32,7 +32,7 @@ In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API mu
|
||||||
- Debugging: check `journalctl -u ngu-api -n 40 --no-pager` first. Make sure rsync ran from the repo (not the deployed copy) before restarting the service.
|
- Debugging: check `journalctl -u ngu-api -n 40 --no-pager` first. Make sure rsync ran from the repo (not the deployed copy) before restarting the service.
|
||||||
- Never run commands against the production server or database unless explicitly asked.
|
- Never run commands against the production server or database unless explicitly asked.
|
||||||
- Uploaded media: `UPLOADS_DIR=/var/lib/ngu/uploads`, served by nginx at `/uploads/`. Setup and the nginx block are in `docs/media-uploads.md`.
|
- Uploaded media: `UPLOADS_DIR=/var/lib/ngu/uploads`, served by nginx at `/uploads/`. Setup and the nginx block are in `docs/media-uploads.md`.
|
||||||
- Page HTML goes through the API, which fills in each page's title, description, preview image and structured data (`server/src/pageMeta.js`), and serves `/sitemap.xml`. It reads `SITE_CONFIG` (site.json) and `SITE_INDEX` (the built index.html). nginx setup: `docs/seo.md`.
|
- Page HTML goes through the API, which fills in each page's title, description, preview image and structured data (`server/src/pageMeta.js`), and serves `/sitemap.xml`. It reads `SITE_CONFIG` (site.json) and `SITE_INDEX` (the built index.html), with Panel → Site settings (the `site_settings` table) laid over site.json, and serves `/robots.txt` from the same merge. nginx setup: `docs/seo.md`.
|
||||||
- Google sign-in for @nextgenerationofunity.org admin accounts: on when `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` are set on the service. Only existing accounts (made by admin-cli) get in; passwords still work. Setup: `docs/google-sign-in.md`.
|
- Google sign-in for @nextgenerationofunity.org admin accounts: on when `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` are set on the service. Only existing accounts (made by admin-cli) get in; passwords still work. Setup: `docs/google-sign-in.md`.
|
||||||
|
|
||||||
## Git workflow
|
## Git workflow
|
||||||
|
|
|
||||||
20
docs/seo.md
20
docs/seo.md
|
|
@ -11,6 +11,14 @@ in `server/src/pageMeta.js`). It also serves `/sitemap.xml`.
|
||||||
|
|
||||||
## Where the words come from
|
## Where the words come from
|
||||||
|
|
||||||
|
Everything below can also be set in the admin, under **Panel → Site
|
||||||
|
settings** (superadmins only): 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. A setting there wins; a
|
||||||
|
blank one falls back to `site.json`. The indexing switch is per
|
||||||
|
database, so the dev server can be off while production is on, from the
|
||||||
|
same build.
|
||||||
|
|
||||||
| What | Where |
|
| What | Where |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| Site name, address, default description | `site.json`: `title`, `url`, `description` (blank uses the front page's subhead) |
|
| Site name, address, default description | `site.json`: `title`, `url`, `description` (blank uses the front page's subhead) |
|
||||||
|
|
@ -83,6 +91,18 @@ with it off it blocks everything.
|
||||||
try_files /index.html =404;
|
try_files /index.html =404;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# From the API, so Site settings' indexing switch applies; the
|
||||||
|
# build's own robots.txt if the API is down.
|
||||||
|
location = /robots.txt {
|
||||||
|
proxy_pass http://127.0.0.1:3001;
|
||||||
|
proxy_intercept_errors on;
|
||||||
|
error_page 500 502 503 504 = @file;
|
||||||
|
}
|
||||||
|
|
||||||
|
location @file {
|
||||||
|
try_files $uri =404;
|
||||||
|
}
|
||||||
|
|
||||||
# Uploads are bigger than the /api/ block's 64k limit allows.
|
# Uploads are bigger than the /api/ block's 64k limit allows.
|
||||||
location = /api/admin/media {
|
location = /api/admin/media {
|
||||||
proxy_pass http://127.0.0.1:3001;
|
proxy_pass http://127.0.0.1:3001;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ what a dropdown in the admin editor says.
|
||||||
| The **label** a dropdown shows in the admin | code | [one file](#renaming-what-a-dropdown-shows) |
|
| The **label** a dropdown shows in the admin | code | [one file](#renaming-what-a-dropdown-shows) |
|
||||||
| The **list of allowed values** behind a fixed dropdown | database CHECK + code | [a migration and three files](#adding-removing-or-renaming-a-stored-value) |
|
| The **list of allowed values** behind a fixed dropdown | database CHECK + code | [a migration and three files](#adding-removing-or-renaming-a-stored-value) |
|
||||||
| Navigation, page section titles, colours, the site banner, history decades, the map grid | code | [the file named below](#other-content-that-lives-in-code) |
|
| Navigation, page section titles, colours, the site banner, history decades, the map grid | code | [the file named below](#other-content-that-lives-in-code) |
|
||||||
| A static page's title and intro (also its search title and description), the site's name, address and default preview image | `site.json` | editing `pages`, `title`, `url`, `openGraph.image`. See `docs/seo.md` |
|
| A static page's title and intro (also its search title and description), the site's name, description, preview image, icons, search indexing | the database, over `site.json` | Admin → Panel → Site settings (superadmins). Blank uses `site.json`, which also holds the site's address and the pages' defaults. See `docs/seo.md` |
|
||||||
| Uploaded images | disk + the `media` table | Admin → Tools → Media, or any image field. See `docs/media-uploads.md` |
|
| Uploaded images | disk + the `media` table | Admin → Tools → Media, or any image field. See `docs/media-uploads.md` |
|
||||||
|
|
||||||
The rule of thumb from `CLAUDE.md`: data belongs in the database,
|
The rule of thumb from `CLAUDE.md`: data belongs in the database,
|
||||||
|
|
|
||||||
|
|
@ -904,6 +904,47 @@ const communityPage = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* ── Site settings (035_site_settings.sql) ──────────────────────
|
||||||
|
A singleton of overrides for what site.json says: name,
|
||||||
|
description, preview image, icons, search indexing, and static
|
||||||
|
pages' titles and intros. Superadmins only. pageMeta.js merges it
|
||||||
|
over site.json. */
|
||||||
|
const siteSettings = {
|
||||||
|
key: "site_settings",
|
||||||
|
table: "site_settings",
|
||||||
|
idColumn: "id",
|
||||||
|
idKind: "slug",
|
||||||
|
singleton: "site",
|
||||||
|
concurrency: "updated_at",
|
||||||
|
writeRole: "superadmin",
|
||||||
|
|
||||||
|
list: {
|
||||||
|
columns: ["id", "site_name", "updated_at"],
|
||||||
|
filters: [],
|
||||||
|
search: [],
|
||||||
|
order: "id",
|
||||||
|
},
|
||||||
|
|
||||||
|
columns: [
|
||||||
|
text("site_name"),
|
||||||
|
text("description"),
|
||||||
|
text("preview_image"),
|
||||||
|
text("favicon"),
|
||||||
|
text("apple_touch_icon"),
|
||||||
|
enumeration("indexing", ["on", "off"]),
|
||||||
|
],
|
||||||
|
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
key: "pages",
|
||||||
|
table: "site_setting_pages",
|
||||||
|
owner: { column: "settings_id" },
|
||||||
|
order: "sort_order",
|
||||||
|
columns: [text("path", { required: true }), text("title"), text("description")],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
export const ENTITIES = {
|
export const ENTITIES = {
|
||||||
organizations,
|
organizations,
|
||||||
events,
|
events,
|
||||||
|
|
@ -914,6 +955,7 @@ export const ENTITIES = {
|
||||||
front_page: frontPage,
|
front_page: frontPage,
|
||||||
blog_posts: blogPosts,
|
blog_posts: blogPosts,
|
||||||
community_page: communityPage,
|
community_page: communityPage,
|
||||||
|
site_settings: siteSettings,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ── Options for the form's select inputs ────────────────────── */
|
/* ── Options for the form's select inputs ────────────────────── */
|
||||||
|
|
|
||||||
|
|
@ -201,6 +201,11 @@ export async function requireAuth(c, next) {
|
||||||
export const ROLES = ["viewer", "editor", "admin", "superadmin"];
|
export const ROLES = ["viewer", "editor", "admin", "superadmin"];
|
||||||
const RANK = { viewer: 1, editor: 2, admin: 3, superadmin: 4 };
|
const RANK = { viewer: 1, editor: 2, admin: 3, superadmin: 4 };
|
||||||
|
|
||||||
|
/* Whether a user is at least this rank. A ladder, never equality. */
|
||||||
|
export function hasRole(user, role) {
|
||||||
|
return (RANK[user?.role] ?? 0) >= (RANK[role] ?? Infinity);
|
||||||
|
}
|
||||||
|
|
||||||
export function requireRole(...roles) {
|
export function requireRole(...roles) {
|
||||||
const need = Math.min(...roles.map((r) => RANK[r] ?? Infinity));
|
const need = Math.min(...roles.map((r) => RANK[r] ?? Infinity));
|
||||||
return async (c, next) => {
|
return async (c, next) => {
|
||||||
|
|
|
||||||
62
server/src/migrations/035_site_settings.sql
Normal file
62
server/src/migrations/035_site_settings.sql
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
-- ═══════════════════════════════════════════════════════════════
|
||||||
|
-- 035 SITE SETTINGS
|
||||||
|
--
|
||||||
|
-- What the site says about itself, editable in the admin (Panel →
|
||||||
|
-- Site settings, superadmins only) instead of only in site.json.
|
||||||
|
-- Every column is an override: null means "whatever site.json
|
||||||
|
-- says", so a fresh database behaves exactly as before and the
|
||||||
|
-- built index.html (made from site.json) stays a true fallback for
|
||||||
|
-- when the API is down.
|
||||||
|
--
|
||||||
|
-- site_name the site's name, in every title
|
||||||
|
-- description the default search description
|
||||||
|
-- preview_image the default link-preview image
|
||||||
|
-- favicon the browser-tab icon ('/uploads/…', PNG or SVG)
|
||||||
|
-- apple_touch_icon the home-screen icon on iPhones (PNG, 180px)
|
||||||
|
-- indexing 'on' or 'off': whether search engines may list
|
||||||
|
-- the site. Per database, so the dev server can
|
||||||
|
-- say off while production says on, from one
|
||||||
|
-- build. Null follows site.json's robots.index.
|
||||||
|
--
|
||||||
|
-- site_setting_pages overrides a static page's title and intro
|
||||||
|
-- (site.json's "pages"), one row per page that differs. The path
|
||||||
|
-- must be one of site.json's pages; the admin only offers those.
|
||||||
|
--
|
||||||
|
-- A singleton like front_page: one row, made here, which the admin
|
||||||
|
-- edits and can't delete.
|
||||||
|
--
|
||||||
|
-- PRAGMA user_version; -- reads 34 before this file
|
||||||
|
-- ═══════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
CREATE TABLE site_settings (
|
||||||
|
id TEXT PRIMARY KEY CHECK (id = 'site'),
|
||||||
|
site_name TEXT,
|
||||||
|
description TEXT,
|
||||||
|
preview_image TEXT,
|
||||||
|
favicon TEXT,
|
||||||
|
apple_touch_icon TEXT,
|
||||||
|
indexing TEXT CHECK (indexing IN ('on', 'off')),
|
||||||
|
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||||
|
) STRICT;
|
||||||
|
|
||||||
|
INSERT INTO site_settings (id) VALUES ('site');
|
||||||
|
|
||||||
|
CREATE TABLE site_setting_pages (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
settings_id TEXT NOT NULL REFERENCES site_settings (id) ON DELETE CASCADE,
|
||||||
|
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||||
|
path TEXT NOT NULL, -- '/retreats'
|
||||||
|
title TEXT,
|
||||||
|
description TEXT,
|
||||||
|
UNIQUE (settings_id, path)
|
||||||
|
) STRICT;
|
||||||
|
|
||||||
|
|
||||||
|
-- ── Triggers last (see CLAUDE.md, Migrations) ──
|
||||||
|
|
||||||
|
CREATE TRIGGER site_settings_touch
|
||||||
|
AFTER UPDATE ON site_settings
|
||||||
|
FOR EACH ROW WHEN new.updated_at = old.updated_at
|
||||||
|
BEGIN
|
||||||
|
UPDATE site_settings SET updated_at = datetime('now') WHERE id = new.id;
|
||||||
|
END;
|
||||||
|
|
@ -13,9 +13,13 @@
|
||||||
|
|
||||||
── Where it comes from ──
|
── Where it comes from ──
|
||||||
/site.json (SITE_CONFIG): the site's name, address, default
|
/site.json (SITE_CONFIG): the site's name, address, default
|
||||||
description and image, and each static page's title and
|
description and image, icons, and each static page's title and
|
||||||
description. The pages read the same file for their heading and
|
description. Laid over it: Panel → Site settings (the
|
||||||
intro, so the two can't drift.
|
site_settings table, 035), 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.__NGU_SITE__, see src/lib/site.ts), so a
|
||||||
|
heading and its search title can't drift.
|
||||||
The database: records' names, taglines, first paragraphs and
|
The database: records' names, taglines, first paragraphs and
|
||||||
images. A blank site description falls back to the front page's
|
images. A blank site description falls back to the front page's
|
||||||
subhead.
|
subhead.
|
||||||
|
|
@ -63,6 +67,57 @@ export function loadSite() {
|
||||||
|
|
||||||
const origin = (site) => (site.url ?? "").replace(/\/$/, "");
|
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. */
|
||||||
|
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'`)
|
||||||
|
.all();
|
||||||
|
for (const page of overrides) {
|
||||||
|
const known = pages[page.path];
|
||||||
|
if (!known) continue;
|
||||||
|
pages[page.path] = {
|
||||||
|
title: page.title || known.title,
|
||||||
|
description: page.description || known.description,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...base,
|
||||||
|
title: row.site_name || base.title,
|
||||||
|
description: row.description || base.description,
|
||||||
|
openGraph: { ...base.openGraph, image: row.preview_image || base.openGraph?.image },
|
||||||
|
icons: {
|
||||||
|
...base.icons,
|
||||||
|
icon: row.favicon || base.icons?.icon,
|
||||||
|
apple: row.apple_touch_icon || base.icons?.apple,
|
||||||
|
},
|
||||||
|
robots: {
|
||||||
|
...base.robots,
|
||||||
|
index: row.indexing ? row.indexing === "on" : base.robots?.index !== false,
|
||||||
|
},
|
||||||
|
pages,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/* What the browser app reads for headings and titles. */
|
||||||
|
const forBrowser = (site) => ({ title: site.title, pages: site.pages });
|
||||||
|
|
||||||
|
/* robots.txt for this database's setting, as the build writes it. */
|
||||||
|
export function robotsTxt(site) {
|
||||||
|
if (site.robots?.index === false) return "User-agent: *\nDisallow: /\n";
|
||||||
|
return (
|
||||||
|
"User-agent: *\nDisallow: /admin\nDisallow: /api\n" +
|
||||||
|
(site.url ? `\nSitemap: ${origin(site)}/sitemap.xml\n` : "")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/* ── Helpers ───────────────────────────────────────────────── */
|
/* ── Helpers ───────────────────────────────────────────────── */
|
||||||
|
|
||||||
/* Text as a description: the formatting marks content blocks allow
|
/* Text as a description: the formatting marks content blocks allow
|
||||||
|
|
@ -112,6 +167,7 @@ function defaults(site, db, pathname) {
|
||||||
type: "website",
|
type: "website",
|
||||||
noindex: false,
|
noindex: false,
|
||||||
jsonLd: null,
|
jsonLd: null,
|
||||||
|
site,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -277,7 +333,7 @@ function blogMeta(site, db, id, meta) {
|
||||||
|
|
||||||
/* The metadata for one request path. */
|
/* The metadata for one request path. */
|
||||||
export function metaFor(db, rawPath) {
|
export function metaFor(db, rawPath) {
|
||||||
const site = loadSite();
|
const site = siteFor(db);
|
||||||
// Canonical form: no trailing slash (but "/" itself), no query.
|
// Canonical form: no trailing slash (but "/" itself), no query.
|
||||||
const pathname = rawPath.split(/[?#]/)[0].replace(/(.)\/+$/, "$1") || "/";
|
const pathname = rawPath.split(/[?#]/)[0].replace(/(.)\/+$/, "$1") || "/";
|
||||||
const meta = defaults(site, db, pathname);
|
const meta = defaults(site, db, pathname);
|
||||||
|
|
@ -352,10 +408,15 @@ const REPLACED = [
|
||||||
/<meta\s+(?:name|property)="(?:description|robots|og:[^"]+|twitter:[^"]+)"[^>]*>\s*/gi,
|
/<meta\s+(?:name|property)="(?:description|robots|og:[^"]+|twitter:[^"]+)"[^>]*>\s*/gi,
|
||||||
/<link\s+rel="canonical"[^>]*>\s*/gi,
|
/<link\s+rel="canonical"[^>]*>\s*/gi,
|
||||||
/<script\s+type="application\/ld\+json"[^>]*>[\s\S]*?<\/script>\s*/gi,
|
/<script\s+type="application\/ld\+json"[^>]*>[\s\S]*?<\/script>\s*/gi,
|
||||||
|
/<link\s+rel="(?:icon|apple-touch-icon)"[^>]*>\s*/gi,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/* A value for a <script>: JSON with "<" escaped, so nothing in it
|
||||||
|
can end the element early. */
|
||||||
|
const scriptJson = (value) => JSON.stringify(value).replace(/</g, "\\u003c");
|
||||||
|
|
||||||
export function renderPage(html, meta) {
|
export function renderPage(html, meta) {
|
||||||
const site = loadSite();
|
const site = meta.site;
|
||||||
let out = html;
|
let out = html;
|
||||||
for (const pattern of REPLACED) out = out.replace(pattern, "");
|
for (const pattern of REPLACED) out = out.replace(pattern, "");
|
||||||
|
|
||||||
|
|
@ -374,12 +435,17 @@ export function renderPage(html, meta) {
|
||||||
meta.image && `<meta name="twitter:image" content="${escapeHtml(meta.image)}">`,
|
meta.image && `<meta name="twitter:image" content="${escapeHtml(meta.image)}">`,
|
||||||
// "</" can't appear inside the script, or the browser would
|
// "</" can't appear inside the script, or the browser would
|
||||||
// end the element there.
|
// end the element there.
|
||||||
meta.jsonLd &&
|
site.icons?.icon && `<link rel="icon" href="${escapeHtml(site.icons.icon)}">`,
|
||||||
`<script type="application/ld+json">${JSON.stringify(meta.jsonLd).replace(/</g, "\\u003c")}</script>`,
|
site.icons?.apple && `<link rel="apple-touch-icon" href="${escapeHtml(site.icons.apple)}">`,
|
||||||
|
meta.jsonLd && `<script type="application/ld+json">${scriptJson(meta.jsonLd)}</script>`,
|
||||||
|
// 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.__NGU_SITE__ = ${scriptJson(forBrowser(site))}</script>`,
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
|
|
||||||
// A blocked site (site.json robots.index false) stays blocked on
|
// A blocked site (Site settings indexing off, or site.json's
|
||||||
// every page, whatever the record says.
|
// robots.index false) stays blocked on every page, whatever the
|
||||||
|
// record says.
|
||||||
if (site.robots?.index === false && !meta.noindex) {
|
if (site.robots?.index === false && !meta.noindex) {
|
||||||
tags.splice(2, 0, `<meta name="robots" content="noindex, nofollow">`);
|
tags.splice(2, 0, `<meta name="robots" content="noindex, nofollow">`);
|
||||||
}
|
}
|
||||||
|
|
@ -390,7 +456,7 @@ export function renderPage(html, meta) {
|
||||||
/* ── Sitemap ───────────────────────────────────────────────── */
|
/* ── Sitemap ───────────────────────────────────────────────── */
|
||||||
|
|
||||||
export function sitemap(db) {
|
export function sitemap(db) {
|
||||||
const site = loadSite();
|
const site = siteFor(db);
|
||||||
const base = origin(site);
|
const base = origin(site);
|
||||||
const day = (value) => (value ? String(value).slice(0, 10) : null);
|
const day = (value) => (value ? String(value).slice(0, 10) : null);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
|
|
||||||
import { requireAuth, requireRole } from "../auth.js";
|
import { hasRole, requireAuth, requireRole } from "../auth.js";
|
||||||
import { ENTITIES, OPTION_QUERIES } from "../admin-schema.js";
|
import { ENTITIES, OPTION_QUERIES } from "../admin-schema.js";
|
||||||
import {
|
import {
|
||||||
HttpError,
|
HttpError,
|
||||||
|
|
@ -41,6 +41,17 @@ function entityOr404(c) {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Saving needs editor, unless the descriptor asks for more
|
||||||
|
(writeRole): site settings are superadmin-only. requireRole on the
|
||||||
|
route is the floor; this is the entity's own bar on top. */
|
||||||
|
function entityForWrite(c) {
|
||||||
|
const entity = entityOr404(c);
|
||||||
|
if (entity.writeRole && !hasRole(c.get("user"), entity.writeRole)) {
|
||||||
|
throw new HttpError(403, "Not allowed.");
|
||||||
|
}
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
/* Everything the select inputs need, in one request. Small enough
|
/* Everything the select inputs need, in one request. Small enough
|
||||||
that paging it would cost more than it saves. */
|
that paging it would cost more than it saves. */
|
||||||
entities.get("/options", (c) => {
|
entities.get("/options", (c) => {
|
||||||
|
|
@ -64,14 +75,14 @@ entities.get("/:entity/:id", (c) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
entities.post("/:entity", requireRole("editor"), async (c) => {
|
entities.post("/:entity", requireRole("editor"), async (c) => {
|
||||||
const entity = entityOr404(c);
|
const entity = entityForWrite(c);
|
||||||
const row = createRow(c.get("db"), entity, await json(c));
|
const row = createRow(c.get("db"), entity, await json(c));
|
||||||
console.log(`${entity.key} ${row[entity.idColumn]} created by ${c.get("user").email}`);
|
console.log(`${entity.key} ${row[entity.idColumn]} created by ${c.get("user").email}`);
|
||||||
return c.json({ row }, 201, NO_STORE);
|
return c.json({ row }, 201, NO_STORE);
|
||||||
});
|
});
|
||||||
|
|
||||||
entities.patch("/:entity/:id", requireRole("editor"), async (c) => {
|
entities.patch("/:entity/:id", requireRole("editor"), async (c) => {
|
||||||
const entity = entityOr404(c);
|
const entity = entityForWrite(c);
|
||||||
const id = c.req.param("id");
|
const id = c.req.param("id");
|
||||||
const row = updateRow(c.get("db"), entity, id, await json(c));
|
const row = updateRow(c.get("db"), entity, id, await json(c));
|
||||||
console.log(`${entity.key} ${id} updated by ${c.get("user").email}`);
|
console.log(`${entity.key} ${id} updated by ${c.get("user").email}`);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@
|
||||||
PAGE ROUTES: the site's HTML, with each page's metadata
|
PAGE ROUTES: the site's HTML, with each page's metadata
|
||||||
|
|
||||||
GET /sitemap.xml every public, listed page
|
GET /sitemap.xml every public, listed page
|
||||||
|
GET /robots.txt this database's indexing setting (Site
|
||||||
|
settings, else site.json), so a dev server
|
||||||
|
can say no while production says yes
|
||||||
GET /anything the built index.html, its title, description,
|
GET /anything the built index.html, its title, description,
|
||||||
preview image, canonical link and structured
|
preview image, canonical link and structured
|
||||||
data filled in for that path (pageMeta.js)
|
data filled in for that path (pageMeta.js)
|
||||||
|
|
@ -32,7 +35,7 @@ import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
|
|
||||||
import { metaFor, renderPage, sitemap } from "../pageMeta.js";
|
import { metaFor, renderPage, robotsTxt, siteFor, sitemap } from "../pageMeta.js";
|
||||||
|
|
||||||
const here = path.dirname(fileURLToPath(import.meta.url));
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
|
|
@ -62,6 +65,17 @@ function warnOnce(key, message) {
|
||||||
console.error(message);
|
console.error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pages.get("/robots.txt", (c) => {
|
||||||
|
let text;
|
||||||
|
try {
|
||||||
|
text = robotsTxt(siteFor(c.get("db")));
|
||||||
|
} catch (err) {
|
||||||
|
warnOnce(`robots:${err.message}`, `pages: can't build robots.txt: ${err.message}`);
|
||||||
|
return c.text("robots.txt isn't available.", 503);
|
||||||
|
}
|
||||||
|
return c.text(text, 200, { "Cache-Control": CACHE });
|
||||||
|
});
|
||||||
|
|
||||||
pages.get("/sitemap.xml", (c) => {
|
pages.get("/sitemap.xml", (c) => {
|
||||||
let xml;
|
let xml;
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
import { preview } from "./text.ts";
|
import { preview } from "./text.ts";
|
||||||
import { PLATFORMS } from "./platforms.ts";
|
import { PLATFORMS } from "./platforms.ts";
|
||||||
import { FORMATTING_HELP } from "../components/InlineText.tsx";
|
import { FORMATTING_HELP } from "../components/InlineText.tsx";
|
||||||
|
import siteConfiguration from "../../site.json";
|
||||||
import {
|
import {
|
||||||
awardLogo,
|
awardLogo,
|
||||||
blockMedia,
|
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> = {
|
export const ADMIN_ENTITIES: Record<string, any> = {
|
||||||
organizations,
|
organizations,
|
||||||
events,
|
events,
|
||||||
|
|
@ -1629,6 +1736,7 @@ export const ADMIN_ENTITIES: Record<string, any> = {
|
||||||
front_page: frontPage,
|
front_page: frontPage,
|
||||||
blog_posts: blogPosts,
|
blog_posts: blogPosts,
|
||||||
community_page: communityPage,
|
community_page: communityPage,
|
||||||
|
site_settings: siteSettings,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function slugify(value) {
|
export function slugify(value) {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,17 @@
|
||||||
/* ═══════════════════════════════════════════════════════════════
|
/* ═══════════════════════════════════════════════════════════════
|
||||||
SITE
|
SITE
|
||||||
|
|
||||||
What /site.json says about the site, for the browser. The server
|
What the site says about itself, for the browser: /site.json, with
|
||||||
reads the same file for the metadata it puts in each page's HTML
|
the admin's Site settings (Panel) laid over it. The server merges
|
||||||
(server/src/pageMeta.js), so a page's visible heading and intro
|
the two and writes the result into each page's HTML as
|
||||||
and its search title and description come from one place.
|
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
|
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
|
where a URL has to leave the browser and still work: a printed QR
|
||||||
|
|
@ -15,16 +22,25 @@
|
||||||
|
|
||||||
import siteConfiguration from '../../site.json'
|
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
|
export const SITE_ORIGIN: string = siteConfiguration.url
|
||||||
|
|
||||||
/** A site path as a full URL on the live site. */
|
/** A site path as a full URL on the live site. */
|
||||||
export const siteUrl = (path: string): string => new URL(path, SITE_ORIGIN).href
|
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". */
|
/** A static page's title and intro, from site.json's "pages". */
|
||||||
export function sitePage(path: string): PageText {
|
export function sitePage(path: string): PageText {
|
||||||
|
|
|
||||||
|
|
@ -128,8 +128,10 @@ export default function AdminHome() {
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{isSuper(user) && (
|
{isSuper(user) && (
|
||||||
<CardBlock title="Superadmin" blurb="Only superadmins see this block.">
|
<CardBlock title={PANEL_NAV.label} blurb={PANEL_NAV.blurb}>
|
||||||
<NavCard item={PANEL_NAV} />
|
{PANEL_NAV.children.map((item) => (
|
||||||
|
<NavCard key={item.to} item={item} />
|
||||||
|
))}
|
||||||
</CardBlock>
|
</CardBlock>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,9 @@ export default function EntityEdit() {
|
||||||
useWideAdminPage();
|
useWideAdminPage();
|
||||||
|
|
||||||
const isNew = id === "new";
|
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");
|
const canDelete = atLeast(user, "admin");
|
||||||
|
|
||||||
// Some entities have no slug: the table assigns an integer id, so
|
// 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
|
// equality test this replaced hid the button from superadmins as
|
||||||
// well as editors, which is the failure mode an == against a
|
// well as editors, which is the failure mode an == against a
|
||||||
// ladder always produces once a rank is added above it.
|
// 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 () => {
|
const load = useCallback(async () => {
|
||||||
if (!manifest || manifest.singleton) return;
|
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
|
/* Accounts, server state and what the site says about itself: the
|
||||||
own area rather than a group of CMS pages. */
|
superadmin's area, its own area rather than a group of CMS pages. */
|
||||||
|
export const SITE_SETTINGS = "/admin/site_settings";
|
||||||
|
|
||||||
export const PANEL_NAV = {
|
export const PANEL_NAV = {
|
||||||
to: ADMIN_PANEL,
|
|
||||||
label: "Panel",
|
label: "Panel",
|
||||||
blurb: "Accounts, sessions and the state of the server.",
|
blurb: "Only superadmins see this.",
|
||||||
separated: true,
|
separated: true,
|
||||||
superOnly: 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];
|
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) {
|
export function areaFor(pathname) {
|
||||||
if (matches(pathname, ADMIN_HOME)) return "home";
|
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";
|
return "cms";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue