feat(website): the four templates and the public site
Heritage, Bold, Community and Clean drawing all 26 section variants with their headers, homepage order and style settings; colours made safe (WCAG AA) by the backend; fonts and corners from the shared brand style. Publishing into numbered versions, the content API with live messages and events and the church profile from Accounts, uploads, every page kind, simple event pages, Coming soon, 404, sitemap, SEO basics and the church's JSON-LD. The demo church (npm run demo) and Playwright e2e: every template's pages pass axe and the SEO checks. website.sh builds packages/seo. Decision 17 (first Owner) recorded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { cache } from "react";
|
||||
import type { Image, Published, SiteContent, Template } from "./types";
|
||||
|
||||
const api = (process.env.WEBSITE_API_URL || "http://127.0.0.1:5300").replace(/\/+$/, "");
|
||||
|
||||
const FALLBACK: SiteContent = {
|
||||
mode: "coming-soon",
|
||||
template: "heritage",
|
||||
comingSoonText: "Our new website is on its way.",
|
||||
church: null,
|
||||
palette: { brand: "31 78 121", brandDark: "25 62 97", onBrand: "255 255 255", brandText: "31 78 121", brandTint: "241 244 248", accent: "87 113 148", onAccent: "255 255 255", notes: [] },
|
||||
style: { fontPairing: "classic", corners: "sharp" },
|
||||
};
|
||||
|
||||
/**
|
||||
* The site as visitors see it: one fetch per request (React `cache`), kept by Next for 30 seconds,
|
||||
* so Publish shows within half a minute. While the backend can't answer: Coming soon, never an
|
||||
* error page.
|
||||
*/
|
||||
export const loadContent = cache(async (): Promise<SiteContent> => {
|
||||
try {
|
||||
// In development (and the e2e run) always fresh, so a Publish shows at once.
|
||||
const res = await fetch(`${api}/api/v1/site/content`, process.env.NODE_ENV === "production" ? { next: { revalidate: 30 } } : { cache: "no-store" });
|
||||
if (res.ok) return (await res.json()) as SiteContent;
|
||||
} catch {
|
||||
// Starting or down.
|
||||
}
|
||||
return FALLBACK;
|
||||
});
|
||||
|
||||
export async function loadPublished(): Promise<Published | null> {
|
||||
const c = await loadContent();
|
||||
return c.mode === "published" ? c : null;
|
||||
}
|
||||
|
||||
/** An image from a section's data (a media id), or null. */
|
||||
export const media = (site: Published, id: unknown): Image | null => (typeof id === "string" ? site.snapshot.media[id] ?? null : null);
|
||||
|
||||
/** Per-template class names: `t(template, { heritage: "…", bold: "…" }, "fallback")`. */
|
||||
export const t = (template: Template, by: Partial<Record<Template, string>>, otherwise = "") => by[template] ?? otherwise;
|
||||
|
||||
export const str = (v: unknown): string | null => (typeof v === "string" && v.trim() ? v : null);
|
||||
Reference in New Issue
Block a user