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,7 +18,7 @@
|
|||
|
||||
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 {
|
||||
HttpError,
|
||||
|
|
@ -41,6 +41,17 @@ function entityOr404(c) {
|
|||
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
|
||||
that paging it would cost more than it saves. */
|
||||
entities.get("/options", (c) => {
|
||||
|
|
@ -64,14 +75,14 @@ entities.get("/:entity/:id", (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));
|
||||
console.log(`${entity.key} ${row[entity.idColumn]} created by ${c.get("user").email}`);
|
||||
return c.json({ row }, 201, NO_STORE);
|
||||
});
|
||||
|
||||
entities.patch("/:entity/:id", requireRole("editor"), async (c) => {
|
||||
const entity = entityOr404(c);
|
||||
const entity = entityForWrite(c);
|
||||
const id = c.req.param("id");
|
||||
const row = updateRow(c.get("db"), entity, id, await json(c));
|
||||
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
|
||||
|
||||
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,
|
||||
preview image, canonical link and structured
|
||||
data filled in for that path (pageMeta.js)
|
||||
|
|
@ -32,7 +35,7 @@ import { fileURLToPath } from "node:url";
|
|||
|
||||
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));
|
||||
|
||||
|
|
@ -62,6 +65,17 @@ function warnOnce(key, 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) => {
|
||||
let xml;
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue