Events 2.4.0 frontend, deploy and docs: Linked products, linked events, seo
- Site settings → Linked products (Connect, Show events from, Publish my events), help, command palette. - Events from linked products on /events, the home and campus pages, and /events/linked/<product>/<id> (markdown with HTML off, canonical to the origin, no JSON-LD, not in the sitemap). - Event page JSON-LD from @crosscode/seo; lib/eventSchema.ts removed. - Readiness check for linked products' sync; e2e spec with a fake Church Website (not run yet: needs the e2e Postgres). - crosscode: install and build the shared packages Events uses first (an older tag still builds as before); scripts/tests/events.bats. - Release notes, changelogs, handovers, hub-protocol.md, and the plan's "Changes while building". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -62,7 +62,7 @@ export const COMMAND_PAGES: CommandPage[] = [
|
||||
// Settings
|
||||
...([
|
||||
["organisation", "Organisation"], ["campuses", "Campuses"], ["branding", "Branding"], ["notifications", "Notifications"],
|
||||
["email", "Email"], ["legal", "Legal"], ["whatsapp", "WhatsApp"], ["payments", "Payments"], ["webhooks", "Webhooks"],
|
||||
["email", "Email"], ["legal", "Legal"], ["whatsapp", "WhatsApp"], ["payments", "Payments"], ["webhooks", "Webhooks"], ["linked", "Linked products"],
|
||||
["backups", "Backups"], ["jobs", "Background jobs"], ["licence", "Licence & updates"], ["ai", "AI helpers"],
|
||||
] as const).map(([tab, label]): CommandPage => ({ group: "Settings", label: `Settings: ${label}`, href: `/dashboard/admin/settings?tab=${tab}`, roles: ADM, keywords: "site settings" })),
|
||||
// Reports — every report in the catalogue
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
// schema.org Event data for an event page, so Google can show the event with its date,
|
||||
// venue and ticket link (event rich results / "events near me").
|
||||
// Checked with https://search.google.com/test/rich-results
|
||||
|
||||
type SchemaOption = {
|
||||
price: number;
|
||||
stockLimit?: number;
|
||||
availableCount?: number;
|
||||
earlyBirdTiers?: { deadline: string; price: number }[];
|
||||
variants?: { price: number | null; stockLimit?: number; availableCount?: number }[];
|
||||
};
|
||||
|
||||
export type SchemaEvent = {
|
||||
id: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
goLiveAt?: string;
|
||||
picture?: string;
|
||||
location?: string | null;
|
||||
requiresRegistration?: boolean;
|
||||
eventOptions?: SchemaOption[];
|
||||
};
|
||||
|
||||
/** Today's price of each ticket (early-bird when one is open, else the variant/base price). */
|
||||
function currentPrices(options: SchemaOption[], now: Date): number[] {
|
||||
const prices: number[] = [];
|
||||
for (const o of options) {
|
||||
if (o.variants && o.variants.length > 0) {
|
||||
for (const v of o.variants) prices.push(v.price ?? o.price);
|
||||
continue;
|
||||
}
|
||||
const open = (o.earlyBirdTiers || []).filter((t) => now < new Date(t.deadline)).map((t) => t.price);
|
||||
prices.push(open.length > 0 ? Math.min(...open) : o.price);
|
||||
}
|
||||
return prices.filter((p) => Number.isFinite(p));
|
||||
}
|
||||
|
||||
export function eventJsonLd(
|
||||
event: SchemaEvent,
|
||||
{ pageUrl, imageUrl, organizerName, siteUrl }: { pageUrl: string; imageUrl: string | null; organizerName: string; siteUrl: string },
|
||||
) {
|
||||
const now = new Date();
|
||||
const options = event.eventOptions || [];
|
||||
const limited = options.filter((o) => (o.stockLimit ?? 0) > 0);
|
||||
const soldOut = limited.length > 0 && limited.every((o) => o.availableCount !== undefined && o.availableCount <= 0);
|
||||
|
||||
// Contact-only events (requiresRegistration false) have no tickets to offer.
|
||||
let offers: Record<string, unknown> | undefined;
|
||||
if (event.requiresRegistration !== false) {
|
||||
const prices = options.length > 0 ? currentPrices(options, now) : [0];
|
||||
const low = Math.min(...prices);
|
||||
const high = Math.max(...prices);
|
||||
offers = {
|
||||
"@type": low === high ? "Offer" : "AggregateOffer",
|
||||
...(low === high ? { price: low.toFixed(2) } : { lowPrice: low.toFixed(2), highPrice: high.toFixed(2) }),
|
||||
priceCurrency: "ZAR",
|
||||
availability: soldOut ? "https://schema.org/SoldOut" : "https://schema.org/InStock",
|
||||
url: `${siteUrl}/register/${event.id}`,
|
||||
...(event.goLiveAt ? { validFrom: new Date(event.goLiveAt).toISOString() } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Event",
|
||||
name: event.title,
|
||||
...(event.description ? { description: event.description.slice(0, 5000) } : {}),
|
||||
startDate: new Date(event.startDate).toISOString(),
|
||||
endDate: new Date(event.endDate).toISOString(),
|
||||
eventStatus: "https://schema.org/EventScheduled",
|
||||
eventAttendanceMode: "https://schema.org/OfflineEventAttendanceMode",
|
||||
...(event.location ? { location: { "@type": "Place", name: event.location, address: event.location } } : {}),
|
||||
...(imageUrl ? { image: [imageUrl] } : {}),
|
||||
url: pageUrl,
|
||||
organizer: { "@type": "Organization", name: organizerName, url: siteUrl },
|
||||
...(offers ? { offers } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
/** JSON for a <script type="application/ld+json">, safe against "</script>" in event text. */
|
||||
export function jsonLdString(data: unknown): string {
|
||||
return JSON.stringify(data).replace(/</g, "\\u003c");
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import type { CrosscodeEvent } from "@crosscode/contracts";
|
||||
import { apiFetchListForPrerender } from "@/lib/api";
|
||||
|
||||
/**
|
||||
* Events from the church's other products (2.4.0, Settings → Linked products → Show events from):
|
||||
* read-only copies as `crosscode.event/1`, each with its own page here (/events/linked/…) that
|
||||
* points search engines and visitors to the product it comes from.
|
||||
*/
|
||||
export type LinkedEvent = {
|
||||
key: string;
|
||||
product: "website" | "app";
|
||||
productName: string;
|
||||
event: CrosscodeEvent;
|
||||
};
|
||||
|
||||
/** Upcoming linked events for a public page. Never fails the page: no events if the API can't answer. */
|
||||
export async function fetchLinkedEvents(campus?: string): Promise<LinkedEvent[]> {
|
||||
const query = campus ? `?campus=${encodeURIComponent(campus)}` : "";
|
||||
try {
|
||||
return await apiFetchListForPrerender<LinkedEvent>(`/api/v2/linked-events${query}`, { nextOptions: { next: { revalidate: 60 } } });
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/** This site's page for a linked event. */
|
||||
export const linkedEventPath = (e: LinkedEvent) => `/events/linked/${e.product}/${e.event.id}`;
|
||||
|
||||
/** "From the Church Website". */
|
||||
export const fromLabel = (e: LinkedEvent) => `From the ${e.productName}`;
|
||||
|
||||
/** Our events and linked ones in one list by start time. `startOf` gives our events' start. */
|
||||
export function mergeByStart<T>(ours: T[], linked: LinkedEvent[], startOf: (e: T) => string): ({ kind: "own"; event: T } | { kind: "linked"; event: LinkedEvent })[] {
|
||||
const all = [
|
||||
...ours.map((event) => ({ kind: "own" as const, event, at: new Date(startOf(event)).getTime() })),
|
||||
...linked.map((event) => ({ kind: "linked" as const, event, at: new Date(event.event.startsAt).getTime() })),
|
||||
];
|
||||
return all.sort((a, b) => a.at - b.at).map((x) => (x.kind === "own" ? { kind: "own" as const, event: x.event } : { kind: "linked" as const, event: x.event }));
|
||||
}
|
||||
Reference in New Issue
Block a user