@vermeulen.solutions/eventual 0.18.6 → 0.19.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/README.md +10 -10
- package/astro/EventList.astro +124 -5
- package/astro/blueprint.d.mts +2 -0
- package/astro/blueprint.mjs +1 -1
- package/astro/events/EventBrowser.astro +261 -0
- package/astro/events/EventDetail.astro +113 -0
- package/astro/events/description.ts +183 -0
- package/astro/events/grid.ts +199 -0
- package/astro/events/i18n.ts +122 -0
- package/astro/events/index.ts +301 -0
- package/astro/events/links.ts +54 -0
- package/astro/events/parts/AgendaItem.astro +74 -0
- package/astro/events/parts/DateTile.astro +24 -0
- package/astro/events/parts/EventCard.astro +63 -0
- package/astro/events/parts/Icon.astro +26 -0
- package/astro/events/parts/StatusBadge.astro +23 -0
- package/astro/events/parts/Styles.astro +1453 -0
- package/astro/events/state.ts +82 -0
- package/dist/index.mjs +1 -11
- package/dist/plugin.mjs +7 -7
- package/docs/collection-setup.md +2 -2
- package/docs/developer-guide.md +76 -2
- package/docs/registry-installation.md +2 -2
- package/docs/release-notes-0.18.7.md +13 -0
- package/docs/release-notes-0.19.0.md +12 -0
- package/docs/user-guide.md +1 -1
- package/emdash-plugin.jsonc +0 -2
- package/package.json +8 -3
- package/scripts/export-native-schema.mjs +7 -3
- package/src/domain/calendar-links.ts +3 -1
- package/src/domain/invocation-budget.ts +12 -7
- package/src/domain/native-calendar.ts +12 -3
- package/src/schema/blueprint.ts +3 -1
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event descriptions as safe HTML. Native events carry Portable Text (`descriptionBlocks`);
|
|
3
|
+
* older or imported events carry plain text, rendered with the showcase's small markdown subset.
|
|
4
|
+
* Everything is escaped; only http(s) and mailto links survive, and they open in a new tab.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
interface Span { _type?: string; text?: string; marks?: string[] }
|
|
8
|
+
interface MarkDef { _key: string; _type: string; href?: string }
|
|
9
|
+
interface Block { _type?: string; style?: string; listItem?: string; level?: number; children?: Span[]; markDefs?: MarkDef[] }
|
|
10
|
+
|
|
11
|
+
export interface DescriptionOptions {
|
|
12
|
+
/** Level for the description's top headings (default 2). */
|
|
13
|
+
headingBase?: number;
|
|
14
|
+
/** Visually hidden text after links that open a new tab, in the page language. */
|
|
15
|
+
newTabText?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** HTML for a description: Portable Text when present, else plain text with light markdown. */
|
|
19
|
+
export function descriptionHtml(blocks: unknown[] | undefined, text: string, options: DescriptionOptions = {}): string {
|
|
20
|
+
return Array.isArray(blocks) && blocks.length ? portableTextHtml(blocks, options) : markdownHtml(text, options);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A plain one-paragraph excerpt for lists and cards. */
|
|
24
|
+
export function descriptionExcerpt(source: string, limit = 180): string {
|
|
25
|
+
const plain = source
|
|
26
|
+
.replace(/<[^>]*>/g, " ")
|
|
27
|
+
.replace(/\[([^\]]+)\]\([^)]*\)/g, "$1")
|
|
28
|
+
.replace(/(^|\s)#{1,3}\s+/g, "$1")
|
|
29
|
+
.replace(/\*\*|__|[*_]/g, "")
|
|
30
|
+
.replace(/(^|\s)[-*]\s+/g, "$1")
|
|
31
|
+
.replace(/\s+/g, " ")
|
|
32
|
+
.trim();
|
|
33
|
+
if (plain.length <= limit) return plain;
|
|
34
|
+
const cut = plain.slice(0, limit + 1);
|
|
35
|
+
const boundary = cut.lastIndexOf(" ");
|
|
36
|
+
return `${cut.slice(0, boundary > limit * 0.7 ? boundary : limit).trimEnd()}…`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function portableTextHtml(blocks: unknown[], options: DescriptionOptions = {}): string {
|
|
40
|
+
const base = clampHeading(options.headingBase ?? 2);
|
|
41
|
+
const out: string[] = [];
|
|
42
|
+
let list: { tag: "ul" | "ol"; items: string[] } | null = null;
|
|
43
|
+
const flush = () => {
|
|
44
|
+
if (list) out.push(`<${list.tag}>${list.items.map((item) => `<li>${item}</li>`).join("")}</${list.tag}>`);
|
|
45
|
+
list = null;
|
|
46
|
+
};
|
|
47
|
+
for (const raw of blocks) {
|
|
48
|
+
if (!raw || typeof raw !== "object") continue;
|
|
49
|
+
const block = raw as Block;
|
|
50
|
+
if (block._type && block._type !== "block") continue;
|
|
51
|
+
const inline = renderSpans(block.children ?? [], block.markDefs ?? [], options);
|
|
52
|
+
if (block.listItem) {
|
|
53
|
+
const tag = block.listItem === "number" ? "ol" : "ul";
|
|
54
|
+
if (!list || list.tag !== tag) {
|
|
55
|
+
flush();
|
|
56
|
+
list = { tag, items: [] };
|
|
57
|
+
}
|
|
58
|
+
list.items.push(inline);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
flush();
|
|
62
|
+
if (!inline.trim()) continue;
|
|
63
|
+
const heading = /^h([1-6])$/.exec(block.style ?? "");
|
|
64
|
+
if (heading) {
|
|
65
|
+
const level = clampHeading(base + Math.max(0, Number(heading[1]) - 2));
|
|
66
|
+
out.push(`<h${level}>${inline}</h${level}>`);
|
|
67
|
+
} else if (block.style === "blockquote") out.push(`<blockquote><p>${inline}</p></blockquote>`);
|
|
68
|
+
else out.push(`<p>${inline}</p>`);
|
|
69
|
+
}
|
|
70
|
+
flush();
|
|
71
|
+
return out.join("");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function renderSpans(spans: Span[], markDefs: MarkDef[], options: DescriptionOptions): string {
|
|
75
|
+
return spans
|
|
76
|
+
.map((span) => {
|
|
77
|
+
if (!span || typeof span.text !== "string") return "";
|
|
78
|
+
let html = escapeHtml(span.text).replace(/\n/g, "<br>");
|
|
79
|
+
for (const mark of span.marks ?? []) {
|
|
80
|
+
if (mark === "strong") html = `<strong>${html}</strong>`;
|
|
81
|
+
else if (mark === "em") html = `<em>${html}</em>`;
|
|
82
|
+
else if (mark === "code") html = `<code>${html}</code>`;
|
|
83
|
+
else {
|
|
84
|
+
const def = markDefs.find((item) => item._key === mark);
|
|
85
|
+
const href = def?._type === "link" ? safeLink(def.href ?? "") : "";
|
|
86
|
+
if (href) html = linkHtml(href, html, options);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return html;
|
|
90
|
+
})
|
|
91
|
+
.join("");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function markdownHtml(source: string, options: DescriptionOptions = {}): string {
|
|
95
|
+
const base = clampHeading(options.headingBase ?? 2);
|
|
96
|
+
const lines = source.replace(/\r\n?/g, "\n").split("\n");
|
|
97
|
+
const blocks: string[] = [];
|
|
98
|
+
let paragraph: string[] = [];
|
|
99
|
+
let list: string[] = [];
|
|
100
|
+
const flushParagraph = () => {
|
|
101
|
+
if (paragraph.length) blocks.push(`<p>${renderInline(paragraph.join(" ").trim(), options)}</p>`);
|
|
102
|
+
paragraph = [];
|
|
103
|
+
};
|
|
104
|
+
const flushList = () => {
|
|
105
|
+
if (list.length) blocks.push(`<ul>${list.map((item) => `<li>${renderInline(item, options)}</li>`).join("")}</ul>`);
|
|
106
|
+
list = [];
|
|
107
|
+
};
|
|
108
|
+
for (const line of lines) {
|
|
109
|
+
const heading = line.match(/^\s{0,3}(#{1,3})\s+(.+?)\s*$/);
|
|
110
|
+
const item = line.match(/^\s*[-*]\s+(.+?)\s*$/);
|
|
111
|
+
if (!line.trim()) {
|
|
112
|
+
flushParagraph();
|
|
113
|
+
flushList();
|
|
114
|
+
} else if (heading) {
|
|
115
|
+
flushParagraph();
|
|
116
|
+
flushList();
|
|
117
|
+
// Same mapping as Portable Text: # and ## are the top level, ### one below.
|
|
118
|
+
const level = clampHeading(base + Math.max(0, heading[1]!.length - 2));
|
|
119
|
+
blocks.push(`<h${level}>${renderInline(heading[2]!, options)}</h${level}>`);
|
|
120
|
+
} else if (item) {
|
|
121
|
+
flushParagraph();
|
|
122
|
+
list.push(item[1]!);
|
|
123
|
+
} else {
|
|
124
|
+
flushList();
|
|
125
|
+
paragraph.push(line.trim());
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
flushParagraph();
|
|
129
|
+
flushList();
|
|
130
|
+
return blocks.join("");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function renderInline(source: string, options: DescriptionOptions): string {
|
|
134
|
+
let html = "";
|
|
135
|
+
let index = 0;
|
|
136
|
+
while (index < source.length) {
|
|
137
|
+
const rest = source.slice(index);
|
|
138
|
+
const link = rest.match(/^\[([^\]]+)\]\(([^)]+)\)/);
|
|
139
|
+
if (link) {
|
|
140
|
+
const href = safeLink(link[2]!);
|
|
141
|
+
html += href ? linkHtml(href, renderInline(link[1]!, options), options) : escapeHtml(link[0]);
|
|
142
|
+
index += link[0].length;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const strong = rest.match(/^\*\*(.+?)\*\*/);
|
|
146
|
+
if (strong) {
|
|
147
|
+
html += `<strong>${renderInline(strong[1]!, options)}</strong>`;
|
|
148
|
+
index += strong[0].length;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const emphasis = rest.match(/^_([^_]+?)_/);
|
|
152
|
+
if (emphasis) {
|
|
153
|
+
html += `<em>${renderInline(emphasis[1]!, options)}</em>`;
|
|
154
|
+
index += emphasis[0].length;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
html += escapeHtml(source[index]!);
|
|
158
|
+
index += 1;
|
|
159
|
+
}
|
|
160
|
+
return html;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function linkHtml(href: string, inner: string, options: DescriptionOptions): string {
|
|
164
|
+
const hint = options.newTabText ? `<span class="eventual-sr-only"> ${escapeHtml(options.newTabText)}</span>` : "";
|
|
165
|
+
return `<a href="${escapeHtml(href)}" target="_blank" rel="noopener noreferrer">${inner}${hint}</a>`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function safeLink(value: string): string {
|
|
169
|
+
try {
|
|
170
|
+
const url = new URL(value);
|
|
171
|
+
return url.protocol === "http:" || url.protocol === "https:" || url.protocol === "mailto:" ? url.href : "";
|
|
172
|
+
} catch {
|
|
173
|
+
return "";
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function clampHeading(level: number): number {
|
|
178
|
+
return Math.min(6, Math.max(2, Math.round(level)));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function escapeHtml(value: string): string {
|
|
182
|
+
return value.replace(/[&<>"']/g, (character) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[character]!);
|
|
183
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Month grid and date formatting for the event views. Moved from the Astro showcase
|
|
3
|
+
* (examples/astro-events/src/lib/calendar.ts); calendar links and ICS now come from Core's feed.
|
|
4
|
+
*/
|
|
5
|
+
import type { PublicEvent } from "../feed";
|
|
6
|
+
import { civilDate } from "../event-list";
|
|
7
|
+
|
|
8
|
+
const SUNDAY_FIRST_REGIONS = new Set(["US", "CA", "JP", "KR", "TW", "IL", "SA", "PH"]);
|
|
9
|
+
|
|
10
|
+
export interface CalendarCell {
|
|
11
|
+
date: string;
|
|
12
|
+
inMonth: boolean;
|
|
13
|
+
dayNumber: number;
|
|
14
|
+
events: PublicEvent[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function normalizeLocale(value: string | undefined): string {
|
|
18
|
+
try {
|
|
19
|
+
return Intl.getCanonicalLocales(value || "en-GB")[0] ?? "en-GB";
|
|
20
|
+
} catch {
|
|
21
|
+
return "en-GB";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function normalizeTimeZone(value: string | undefined): string {
|
|
26
|
+
try {
|
|
27
|
+
new Intl.DateTimeFormat("en", { timeZone: value || "UTC" });
|
|
28
|
+
return value || "UTC";
|
|
29
|
+
} catch {
|
|
30
|
+
return "UTC";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function isMonthKey(value: string | null | undefined): value is string {
|
|
35
|
+
return Boolean(value && /^\d{4}-(0[1-9]|1[0-2])$/.test(value) && Number(value.slice(0, 4)) >= 1000);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function addMonths(value: string, amount: number): string {
|
|
39
|
+
const [year, month] = value.split("-").map(Number);
|
|
40
|
+
const date = new Date(Date.UTC(year!, month! - 1 + amount, 1));
|
|
41
|
+
return `${date.getUTCFullYear()}-${String(date.getUTCMonth() + 1).padStart(2, "0")}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The month a given instant falls in, in a time zone ("2026-11"). */
|
|
45
|
+
export function monthOf(now: Date, timeZone: string): string {
|
|
46
|
+
return localDate(now.toISOString(), timeZone).slice(0, 7);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Whole weeks around a month, starting on the locale's first day of the week. */
|
|
50
|
+
export function calendarRange(month: string, locale: string): { from: string; through: string } {
|
|
51
|
+
const [year, monthNumber] = month.split("-").map(Number);
|
|
52
|
+
const first = new Date(Date.UTC(year!, monthNumber! - 1, 1));
|
|
53
|
+
const last = new Date(Date.UTC(year!, monthNumber!, 0));
|
|
54
|
+
const offset = (first.getUTCDay() - firstDayOfWeek(locale) + 7) % 7;
|
|
55
|
+
const from = new Date(Date.UTC(year!, monthNumber! - 1, 1 - offset));
|
|
56
|
+
const cells = Math.ceil((offset + last.getUTCDate()) / 7) * 7;
|
|
57
|
+
const through = new Date(from);
|
|
58
|
+
through.setUTCDate(through.getUTCDate() + cells - 1);
|
|
59
|
+
return { from: dateKey(from), through: dateKey(through) };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function monthDateRange(month: string): { from: string; through: string } {
|
|
63
|
+
const [year, monthNumber] = month.split("-").map(Number);
|
|
64
|
+
const last = new Date(Date.UTC(year!, monthNumber!, 0));
|
|
65
|
+
return {
|
|
66
|
+
from: `${month}-01`,
|
|
67
|
+
through: `${month}-${String(last.getUTCDate()).padStart(2, "0")}`,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 0 = Sunday … 6 = Saturday. */
|
|
72
|
+
export function firstDayOfWeek(locale: string): number {
|
|
73
|
+
try {
|
|
74
|
+
const localeObject = new Intl.Locale(locale) as Intl.Locale & {
|
|
75
|
+
getWeekInfo?: () => { firstDay: number };
|
|
76
|
+
weekInfo?: { firstDay: number };
|
|
77
|
+
};
|
|
78
|
+
const firstDay = localeObject.getWeekInfo?.().firstDay ?? localeObject.weekInfo?.firstDay;
|
|
79
|
+
if (firstDay && firstDay >= 1 && firstDay <= 7) return firstDay % 7;
|
|
80
|
+
const region = localeObject.region?.toUpperCase();
|
|
81
|
+
if (region && SUNDAY_FIRST_REGIONS.has(region)) return 0;
|
|
82
|
+
} catch {
|
|
83
|
+
// Invalid locales use the documented Monday-first fallback.
|
|
84
|
+
}
|
|
85
|
+
return 1;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function weekdayHeadings(locale: string, width: "short" | "long" = "short"): string[] {
|
|
89
|
+
const first = firstDayOfWeek(locale);
|
|
90
|
+
return Array.from({ length: 7 }, (_, index) => {
|
|
91
|
+
const date = new Date(Date.UTC(2023, 0, 1 + first + index));
|
|
92
|
+
return new Intl.DateTimeFormat(locale, { weekday: width, timeZone: "UTC" }).format(date);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function buildCalendar(month: string, locale: string, events: PublicEvent[]): CalendarCell[][] {
|
|
97
|
+
const range = calendarRange(month, locale);
|
|
98
|
+
const [year, monthNumber] = month.split("-").map(Number);
|
|
99
|
+
const first = new Date(`${range.from}T00:00:00Z`);
|
|
100
|
+
const last = new Date(`${range.through}T00:00:00Z`);
|
|
101
|
+
const days = Math.round((last.getTime() - first.getTime()) / 86_400_000) + 1;
|
|
102
|
+
const cells: CalendarCell[] = [];
|
|
103
|
+
for (let index = 0; index < days; index += 1) {
|
|
104
|
+
const date = new Date(first);
|
|
105
|
+
date.setUTCDate(first.getUTCDate() + index);
|
|
106
|
+
const key = dateKey(date);
|
|
107
|
+
cells.push({
|
|
108
|
+
date: key,
|
|
109
|
+
inMonth: date.getUTCMonth() === monthNumber! - 1 && date.getUTCFullYear() === year,
|
|
110
|
+
dayNumber: date.getUTCDate(),
|
|
111
|
+
events: events.filter((event) => eventTouchesDate(event, key)),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const weeks: CalendarCell[][] = [];
|
|
115
|
+
for (let index = 0; index < cells.length; index += 7) weeks.push(cells.slice(index, index + 7));
|
|
116
|
+
return weeks;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function eventTouchesDate(event: PublicEvent, date: string): boolean {
|
|
120
|
+
const start = eventStartDate(event);
|
|
121
|
+
const end = eventEndDate(event);
|
|
122
|
+
return Boolean(start && end && start <= date && end >= date);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The event's first and last calendar day where it takes place (all-day ends are inclusive). */
|
|
126
|
+
export function eventStartDate(event: PublicEvent): string {
|
|
127
|
+
return event.allDay ? event.start.slice(0, 10) : localDate(event.start, event.timezone);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function eventEndDate(event: PublicEvent): string {
|
|
131
|
+
return event.allDay ? event.end.slice(0, 10) : localDate(event.end, event.timezone);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function displayDate(value: string, locale: string, timeZone: string, allDay: boolean, style: "medium" | "full" = "medium"): string {
|
|
135
|
+
const date = allDay ? new Date(`${value.slice(0, 10)}T00:00:00Z`) : new Date(value);
|
|
136
|
+
try {
|
|
137
|
+
return new Intl.DateTimeFormat(locale, { dateStyle: style, timeZone: allDay ? "UTC" : timeZone }).format(date);
|
|
138
|
+
} catch {
|
|
139
|
+
return value.slice(0, 10);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** "18:15–19:15 CET"; empty for all-day events. Each end shows its zone when the two differ. */
|
|
144
|
+
export function eventTimeRange(event: PublicEvent, locale: string): string {
|
|
145
|
+
if (event.allDay) return "";
|
|
146
|
+
try {
|
|
147
|
+
const time = new Intl.DateTimeFormat(locale, { hour: "numeric", minute: "2-digit", timeZone: event.timezone });
|
|
148
|
+
const zoneFormat = new Intl.DateTimeFormat(locale, { timeZone: event.timezone, timeZoneName: "short" });
|
|
149
|
+
const start = new Date(event.start);
|
|
150
|
+
const end = new Date(event.end);
|
|
151
|
+
const zoneName = (date: Date) => zoneFormat.formatToParts(date).find((part) => part.type === "timeZoneName")?.value ?? event.timezone;
|
|
152
|
+
const startZone = zoneName(start);
|
|
153
|
+
const endZone = zoneName(end);
|
|
154
|
+
return startZone === endZone
|
|
155
|
+
? `${time.format(start)}–${time.format(end)} ${startZone}`
|
|
156
|
+
: `${time.format(start)} ${startZone}–${time.format(end)} ${endZone}`;
|
|
157
|
+
} catch {
|
|
158
|
+
return "";
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Start and end time ("18:15", "19:15") and the zone ("CET") for a compact time column; null for all-day events. */
|
|
163
|
+
export function eventTimeParts(event: PublicEvent, locale: string): { start: string; end: string; zone: string } | null {
|
|
164
|
+
if (event.allDay) return null;
|
|
165
|
+
try {
|
|
166
|
+
const time = new Intl.DateTimeFormat(locale, { hour: "numeric", minute: "2-digit", timeZone: event.timezone });
|
|
167
|
+
const zone = new Intl.DateTimeFormat(locale, { timeZone: event.timezone, timeZoneName: "short" })
|
|
168
|
+
.formatToParts(new Date(event.start)).find((part) => part.type === "timeZoneName")?.value ?? event.timezone;
|
|
169
|
+
return { start: time.format(new Date(event.start)), end: time.format(new Date(event.end)), zone };
|
|
170
|
+
} catch {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function monthLabel(month: string, locale: string): string {
|
|
176
|
+
const [year, monthNumber] = month.split("-").map(Number);
|
|
177
|
+
return new Intl.DateTimeFormat(locale, { month: "long", year: "numeric", timeZone: "UTC" })
|
|
178
|
+
.format(new Date(Date.UTC(year!, monthNumber! - 1, 1)));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function addCalendarDay(value: string): string {
|
|
182
|
+
const date = new Date(`${value}T00:00:00Z`);
|
|
183
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(value) || !Number.isFinite(date.getTime())) return "";
|
|
184
|
+
date.setUTCDate(date.getUTCDate() + 1);
|
|
185
|
+
return dateKey(date);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function localDate(instant: string, timezone: string): string {
|
|
189
|
+
if (!Number.isFinite(new Date(instant).getTime())) return "";
|
|
190
|
+
try {
|
|
191
|
+
return civilDate(instant, timezone);
|
|
192
|
+
} catch {
|
|
193
|
+
return "";
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function dateKey(date: Date): string {
|
|
198
|
+
return `${date.getUTCFullYear()}-${String(date.getUTCMonth() + 1).padStart(2, "0")}-${String(date.getUTCDate()).padStart(2, "0")}`;
|
|
199
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { bindMessages, localeDirection, resolveLocale, type Bound } from "@vermeulen.solutions/eventual-locales";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Every visible string of the event pages (EventBrowser, EventDetail). English is
|
|
5
|
+
* the source; other languages ship in @vermeulen.solutions/eventual-locales
|
|
6
|
+
* (catalogs/core-site/<lang>.json, flat dotted keys over this tree). Leaves written as
|
|
7
|
+
* ["template", "arg", …] become functions; templates use ICU syntax ({count, plural, …}).
|
|
8
|
+
*/
|
|
9
|
+
const en = {
|
|
10
|
+
pageTitle: ["Events – {month}", "month"],
|
|
11
|
+
intro: "Browse the month in the format that suits you.",
|
|
12
|
+
views: {
|
|
13
|
+
label: "View",
|
|
14
|
+
list: "List",
|
|
15
|
+
timeline: "Timeline",
|
|
16
|
+
cards: "Cards",
|
|
17
|
+
schedule: "Schedule",
|
|
18
|
+
dates: "Date strip",
|
|
19
|
+
month: "Month",
|
|
20
|
+
locations: "Locations",
|
|
21
|
+
},
|
|
22
|
+
month: {
|
|
23
|
+
navigation: "Choose a month",
|
|
24
|
+
previous: ["Previous month: {month}", "month"],
|
|
25
|
+
next: ["Next month: {month}", "month"],
|
|
26
|
+
current: "This month",
|
|
27
|
+
events: ["Events in {month}", "month"],
|
|
28
|
+
},
|
|
29
|
+
filter: {
|
|
30
|
+
label: "Category",
|
|
31
|
+
all: "All categories",
|
|
32
|
+
apply: "Show",
|
|
33
|
+
active: ["Showing: {category}", "category"],
|
|
34
|
+
clear: "Show all categories",
|
|
35
|
+
},
|
|
36
|
+
count: ["{count, plural, one {# event} other {# events}}", "count"],
|
|
37
|
+
notice: {
|
|
38
|
+
unavailable: "Events are temporarily unavailable.",
|
|
39
|
+
unavailableDetail: "The events could not be loaded. Please try again later.",
|
|
40
|
+
tryAgain: "Try again",
|
|
41
|
+
empty: "No events are scheduled for this month.",
|
|
42
|
+
emptyFiltered: "No events in this category this month.",
|
|
43
|
+
notFound: "This event is unavailable or has been removed.",
|
|
44
|
+
},
|
|
45
|
+
event: {
|
|
46
|
+
allDay: "All day",
|
|
47
|
+
organizer: ["Organized by {name}", "name"],
|
|
48
|
+
directions: "Directions",
|
|
49
|
+
details: "Event details",
|
|
50
|
+
website: "Event website",
|
|
51
|
+
joinOnline: "Join online",
|
|
52
|
+
categories: "Categories",
|
|
53
|
+
locationToConfirm: "Location to be confirmed",
|
|
54
|
+
originally: ["Originally {date}", "date"],
|
|
55
|
+
back: "Back to events",
|
|
56
|
+
},
|
|
57
|
+
status: {
|
|
58
|
+
cancelled: "Cancelled",
|
|
59
|
+
postponed: "Postponed",
|
|
60
|
+
rescheduled: "Rescheduled",
|
|
61
|
+
},
|
|
62
|
+
calendar: {
|
|
63
|
+
add: "Add to calendar",
|
|
64
|
+
addFor: ["Add to calendar: {title}", "title"],
|
|
65
|
+
google: "Google Calendar",
|
|
66
|
+
outlook: "Outlook",
|
|
67
|
+
office365: "Office 365",
|
|
68
|
+
ics: "Download iCal file",
|
|
69
|
+
subscribe: "Subscribe to calendar",
|
|
70
|
+
},
|
|
71
|
+
dates: {
|
|
72
|
+
jump: "Jump to a date",
|
|
73
|
+
},
|
|
74
|
+
newTab: "(opens in a new tab)",
|
|
75
|
+
} as const;
|
|
76
|
+
|
|
77
|
+
/** English source; its dotted paths are the keys of the core-site catalogs. */
|
|
78
|
+
export const EVENT_PAGES_EN = en;
|
|
79
|
+
|
|
80
|
+
export type EventPageText = Bound<typeof en>;
|
|
81
|
+
|
|
82
|
+
// Each import becomes its own chunk, loaded per language.
|
|
83
|
+
const catalogs: Record<string, () => Promise<{ default: Record<string, string> }>> = {
|
|
84
|
+
fr: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/fr.json", { with: { type: "json" } }),
|
|
85
|
+
de: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/de.json", { with: { type: "json" } }),
|
|
86
|
+
nl: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/nl.json", { with: { type: "json" } }),
|
|
87
|
+
es: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/es.json", { with: { type: "json" } }),
|
|
88
|
+
it: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/it.json", { with: { type: "json" } }),
|
|
89
|
+
pt: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/pt.json", { with: { type: "json" } }),
|
|
90
|
+
"pt-BR": () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/pt-BR.json", { with: { type: "json" } }),
|
|
91
|
+
pl: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/pl.json", { with: { type: "json" } }),
|
|
92
|
+
cs: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/cs.json", { with: { type: "json" } }),
|
|
93
|
+
sv: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/sv.json", { with: { type: "json" } }),
|
|
94
|
+
da: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/da.json", { with: { type: "json" } }),
|
|
95
|
+
nb: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/nb.json", { with: { type: "json" } }),
|
|
96
|
+
fi: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/fi.json", { with: { type: "json" } }),
|
|
97
|
+
ja: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/ja.json", { with: { type: "json" } }),
|
|
98
|
+
"zh-CN": () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/zh-CN.json", { with: { type: "json" } }),
|
|
99
|
+
ko: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/ko.json", { with: { type: "json" } }),
|
|
100
|
+
tr: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/tr.json", { with: { type: "json" } }),
|
|
101
|
+
uk: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/uk.json", { with: { type: "json" } }),
|
|
102
|
+
ar: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/ar.json", { with: { type: "json" } }),
|
|
103
|
+
he: () => import("@vermeulen.solutions/eventual-locales/catalogs/core-site/he.json", { with: { type: "json" } }),
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/** The page texts in a language (English when there is no catalog), and its writing direction. */
|
|
107
|
+
export async function eventPageText(locale: string | undefined): Promise<{ text: EventPageText; lang: string; dir: "ltr" | "rtl" }> {
|
|
108
|
+
const wanted = resolveLocale(locale ?? "en", Object.keys(catalogs));
|
|
109
|
+
let catalog: Record<string, string> | undefined;
|
|
110
|
+
try {
|
|
111
|
+
catalog = wanted !== "en" ? (await catalogs[wanted]?.())?.default : undefined;
|
|
112
|
+
} catch {
|
|
113
|
+
catalog = undefined;
|
|
114
|
+
}
|
|
115
|
+
// The texts are English until that language's catalog exists: then lang and dir are English too.
|
|
116
|
+
const lang = catalog ? wanted : "en";
|
|
117
|
+
return {
|
|
118
|
+
text: bindMessages(en, catalog, lang) as EventPageText,
|
|
119
|
+
lang,
|
|
120
|
+
dir: localeDirection(lang) === "rtl" ? "rtl" : "ltr",
|
|
121
|
+
};
|
|
122
|
+
}
|