@sarimarcus/content-sites-core 0.77.0 → 0.79.0
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/CHANGELOG.md +15 -0
- package/dist/dates/ics.d.ts +4 -0
- package/dist/dates/ics.js +6 -3
- package/dist/schema/agenda.d.ts +7 -0
- package/dist/schema/agenda.js +5 -0
- package/dist/schema/events.d.ts +4 -2
- package/dist/schema/events.js +25 -8
- package/dist/schema/index.d.ts +2 -2
- package/dist/schema/index.js +1 -1
- package/package.json +1 -1
- package/src/dates/ics.ts +11 -3
- package/src/schema/agenda.ts +10 -0
- package/src/schema/events.ts +27 -8
- package/src/schema/index.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
All packages in the platform release in lockstep; entries are per release version.
|
|
4
4
|
|
|
5
|
+
## 0.79.0 (2026-11-20)
|
|
6
|
+
|
|
7
|
+
- No source change; lockstep release with the ui article end-matter change (SLA-4397).
|
|
8
|
+
|
|
9
|
+
## 0.78.0 (2026-11-19)
|
|
10
|
+
|
|
11
|
+
What's On structured data and agenda contract (SLA-4380):
|
|
12
|
+
- `agendaItemListBuilder`: an Event's `image` is its venue page's OG jpg when that file exists (route segment to collection: `monument` → `monuments`, `activity` → `activities`), else `data.image`; a one-day Event gets `endDate` = its start day; the venue organizer carries `url` (the venue page, else the source page); `performer` is a `PerformingGroup` only when the item names one; `eventStatus` follows the item's `status`. `data.stale: true` emits every item as a WebPage, so no Event claims dates nobody has rechecked.
|
|
13
|
+
- `AgendaItem` gains optional `performer` and `status` (`cancelled` | `postponed`, exported as `AGENDA_STATUSES`); `agendaItemIssues` validates both. Optional fields: existing snapshots stay valid.
|
|
14
|
+
- `eventToIcs`: optional `startTime` (ISO with offset) emits a timed `DTSTART` in UTC and no invented `DTEND`; optional per-event `location`. Existing callers' output is unchanged.
|
|
15
|
+
|
|
16
|
+
### Intended output changes
|
|
17
|
+
|
|
18
|
+
- `seo.jsonld` on `whats-on.html` — Event `image`, `endDate`, organizer `url` (fixes Google's non-critical warnings), and `eventStatus` from the snapshot.
|
|
19
|
+
|
|
5
20
|
## 0.77.0 (2026-11-19)
|
|
6
21
|
|
|
7
22
|
- No source change; lockstep release with the tourism `/whats-on` fixes (SLA-4361).
|
package/dist/dates/ics.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ export interface IcsEvent {
|
|
|
15
15
|
endDate?: string;
|
|
16
16
|
/** Absolute URL of the event page */
|
|
17
17
|
url: string;
|
|
18
|
+
/** ISO instant with offset (`2026-11-21T20:00:00+01:00`): a timed event starting then, instead of an all-day one. */
|
|
19
|
+
startTime?: string;
|
|
20
|
+
/** This event's place; defaults to the calendar's `location`. */
|
|
21
|
+
location?: string;
|
|
18
22
|
}
|
|
19
23
|
export interface IcsCalendar {
|
|
20
24
|
/** Domain after `@` in each UID, e.g. `example.com`. */
|
package/dist/dates/ics.js
CHANGED
|
@@ -45,19 +45,22 @@ function foldLine(line) {
|
|
|
45
45
|
parts.push(current);
|
|
46
46
|
return parts.join('\r\n ');
|
|
47
47
|
}
|
|
48
|
+
/** `2026-11-21T20:00:00+01:00` → `20261121T190000Z`. */
|
|
49
|
+
const utcCompact = (instant) => new Date(instant).toISOString().replace(/[-:]/g, '').replace(/\.\d{3}/, '');
|
|
48
50
|
function vevent(ev, cal) {
|
|
49
51
|
const start = compact(ev.startDate);
|
|
50
52
|
const end = nextDayCompact(ev.endDate || ev.startDate);
|
|
53
|
+
// A timed start with no published end: DTSTART alone, never an invented duration.
|
|
54
|
+
const when = ev.startTime && !ev.endDate ? [`DTSTART:${utcCompact(ev.startTime)}`] : [`DTSTART;VALUE=DATE:${start}`, `DTEND;VALUE=DATE:${end}`];
|
|
51
55
|
return [
|
|
52
56
|
'BEGIN:VEVENT',
|
|
53
57
|
// Deterministic UID + DTSTAMP so rebuilds don't churn the committed output.
|
|
54
58
|
`UID:${ev.slug}-${start}@${cal.uidDomain}`,
|
|
55
59
|
`DTSTAMP:${start}T000000Z`,
|
|
56
|
-
|
|
57
|
-
`DTEND;VALUE=DATE:${end}`,
|
|
60
|
+
...when,
|
|
58
61
|
`SUMMARY:${escapeText(ev.name)}`,
|
|
59
62
|
...(ev.description ? [`DESCRIPTION:${escapeText(ev.description.slice(0, 300))}`] : []),
|
|
60
|
-
`LOCATION:${escapeText(cal.location)}`,
|
|
63
|
+
`LOCATION:${escapeText(ev.location ?? cal.location)}`,
|
|
61
64
|
`URL:${ev.url}`,
|
|
62
65
|
'END:VEVENT',
|
|
63
66
|
];
|
package/dist/schema/agenda.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ export type AgendaCategory = (typeof AGENDA_CATEGORIES)[number];
|
|
|
4
4
|
/** `dated` items carry real dates; `recurring` items are the thin-week fallback (markets, free-entry slots). */
|
|
5
5
|
export declare const AGENDA_KINDS: readonly ["dated", "recurring"];
|
|
6
6
|
export type AgendaKind = (typeof AGENDA_KINDS)[number];
|
|
7
|
+
/** A status the source states; absent means scheduled. */
|
|
8
|
+
export declare const AGENDA_STATUSES: readonly ["cancelled", "postponed"];
|
|
9
|
+
export type AgendaStatus = (typeof AGENDA_STATUSES)[number];
|
|
7
10
|
export interface AgendaVenue {
|
|
8
11
|
name: string;
|
|
9
12
|
/** Internal route of the site's own venue page, e.g. `/monument/mezquita`. */
|
|
@@ -23,6 +26,10 @@ export interface AgendaItem {
|
|
|
23
26
|
/** Recurrence in words for a `recurring` item, e.g. "Every Sunday, 10:00–14:00". */
|
|
24
27
|
recurrence?: string;
|
|
25
28
|
venue: AgendaVenue;
|
|
29
|
+
/** Set only when the source says the event is cancelled or postponed. */
|
|
30
|
+
status?: AgendaStatus;
|
|
31
|
+
/** Performer as the source names it; absent when it names none (never inferred). */
|
|
32
|
+
performer?: string;
|
|
26
33
|
/** Internal link: the venue page or, when a festival page owns the query, `/event/<slug>` (Rule 34). */
|
|
27
34
|
href?: string;
|
|
28
35
|
/** The official page the dates were read from. */
|
package/dist/schema/agenda.js
CHANGED
|
@@ -5,6 +5,8 @@ export const AGENDA_CATEGORIES = [
|
|
|
5
5
|
];
|
|
6
6
|
/** `dated` items carry real dates; `recurring` items are the thin-week fallback (markets, free-entry slots). */
|
|
7
7
|
export const AGENDA_KINDS = ['dated', 'recurring'];
|
|
8
|
+
/** A status the source states; absent means scheduled. */
|
|
9
|
+
export const AGENDA_STATUSES = ['cancelled', 'postponed'];
|
|
8
10
|
const DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
9
11
|
const DAY_OR_LOCAL_TIME = /^\d{4}-\d{2}-\d{2}(T([01]\d|2[0-3]):[0-5]\d)?$/;
|
|
10
12
|
const INTERNAL_HREF = /^\/[a-z0-9-]+(\/[a-z0-9-]+)*\/?(#[a-z0-9-]+)?$/;
|
|
@@ -53,6 +55,9 @@ export function agendaItemIssues(item, path = '') {
|
|
|
53
55
|
if (vh !== undefined && !(typeof vh === 'string' && INTERNAL_HREF.test(vh)))
|
|
54
56
|
issues.push({ path: at('venue.href'), message: 'must be an internal route like /monument/<slug>' });
|
|
55
57
|
}
|
|
58
|
+
str('performer', false);
|
|
59
|
+
if (it.status !== undefined && !AGENDA_STATUSES.includes(it.status))
|
|
60
|
+
issues.push({ path: at('status'), message: `must be one of ${AGENDA_STATUSES.join(', ')}` });
|
|
56
61
|
const href = str('href', false);
|
|
57
62
|
if (href !== undefined && !INTERNAL_HREF.test(href))
|
|
58
63
|
issues.push({ path: at('href'), message: 'must be an internal route like /event/<slug>' });
|
package/dist/schema/events.d.ts
CHANGED
|
@@ -33,8 +33,10 @@ export interface EventItemListOptions extends EventPolicy {
|
|
|
33
33
|
*/
|
|
34
34
|
export type AgendaItemListOptions = Omit<EventItemListOptions, 'isEvent' | 'organizer' | 'performer' | 'itemOrganizer'> & Partial<Pick<EventItemListOptions, 'organizer' | 'performer' | 'itemOrganizer'>>;
|
|
35
35
|
/**
|
|
36
|
-
* ItemList for a What's On window (SLA-4221): `data` is `{ name, items: AgendaItem[], timezone }`, already
|
|
37
|
-
* the window. Dated items become Events; a recurring item becomes a WebPage, since it has no single date.
|
|
36
|
+
* ItemList for a What's On window (SLA-4221): `data` is `{ name, items: AgendaItem[], timezone, image?, stale? }`, already
|
|
37
|
+
* filtered to the window. Dated items become Events; a recurring item becomes a WebPage, since it has no single date.
|
|
38
|
+
* An Event's image is its venue page's OG image, else `data.image` (the page's); a one-day Event ends on its start day.
|
|
39
|
+
* `data.stale` (the freshness guard) turns every item into a WebPage: no Event claims dates nobody has rechecked.
|
|
38
40
|
*/
|
|
39
41
|
export declare function agendaItemListBuilder(options: AgendaItemListOptions): SchemaBuilder;
|
|
40
42
|
/** ItemList of events, each linked at its `url`; an item that cannot be a valid Event becomes a WebPage. */
|
package/dist/schema/events.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createPersonSchema } from "./context.js";
|
|
2
2
|
import { offer } from "./nodes.js";
|
|
3
3
|
import { geoCoordinates, isFreeEntry, parsePriceFromString, postalAddress } from "./values.js";
|
|
4
|
-
import { agendaIsoDate } from "../dates/agenda.js";
|
|
4
|
+
import { agendaDay, agendaIsoDate } from "../dates/agenda.js";
|
|
5
|
+
import { getOgImagePath } from "../url/ogImage.js";
|
|
5
6
|
function eventPrice(data) {
|
|
6
7
|
const isFree = isFreeEntry(data);
|
|
7
8
|
return { isFree, price: isFree ? 0 : typeof data.priceValue === 'number' ? data.priceValue : parsePriceFromString(data.price) };
|
|
@@ -30,6 +31,7 @@ function eventLocation(policy, data) {
|
|
|
30
31
|
}
|
|
31
32
|
const EVENT_STATUS = (rescheduled) => (rescheduled ? 'https://schema.org/EventRescheduled' : 'https://schema.org/EventScheduled');
|
|
32
33
|
const OFFLINE = 'https://schema.org/OfflineEventAttendanceMode';
|
|
34
|
+
const AGENDA_EVENT_STATUS = { cancelled: 'https://schema.org/EventCancelled', postponed: 'https://schema.org/EventPostponed' };
|
|
33
35
|
/** An Event node: its dates, status, attendance mode, free entry, location, organizer, performer and offers. */
|
|
34
36
|
function eventNode(ctx, policy, data, parts) {
|
|
35
37
|
return {
|
|
@@ -41,7 +43,7 @@ function eventNode(ctx, policy, data, parts) {
|
|
|
41
43
|
startDate: data.startDate || undefined,
|
|
42
44
|
endDate: data.endDate || undefined,
|
|
43
45
|
previousStartDate: data.previousStartDate || undefined,
|
|
44
|
-
eventStatus: EVENT_STATUS(data.previousStartDate),
|
|
46
|
+
eventStatus: data.eventStatus ?? EVENT_STATUS(data.previousStartDate),
|
|
45
47
|
eventAttendanceMode: OFFLINE,
|
|
46
48
|
isAccessibleForFree: parts.isFree,
|
|
47
49
|
location: eventLocation(policy, data),
|
|
@@ -87,18 +89,28 @@ export function eventBuilder(options) {
|
|
|
87
89
|
return author ? [createPersonSchema(author), ...nodes] : nodes;
|
|
88
90
|
};
|
|
89
91
|
}
|
|
92
|
+
/** A singular route segment's collection: `monument` → `monuments`, `activity` → `activities`, `dish` → `dishes`. */
|
|
93
|
+
const collectionOfSegment = (s) => (/[^aeiou]y$/.test(s) ? `${s.slice(0, -1)}ies` : /(s|sh|ch|x|z)$/.test(s) ? `${s}es` : `${s}s`);
|
|
94
|
+
/** The OG jpg of a venue page (`/monument/x` → `/images/og/monuments/x.jpg`), when that file exists. */
|
|
95
|
+
function venueOgImage(ctx, venueHref) {
|
|
96
|
+
const [, segment, slug] = venueHref?.match(/^\/([a-z0-9-]+)\/([a-z0-9-]+)\/?$/) ?? [];
|
|
97
|
+
const path = segment ? getOgImagePath(collectionOfSegment(segment), slug) : undefined;
|
|
98
|
+
return path && ctx.fileExists(path) ? path : undefined;
|
|
99
|
+
}
|
|
90
100
|
/**
|
|
91
|
-
* ItemList for a What's On window (SLA-4221): `data` is `{ name, items: AgendaItem[], timezone }`, already
|
|
92
|
-
* the window. Dated items become Events; a recurring item becomes a WebPage, since it has no single date.
|
|
101
|
+
* ItemList for a What's On window (SLA-4221): `data` is `{ name, items: AgendaItem[], timezone, image?, stale? }`, already
|
|
102
|
+
* filtered to the window. Dated items become Events; a recurring item becomes a WebPage, since it has no single date.
|
|
103
|
+
* An Event's image is its venue page's OG image, else `data.image` (the page's); a one-day Event ends on its start day.
|
|
104
|
+
* `data.stale` (the freshness guard) turns every item into a WebPage: no Event claims dates nobody has rechecked.
|
|
93
105
|
*/
|
|
94
106
|
export function agendaItemListBuilder(options) {
|
|
95
|
-
const venueOrganizer = (item) => ({ '@type': 'Organization', name: item.location });
|
|
107
|
+
const venueOrganizer = (item) => ({ '@type': 'Organization', name: item.location, url: item.organizerUrl });
|
|
96
108
|
const list = eventItemListBuilder({
|
|
97
109
|
...options,
|
|
98
110
|
organizer: options.organizer ?? venueOrganizer,
|
|
99
111
|
itemOrganizer: options.itemOrganizer ?? venueOrganizer,
|
|
100
|
-
performer: options.performer ?? (() => undefined),
|
|
101
|
-
isEvent: (item) => item.kind === 'dated',
|
|
112
|
+
performer: options.performer ?? ((item) => (item.performer ? { '@type': 'PerformingGroup', name: item.performer } : undefined)),
|
|
113
|
+
isEvent: (item) => item.kind === 'dated' && !item.stale,
|
|
102
114
|
});
|
|
103
115
|
return (data, ctx) => list({
|
|
104
116
|
name: data.name,
|
|
@@ -108,11 +120,16 @@ export function agendaItemListBuilder(options) {
|
|
|
108
120
|
category: item.category,
|
|
109
121
|
name: item.title,
|
|
110
122
|
description: item.blurb,
|
|
123
|
+
image: venueOgImage(ctx, item.venue.href) ?? data.image,
|
|
111
124
|
url: item.href ?? item.venue.href ?? item.sourceUrl,
|
|
112
125
|
startDate: agendaIsoDate(item.startDate, data.timezone),
|
|
113
|
-
endDate: item.endDate,
|
|
126
|
+
endDate: item.endDate ?? agendaDay(item.startDate),
|
|
114
127
|
location: item.venue.name,
|
|
115
128
|
streetAddress: item.venue.address,
|
|
129
|
+
organizerUrl: ctx.absOrHttp(item.venue.href ?? item.sourceUrl),
|
|
130
|
+
performer: item.performer,
|
|
131
|
+
eventStatus: item.status ? AGENDA_EVENT_STATUS[item.status] : undefined,
|
|
132
|
+
stale: data.stale === true,
|
|
116
133
|
price: item.free ? 'Free' : undefined,
|
|
117
134
|
priceValue: item.free ? undefined : item.priceFrom,
|
|
118
135
|
officialWebsite: item.sourceUrl,
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -19,5 +19,5 @@ export { hotelBuilder, activityBuilder } from './places.ts';
|
|
|
19
19
|
export type { HotelOptions, ActivityOptions } from './places.ts';
|
|
20
20
|
export { eventBuilder, eventItemListBuilder, agendaItemListBuilder } from './events.ts';
|
|
21
21
|
export type { EventPolicy, EventOptions, EventItemListOptions, AgendaItemListOptions } from './events.ts';
|
|
22
|
-
export { AGENDA_CATEGORIES, AGENDA_KINDS, agendaItemIssues, agendaSnapshotIssues } from './agenda.ts';
|
|
23
|
-
export type { AgendaCategory, AgendaKind, AgendaVenue, AgendaItem, AgendaSnapshot } from './agenda.ts';
|
|
22
|
+
export { AGENDA_CATEGORIES, AGENDA_KINDS, AGENDA_STATUSES, agendaItemIssues, agendaSnapshotIssues } from './agenda.ts';
|
|
23
|
+
export type { AgendaCategory, AgendaKind, AgendaStatus, AgendaVenue, AgendaItem, AgendaSnapshot } from './agenda.ts';
|
package/dist/schema/index.js
CHANGED
|
@@ -9,4 +9,4 @@ export { buildBreadcrumbList, buildWebPageNode, assembleGraph, finalizeGraph } f
|
|
|
9
9
|
export { faqPageBuilder, articleBuilder, collectionPageBuilder, itemListBuilder, howToBuilder, aboutPageBuilder, contactPageBuilder, personBuilder, historicalPersonSchema, aggregateOfferBuilder, touristDestinationBuilder, organizationBuilder, } from "./pages.js";
|
|
10
10
|
export { hotelBuilder, activityBuilder } from "./places.js";
|
|
11
11
|
export { eventBuilder, eventItemListBuilder, agendaItemListBuilder } from "./events.js";
|
|
12
|
-
export { AGENDA_CATEGORIES, AGENDA_KINDS, agendaItemIssues, agendaSnapshotIssues } from "./agenda.js";
|
|
12
|
+
export { AGENDA_CATEGORIES, AGENDA_KINDS, AGENDA_STATUSES, agendaItemIssues, agendaSnapshotIssues } from "./agenda.js";
|
package/package.json
CHANGED
package/src/dates/ics.ts
CHANGED
|
@@ -16,6 +16,10 @@ export interface IcsEvent {
|
|
|
16
16
|
endDate?: string;
|
|
17
17
|
/** Absolute URL of the event page */
|
|
18
18
|
url: string;
|
|
19
|
+
/** ISO instant with offset (`2026-11-21T20:00:00+01:00`): a timed event starting then, instead of an all-day one. */
|
|
20
|
+
startTime?: string;
|
|
21
|
+
/** This event's place; defaults to the calendar's `location`. */
|
|
22
|
+
location?: string;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
export interface IcsCalendar {
|
|
@@ -70,19 +74,23 @@ function foldLine(line: string): string {
|
|
|
70
74
|
return parts.join('\r\n ');
|
|
71
75
|
}
|
|
72
76
|
|
|
77
|
+
/** `2026-11-21T20:00:00+01:00` → `20261121T190000Z`. */
|
|
78
|
+
const utcCompact = (instant: string): string => new Date(instant).toISOString().replace(/[-:]/g, '').replace(/\.\d{3}/, '');
|
|
79
|
+
|
|
73
80
|
function vevent(ev: IcsEvent, cal: IcsCalendar): string[] {
|
|
74
81
|
const start = compact(ev.startDate);
|
|
75
82
|
const end = nextDayCompact(ev.endDate || ev.startDate);
|
|
83
|
+
// A timed start with no published end: DTSTART alone, never an invented duration.
|
|
84
|
+
const when = ev.startTime && !ev.endDate ? [`DTSTART:${utcCompact(ev.startTime)}`] : [`DTSTART;VALUE=DATE:${start}`, `DTEND;VALUE=DATE:${end}`];
|
|
76
85
|
return [
|
|
77
86
|
'BEGIN:VEVENT',
|
|
78
87
|
// Deterministic UID + DTSTAMP so rebuilds don't churn the committed output.
|
|
79
88
|
`UID:${ev.slug}-${start}@${cal.uidDomain}`,
|
|
80
89
|
`DTSTAMP:${start}T000000Z`,
|
|
81
|
-
|
|
82
|
-
`DTEND;VALUE=DATE:${end}`,
|
|
90
|
+
...when,
|
|
83
91
|
`SUMMARY:${escapeText(ev.name)}`,
|
|
84
92
|
...(ev.description ? [`DESCRIPTION:${escapeText(ev.description.slice(0, 300))}`] : []),
|
|
85
|
-
`LOCATION:${escapeText(cal.location)}`,
|
|
93
|
+
`LOCATION:${escapeText(ev.location ?? cal.location)}`,
|
|
86
94
|
`URL:${ev.url}`,
|
|
87
95
|
'END:VEVENT',
|
|
88
96
|
];
|
package/src/schema/agenda.ts
CHANGED
|
@@ -13,6 +13,10 @@ export type AgendaCategory = (typeof AGENDA_CATEGORIES)[number];
|
|
|
13
13
|
export const AGENDA_KINDS = ['dated', 'recurring'] as const;
|
|
14
14
|
export type AgendaKind = (typeof AGENDA_KINDS)[number];
|
|
15
15
|
|
|
16
|
+
/** A status the source states; absent means scheduled. */
|
|
17
|
+
export const AGENDA_STATUSES = ['cancelled', 'postponed'] as const;
|
|
18
|
+
export type AgendaStatus = (typeof AGENDA_STATUSES)[number];
|
|
19
|
+
|
|
16
20
|
export interface AgendaVenue {
|
|
17
21
|
name: string;
|
|
18
22
|
/** Internal route of the site's own venue page, e.g. `/monument/mezquita`. */
|
|
@@ -33,6 +37,10 @@ export interface AgendaItem {
|
|
|
33
37
|
/** Recurrence in words for a `recurring` item, e.g. "Every Sunday, 10:00–14:00". */
|
|
34
38
|
recurrence?: string;
|
|
35
39
|
venue: AgendaVenue;
|
|
40
|
+
/** Set only when the source says the event is cancelled or postponed. */
|
|
41
|
+
status?: AgendaStatus;
|
|
42
|
+
/** Performer as the source names it; absent when it names none (never inferred). */
|
|
43
|
+
performer?: string;
|
|
36
44
|
/** Internal link: the venue page or, when a festival page owns the query, `/event/<slug>` (Rule 34). */
|
|
37
45
|
href?: string;
|
|
38
46
|
/** The official page the dates were read from. */
|
|
@@ -99,6 +107,8 @@ export function agendaItemIssues(item: unknown, path = ''): FieldIssue[] {
|
|
|
99
107
|
const vh = venue.href;
|
|
100
108
|
if (vh !== undefined && !(typeof vh === 'string' && INTERNAL_HREF.test(vh))) issues.push({ path: at('venue.href'), message: 'must be an internal route like /monument/<slug>' });
|
|
101
109
|
}
|
|
110
|
+
str('performer', false);
|
|
111
|
+
if (it.status !== undefined && !AGENDA_STATUSES.includes(it.status as AgendaStatus)) issues.push({ path: at('status'), message: `must be one of ${AGENDA_STATUSES.join(', ')}` });
|
|
102
112
|
const href = str('href', false);
|
|
103
113
|
if (href !== undefined && !INTERNAL_HREF.test(href)) issues.push({ path: at('href'), message: 'must be an internal route like /event/<slug>' });
|
|
104
114
|
|
package/src/schema/events.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { offer } from './nodes.ts';
|
|
|
3
3
|
import { geoCoordinates, isFreeEntry, parsePriceFromString, postalAddress, type AddressPolicy } from './values.ts';
|
|
4
4
|
import type { JsonLdNode, SchemaBuilder, SchemaContext } from './types.ts';
|
|
5
5
|
import type { AgendaItem } from './agenda.ts';
|
|
6
|
-
import { agendaIsoDate } from '../dates/agenda.ts';
|
|
6
|
+
import { agendaDay, agendaIsoDate } from '../dates/agenda.ts';
|
|
7
|
+
import { getOgImagePath } from '../url/ogImage.ts';
|
|
7
8
|
|
|
8
9
|
/** Where events take place and who runs them; every value is the site's. */
|
|
9
10
|
export interface EventPolicy {
|
|
@@ -49,6 +50,7 @@ function eventLocation(policy: EventPolicy, data: Record<string, any>): JsonLdNo
|
|
|
49
50
|
|
|
50
51
|
const EVENT_STATUS = (rescheduled: unknown) => (rescheduled ? 'https://schema.org/EventRescheduled' : 'https://schema.org/EventScheduled');
|
|
51
52
|
const OFFLINE = 'https://schema.org/OfflineEventAttendanceMode';
|
|
53
|
+
const AGENDA_EVENT_STATUS = { cancelled: 'https://schema.org/EventCancelled', postponed: 'https://schema.org/EventPostponed' } as const;
|
|
52
54
|
|
|
53
55
|
interface EventNodeParts {
|
|
54
56
|
isFree: boolean | undefined;
|
|
@@ -71,7 +73,7 @@ function eventNode(ctx: SchemaContext, policy: EventPolicy, data: Record<string,
|
|
|
71
73
|
startDate: data.startDate || undefined,
|
|
72
74
|
endDate: data.endDate || undefined,
|
|
73
75
|
previousStartDate: data.previousStartDate || undefined,
|
|
74
|
-
eventStatus: EVENT_STATUS(data.previousStartDate),
|
|
76
|
+
eventStatus: data.eventStatus ?? EVENT_STATUS(data.previousStartDate),
|
|
75
77
|
eventAttendanceMode: OFFLINE,
|
|
76
78
|
isAccessibleForFree: parts.isFree,
|
|
77
79
|
location: eventLocation(policy, data),
|
|
@@ -146,18 +148,30 @@ export interface EventItemListOptions extends EventPolicy {
|
|
|
146
148
|
export type AgendaItemListOptions = Omit<EventItemListOptions, 'isEvent' | 'organizer' | 'performer' | 'itemOrganizer'>
|
|
147
149
|
& Partial<Pick<EventItemListOptions, 'organizer' | 'performer' | 'itemOrganizer'>>;
|
|
148
150
|
|
|
151
|
+
/** A singular route segment's collection: `monument` → `monuments`, `activity` → `activities`, `dish` → `dishes`. */
|
|
152
|
+
const collectionOfSegment = (s: string) => (/[^aeiou]y$/.test(s) ? `${s.slice(0, -1)}ies` : /(s|sh|ch|x|z)$/.test(s) ? `${s}es` : `${s}s`);
|
|
153
|
+
|
|
154
|
+
/** The OG jpg of a venue page (`/monument/x` → `/images/og/monuments/x.jpg`), when that file exists. */
|
|
155
|
+
function venueOgImage(ctx: SchemaContext, venueHref: string | undefined): string | undefined {
|
|
156
|
+
const [, segment, slug] = venueHref?.match(/^\/([a-z0-9-]+)\/([a-z0-9-]+)\/?$/) ?? [];
|
|
157
|
+
const path = segment ? getOgImagePath(collectionOfSegment(segment), slug) : undefined;
|
|
158
|
+
return path && ctx.fileExists(path) ? path : undefined;
|
|
159
|
+
}
|
|
160
|
+
|
|
149
161
|
/**
|
|
150
|
-
* ItemList for a What's On window (SLA-4221): `data` is `{ name, items: AgendaItem[], timezone }`, already
|
|
151
|
-
* the window. Dated items become Events; a recurring item becomes a WebPage, since it has no single date.
|
|
162
|
+
* ItemList for a What's On window (SLA-4221): `data` is `{ name, items: AgendaItem[], timezone, image?, stale? }`, already
|
|
163
|
+
* filtered to the window. Dated items become Events; a recurring item becomes a WebPage, since it has no single date.
|
|
164
|
+
* An Event's image is its venue page's OG image, else `data.image` (the page's); a one-day Event ends on its start day.
|
|
165
|
+
* `data.stale` (the freshness guard) turns every item into a WebPage: no Event claims dates nobody has rechecked.
|
|
152
166
|
*/
|
|
153
167
|
export function agendaItemListBuilder(options: AgendaItemListOptions): SchemaBuilder {
|
|
154
|
-
const venueOrganizer = (item: Record<string, any>): JsonLdNode => ({ '@type': 'Organization', name: item.location });
|
|
168
|
+
const venueOrganizer = (item: Record<string, any>): JsonLdNode => ({ '@type': 'Organization', name: item.location, url: item.organizerUrl });
|
|
155
169
|
const list = eventItemListBuilder({
|
|
156
170
|
...options,
|
|
157
171
|
organizer: options.organizer ?? venueOrganizer,
|
|
158
172
|
itemOrganizer: options.itemOrganizer ?? venueOrganizer,
|
|
159
|
-
performer: options.performer ?? (() => undefined),
|
|
160
|
-
isEvent: (item) => item.kind === 'dated',
|
|
173
|
+
performer: options.performer ?? ((item) => (item.performer ? { '@type': 'PerformingGroup', name: item.performer } : undefined)),
|
|
174
|
+
isEvent: (item) => item.kind === 'dated' && !item.stale,
|
|
161
175
|
});
|
|
162
176
|
return (data, ctx) => list({
|
|
163
177
|
name: data.name,
|
|
@@ -167,11 +181,16 @@ export function agendaItemListBuilder(options: AgendaItemListOptions): SchemaBui
|
|
|
167
181
|
category: item.category,
|
|
168
182
|
name: item.title,
|
|
169
183
|
description: item.blurb,
|
|
184
|
+
image: venueOgImage(ctx, item.venue.href) ?? data.image,
|
|
170
185
|
url: item.href ?? item.venue.href ?? item.sourceUrl,
|
|
171
186
|
startDate: agendaIsoDate(item.startDate, data.timezone),
|
|
172
|
-
endDate: item.endDate,
|
|
187
|
+
endDate: item.endDate ?? agendaDay(item.startDate),
|
|
173
188
|
location: item.venue.name,
|
|
174
189
|
streetAddress: item.venue.address,
|
|
190
|
+
organizerUrl: ctx.absOrHttp(item.venue.href ?? item.sourceUrl),
|
|
191
|
+
performer: item.performer,
|
|
192
|
+
eventStatus: item.status ? AGENDA_EVENT_STATUS[item.status] : undefined,
|
|
193
|
+
stale: data.stale === true,
|
|
175
194
|
price: item.free ? 'Free' : undefined,
|
|
176
195
|
priceValue: item.free ? undefined : item.priceFrom,
|
|
177
196
|
officialWebsite: item.sourceUrl,
|
package/src/schema/index.ts
CHANGED
|
@@ -38,5 +38,5 @@ export { hotelBuilder, activityBuilder } from './places.ts';
|
|
|
38
38
|
export type { HotelOptions, ActivityOptions } from './places.ts';
|
|
39
39
|
export { eventBuilder, eventItemListBuilder, agendaItemListBuilder } from './events.ts';
|
|
40
40
|
export type { EventPolicy, EventOptions, EventItemListOptions, AgendaItemListOptions } from './events.ts';
|
|
41
|
-
export { AGENDA_CATEGORIES, AGENDA_KINDS, agendaItemIssues, agendaSnapshotIssues } from './agenda.ts';
|
|
42
|
-
export type { AgendaCategory, AgendaKind, AgendaVenue, AgendaItem, AgendaSnapshot } from './agenda.ts';
|
|
41
|
+
export { AGENDA_CATEGORIES, AGENDA_KINDS, AGENDA_STATUSES, agendaItemIssues, agendaSnapshotIssues } from './agenda.ts';
|
|
42
|
+
export type { AgendaCategory, AgendaKind, AgendaStatus, AgendaVenue, AgendaItem, AgendaSnapshot } from './agenda.ts';
|