@vermeulen.solutions/eventual 0.0.0-stage → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +139 -2
- package/astro/EventList.astro +57 -0
- package/astro/admin.d.mts +3 -0
- package/astro/admin.mjs +158 -0
- package/astro/blueprint.d.mts +51 -0
- package/astro/blueprint.mjs +236 -0
- package/astro/cache.ts +82 -0
- package/astro/descriptor.mjs +7 -0
- package/astro/editor-compat.mjs +197 -0
- package/astro/editor-i18n.d.mts +8 -0
- package/astro/editor-i18n.mjs +157 -0
- package/astro/event-details.ts +29 -0
- package/astro/event-list.ts +56 -0
- package/astro/feed.ts +201 -0
- package/astro/install.d.mts +9 -0
- package/astro/install.mjs +66 -0
- package/astro/schema.ts +88 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +1585 -0
- package/dist/plugin.d.mts +6 -0
- package/dist/plugin.mjs +13 -0
- package/docs/collection-setup.md +46 -0
- package/docs/history.md +16 -0
- package/docs/native-modernization.md +99 -0
- package/docs/public-feed-caching.md +259 -0
- package/docs/registry-installation.md +13 -0
- package/docs/release-notes-0.14.0.md +27 -0
- package/docs/release-notes-0.14.1.md +40 -0
- package/docs/release-notes-0.15.0.md +18 -0
- package/docs/release-notes-0.16.0.md +7 -0
- package/docs/release-notes-0.17.0.md +7 -0
- package/docs/release-notes-0.18.0.md +8 -0
- package/docs/release-notes-0.18.1.md +7 -0
- package/docs/release-notes-0.18.2.md +6 -0
- package/docs/upgrade-0.13.0.md +21 -0
- package/docs/user-guide.md +40 -0
- package/emdash-plugin.jsonc +77 -0
- package/package.json +143 -4
- package/scripts/check-editor-installation.mjs +32 -0
- package/scripts/export-native-schema.mjs +28 -0
- package/scripts/upgrade-native-editor.mjs +296 -0
- package/src/domain/calendar-links.ts +80 -0
- package/src/domain/category.ts +32 -0
- package/src/domain/collections.ts +101 -0
- package/src/domain/date-time.ts +220 -0
- package/src/domain/description.ts +108 -0
- package/src/domain/event-data.ts +217 -0
- package/src/domain/event-expansion.ts +305 -0
- package/src/domain/event.ts +195 -0
- package/src/domain/icalendar.ts +165 -0
- package/src/domain/image.ts +18 -0
- package/src/domain/invocation-budget.ts +56 -0
- package/src/domain/messages.ts +8 -0
- package/src/domain/migration.ts +666 -0
- package/src/domain/native-calendar.ts +256 -0
- package/src/domain/native-references.ts +41 -0
- package/src/domain/native-source.ts +261 -0
- package/src/domain/native-validation.ts +366 -0
- package/src/domain/occurrences.ts +54 -0
- package/src/domain/portable-text.ts +180 -0
- package/src/domain/public-cache.ts +24 -0
- package/src/domain/recurrence-rule.ts +34 -0
- package/src/domain/recurrence.ts +350 -0
- package/src/domain/request-memo.ts +8 -0
- package/src/domain/schedule-history.ts +14 -0
- package/src/domain/text.ts +2 -0
- package/src/domain/time-entry.ts +23 -0
- package/src/domain/venue-adapter.ts +101 -0
- package/src/domain/venue.ts +42 -0
- package/src/public-event.ts +88 -0
- package/src/schema/blueprint.ts +315 -0
- package/src/storage.ts +257 -0
- package/transfer/index.d.mts +13 -0
- package/transfer/index.mjs +155 -0
package/astro/feed.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { safeWebUrl, type CalendarLinks } from "./event-details";
|
|
2
|
+
import { parsePublicFeedCache, type PublicFeedCache } from './cache';
|
|
3
|
+
export { parsePublicFeedCache, publicFeedCacheOptions, publicEventTimeBoundary, publicCalendarDateBoundary, type PublicFeedCache } from './cache';
|
|
4
|
+
export interface PublicVenue {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
address: string;
|
|
8
|
+
addressParts?: { street?: string; street2?: string; locality?: string; region?: string; postalCode?: string; country?: string };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface PublicEvent {
|
|
12
|
+
slug?: string;
|
|
13
|
+
publicUrl?: string;
|
|
14
|
+
id: string;
|
|
15
|
+
updatedAt?: string;
|
|
16
|
+
title: string;
|
|
17
|
+
description: string;
|
|
18
|
+
descriptionBlocks?: unknown[];
|
|
19
|
+
start: string;
|
|
20
|
+
end: string;
|
|
21
|
+
allDay: boolean;
|
|
22
|
+
timezone: string;
|
|
23
|
+
location: string;
|
|
24
|
+
locationType?: "physical" | "virtual" | "hybrid";
|
|
25
|
+
virtualUrl?: string;
|
|
26
|
+
status?: "draft" | "published" | "cancelled" | "postponed" | "rescheduled";
|
|
27
|
+
organizer: string;
|
|
28
|
+
organizerDetails?: { id: string; name: string; website: string; contactUrl: string };
|
|
29
|
+
previousStartDate?: string;
|
|
30
|
+
externalUrl: string;
|
|
31
|
+
imageUrl: string;
|
|
32
|
+
imageMedia?: { src: string; width?: number; height?: number; alt?: string };
|
|
33
|
+
categories: string[];
|
|
34
|
+
venue: PublicVenue | null;
|
|
35
|
+
directionsUrl: string;
|
|
36
|
+
locale?: string;
|
|
37
|
+
translationGroup?: string;
|
|
38
|
+
calendarLinks?: CalendarLinks;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { eventToJsonLd, serializeJsonLd, type EventJsonLdOptions } from "./schema";
|
|
42
|
+
export { calendarLocation, calendarStatus, calendarEventUrl, buildCalendarLinks, type CalendarLinks } from './event-details';
|
|
43
|
+
|
|
44
|
+
export interface PublicFeed {
|
|
45
|
+
ok: true;
|
|
46
|
+
from: string;
|
|
47
|
+
through: string;
|
|
48
|
+
events: PublicEvent[];
|
|
49
|
+
cache?: PublicFeedCache;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class FeedError extends Error {
|
|
53
|
+
constructor(message: string, readonly status = 502) {
|
|
54
|
+
super(message);
|
|
55
|
+
this.name = "FeedError";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function fetchPublicFeed(
|
|
60
|
+
apiOrigin: string,
|
|
61
|
+
from: string,
|
|
62
|
+
through: string,
|
|
63
|
+
category = "",
|
|
64
|
+
options: {locale?:string;strict?:boolean;publicUrls?:boolean;pluginId?:string} = {},
|
|
65
|
+
): Promise<PublicFeed> {
|
|
66
|
+
let url: URL;
|
|
67
|
+
try {
|
|
68
|
+
url = new URL(`/_emdash/api/plugins/${encodeURIComponent(options.pluginId ?? 'eventual')}/publicEvents`, apiOrigin);
|
|
69
|
+
} catch {
|
|
70
|
+
throw new FeedError("Set EVENTUAL_API_ORIGIN to a reachable HTTP(S) EmDash site.", 502);
|
|
71
|
+
}
|
|
72
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
73
|
+
throw new FeedError("Set EVENTUAL_API_ORIGIN to a reachable HTTP(S) EmDash site.", 502);
|
|
74
|
+
}
|
|
75
|
+
url.searchParams.set("from", from);
|
|
76
|
+
url.searchParams.set("through", through);
|
|
77
|
+
if (category) url.searchParams.set("category", category);
|
|
78
|
+
if (options.locale) url.searchParams.set('locale',options.locale);
|
|
79
|
+
if (options.strict !== undefined) url.searchParams.set('strict',String(options.strict));
|
|
80
|
+
if (options.publicUrls !== undefined) url.searchParams.set('publicUrls',String(options.publicUrls));
|
|
81
|
+
|
|
82
|
+
let response: Response;
|
|
83
|
+
try {
|
|
84
|
+
response = await fetch(url, { headers: { accept: "application/json" }, cache: "no-store" });
|
|
85
|
+
} catch {
|
|
86
|
+
throw new FeedError("The Eventual API could not be reached.", 502);
|
|
87
|
+
}
|
|
88
|
+
if (!response.ok) throw new FeedError(`The Eventual API returned HTTP ${response.status}.`, 502);
|
|
89
|
+
|
|
90
|
+
let envelope: unknown;
|
|
91
|
+
try {
|
|
92
|
+
envelope = await response.json();
|
|
93
|
+
} catch {
|
|
94
|
+
throw new FeedError("The Eventual API returned invalid JSON.", 502);
|
|
95
|
+
}
|
|
96
|
+
return parsePublicFeed(envelope);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Shared validation for HTTP envelopes and handlePublicPluginApiRoute() results. */
|
|
100
|
+
export function parsePublicFeed(envelope: unknown): PublicFeed {
|
|
101
|
+
if (!isRecord(envelope) || envelope.success !== true || !isRecord(envelope.data)) {
|
|
102
|
+
throw new FeedError("The Eventual API returned an unsuccessful response.", 502);
|
|
103
|
+
}
|
|
104
|
+
if (envelope.data.ok !== true) {
|
|
105
|
+
const error = typeof envelope.data.error === "string" ? envelope.data.error : "The event feed could not be loaded.";
|
|
106
|
+
throw new FeedError(error, 502);
|
|
107
|
+
}
|
|
108
|
+
if (!Array.isArray(envelope.data.events) || !envelope.data.events.every(isPublicEvent)) {
|
|
109
|
+
throw new FeedError("The Eventual API returned an invalid event list.", 502);
|
|
110
|
+
}
|
|
111
|
+
if (typeof envelope.data.from !== "string" || typeof envelope.data.through !== "string") {
|
|
112
|
+
throw new FeedError("The Eventual API returned an invalid date range.", 502);
|
|
113
|
+
}
|
|
114
|
+
const cache = parsePublicFeedCache(envelope.data.cache);
|
|
115
|
+
return {
|
|
116
|
+
ok: true,
|
|
117
|
+
from: envelope.data.from,
|
|
118
|
+
through: envelope.data.through,
|
|
119
|
+
events: envelope.data.events,
|
|
120
|
+
...(cache ? { cache } : {}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function isPublicEvent(value: unknown): value is PublicEvent {
|
|
125
|
+
if (!isRecord(value)) return false;
|
|
126
|
+
if (['slug','publicUrl','locale','translationGroup'].some(key=>value[key]!==undefined && typeof value[key]!=='string'))return false;
|
|
127
|
+
if (value.descriptionBlocks !== undefined && !Array.isArray(value.descriptionBlocks)) return false;
|
|
128
|
+
if (!(typeof value.id === "string"
|
|
129
|
+
&& typeof value.title === "string"
|
|
130
|
+
&& typeof value.description === "string"
|
|
131
|
+
&& typeof value.start === "string"
|
|
132
|
+
&& typeof value.end === "string"
|
|
133
|
+
&& typeof value.allDay === "boolean"
|
|
134
|
+
&& typeof value.timezone === "string"
|
|
135
|
+
&& typeof value.location === "string"
|
|
136
|
+
&& typeof value.organizer === "string"
|
|
137
|
+
&& typeof value.externalUrl === "string"
|
|
138
|
+
&& typeof value.imageUrl === "string"
|
|
139
|
+
&& Array.isArray(value.categories)
|
|
140
|
+
&& value.categories.every((category) => typeof category === "string")
|
|
141
|
+
&& (value.venue === null || (isRecord(value.venue)
|
|
142
|
+
&& typeof value.venue.id === "string"
|
|
143
|
+
&& typeof value.venue.name === "string"
|
|
144
|
+
&& typeof value.venue.address === "string"))
|
|
145
|
+
&& typeof value.directionsUrl === "string")) return false;
|
|
146
|
+
if (value.locationType !== undefined && value.locationType !== "physical" && value.locationType !== "virtual" && value.locationType !== "hybrid") return false;
|
|
147
|
+
if (value.virtualUrl !== undefined && (typeof value.virtualUrl !== "string" || value.virtualUrl.trim() !== "" && !safeWebUrl(value.virtualUrl))) return false;
|
|
148
|
+
if (value.status !== undefined && !["draft", "published", "cancelled", "postponed", "rescheduled"].includes(value.status as string)) return false;
|
|
149
|
+
if (value.updatedAt !== undefined && (typeof value.updatedAt !== "string" || !isInstant(value.updatedAt))) return false;
|
|
150
|
+
if (value.previousStartDate !== undefined && !isDateOnly(value.previousStartDate) && !isInstant(value.previousStartDate)) return false;
|
|
151
|
+
if (isRecord(value.venue) && value.venue.addressParts !== undefined && (!isRecord(value.venue.addressParts) || !Object.values(value.venue.addressParts).every(part => typeof part === 'string'))) return false;
|
|
152
|
+
if (value.organizerDetails !== undefined && (!isRecord(value.organizerDetails) || !['id', 'name', 'website', 'contactUrl'].every(key => typeof (value.organizerDetails as Record<string, unknown>)[key] === 'string') || ['website', 'contactUrl'].some(key => (value.organizerDetails as Record<string, string>)[key] && !safeWebUrl((value.organizerDetails as Record<string, string>)[key]!)))) return false;
|
|
153
|
+
if (value.imageMedia !== undefined && (!isRecord(value.imageMedia) || typeof value.imageMedia.src !== 'string' || !value.imageMedia.src || (value.imageMedia.width !== undefined && (!Number.isFinite(value.imageMedia.width) || (value.imageMedia.width as number) <= 0)) || (value.imageMedia.height !== undefined && (!Number.isFinite(value.imageMedia.height) || (value.imageMedia.height as number) <= 0)) || (value.imageMedia.alt !== undefined && typeof value.imageMedia.alt !== 'string'))) return false;
|
|
154
|
+
if (value.allDay) {
|
|
155
|
+
if (!isDateOnly(value.start) || !isDateOnly(value.end) || value.end < value.start) return false;
|
|
156
|
+
} else {
|
|
157
|
+
if (!isInstant(value.start) || !isInstant(value.end) || !isTimeZone(value.timezone)) return false;
|
|
158
|
+
if (Date.parse(value.end) < Date.parse(value.start)) return false;
|
|
159
|
+
}
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
164
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function isInstant(value: unknown): value is string {
|
|
168
|
+
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}T.*(?:Z|[+-]\d{2}:?\d{2})$/i.test(value)) return false;
|
|
169
|
+
return Number.isFinite(Date.parse(value));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function isDateOnly(value: unknown): value is string {
|
|
173
|
+
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
|
|
174
|
+
const date = new Date(`${value}T00:00:00.000Z`);
|
|
175
|
+
return Number.isFinite(date.getTime()) && date.toISOString().slice(0, 10) === value;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function isTimeZone(value: string): boolean {
|
|
179
|
+
try {
|
|
180
|
+
new Intl.DateTimeFormat("en", { timeZone: value });
|
|
181
|
+
return true;
|
|
182
|
+
} catch {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export {
|
|
188
|
+
portableTextToPlainText,
|
|
189
|
+
plainTextToPortableText,
|
|
190
|
+
type PortableTextBlock,
|
|
191
|
+
} from "../src/domain/portable-text";
|
|
192
|
+
export {
|
|
193
|
+
normalizeVenueRecord,
|
|
194
|
+
type NormalizedVenue,
|
|
195
|
+
} from "../src/domain/venue-adapter";
|
|
196
|
+
export {
|
|
197
|
+
expandEventOccurrences,
|
|
198
|
+
nativeEntryToEventRecord,
|
|
199
|
+
eventRecordToPublicEvent,
|
|
200
|
+
type ExpandOccurrencesOptions,
|
|
201
|
+
} from "../src/domain/event-expansion";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AstroIntegration } from "astro";
|
|
2
|
+
import type { EmDashConfig } from "emdash/astro";
|
|
3
|
+
export const testedVersions: Readonly<Record<string, readonly string[]>>;
|
|
4
|
+
export const testedToolchain: Readonly<Record<string, string>>;
|
|
5
|
+
export function installedVersion(name: string): string;
|
|
6
|
+
export function checkEditorVersions(resolveVersion?: (name: string) => string): Record<string, string>;
|
|
7
|
+
export function checkToolchainVersions(resolveVersion?: (name: string) => string): Record<string, string>;
|
|
8
|
+
export function emdashWithEventual(options?: EmDashConfig): AstroIntegration;
|
|
9
|
+
export default emdashWithEventual;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** One host integration for the sandbox backend and its frontend companion. */
|
|
2
|
+
import emdash from "emdash/astro";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { eventualEditor } from "./descriptor.mjs";
|
|
7
|
+
import { eventualEditorCompatibility } from "./editor-compat.mjs";
|
|
8
|
+
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
export const testedVersions = Object.freeze({
|
|
11
|
+
emdash: Object.freeze(["1.2.0", "1.4.0"]),
|
|
12
|
+
"@emdash-cms/admin": Object.freeze(["1.2.0", "1.4.0"]),
|
|
13
|
+
"@emdash-cms/blocks": Object.freeze(["1.2.0", "1.4.0"]),
|
|
14
|
+
});
|
|
15
|
+
export const testedToolchain = Object.freeze({astro:"7.3.x-7.4.x (>=7.3.2 <7.5.0)",vite:"8.3.x",react:"19.x"});
|
|
16
|
+
export function installedVersion(name, resolver = require) {
|
|
17
|
+
let directory = dirname(resolver.resolve(name));
|
|
18
|
+
for (;;) {
|
|
19
|
+
try {
|
|
20
|
+
const pkg = JSON.parse(readFileSync(join(directory, "package.json"), "utf8"));
|
|
21
|
+
if (pkg.name === name) return pkg.version;
|
|
22
|
+
} catch (error) { if (error.code !== "ENOENT") throw error; }
|
|
23
|
+
const parent = dirname(directory);
|
|
24
|
+
if (parent === directory) throw new Error(`Cannot identify ${name}'s installed version.`);
|
|
25
|
+
directory = parent;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function checkEditorVersions(resolveVersion = installedVersion) {
|
|
29
|
+
const versions = Object.fromEntries(Object.keys(testedVersions).map(name => [name, resolveVersion(name)]));
|
|
30
|
+
for (const [name, version] of Object.entries(versions)) {
|
|
31
|
+
const expected = testedVersions[name];
|
|
32
|
+
if (!expected.includes(version)) throw new Error(`Eventual editor requires tested ${name} ${expected.join(" or ")}; found ${version}. Use the documented compatibility matrix before upgrading.`);
|
|
33
|
+
}
|
|
34
|
+
return versions;
|
|
35
|
+
}
|
|
36
|
+
export function checkToolchainVersions(resolveVersion = installedVersion) {
|
|
37
|
+
const versions={};
|
|
38
|
+
for (const [name, range] of Object.entries(testedToolchain)) {
|
|
39
|
+
const version=resolveVersion(name);
|
|
40
|
+
if (!(name === "astro" ? /^7\.[34]\.\d+$/.test(version) && (version.startsWith("7.4.") || Number(version.split(".")[2]) >= 2) : name === "vite" ? /^8\.3\.\d+$/.test(version) : /^19\.\d+\.\d+$/.test(version))) throw new Error(`Eventual editor requires ${name} ${range}; found ${version}. See the editor compatibility matrix.`);
|
|
41
|
+
versions[name]=version;
|
|
42
|
+
}
|
|
43
|
+
return versions;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Preserve existing backend registration, adapters, storage, plugins and hooks. */
|
|
47
|
+
export function emdashWithEventual(options = {}) {
|
|
48
|
+
checkEditorVersions();
|
|
49
|
+
checkToolchainVersions();
|
|
50
|
+
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
51
|
+
const registered = (options.plugins ?? []).find(plugin => plugin.id === "eventual-editor");
|
|
52
|
+
if (registered && (registered.version !== pkg.version || registered.format !== "native")) throw new Error("Remove the mismatched Eventual editor companion before using emdashWithEventual.");
|
|
53
|
+
const backends = [...(options.plugins ?? []), ...(options.sandboxed ?? [])].filter(plugin => plugin.id === "eventual");
|
|
54
|
+
if (backends.length > 1) throw new Error("Eventual backend is registered twice. Keep a single sandboxed or registry installation.");
|
|
55
|
+
if (backends.some(plugin => plugin.version !== pkg.version || plugin.format !== "standard")) throw new Error("Eventual's source backend must be sandboxed and match its frontend companion version.");
|
|
56
|
+
const integration = emdash({ ...options, plugins: registered ? options.plugins : [...(options.plugins ?? []), eventualEditor(pkg.version)] });
|
|
57
|
+
const setup = integration.hooks["astro:config:setup"];
|
|
58
|
+
return {
|
|
59
|
+
...integration,
|
|
60
|
+
hooks: { ...integration.hooks, "astro:config:setup": async context => {
|
|
61
|
+
context.updateConfig({ vite: { plugins: [eventualEditorCompatibility()] } });
|
|
62
|
+
return setup?.(context);
|
|
63
|
+
} },
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export default emdashWithEventual;
|
package/astro/schema.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { safeWebUrl } from "./event-details";
|
|
2
|
+
import type { PublicEvent } from "./feed";
|
|
3
|
+
import { portableTextToPlainText } from "../src/domain/portable-text";
|
|
4
|
+
|
|
5
|
+
export interface EventJsonLdOptions {
|
|
6
|
+
/** HTTP(S) base used to resolve relative image, event, and meeting URLs. */
|
|
7
|
+
siteUrl?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generates Schema.org JSON-LD structured data for an Eventual event.
|
|
12
|
+
* Follows schema.org/Event with attendance modes, event statuses, and locations.
|
|
13
|
+
*/
|
|
14
|
+
export function eventToJsonLd(event: PublicEvent, options?: EventJsonLdOptions): Record<string, unknown> {
|
|
15
|
+
const attendanceMode =
|
|
16
|
+
event.locationType === "virtual"
|
|
17
|
+
? "https://schema.org/OnlineEventAttendanceMode"
|
|
18
|
+
: event.locationType === "hybrid"
|
|
19
|
+
? "https://schema.org/MixedEventAttendanceMode"
|
|
20
|
+
: "https://schema.org/OfflineEventAttendanceMode";
|
|
21
|
+
|
|
22
|
+
const eventStatus =
|
|
23
|
+
event.status === "cancelled"
|
|
24
|
+
? "https://schema.org/EventCancelled"
|
|
25
|
+
: event.status === "postponed"
|
|
26
|
+
? "https://schema.org/EventPostponed"
|
|
27
|
+
: event.status === "rescheduled"
|
|
28
|
+
? "https://schema.org/EventRescheduled"
|
|
29
|
+
: "https://schema.org/EventScheduled";
|
|
30
|
+
|
|
31
|
+
const locations: Record<string, unknown>[] = [];
|
|
32
|
+
const parts = event.venue?.addressParts;
|
|
33
|
+
const address = parts ? {
|
|
34
|
+
'@type': 'PostalAddress',
|
|
35
|
+
...Object.fromEntries(Object.entries({ streetAddress: [parts.street, parts.street2].filter(Boolean).join(', '), addressLocality: parts.locality, addressRegion: parts.region, postalCode: parts.postalCode, addressCountry: parts.country }).filter(([, value]) => !!value)),
|
|
36
|
+
} : undefined;
|
|
37
|
+
if (event.locationType !== "virtual") {
|
|
38
|
+
if (event.venue) locations.push({
|
|
39
|
+
"@type": "Place", name: event.venue.name,
|
|
40
|
+
...(address && Object.keys(address).length > 1 ? { address } : event.venue.address ? { address: event.venue.address } : {}),
|
|
41
|
+
});
|
|
42
|
+
else if (event.location) locations.push({ "@type": "Place", name: event.location });
|
|
43
|
+
}
|
|
44
|
+
const virtualUrl = safeWebUrl(event.virtualUrl ?? "", options?.siteUrl);
|
|
45
|
+
if ((event.locationType === "virtual" || event.locationType === "hybrid") && virtualUrl) {
|
|
46
|
+
locations.push({ "@type": "VirtualLocation", url: virtualUrl });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const record: Record<string, unknown> = {
|
|
50
|
+
"@context": "https://schema.org",
|
|
51
|
+
"@type": "Event",
|
|
52
|
+
name: event.title,
|
|
53
|
+
startDate: event.start,
|
|
54
|
+
endDate: event.end,
|
|
55
|
+
eventStatus,
|
|
56
|
+
eventAttendanceMode: attendanceMode,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Public feeds already contain plain text. Only serialized block trees need
|
|
60
|
+
// decoding here; a second Markdown pass would erase literal punctuation.
|
|
61
|
+
if (event.description) {
|
|
62
|
+
let description:unknown=event.description;
|
|
63
|
+
if(typeof description==='string' && description.trim().startsWith('['))try {const parsed=JSON.parse(description);if(Array.isArray(parsed) && parsed.every(block=>block && typeof block==='object' && typeof block._type==='string'))description=parsed;} catch {}
|
|
64
|
+
record.description=Array.isArray(description) ? portableTextToPlainText(description) : description;
|
|
65
|
+
}
|
|
66
|
+
if (event.status === 'rescheduled' && event.previousStartDate) record.previousStartDate = event.previousStartDate;
|
|
67
|
+
const image = safeWebUrl(event.imageUrl, options?.siteUrl);
|
|
68
|
+
if (image) record.image = image;
|
|
69
|
+
const url = safeWebUrl(event.publicUrl || event.externalUrl, options?.siteUrl);
|
|
70
|
+
if (url) record.url = url;
|
|
71
|
+
if (locations.length) record.location = locations.length === 1 ? locations[0] : locations;
|
|
72
|
+
if (event.organizer) record.organizer = { "@type": "Organization", name: event.organizerDetails?.name ?? event.organizer, ...(safeWebUrl(event.organizerDetails?.website ?? '', options?.siteUrl) ? { url: safeWebUrl(event.organizerDetails!.website, options?.siteUrl) } : {}) };
|
|
73
|
+
|
|
74
|
+
return record;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Safe JSON serialization for an HTML script element; preserves JSON values. */
|
|
78
|
+
export function serializeJsonLd(record: Record<string, unknown>): string {
|
|
79
|
+
return JSON.stringify(record).replaceAll("<", "\\u003c");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
createEventsCollectionBlueprint,
|
|
84
|
+
createVenuesCollectionBlueprint,
|
|
85
|
+
type CollectionBlueprint,
|
|
86
|
+
type BlueprintField,
|
|
87
|
+
type SchemaBlueprintOptions,
|
|
88
|
+
} from "../src/schema/blueprint";
|