ferst-core 0.11.1 → 0.12.1
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/bin/ferst-modules.mjs +32 -8
- package/bin/ferst-update.mjs +35 -0
- package/cms/config.template.yml +239 -232
- package/components/BlockRenderer.astro +2 -0
- package/components/recipes/Book.astro +386 -0
- package/content/blocks.ts +23 -2
- package/content/recipe-questions.ts +1 -0
- package/lib/book.ts +118 -0
- package/package.json +1 -1
package/bin/ferst-modules.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// ferst-modules — what this site has from its organisation's modules in the Ferst portal:
|
|
3
|
-
// the forms it can place, what it can take payment for, and the calendar it shows.
|
|
3
|
+
// the forms it can place, what it can take payment for and bookings for, and the calendar it shows.
|
|
4
|
+
// Run it in a client repo root:
|
|
4
5
|
//
|
|
5
6
|
// npx --no-install ferst-modules # the site named in ferst-site.json
|
|
6
7
|
// npx --no-install ferst-modules --site <address> # or ask by the site's address
|
|
@@ -8,7 +9,8 @@
|
|
|
8
9
|
//
|
|
9
10
|
// Forms and calendars live in the portal, never in the repo: place a form with a
|
|
10
11
|
// `{ "type": "form", "form": "<its name on this site>" }` block, take a payment with a
|
|
11
|
-
// `{ "type": "pay", "item": "<its id>" }` block,
|
|
12
|
+
// `{ "type": "pay", "item": "<its id>" }` block, take bookings with a
|
|
13
|
+
// `{ "type": "book", "service": "<its id>" }` block, and show the calendar by setting
|
|
12
14
|
// calendarSettings.embedUrl to the address printed here.
|
|
13
15
|
import { readFileSync, realpathSync } from 'node:fs';
|
|
14
16
|
import { resolve } from 'node:path';
|
|
@@ -22,6 +24,15 @@ const price = (amount, currency = 'gbp') => {
|
|
|
22
24
|
return currency.toLowerCase() === 'gbp' ? `£${text}` : `${text} ${currency.toUpperCase()}`;
|
|
23
25
|
};
|
|
24
26
|
|
|
27
|
+
/** 30 minutes, 1 hour, 1 hour 30 minutes (lib/book lengthText, for a plain .mjs bin). */
|
|
28
|
+
const minutesText = (m) => {
|
|
29
|
+
const h = Math.floor(m / 60);
|
|
30
|
+
const rest = m % 60;
|
|
31
|
+
const hours = h ? `${h} hour${h === 1 ? '' : 's'}` : '';
|
|
32
|
+
const mins = rest ? `${rest} minutes` : '';
|
|
33
|
+
return [hours, mins].filter(Boolean).join(' ');
|
|
34
|
+
};
|
|
35
|
+
|
|
25
36
|
/**
|
|
26
37
|
* True when THIS file is run as a CLI (not imported). Each bin needs its own copy:
|
|
27
38
|
* `import.meta.url` is per file, so one borrowed from another bin only ever matches that
|
|
@@ -68,14 +79,27 @@ export function formatModules(data) {
|
|
|
68
79
|
}
|
|
69
80
|
out.push('');
|
|
70
81
|
|
|
71
|
-
|
|
72
|
-
if (
|
|
82
|
+
// Events and bookings: the offers visitors book online on this site (platform 2026-11-20+).
|
|
83
|
+
if (data.book !== undefined) {
|
|
84
|
+
out.push('Bookings');
|
|
85
|
+
if (!data.book.length) out.push(' Nothing booked online on this site yet (portal: Events and bookings, "Book online").');
|
|
86
|
+
for (const b of data.book) {
|
|
87
|
+
out.push(` ${b.name}: ${minutesText(b.minutes)}`);
|
|
88
|
+
out.push(` place it with: { "type": "book", "service": "${b.id}" }`);
|
|
89
|
+
}
|
|
90
|
+
out.push('');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// `calendar` since the platform renamed the module (2026-11-19); `events` before it.
|
|
94
|
+
const calendar = data.calendar !== undefined ? data.calendar : data.events;
|
|
95
|
+
out.push('Calendar');
|
|
96
|
+
if (!calendar) out.push(' The Calendar module is off for this site.');
|
|
73
97
|
else {
|
|
74
|
-
out.push(` calendarSettings.embedUrl = ${
|
|
98
|
+
out.push(` calendarSettings.embedUrl = ${calendar.embedUrl}`);
|
|
75
99
|
out.push(
|
|
76
|
-
|
|
77
|
-
? ` shows: ${
|
|
78
|
-
: ' No calendars chosen yet. They are connected in the portal (
|
|
100
|
+
calendar.calendars.length
|
|
101
|
+
? ` shows: ${calendar.calendars.map((c) => c.name).join(', ')}`
|
|
102
|
+
: ' No calendars chosen yet. They are connected in the portal (Calendar).',
|
|
79
103
|
);
|
|
80
104
|
}
|
|
81
105
|
return out.join('\n');
|
package/bin/ferst-update.mjs
CHANGED
|
@@ -312,6 +312,28 @@ export function scaffoldFileAfterUpdate(path, upstreamRaw, currentRaw, coreRange
|
|
|
312
312
|
return out;
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
+
/** The site's content folders the first scaffold ignored; routines and sessions commit them. */
|
|
316
|
+
const NO_LONGER_IGNORED = new Set(['public/uploads', 'public/uploads/', 'src/content/posts', 'src/content/posts/']);
|
|
317
|
+
const OLD_IGNORE_COMMENT = ['# Content authored in production by editors via /admin', '# git-proxy straight to the configured branch). Local dev edits must not pollute.'];
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Take `public/uploads/` and `src/content/posts/` (and the comment the first scaffold put above
|
|
321
|
+
* them) out of a site's .gitignore. The file is the site's own (a seed path, copied once), so
|
|
322
|
+
* only those lines go and every other rule stays. Keeps the file's line endings. Pure.
|
|
323
|
+
* @param {string} raw the site's .gitignore
|
|
324
|
+
* @returns {string | null} the new text, or null when there's nothing to change
|
|
325
|
+
*/
|
|
326
|
+
export function unignoreClientContent(raw) {
|
|
327
|
+
if (typeof raw !== 'string') return null;
|
|
328
|
+
const eol = raw.includes('\r\n') ? '\r\n' : '\n';
|
|
329
|
+
const lines = raw.split(/\r?\n/);
|
|
330
|
+
if (!lines.some((l) => NO_LONGER_IGNORED.has(l.trim()))) return null;
|
|
331
|
+
const kept = lines.filter((l) => !NO_LONGER_IGNORED.has(l.trim()) && !OLD_IGNORE_COMMENT.some((c) => l.trim().startsWith(c)));
|
|
332
|
+
// Don't leave a run of blank lines where the block was.
|
|
333
|
+
const tidy = kept.filter((l, i) => !(l.trim() === '' && i > 0 && kept[i - 1].trim() === ''));
|
|
334
|
+
return tidy.join(eol);
|
|
335
|
+
}
|
|
336
|
+
|
|
315
337
|
/** Whether a new drift stamp records a different state than the last (the time alone isn't). */
|
|
316
338
|
export function stampChanged(previous, next) {
|
|
317
339
|
if (!previous || typeof previous !== 'object') return true;
|
|
@@ -454,6 +476,9 @@ function main() {
|
|
|
454
476
|
const lf = (t) => t.replace(/\r\n/g, '\n'); // a checkout's line endings aren't a change
|
|
455
477
|
if (upstreamRaw === null || current === null || lf(scaffoldFileAfterUpdate(f, lf(upstreamRaw), lf(current), range)) !== lf(current)) dryScaffold.push(f);
|
|
456
478
|
}
|
|
479
|
+
try {
|
|
480
|
+
if (unignoreClientContent(readFileSync(resolve(cwd, '.gitignore'), 'utf8')) !== null) dryScaffold.push('.gitignore');
|
|
481
|
+
} catch { /* no .gitignore */ }
|
|
457
482
|
console.log('ferst-update: --dry-run — scaffold changes that WOULD apply:');
|
|
458
483
|
console.log(dryScaffold.length ? dryScaffold.map((f) => ` ${f}`).join('\n') : ' (no scaffold changes)');
|
|
459
484
|
} else {
|
|
@@ -500,6 +525,16 @@ function main() {
|
|
|
500
525
|
}
|
|
501
526
|
}
|
|
502
527
|
templateVersion = upstreamVersion ?? readTemplateVersion(raw);
|
|
528
|
+
// .gitignore is the site's own, but two of the first scaffold's lines stopped routines and
|
|
529
|
+
// sessions committing pictures and posts: take just those out.
|
|
530
|
+
const ignorePath = resolve(cwd, '.gitignore');
|
|
531
|
+
try {
|
|
532
|
+
const unignored = unignoreClientContent(readFileSync(ignorePath, 'utf8'));
|
|
533
|
+
if (unignored !== null) {
|
|
534
|
+
writeFileSync(ignorePath, unignored);
|
|
535
|
+
console.log('ferst-update: .gitignore no longer ignores public/uploads/ or src/content/posts/.');
|
|
536
|
+
}
|
|
537
|
+
} catch { /* no .gitignore */ }
|
|
503
538
|
const status = (tryGit('status --short', cwd) || '').trim();
|
|
504
539
|
scaffoldCount = status ? status.split(/\r?\n/).filter(Boolean).length : 0;
|
|
505
540
|
console.log('ferst-update: scaffold synced. git status --short:');
|
package/cms/config.template.yml
CHANGED
|
@@ -1,232 +1,239 @@
|
|
|
1
|
-
# Sveltia CMS — the content editor for a Ferst site. SINGLE SOURCE: this file lives
|
|
2
|
-
# in ferst-core and is written to dist/admin/config.yml at build by `ferst-cms-config`,
|
|
3
|
-
# so every client's collections are identical and always match the engine. The client
|
|
4
|
-
# repo commits NO config.yml — it is a build product, so it can never drift by hand.
|
|
5
|
-
#
|
|
6
|
-
# The backend repo (owner/name), git-proxy origin, its /git api_root and this
|
|
7
|
-
# deployment's branch are injected at build by ferst-cms-config.
|
|
8
|
-
backend:
|
|
9
|
-
name: github
|
|
10
|
-
repo: __REPO__
|
|
11
|
-
branch: __BRANCH__
|
|
12
|
-
base_url: __BASE_URL__
|
|
13
|
-
auth_endpoint: auth
|
|
14
|
-
api_root: __API_ROOT__
|
|
15
|
-
|
|
16
|
-
media_folder: public/uploads
|
|
17
|
-
public_folder: /uploads
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
- { name:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
- { name:
|
|
59
|
-
- { name:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
- { name:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
- { name:
|
|
136
|
-
- { name:
|
|
137
|
-
- { name:
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
1
|
+
# Sveltia CMS — the content editor for a Ferst site. SINGLE SOURCE: this file lives
|
|
2
|
+
# in ferst-core and is written to dist/admin/config.yml at build by `ferst-cms-config`,
|
|
3
|
+
# so every client's collections are identical and always match the engine. The client
|
|
4
|
+
# repo commits NO config.yml — it is a build product, so it can never drift by hand.
|
|
5
|
+
#
|
|
6
|
+
# The backend repo (owner/name), git-proxy origin, its /git api_root and this
|
|
7
|
+
# deployment's branch are injected at build by ferst-cms-config.
|
|
8
|
+
backend:
|
|
9
|
+
name: github
|
|
10
|
+
repo: __REPO__
|
|
11
|
+
branch: __BRANCH__
|
|
12
|
+
base_url: __BASE_URL__
|
|
13
|
+
auth_endpoint: auth
|
|
14
|
+
api_root: __API_ROOT__
|
|
15
|
+
|
|
16
|
+
media_folder: public/uploads
|
|
17
|
+
public_folder: /uploads
|
|
18
|
+
|
|
19
|
+
# The site's own icon on the sign-in and in the header (the ferst() integration writes it
|
|
20
|
+
# into every build), so editors see their site, not the tools behind it.
|
|
21
|
+
logo_url: /apple-touch-icon.png
|
|
22
|
+
|
|
23
|
+
collections:
|
|
24
|
+
- name: settings
|
|
25
|
+
label: Site settings
|
|
26
|
+
files:
|
|
27
|
+
# No design tokens pane: a site's look is set in the portal, on its Design tab, for every
|
|
28
|
+
# site and branch (myai4-webdev #119). The themeSettings file is the portal's to write.
|
|
29
|
+
- name: identity
|
|
30
|
+
label: Identity & contact
|
|
31
|
+
file: src/content/siteSettings/index.json
|
|
32
|
+
icon: info
|
|
33
|
+
fields:
|
|
34
|
+
- name: identity
|
|
35
|
+
label: Identity
|
|
36
|
+
widget: object
|
|
37
|
+
fields:
|
|
38
|
+
- { name: siteTitle, label: Site title, widget: string }
|
|
39
|
+
- { name: shortName, label: Short name, widget: string }
|
|
40
|
+
- { name: description, label: Description, widget: text }
|
|
41
|
+
- { name: location, label: Location, widget: string, required: false }
|
|
42
|
+
- { name: kind, label: Kind of organisation, widget: select, required: false, default: organisation, options: [{ label: Church, value: church }, { label: School, value: school }, { label: Charity, value: charity }, { label: Business, value: business }, { label: Other organisation, value: organisation }], hint: "Tells search engines what the site is for." }
|
|
43
|
+
- name: contact
|
|
44
|
+
label: Contact
|
|
45
|
+
widget: object
|
|
46
|
+
fields:
|
|
47
|
+
- { name: phoneDisplay, label: Phone (display), widget: string, required: false }
|
|
48
|
+
- { name: phoneTel, label: 'Phone (tel: digits)', widget: string, required: false }
|
|
49
|
+
- { name: email, label: Email, widget: string, required: false }
|
|
50
|
+
- { name: facebookUrl, label: Facebook URL, widget: string, required: false }
|
|
51
|
+
- name: places
|
|
52
|
+
label: Places
|
|
53
|
+
label_singular: Place
|
|
54
|
+
widget: list
|
|
55
|
+
required: false
|
|
56
|
+
hint: "Each place the site is for, with its address (a parish may have several churches). Search engines read these."
|
|
57
|
+
fields:
|
|
58
|
+
- { name: name, label: Name, widget: string }
|
|
59
|
+
- { name: streetAddress, label: Street address, widget: string, required: false }
|
|
60
|
+
- { name: locality, label: Town, widget: string, required: false }
|
|
61
|
+
- { name: postalCode, label: Postcode, widget: string, required: false }
|
|
62
|
+
- { name: country, label: Country code, widget: string, required: false, default: GB }
|
|
63
|
+
- { name: mapUrl, label: Map link, widget: string, required: false }
|
|
64
|
+
- name: verification
|
|
65
|
+
label: Search engine verification
|
|
66
|
+
widget: object
|
|
67
|
+
required: false
|
|
68
|
+
collapsed: true
|
|
69
|
+
hint: "Codes from Google Search Console and Bing Webmaster Tools, when they ask for an HTML tag."
|
|
70
|
+
fields:
|
|
71
|
+
- { name: google, label: Google code, widget: string, required: false }
|
|
72
|
+
- { name: bing, label: Bing code, widget: string, required: false }
|
|
73
|
+
|
|
74
|
+
- name: logos
|
|
75
|
+
label: Logos
|
|
76
|
+
file: src/content/logoSettings/index.json
|
|
77
|
+
icon: image
|
|
78
|
+
fields:
|
|
79
|
+
- { name: primaryLogoLight, label: Header logo (light), widget: image, required: false }
|
|
80
|
+
- { name: primaryLogoDark, label: Header logo (dark), widget: image, required: false }
|
|
81
|
+
- { name: secondaryLogoLight, label: Footer logo (light), widget: image, required: false }
|
|
82
|
+
- { name: secondaryLogoDark, label: Footer logo (dark), widget: image, required: false }
|
|
83
|
+
- { name: favicon, label: Browser icon, widget: image, required: false, hint: "A square image (PNG or SVG), at least 48 x 48. Leave blank to use the header logo if it's square, or the site's initial in its brand colour." }
|
|
84
|
+
|
|
85
|
+
- name: navbar
|
|
86
|
+
label: Navigation
|
|
87
|
+
file: src/content/navbarSettings/index.json
|
|
88
|
+
icon: menu
|
|
89
|
+
fields:
|
|
90
|
+
- name: primary
|
|
91
|
+
label: Primary links
|
|
92
|
+
widget: list
|
|
93
|
+
fields:
|
|
94
|
+
- { name: label, label: Label, widget: string }
|
|
95
|
+
- { name: href, label: Link, widget: string }
|
|
96
|
+
- name: cta
|
|
97
|
+
label: Header button
|
|
98
|
+
widget: object
|
|
99
|
+
required: false
|
|
100
|
+
hint: The button at the right of the header (and in the footer). Leave as Contact → /contact/ unless your contact page lives elsewhere.
|
|
101
|
+
fields:
|
|
102
|
+
- { name: label, label: Label, widget: string, default: Contact }
|
|
103
|
+
- { name: href, label: Link, widget: string, default: /contact/ }
|
|
104
|
+
|
|
105
|
+
- name: footer
|
|
106
|
+
label: Footer
|
|
107
|
+
file: src/content/footerSettings/index.json
|
|
108
|
+
icon: table_rows
|
|
109
|
+
fields:
|
|
110
|
+
- name: footer
|
|
111
|
+
label: Footer links
|
|
112
|
+
widget: list
|
|
113
|
+
fields:
|
|
114
|
+
- { name: label, label: Label, widget: string }
|
|
115
|
+
- { name: href, label: Link, widget: string }
|
|
116
|
+
- name: groups
|
|
117
|
+
label: Footer columns
|
|
118
|
+
widget: list
|
|
119
|
+
required: false
|
|
120
|
+
hint: Headed columns for policies, safeguarding, documents and forms — keep the main menu short.
|
|
121
|
+
fields:
|
|
122
|
+
- { name: heading, label: Heading, widget: string }
|
|
123
|
+
- name: links
|
|
124
|
+
label: Links
|
|
125
|
+
widget: list
|
|
126
|
+
fields:
|
|
127
|
+
- { name: label, label: Label, widget: string }
|
|
128
|
+
- { name: href, label: Link, widget: string }
|
|
129
|
+
|
|
130
|
+
- name: calendar-settings
|
|
131
|
+
label: Calendar
|
|
132
|
+
file: src/content/calendarSettings/index.json
|
|
133
|
+
icon: calendar_today
|
|
134
|
+
fields:
|
|
135
|
+
- { name: title, label: Heading, widget: string, default: Calendar }
|
|
136
|
+
- { name: intro, label: Intro, widget: text, required: false }
|
|
137
|
+
- { name: embedUrl, label: Embed URL, widget: string, required: false }
|
|
138
|
+
- { name: publicUrl, label: Public link, widget: string, required: false }
|
|
139
|
+
- { name: height, label: Height (px), widget: number, default: 700, value_type: int, min: 200, max: 2000 }
|
|
140
|
+
- { name: provider, label: Provider name, widget: string, default: Google Calendar }
|
|
141
|
+
- { name: weekStart, label: Week starts on, widget: select, default: monday, options: [{ label: "Monday", value: monday }, { label: "Sunday", value: sunday }] }
|
|
142
|
+
|
|
143
|
+
- name: posts-settings
|
|
144
|
+
label: News
|
|
145
|
+
file: src/content/postsSettings/index.json
|
|
146
|
+
icon: newspaper
|
|
147
|
+
fields:
|
|
148
|
+
- { name: title, label: Heading, widget: string, default: News }
|
|
149
|
+
- { name: intro, label: Intro, widget: text, required: false }
|
|
150
|
+
- { name: perPage, label: Posts per page, widget: number, default: 12, value_type: int, min: 1, max: 48, hint: "How many posts each news page shows. 12 fills rows of one, two, three or four evenly." }
|
|
151
|
+
- { name: excludeFromIndex, label: Tags kept off the main news page, widget: list, required: false, hint: "Tag names (for example newsletter) whose posts appear only on their own tag page." }
|
|
152
|
+
|
|
153
|
+
- name: posts
|
|
154
|
+
label: Posts
|
|
155
|
+
label_singular: Post
|
|
156
|
+
folder: src/content/posts
|
|
157
|
+
create: true
|
|
158
|
+
slug: "{{slug}}"
|
|
159
|
+
extension: md
|
|
160
|
+
format: frontmatter
|
|
161
|
+
icon: article
|
|
162
|
+
summary: "{{title}} — {{date}}"
|
|
163
|
+
# Newest first: editors look for what they wrote last.
|
|
164
|
+
sortable_fields:
|
|
165
|
+
fields: [date, title]
|
|
166
|
+
default: { field: date, direction: descending }
|
|
167
|
+
fields:
|
|
168
|
+
- { name: title, label: Title, widget: string }
|
|
169
|
+
- { name: date, label: Date, widget: datetime, picker_utc: true }
|
|
170
|
+
- { name: summary, label: Summary, widget: text, required: false }
|
|
171
|
+
- name: tags
|
|
172
|
+
label: Tags
|
|
173
|
+
widget: relation
|
|
174
|
+
required: false
|
|
175
|
+
collection: tags
|
|
176
|
+
value_field: "{{slug}}"
|
|
177
|
+
display_fields: [label]
|
|
178
|
+
search_fields: [label]
|
|
179
|
+
multiple: true
|
|
180
|
+
- { name: heroImage, label: Hero image, widget: image, required: false }
|
|
181
|
+
- { name: heroImageAlt, label: Picture description, widget: string, required: false, hint: "Who or what the picture shows, in a short sentence, for people who can't see it (e.g. Parishioners outside the church after the Easter Vigil). Leave empty if it's only decoration." }
|
|
182
|
+
- { name: attachment, label: Attachment (e.g. PDF), widget: file, required: false }
|
|
183
|
+
- { name: draft, label: Draft, widget: boolean, default: false, required: false }
|
|
184
|
+
- { name: body, label: Body, widget: markdown, required: false }
|
|
185
|
+
|
|
186
|
+
- name: tags
|
|
187
|
+
label: Tags
|
|
188
|
+
label_singular: Tag
|
|
189
|
+
folder: src/content/tags
|
|
190
|
+
create: true
|
|
191
|
+
slug: "{{slug}}"
|
|
192
|
+
extension: json
|
|
193
|
+
format: json
|
|
194
|
+
icon: label
|
|
195
|
+
identifier_field: label
|
|
196
|
+
fields:
|
|
197
|
+
- { name: label, label: Label, widget: string }
|
|
198
|
+
- { name: description, label: Description, widget: text, required: false }
|
|
199
|
+
- { name: hidden, label: Hidden, widget: boolean, default: false, required: false }
|
|
200
|
+
|
|
201
|
+
- name: pages
|
|
202
|
+
label: Pages
|
|
203
|
+
label_singular: Page
|
|
204
|
+
description: "__PAGES_DESCRIPTION__"
|
|
205
|
+
folder: src/content/pages
|
|
206
|
+
extension: json
|
|
207
|
+
format: json
|
|
208
|
+
icon: description
|
|
209
|
+
# Pages are added, published and made drafts on the portal's Pages tab, within the site's
|
|
210
|
+
# plan (myai4-webdev #119): the CMS shows each page, for its people to request changes.
|
|
211
|
+
create: false
|
|
212
|
+
delete: false
|
|
213
|
+
nested: { depth: 3, summary: "{{title}}" }
|
|
214
|
+
summary: "{{title}}"
|
|
215
|
+
identifier_field: title
|
|
216
|
+
fields:
|
|
217
|
+
- { name: title, label: Page title, widget: string }
|
|
218
|
+
# ferst:requests (the Basic plan only: bin/cms-config.mjs leaves it out on the free plan)
|
|
219
|
+
- name: requests
|
|
220
|
+
label: Requested changes
|
|
221
|
+
label_singular: Request
|
|
222
|
+
widget: list
|
|
223
|
+
required: false
|
|
224
|
+
summary: "{{fields.text}}"
|
|
225
|
+
fields:
|
|
226
|
+
- { name: text, label: "What would you like changed?", widget: text }
|
|
227
|
+
- { name: status, label: Status, widget: select, default: open, options: [{ label: Open, value: open }, { label: Done, value: done }] }
|
|
228
|
+
# Stamped by the platform when the request is raised with the team (who, when, the
|
|
229
|
+
# tracking number). Hidden, but kept on every save so a request is raised only once.
|
|
230
|
+
- { name: issue, widget: hidden, required: false }
|
|
231
|
+
- { name: by, widget: hidden, required: false }
|
|
232
|
+
- { name: at, widget: hidden, required: false }
|
|
233
|
+
# /ferst:requests
|
|
234
|
+
- { name: description, label: SEO description, widget: hidden, required: false }
|
|
235
|
+
- { name: heroImage, widget: hidden, required: false }
|
|
236
|
+
- { name: align, widget: hidden, required: false }
|
|
237
|
+
- { name: templateId, widget: hidden, required: false }
|
|
238
|
+
- { name: draft, widget: hidden, required: false }
|
|
239
|
+
- { name: blocks, widget: hidden }
|
|
@@ -28,6 +28,7 @@ import Testimonial from './recipes/Testimonial.astro';
|
|
|
28
28
|
import ContactForm from './recipes/ContactForm.astro';
|
|
29
29
|
import Form from './recipes/Form.astro';
|
|
30
30
|
import Pay from './recipes/Pay.astro';
|
|
31
|
+
import Book from './recipes/Book.astro';
|
|
31
32
|
import Accordion from './recipes/Accordion.astro';
|
|
32
33
|
import Tiles from './recipes/Tiles.astro';
|
|
33
34
|
import Banner from './recipes/Banner.astro';
|
|
@@ -83,6 +84,7 @@ const registry: Record<BlockType, any> = {
|
|
|
83
84
|
contactForm: ContactForm,
|
|
84
85
|
form: Form,
|
|
85
86
|
pay: Pay,
|
|
87
|
+
book: Book,
|
|
86
88
|
accordion: Accordion,
|
|
87
89
|
tiles: Tiles,
|
|
88
90
|
banner: Banner,
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Book — visitors book a time for one of the organisation's offers, from the Ferst Events and
|
|
4
|
+
* bookings module ("Haircut", 30 minutes, with Sam or Alex). The offer's name, length and who gives
|
|
5
|
+
* it are read from the platform at build time (lib/book); its free times are read in the browser,
|
|
6
|
+
* a fortnight at a time, since they change by the minute.
|
|
7
|
+
*
|
|
8
|
+
* Three steps, all on the platform's say: pick a day and a time (the platform holds it for the
|
|
9
|
+
* visitor at once, for 10 minutes, so nobody else can take it), give a name and email (and a phone
|
|
10
|
+
* number or a note if they like), then book. The platform emails them the booking with an
|
|
11
|
+
* invitation for their calendar. "Choose another time" lets the held time go.
|
|
12
|
+
*
|
|
13
|
+
* Needs JavaScript: choosing among live times can't be a plain form. Without it, the block says so.
|
|
14
|
+
*/
|
|
15
|
+
import ContactForm from './ContactForm.astro';
|
|
16
|
+
import Heading from '../blocks/Heading.astro';
|
|
17
|
+
import { lengthText, loadBookService } from '../../lib/book';
|
|
18
|
+
import { resolveGitBase, resolveSiteId } from '../../lib/git-base.mjs';
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
service: string;
|
|
22
|
+
title?: string;
|
|
23
|
+
intro?: string;
|
|
24
|
+
note?: string;
|
|
25
|
+
buttonLabel?: string;
|
|
26
|
+
}
|
|
27
|
+
const { service, title, intro, note, buttonLabel = 'Book' } = Astro.props;
|
|
28
|
+
const def = await loadBookService(service, { base: resolveGitBase(), siteId: resolveSiteId() });
|
|
29
|
+
const anchor = `book-${def.id}`;
|
|
30
|
+
const who = def.resources.map((r) => r.name);
|
|
31
|
+
const withWhom = who.length === 0 ? '' : who.length === 1 ? `with ${who[0]}` : `with ${who.slice(0, -1).join(', ')} or ${who[who.length - 1]}`;
|
|
32
|
+
const { align: blockAlign, headingAlign } = Astro.props as { align?: 'start' | 'center' | 'end'; headingAlign?: 'start' | 'center' | 'end' };
|
|
33
|
+
const headAlign = headingAlign ?? blockAlign ?? 'center';
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
<section class="b-book" id={anchor} data-book={def.definition} data-holds={def.holds} data-name={def.name} data-label={buttonLabel}>
|
|
37
|
+
<div class="b-book__head" data-recipe-head data-content-align={headAlign}>
|
|
38
|
+
<Heading text={title ?? def.name} level={2} />
|
|
39
|
+
<p class="b-book__meta">{lengthText(def.minutes)}{withWhom && ` · ${withWhom}`}</p>
|
|
40
|
+
{(intro ?? def.description) && <p class="b-book__intro">{intro ?? def.description}</p>}
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<noscript><p class="b-book__notice">Booking a time needs JavaScript switched on in your browser.</p></noscript>
|
|
44
|
+
<div class="b-book__notice" role="alert" data-book-error hidden></div>
|
|
45
|
+
|
|
46
|
+
<!-- Step 1: a day, then a time -->
|
|
47
|
+
<div class="b-book__pick" data-book-pick hidden>
|
|
48
|
+
{def.resources.length > 1 && (
|
|
49
|
+
<label class="b-book__who">
|
|
50
|
+
<span>Who with</span>
|
|
51
|
+
<select data-book-who>
|
|
52
|
+
<option value="">Anyone available</option>
|
|
53
|
+
{def.resources.map((r) => <option value={r.id}>{r.name}</option>)}
|
|
54
|
+
</select>
|
|
55
|
+
</label>
|
|
56
|
+
)}
|
|
57
|
+
<div class="b-book__days-bar">
|
|
58
|
+
<button type="button" class="b-book__nav" data-book-earlier aria-label="Earlier dates" disabled>‹</button>
|
|
59
|
+
<div class="b-book__days" role="group" aria-label="Choose a day" data-book-days></div>
|
|
60
|
+
<button type="button" class="b-book__nav" data-book-later aria-label="Later dates">›</button>
|
|
61
|
+
</div>
|
|
62
|
+
<div class="b-book__times" role="group" aria-label="Choose a time" data-book-times aria-live="polite">
|
|
63
|
+
<p class="b-book__empty">Loading free times…</p>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<!-- Step 2: who they are -->
|
|
68
|
+
<div class="b-book__details" data-book-details hidden>
|
|
69
|
+
<p class="b-book__held" data-book-held></p>
|
|
70
|
+
<ContactForm
|
|
71
|
+
action={def.holds}
|
|
72
|
+
method="post"
|
|
73
|
+
submitLabel={buttonLabel}
|
|
74
|
+
note={note ?? 'We’ll email you the booking, with an invitation for your calendar.'}
|
|
75
|
+
fields={[
|
|
76
|
+
{ name: 'name', label: 'Your name', type: 'text', required: true },
|
|
77
|
+
{ name: 'email', label: 'Your email', type: 'email', required: true },
|
|
78
|
+
{ name: 'phone', label: 'Your phone (optional)', type: 'tel' },
|
|
79
|
+
{ name: 'notes', label: 'Anything we should know? (optional)', type: 'textarea' },
|
|
80
|
+
]}
|
|
81
|
+
honeypot
|
|
82
|
+
idPrefix={anchor}
|
|
83
|
+
/>
|
|
84
|
+
<button type="button" class="b-book__link" data-book-again>Choose another time</button>
|
|
85
|
+
</div>
|
|
86
|
+
|
|
87
|
+
<!-- Step 3: booked -->
|
|
88
|
+
<div class="b-book__notice b-book__notice--done" role="status" data-book-done hidden></div>
|
|
89
|
+
</section>
|
|
90
|
+
|
|
91
|
+
<script>
|
|
92
|
+
import { addDays, bookingMessage, dayChip, londonDay, whenText, type TimesAnswer } from '../../lib/book';
|
|
93
|
+
|
|
94
|
+
const SPAN = 14; // days shown at once
|
|
95
|
+
const AHEAD = 60; // how far ahead the platform takes bookings
|
|
96
|
+
|
|
97
|
+
function setUp(block: HTMLElement) {
|
|
98
|
+
const src = block.dataset.book!;
|
|
99
|
+
const holds = block.dataset.holds!;
|
|
100
|
+
const $ = <T extends HTMLElement>(sel: string) => block.querySelector<T>(sel)!;
|
|
101
|
+
const pick = $('[data-book-pick]');
|
|
102
|
+
const details = $('[data-book-details]');
|
|
103
|
+
const done = $('[data-book-done]');
|
|
104
|
+
const error = $('[data-book-error]');
|
|
105
|
+
const daysEl = $('[data-book-days]');
|
|
106
|
+
const timesEl = $('[data-book-times]');
|
|
107
|
+
const earlier = $<HTMLButtonElement>('[data-book-earlier]');
|
|
108
|
+
const later = $<HTMLButtonElement>('[data-book-later]');
|
|
109
|
+
const who = block.querySelector<HTMLSelectElement>('[data-book-who]');
|
|
110
|
+
const form = details.querySelector<HTMLFormElement>('form')!;
|
|
111
|
+
const submit = form.querySelector<HTMLButtonElement>('button[type="submit"]');
|
|
112
|
+
|
|
113
|
+
const today = londonDay();
|
|
114
|
+
let from = today;
|
|
115
|
+
let answer: TimesAnswer | null = null;
|
|
116
|
+
let day: string | null = null;
|
|
117
|
+
let hold: { id: string; start: string; resource: { name: string } } | null = null;
|
|
118
|
+
|
|
119
|
+
const say = (text: string | null) => { error.textContent = text ?? ''; error.hidden = !text; };
|
|
120
|
+
const show = (step: 'pick' | 'details' | 'done') => { pick.hidden = step !== 'pick'; details.hidden = step !== 'details'; done.hidden = step !== 'done'; };
|
|
121
|
+
const free = (d: string) => (answer?.days.find((x) => x.day === d)?.times ?? []).filter((t) => !who?.value || t.resources.includes(who.value));
|
|
122
|
+
|
|
123
|
+
function drawDays() {
|
|
124
|
+
daysEl.replaceChildren(...(answer?.days ?? []).map((d) => {
|
|
125
|
+
const chip = dayChip(d.day);
|
|
126
|
+
const b = document.createElement('button');
|
|
127
|
+
b.type = 'button';
|
|
128
|
+
b.className = 'b-book__day';
|
|
129
|
+
b.disabled = free(d.day).length === 0;
|
|
130
|
+
b.setAttribute('aria-pressed', String(d.day === day));
|
|
131
|
+
b.innerHTML = `<span>${chip.weekday}</span><strong>${chip.date}</strong>`;
|
|
132
|
+
b.setAttribute('aria-label', `${chip.weekday} ${chip.date}${b.disabled ? ', nothing free' : ''}`);
|
|
133
|
+
b.addEventListener('click', () => { day = d.day; drawDays(); drawTimes(); });
|
|
134
|
+
return b;
|
|
135
|
+
}));
|
|
136
|
+
earlier.disabled = from <= today;
|
|
137
|
+
later.disabled = addDays(from, SPAN) > addDays(today, AHEAD);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function drawTimes() {
|
|
141
|
+
const times = day ? free(day) : [];
|
|
142
|
+
if (!day) { timesEl.innerHTML = `<p class="b-book__empty">${answer?.days.some((d) => free(d.day).length) ? 'Choose a day.' : 'Nothing free in these dates. Try later dates.'}</p>`; return; }
|
|
143
|
+
if (!times.length) { timesEl.innerHTML = '<p class="b-book__empty">Nothing free that day.</p>'; return; }
|
|
144
|
+
timesEl.replaceChildren(...times.map((t) => {
|
|
145
|
+
const b = document.createElement('button');
|
|
146
|
+
b.type = 'button';
|
|
147
|
+
b.className = 'b-book__time';
|
|
148
|
+
b.textContent = t.time;
|
|
149
|
+
b.addEventListener('click', () => void take(t.start));
|
|
150
|
+
return b;
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function load() {
|
|
155
|
+
say(null);
|
|
156
|
+
timesEl.innerHTML = '<p class="b-book__empty">Loading free times…</p>';
|
|
157
|
+
try {
|
|
158
|
+
const res = await fetch(`${src}?from=${from}&to=${addDays(from, SPAN)}`, { headers: { Accept: 'application/json' } });
|
|
159
|
+
if (!res.ok) { const b = await res.json().catch(() => ({})); throw new Error(b.error ?? String(res.status)); }
|
|
160
|
+
answer = (await res.json()) as TimesAnswer;
|
|
161
|
+
day = answer.days.find((d) => free(d.day).length)?.day ?? null;
|
|
162
|
+
drawDays(); drawTimes();
|
|
163
|
+
} catch (e) {
|
|
164
|
+
timesEl.innerHTML = '';
|
|
165
|
+
say(bookingMessage(e instanceof Error ? e.message : ''));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function take(start: string) {
|
|
170
|
+
say(null);
|
|
171
|
+
const res = await fetch(`${src}/hold`, {
|
|
172
|
+
method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
173
|
+
body: JSON.stringify({ start, ...(who?.value ? { resource_id: who.value } : {}) }),
|
|
174
|
+
}).catch(() => null);
|
|
175
|
+
const body = res ? await res.json().catch(() => ({})) : {};
|
|
176
|
+
if (!res || res.status !== 201) { say(bookingMessage(body.error ?? '')); await load(); return; }
|
|
177
|
+
hold = body.hold;
|
|
178
|
+
$('[data-book-held]').textContent = `${whenText(hold!.start)}, with ${hold!.resource.name}. We’re keeping this time for you for 10 minutes while you give your details.`;
|
|
179
|
+
show('details');
|
|
180
|
+
form.querySelector<HTMLInputElement>('input[name="name"]')?.focus();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
form.addEventListener('submit', async (ev) => {
|
|
184
|
+
ev.preventDefault();
|
|
185
|
+
if (!hold) return;
|
|
186
|
+
say(null);
|
|
187
|
+
const data = Object.fromEntries(new FormData(form).entries());
|
|
188
|
+
if (submit) submit.disabled = true;
|
|
189
|
+
const res = await fetch(`${holds}/${hold.id}`, {
|
|
190
|
+
method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, body: JSON.stringify(data),
|
|
191
|
+
}).catch(() => null);
|
|
192
|
+
if (submit) submit.disabled = false;
|
|
193
|
+
const body = res ? await res.json().catch(() => ({})) : {};
|
|
194
|
+
if (!res || !res.ok) {
|
|
195
|
+
say(bookingMessage(body.error ?? ''));
|
|
196
|
+
if (body.error === 'hold_expired' || body.error === 'already_booked') { hold = null; show('pick'); await load(); }
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
done.innerHTML = '';
|
|
200
|
+
const strong = document.createElement('strong');
|
|
201
|
+
strong.textContent = `Booked: ${block.dataset.name}, ${whenText(body.booking.start)}, with ${body.booking.resource}.`;
|
|
202
|
+
done.append(strong, ' We’ve emailed you the booking.');
|
|
203
|
+
hold = null;
|
|
204
|
+
show('done');
|
|
205
|
+
done.focus();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
$('[data-book-again]').addEventListener('click', async () => {
|
|
209
|
+
if (hold) await fetch(`${holds}/${hold.id}`, { method: 'DELETE' }).catch(() => null);
|
|
210
|
+
hold = null;
|
|
211
|
+
show('pick');
|
|
212
|
+
await load();
|
|
213
|
+
});
|
|
214
|
+
earlier.addEventListener('click', () => { from = addDays(from, -SPAN) < today ? today : addDays(from, -SPAN); void load(); });
|
|
215
|
+
later.addEventListener('click', () => { from = addDays(from, SPAN); void load(); });
|
|
216
|
+
who?.addEventListener('change', () => { day = answer?.days.find((d) => free(d.day).length)?.day ?? null; drawDays(); drawTimes(); });
|
|
217
|
+
done.tabIndex = -1;
|
|
218
|
+
|
|
219
|
+
show('pick');
|
|
220
|
+
void load();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
document.querySelectorAll<HTMLElement>('[data-book]').forEach(setUp);
|
|
224
|
+
</script>
|
|
225
|
+
|
|
226
|
+
<style>
|
|
227
|
+
.b-book {
|
|
228
|
+
display: flex;
|
|
229
|
+
flex-direction: column;
|
|
230
|
+
gap: 1.25rem;
|
|
231
|
+
max-width: 40rem;
|
|
232
|
+
margin-inline: auto;
|
|
233
|
+
padding-inline: 1rem;
|
|
234
|
+
}
|
|
235
|
+
.b-book :global(.b-contact-form) {
|
|
236
|
+
padding-inline: 0;
|
|
237
|
+
}
|
|
238
|
+
.b-book__head {
|
|
239
|
+
display: flex;
|
|
240
|
+
flex-direction: column;
|
|
241
|
+
gap: 0.5rem;
|
|
242
|
+
}
|
|
243
|
+
.b-book__meta {
|
|
244
|
+
margin: 0;
|
|
245
|
+
color: var(--muted);
|
|
246
|
+
font-weight: 600;
|
|
247
|
+
}
|
|
248
|
+
.b-book__intro {
|
|
249
|
+
margin: 0;
|
|
250
|
+
color: var(--muted);
|
|
251
|
+
line-height: 1.6;
|
|
252
|
+
}
|
|
253
|
+
.b-book__pick,
|
|
254
|
+
.b-book__details {
|
|
255
|
+
display: flex;
|
|
256
|
+
flex-direction: column;
|
|
257
|
+
gap: 1rem;
|
|
258
|
+
}
|
|
259
|
+
.b-book__who {
|
|
260
|
+
display: flex;
|
|
261
|
+
flex-direction: column;
|
|
262
|
+
gap: 0.4rem;
|
|
263
|
+
font-weight: 600;
|
|
264
|
+
color: var(--fg);
|
|
265
|
+
}
|
|
266
|
+
.b-book__who select {
|
|
267
|
+
font: inherit;
|
|
268
|
+
font-weight: 400;
|
|
269
|
+
color: var(--fg);
|
|
270
|
+
background: var(--field-bg, var(--bg-surface));
|
|
271
|
+
border: var(--field-border, 1px solid var(--border));
|
|
272
|
+
border-radius: var(--field-radius, var(--radius-sm));
|
|
273
|
+
padding: 0.6rem 0.75rem;
|
|
274
|
+
max-width: 20rem;
|
|
275
|
+
}
|
|
276
|
+
.b-book__days-bar {
|
|
277
|
+
display: flex;
|
|
278
|
+
align-items: center;
|
|
279
|
+
gap: 0.5rem;
|
|
280
|
+
}
|
|
281
|
+
.b-book__days {
|
|
282
|
+
display: flex;
|
|
283
|
+
gap: 0.5rem;
|
|
284
|
+
overflow-x: auto;
|
|
285
|
+
flex: 1;
|
|
286
|
+
padding-block: 0.25rem;
|
|
287
|
+
scrollbar-width: thin;
|
|
288
|
+
}
|
|
289
|
+
.b-book__day,
|
|
290
|
+
.b-book__time,
|
|
291
|
+
.b-book__nav {
|
|
292
|
+
font: inherit;
|
|
293
|
+
color: var(--fg);
|
|
294
|
+
background: var(--bg-surface);
|
|
295
|
+
border: 1px solid var(--border);
|
|
296
|
+
border-radius: var(--radius-sm);
|
|
297
|
+
cursor: pointer;
|
|
298
|
+
transition: border-color 0.15s ease, background 0.15s ease;
|
|
299
|
+
}
|
|
300
|
+
.b-book__day {
|
|
301
|
+
display: flex;
|
|
302
|
+
flex-direction: column;
|
|
303
|
+
align-items: center;
|
|
304
|
+
min-width: 4.25rem;
|
|
305
|
+
padding: 0.5rem 0.4rem;
|
|
306
|
+
font-size: 0.85rem;
|
|
307
|
+
line-height: 1.3;
|
|
308
|
+
}
|
|
309
|
+
.b-book__day strong {
|
|
310
|
+
font-size: 0.95rem;
|
|
311
|
+
}
|
|
312
|
+
.b-book__nav {
|
|
313
|
+
padding: 0.6rem 0.8rem;
|
|
314
|
+
font-size: 1.1rem;
|
|
315
|
+
}
|
|
316
|
+
.b-book__day[aria-pressed='true'] {
|
|
317
|
+
border-color: var(--gold);
|
|
318
|
+
background: var(--gold-light);
|
|
319
|
+
}
|
|
320
|
+
.b-book__day:disabled,
|
|
321
|
+
.b-book__nav:disabled {
|
|
322
|
+
opacity: 0.4;
|
|
323
|
+
cursor: default;
|
|
324
|
+
}
|
|
325
|
+
.b-book__day:not(:disabled):hover,
|
|
326
|
+
.b-book__time:hover,
|
|
327
|
+
.b-book__nav:not(:disabled):hover {
|
|
328
|
+
border-color: var(--gold);
|
|
329
|
+
}
|
|
330
|
+
.b-book__day:focus-visible,
|
|
331
|
+
.b-book__time:focus-visible,
|
|
332
|
+
.b-book__nav:focus-visible,
|
|
333
|
+
.b-book__link:focus-visible {
|
|
334
|
+
outline: 2px solid var(--gold);
|
|
335
|
+
outline-offset: 2px;
|
|
336
|
+
}
|
|
337
|
+
.b-book__times {
|
|
338
|
+
display: grid;
|
|
339
|
+
grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr));
|
|
340
|
+
gap: 0.5rem;
|
|
341
|
+
}
|
|
342
|
+
.b-book__time {
|
|
343
|
+
padding: 0.6rem 0.5rem;
|
|
344
|
+
font-variant-numeric: tabular-nums;
|
|
345
|
+
font-weight: 600;
|
|
346
|
+
}
|
|
347
|
+
.b-book__empty {
|
|
348
|
+
grid-column: 1 / -1;
|
|
349
|
+
margin: 0;
|
|
350
|
+
color: var(--muted);
|
|
351
|
+
}
|
|
352
|
+
.b-book__held {
|
|
353
|
+
margin: 0;
|
|
354
|
+
padding: 0.85rem 1rem;
|
|
355
|
+
border-radius: var(--radius-sm);
|
|
356
|
+
background: var(--bg-section);
|
|
357
|
+
line-height: 1.5;
|
|
358
|
+
}
|
|
359
|
+
.b-book__link {
|
|
360
|
+
align-self: flex-start;
|
|
361
|
+
padding: 0;
|
|
362
|
+
border: 0;
|
|
363
|
+
background: none;
|
|
364
|
+
color: var(--fg);
|
|
365
|
+
font: inherit;
|
|
366
|
+
text-decoration: underline;
|
|
367
|
+
cursor: pointer;
|
|
368
|
+
}
|
|
369
|
+
.b-book__notice {
|
|
370
|
+
padding: 0.85rem 1rem;
|
|
371
|
+
border: 1px solid var(--border);
|
|
372
|
+
border-radius: var(--radius-sm);
|
|
373
|
+
background: var(--bg-section);
|
|
374
|
+
color: var(--fg);
|
|
375
|
+
line-height: 1.5;
|
|
376
|
+
}
|
|
377
|
+
.b-book__notice--done {
|
|
378
|
+
border-color: var(--gold);
|
|
379
|
+
background: var(--gold-light);
|
|
380
|
+
}
|
|
381
|
+
.b-book__notice[hidden],
|
|
382
|
+
.b-book__pick[hidden],
|
|
383
|
+
.b-book__details[hidden] {
|
|
384
|
+
display: none;
|
|
385
|
+
}
|
|
386
|
+
</style>
|
package/content/blocks.ts
CHANGED
|
@@ -261,6 +261,25 @@ export const payBlock = z.object({
|
|
|
261
261
|
buttonLabel: z.string().max(40).optional(),
|
|
262
262
|
});
|
|
263
263
|
|
|
264
|
+
/** Visitors book a time for one of the organisation's offers, from the Ferst Events and bookings
|
|
265
|
+
* module ("Haircut", 30 minutes). The block names the offer; its name, length, who gives it and
|
|
266
|
+
* its free times are the organisation's, read from the platform (lib/book), never written here.
|
|
267
|
+
* A picked time is held for the visitor while they give their details, then booked; the visitor
|
|
268
|
+
* is emailed. List what a site takes bookings for with `npx ferst-modules`. */
|
|
269
|
+
export const bookBlock = z.object({
|
|
270
|
+
type: z.literal('book'),
|
|
271
|
+
enabled: z.boolean().default(true),
|
|
272
|
+
/** The offer's id in the portal (e.g. `evs_8c1d…`). */
|
|
273
|
+
service: z.string().min(1),
|
|
274
|
+
/** Defaults to the offer's name. */
|
|
275
|
+
title: z.string().optional(),
|
|
276
|
+
intro: z.string().optional(),
|
|
277
|
+
/** Small print under the form (e.g. how to cancel). */
|
|
278
|
+
note: z.string().optional(),
|
|
279
|
+
/** The button's words ("Book"). */
|
|
280
|
+
buttonLabel: z.string().max(40).optional(),
|
|
281
|
+
});
|
|
282
|
+
|
|
264
283
|
/** A contact form recipe. `fields` is generic (any labelled input list) so the
|
|
265
284
|
* same recipe serves a contact page, an enquiry form, a sign-up, etc. `action`
|
|
266
285
|
* is optional: the core ships no backend, so with none it renders a standard
|
|
@@ -747,6 +766,7 @@ export type RecipeBlock =
|
|
|
747
766
|
| z.infer<typeof contactFormBlock>
|
|
748
767
|
| z.infer<typeof formBlock>
|
|
749
768
|
| z.infer<typeof payBlock>
|
|
769
|
+
| z.infer<typeof bookBlock>
|
|
750
770
|
| z.infer<typeof accordionBlock>
|
|
751
771
|
| z.infer<typeof tilesBlock>
|
|
752
772
|
| z.infer<typeof bannerBlock>
|
|
@@ -891,6 +911,7 @@ export const blockSchema = z.discriminatedUnion(
|
|
|
891
911
|
contactFormBlock,
|
|
892
912
|
formBlock,
|
|
893
913
|
payBlock,
|
|
914
|
+
bookBlock,
|
|
894
915
|
accordionBlock,
|
|
895
916
|
tilesBlock,
|
|
896
917
|
bannerBlock,
|
|
@@ -981,7 +1002,7 @@ export const blockTypes = (
|
|
|
981
1002
|
blockSchema as unknown as { options: ReadonlyArray<{ shape: { type: { value: BlockType } } }> }
|
|
982
1003
|
).options.map((o) => o.shape.type.value);
|
|
983
1004
|
|
|
984
|
-
/** Blocks whose content comes from the Ferst platform at build time (a form, an item to pay for).
|
|
1005
|
+
/** Blocks whose content comes from the Ferst platform at build time (a form, an item to pay for, an offer to book).
|
|
985
1006
|
* The public showcase can't render them without the platform, so its galleries show the
|
|
986
1007
|
* look through their local twin instead (`form` renders with the contactForm recipe). */
|
|
987
|
-
export const platformBlockTypes: readonly BlockType[] = ['form', 'pay'];
|
|
1008
|
+
export const platformBlockTypes: readonly BlockType[] = ['form', 'pay', 'book'];
|
|
@@ -30,6 +30,7 @@ const QUESTIONS: Record<string, RecipeQuestion | null> = {
|
|
|
30
30
|
contactForm: ask('Contact form', 'What should people be able to ask you through this form?', 'Who answers, what you need to know from them, and how soon they can expect a reply.'),
|
|
31
31
|
form: note('Form', 'This shows one of your organisation’s forms. Choose or create it in the portal under Forms.'),
|
|
32
32
|
pay: note('Payment', 'This takes a payment for one of the things your sites take payment for. Set what it’s for and its price in the portal, under Payments.'),
|
|
33
|
+
book: note('Booking', 'This lets visitors book a time for one of your offers. Set the offer, who gives it and their opening hours in the portal, under Events and bookings.'),
|
|
33
34
|
accordion: ask('Expandable sections', 'What information should people be able to open up and read here?', 'Give each topic a short heading and the detail that goes under it.'),
|
|
34
35
|
tiles: ask('Quick links', 'Where do visitors most often want to go from here?', 'List the places or tasks, a few words each, for example: opening times, book now, prices.'),
|
|
35
36
|
banner: ask('Banner', 'What message deserves a bold band across the page?', 'A short statement or invitation, and where it should lead if anywhere.'),
|
package/lib/book.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A "Book" block lets visitors book a time for one of the organisation's offers (the Ferst Events
|
|
3
|
+
* and bookings module). The block names the offer; its name, length and who gives it are the
|
|
4
|
+
* organisation's, read from the platform at build time, and its free times are read in the browser
|
|
5
|
+
* (they change by the minute). A picked time is held by the platform for the visitor while they
|
|
6
|
+
* give their details; the page never decides what's free.
|
|
7
|
+
*
|
|
8
|
+
* A booking is always the site's own, so the site must say who it is (`siteId` in
|
|
9
|
+
* ferst-site.json). An offer that isn't booked online, or a platform that can't be reached, fails
|
|
10
|
+
* the build: better the last good deploy stays live than a Book button that can't book.
|
|
11
|
+
*/
|
|
12
|
+
export interface BookService {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
minutes: number;
|
|
17
|
+
/** Who or what gives it (a visitor may choose, or take anyone available). */
|
|
18
|
+
resources: Array<{ id: string; name: string }>;
|
|
19
|
+
/** Where the browser reads free times (`?from&to`) and holds a time (`/hold`). */
|
|
20
|
+
definition: string;
|
|
21
|
+
/** Where the browser books a held time (`/:hold`) or lets it go. */
|
|
22
|
+
holds: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type FetchFn = (input: string, init?: RequestInit) => Promise<Response>;
|
|
26
|
+
|
|
27
|
+
/** Today's date in London ('YYYY-MM-DD'). */
|
|
28
|
+
export const londonDay = (d = new Date()): string => d.toLocaleDateString('en-CA', { timeZone: 'Europe/London' });
|
|
29
|
+
/** A date some days on ('YYYY-MM-DD'). */
|
|
30
|
+
export function addDays(day: string, n: number): string {
|
|
31
|
+
const [y, m, d] = day.split('-').map(Number);
|
|
32
|
+
return new Date(Date.UTC(y, m - 1, d + n)).toISOString().slice(0, 10);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 30 minutes, 1 hour, 1 hour 30 minutes. */
|
|
36
|
+
export function lengthText(minutes: number): string {
|
|
37
|
+
const h = Math.floor(minutes / 60);
|
|
38
|
+
const rest = minutes % 60;
|
|
39
|
+
return [h ? `${h} hour${h === 1 ? '' : 's'}` : '', rest ? `${rest} minutes` : ''].filter(Boolean).join(' ');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
43
|
+
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
44
|
+
const WEEKDAYS_LONG = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
45
|
+
const MONTHS_LONG = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
46
|
+
|
|
47
|
+
/** A day, short enough for a row of days: { weekday: 'Mon', date: '4 Jan' }. */
|
|
48
|
+
export function dayChip(day: string): { weekday: string; date: string } {
|
|
49
|
+
const [y, m, d] = day.split('-').map(Number);
|
|
50
|
+
return { weekday: WEEKDAYS[new Date(Date.UTC(y, m - 1, d)).getUTCDay()], date: `${d} ${MONTHS[m - 1]}` };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 'Monday 4 January at 10:00', from a London time ('YYYY-MM-DDTHH:MM'). */
|
|
54
|
+
export function whenText(local: string): string {
|
|
55
|
+
const [y, m, d] = local.slice(0, 10).split('-').map(Number);
|
|
56
|
+
return `${WEEKDAYS_LONG[new Date(Date.UTC(y, m - 1, d)).getUTCDay()]} ${d} ${MONTHS_LONG[m - 1]} at ${local.slice(11, 16)}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** What to tell the visitor when the platform says no. */
|
|
60
|
+
export function bookingMessage(code: string): string {
|
|
61
|
+
switch (code) {
|
|
62
|
+
case 'time_taken': return 'That time has just been taken. Please choose another.';
|
|
63
|
+
case 'hold_expired': return 'We kept that time for 10 minutes and it has gone. Please choose a time again.';
|
|
64
|
+
case 'too_many_holds': return 'You’re already holding a few times. Book one, or let one go, first.';
|
|
65
|
+
case 'rate_limited': return 'Too many tries in a short time. Please wait a minute and try again.';
|
|
66
|
+
case 'name_required': return 'Please give your name.';
|
|
67
|
+
case 'invalid_email': return 'Please give an email address we can send your booking to.';
|
|
68
|
+
case 'bookings_not_open': return 'This website isn’t taking bookings just now.';
|
|
69
|
+
default: return 'The booking couldn’t be made just now. Please try again.';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The platform's answer for an offer's free times, as the block reads it. */
|
|
74
|
+
export interface TimesAnswer {
|
|
75
|
+
service: { id: string; name: string; description?: string; minutes: number };
|
|
76
|
+
resources: Array<{ id: string; name: string }>;
|
|
77
|
+
days: Array<{ day: string; times: Array<{ time: string; start: string; resources: string[] }> }>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const cache = new Map<string, Promise<BookService>>();
|
|
81
|
+
|
|
82
|
+
export function loadBookService(service: string, opts: { base: string; siteId?: string | null; fetch?: FetchFn; now?: Date }): Promise<BookService> {
|
|
83
|
+
const key = `${opts.base}|${opts.siteId ?? ''}|${service}`;
|
|
84
|
+
let hit = cache.get(key);
|
|
85
|
+
if (!hit) {
|
|
86
|
+
hit = fetchService(service, opts.base, opts.siteId ?? null, opts.fetch ?? fetch, opts.now ?? new Date());
|
|
87
|
+
cache.set(key, hit);
|
|
88
|
+
hit.catch(() => cache.delete(key)); // a failure is retried by the next caller
|
|
89
|
+
}
|
|
90
|
+
return hit;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function fetchService(service: string, base: string, siteId: string | null, fetchFn: FetchFn, now: Date): Promise<BookService> {
|
|
94
|
+
if (!siteId) {
|
|
95
|
+
throw new Error(`Book block: this site doesn't say who it is, so it can't take bookings. Add "siteId" to ferst-site.json (or set FERST_SITE_ID).`);
|
|
96
|
+
}
|
|
97
|
+
const definition = `${base}/sites/${encodeURIComponent(siteId)}/book/${encodeURIComponent(service)}`;
|
|
98
|
+
const today = londonDay(now);
|
|
99
|
+
const url = `${definition}?from=${today}&to=${addDays(today, 1)}`;
|
|
100
|
+
let res: Response;
|
|
101
|
+
try {
|
|
102
|
+
res = await fetchFn(url, { headers: { Accept: 'application/json' } });
|
|
103
|
+
} catch (e) {
|
|
104
|
+
throw new Error(`Book block: couldn’t reach the Ferst platform for offer "${service}" (${url}): ${e instanceof Error ? e.message : String(e)}`);
|
|
105
|
+
}
|
|
106
|
+
if (res.status === 404) {
|
|
107
|
+
throw new Error(`Book block: "${service}" isn’t booked online on this site. Check it in the portal (Events and bookings: the offer, "Book online", and opening hours for who gives it), or run \`npx ferst-modules\` to list what this site takes bookings for.`);
|
|
108
|
+
}
|
|
109
|
+
if (res.status === 403) {
|
|
110
|
+
throw new Error(`Book block: this site isn’t taking bookings (offer "${service}"). Check Events and bookings is switched on for the site, and that the organisation takes bookings.`);
|
|
111
|
+
}
|
|
112
|
+
if (!res.ok) throw new Error(`Book block: the Ferst platform answered ${res.status} for offer "${service}" (${url}).`);
|
|
113
|
+
const d = (await res.json()) as TimesAnswer;
|
|
114
|
+
return {
|
|
115
|
+
id: d.service.id, name: d.service.name, description: d.service.description ?? '', minutes: d.service.minutes,
|
|
116
|
+
resources: d.resources, definition, holds: `${base}/sites/${encodeURIComponent(siteId)}/book/holds`,
|
|
117
|
+
};
|
|
118
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ferst-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Ferst Core — the shared, brand-agnostic client-site system: Astro components, layouts, content schemas, the layered config resolver, and a neutral styling architecture that every client overrides.",
|
|
6
6
|
"license": "BUSL-1.1",
|