Daily (yesterday) and weekly (Mondays, last 7 days vs the 7 before) summaries: visitors, pageviews, bounce rate, visit length, top pages and sources. Each has its own switch in Site settings > Reports; off until PLAUSIBLE_API_KEY and DISCORD_WEBHOOK_URL are set. Sent at 8:00 REPORT_TZ (default America/Chicago); analytics_reports keeps one a day. node src/analyticsReport.js daily|weekly sends one by hand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
245 lines
9 KiB
TypeScript
245 lines
9 KiB
TypeScript
import siteConfiguration from "../../../site.json";
|
||
import { mediaUrl } from "../media.ts";
|
||
import { THEME_DEFAULTS } from "../../../server/src/themeDefaults.js";
|
||
|
||
/* ── 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})`],
|
||
);
|
||
|
||
/* The palette an admin can change, in the order the dropdown lists
|
||
it: token and label. The defaults come from the server's list
|
||
(server/src/themeDefaults.js), which the build checks against
|
||
src/index.css, so there's one copy of each color to change. */
|
||
const THEME_LABELS: [string, string][] = [
|
||
["ink", "Headings"],
|
||
["body", "Body text"],
|
||
["muted", "Secondary text and quiet borders"],
|
||
["link", "Links and teal text"],
|
||
["brand", "Brand teal (borders, rules, rings)"],
|
||
["action", "Buttons (under white text)"],
|
||
["action-hover", "Buttons, hovered"],
|
||
["surface", "Page and card background"],
|
||
["tint", "Tinted sections and panels"],
|
||
["tint-soft", "Faint panels and hovered rows"],
|
||
["danger", "Errors and warnings"],
|
||
["danger-tint", "Error panel background"],
|
||
];
|
||
|
||
const THEME_COLORS: [string, string, string, string][] = THEME_LABELS.map(([token, label]) => [
|
||
token,
|
||
label,
|
||
THEME_DEFAULTS[token][0],
|
||
THEME_DEFAULTS[token][1],
|
||
]);
|
||
|
||
const defaultHelp = (row, column: 2 | 3) => {
|
||
const entry = THEME_COLORS.find(([token]) => token === row?.token);
|
||
return entry ? `Default: ${entry[column]}` : undefined;
|
||
};
|
||
|
||
export 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: mediaUrl,
|
||
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",
|
||
folder: "logos",
|
||
resolve: mediaUrl,
|
||
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",
|
||
folder: "logos",
|
||
resolve: mediaUrl,
|
||
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.",
|
||
},
|
||
],
|
||
},
|
||
{
|
||
legend: "Privacy",
|
||
fields: [
|
||
{
|
||
path: "privacy_email",
|
||
label: "Privacy contact email",
|
||
help: `The Privacy page gives this for privacy questions and data requests, eg. privacy@nextgenerationofunity.org. ${
|
||
siteConfiguration.privacyEmail ? `Default: ${siteConfiguration.privacyEmail}` : "Default: none, the page offers its request form only"
|
||
}.`,
|
||
},
|
||
],
|
||
},
|
||
{
|
||
legend: "Access (Google groups)",
|
||
note: "Anyone in one of these Workspace groups can sign in to the admin with Google; their account is made at first sign-in, with the highest role their groups give. Their role follows the groups (checked at sign-in, hourly, and by Panel → Re-sync now); out of every group, the account is disabled. Superadmins and accounts made with admin-cli aren't affected. Needs GOOGLE_DIRECTORY_AS on the server (docs/google-sign-in.md).",
|
||
fields: [
|
||
{
|
||
path: "access_group_admin",
|
||
label: "Admins group",
|
||
help: "Its members sign in as admins: edit and delete anything. eg. web-admins@nextgenerationofunity.org. Default: none.",
|
||
},
|
||
{
|
||
path: "access_group_editor",
|
||
label: "Editors group",
|
||
help: "Its members sign in as editors: create and edit, not delete. eg. web-editors@nextgenerationofunity.org. Default: none.",
|
||
},
|
||
{
|
||
path: "access_group_viewer",
|
||
label: "Viewers group",
|
||
help: "Its members sign in as viewers: read only. eg. web-viewers@nextgenerationofunity.org. Default: none.",
|
||
},
|
||
],
|
||
},
|
||
{
|
||
legend: "Reports",
|
||
fields: [
|
||
{
|
||
path: "report_daily",
|
||
label: "Daily analytics report",
|
||
widget: "select",
|
||
options: [
|
||
["on", "On"],
|
||
["off", "Off"],
|
||
],
|
||
blankLabel: "Default: off",
|
||
help: "Yesterday's visitors, pageviews and top pages from Plausible, posted to Discord each morning. Needs PLAUSIBLE_API_KEY and DISCORD_WEBHOOK_URL on the server (server/src/analyticsReport.js).",
|
||
},
|
||
{
|
||
path: "report_weekly",
|
||
label: "Weekly analytics report",
|
||
widget: "select",
|
||
options: [
|
||
["on", "On"],
|
||
["off", "Off"],
|
||
],
|
||
blankLabel: "Default: off",
|
||
help: "The last 7 days, with the change from the week before, posted to Discord each Monday morning.",
|
||
},
|
||
],
|
||
},
|
||
{
|
||
legend: "Notices",
|
||
fields: [
|
||
{
|
||
path: "notify_emails",
|
||
label: "Email new requests to",
|
||
widget: "testNotice",
|
||
full: true,
|
||
help: "Who gets an email for each new content request (the Request form) and data request (the Privacy page), separated by commas, eg. web@nextgenerationofunity.org, board@nextgenerationofunity.org. Needs Gmail set up on the server (docs/google-drive-and-mail.md). Send a test notice emails whatever is in the box now, saved or not, and shows Google's answer. Default: none, check Forms instead.",
|
||
},
|
||
],
|
||
},
|
||
],
|
||
|
||
children: [
|
||
{
|
||
key: "colors",
|
||
label: "Colors",
|
||
note: "Change any of the site's colors, for light mode, dark mode or both; a blank keeps the default. Saving refuses a palette that would make text hard to read (under 4.5:1). Changes show on the next page load.",
|
||
addLabel: "Change a color",
|
||
title: (row) => THEME_COLORS.find(([token]) => token === row.token)?.[1] ?? "New color",
|
||
blank: { token: "", light: "", dark: "" },
|
||
fields: [
|
||
{
|
||
path: "token",
|
||
label: "Color",
|
||
widget: "select",
|
||
options: THEME_COLORS.map(([token, label]) => [token, label]),
|
||
required: true,
|
||
},
|
||
{
|
||
path: "light",
|
||
label: "Light mode",
|
||
widget: "color",
|
||
placeholder: (row) => THEME_COLORS.find(([token]) => token === row?.token)?.[2],
|
||
help: (row) => defaultHelp(row, 2),
|
||
},
|
||
{
|
||
path: "dark",
|
||
label: "Dark mode",
|
||
widget: "color",
|
||
placeholder: (row) => THEME_COLORS.find(([token]) => token === row?.token)?.[3],
|
||
help: (row) => defaultHelp(row, 3),
|
||
},
|
||
],
|
||
},
|
||
{
|
||
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),
|
||
},
|
||
],
|
||
},
|
||
],
|
||
};
|