/** * 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" }, }; } /** `