Church details saved through Accounts' church.update (live at once). Settings: Search Console and Bing codes, Coming soon line, menu order. Audit log and recent edits. A made share image, Event / VideoObject / PodcastEpisode / BreadcrumbList structured data, permanent redirects from old page addresses. Saves refused when someone else saved in between; Ministry leaders' events; templates previewed with the church's own content before choosing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
97 lines
4.7 KiB
TypeScript
97 lines
4.7 KiB
TypeScript
/**
|
||
* Search engine basics on every page (ROADMAP-v3 §11, WEBSITE-1.0-PLAN §6): a unique title and
|
||
* description, a canonical address, Open Graph with an image (the page's own, else one made from
|
||
* the church's colours, logo and name: app/share-image), and schema.org JSON-LD: `Church` on home
|
||
* and contact, `Event` on the Website's own event pages, `VideoObject` / `PodcastEpisode` for
|
||
* messages, and `BreadcrumbList` on every page but home.
|
||
*/
|
||
import type { Metadata } from "next";
|
||
import { churchJsonLd, jsonLdString, pageMeta } from "@crosscode/seo";
|
||
import type { Page, Published, SiteEvent, SiteMessage } from "./types";
|
||
|
||
export function siteBase(site: Published): URL | undefined {
|
||
try {
|
||
return site.church?.links.website ? new URL(site.church.links.website) : undefined;
|
||
} catch {
|
||
return undefined;
|
||
}
|
||
}
|
||
|
||
const abs = (site: Published, path: string) => {
|
||
const base = siteBase(site);
|
||
return base ? new URL(path, base).toString() : path;
|
||
};
|
||
|
||
/** The made share image for a title. */
|
||
export const shareImage = (title: string) => `/share-image?t=${encodeURIComponent(title.slice(0, 90))}`;
|
||
|
||
export function pageMetadata(site: Published, page: Page): Metadata {
|
||
const name = site.church?.name ?? "Church";
|
||
const meta = pageMeta({ title: page.kind === "home" ? null : page.seoTitle || page.title, description: page.description, fallbackDescription: `${name}: ${page.title}` });
|
||
const own = page.image && !page.image.url.endsWith(".svg") ? page.image : null;
|
||
const title = page.kind === "home" ? name : page.title;
|
||
return {
|
||
metadataBase: siteBase(site),
|
||
title: page.kind === "home" ? { absolute: page.seoTitle || name } : meta.title,
|
||
description: meta.description,
|
||
alternates: { canonical: page.path },
|
||
openGraph: {
|
||
type: "website", siteName: name, title, description: meta.description, url: page.path, locale: "en_ZA",
|
||
images: [own ? { url: own.url, alt: own.alt } : { url: shareImage(title), width: 1200, height: 630, alt: title }],
|
||
},
|
||
twitter: { card: "summary_large_image" },
|
||
};
|
||
}
|
||
|
||
/** `<script type="application/ld+json">` contents for the church (home and contact pages). */
|
||
export function churchLd(site: Published, path: string): string | null {
|
||
if (!site.church) return null;
|
||
return jsonLdString(churchJsonLd(site.church, siteBase(site) ? { url: abs(site, path) } : {}));
|
||
}
|
||
|
||
/** Home › … › this page. */
|
||
export function breadcrumbLd(site: Published, trail: { name: string; path: string }[]): string {
|
||
const items = [{ name: site.church?.name ?? "Home", path: "/" }, ...trail];
|
||
return jsonLdString({
|
||
"@context": "https://schema.org",
|
||
"@type": "BreadcrumbList",
|
||
itemListElement: items.map((x, i) => ({ "@type": "ListItem", position: i + 1, name: x.name, item: abs(site, x.path) })),
|
||
});
|
||
}
|
||
|
||
/** A simple event of the Website's own (events from Cross Events have theirs at the origin). */
|
||
export function eventLd(site: Published, e: SiteEvent): string {
|
||
const a = site.church?.contact.address;
|
||
const place = e.location || a
|
||
? { "@type": "Place", name: e.location ?? site.church?.name, ...(a ? { address: { "@type": "PostalAddress", streetAddress: [a.line1, a.line2].filter(Boolean).join(", "), addressLocality: a.city, postalCode: a.postalCode ?? undefined, addressCountry: a.country } } : {}) }
|
||
: undefined;
|
||
return jsonLdString({
|
||
"@context": "https://schema.org",
|
||
"@type": "Event",
|
||
name: e.title,
|
||
startDate: e.startsAt,
|
||
...(e.endsAt ? { endDate: e.endsAt } : {}),
|
||
eventStatus: "https://schema.org/EventScheduled",
|
||
eventAttendanceMode: "https://schema.org/OfflineEventAttendanceMode",
|
||
...(place ? { location: place } : {}),
|
||
...(e.summary ? { description: e.summary } : {}),
|
||
...(e.image ? { image: [abs(site, e.image.url)] } : {}),
|
||
url: abs(site, e.url),
|
||
organizer: { "@type": "Organization", name: site.church?.name, url: abs(site, "/") },
|
||
});
|
||
}
|
||
|
||
/** The messages on the Messages page: a VideoObject (YouTube) or PodcastEpisode (Spotify) each. */
|
||
export function messagesLd(site: Published, messages: SiteMessage[]): string | null {
|
||
if (!messages.length) return null;
|
||
return jsonLdString({
|
||
"@context": "https://schema.org",
|
||
"@graph": messages.slice(0, 20).map((m) => {
|
||
const description = [m.speaker, m.passage, m.series].filter(Boolean).join(" · ") || m.title;
|
||
return m.source === "spotify"
|
||
? { "@type": "PodcastEpisode", name: m.title, datePublished: m.date.slice(0, 10), description, url: m.url }
|
||
: { "@type": "VideoObject", name: m.title, uploadDate: m.date, description, ...(m.thumbnail ? { thumbnailUrl: [m.thumbnail] } : {}), ...(m.embedUrl ? { embedUrl: m.embedUrl.replace("?autoplay=1", "") } : {}), contentUrl: m.url };
|
||
}),
|
||
});
|
||
}
|