ferst-core 0.7.6 → 0.7.7

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.
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env node
2
+ // ferst-modules — what this site has from its organisation's modules in the Ferst portal:
3
+ // the forms it can place and the calendar it shows. Run it in a client repo root:
4
+ //
5
+ // npx --no-install ferst-modules # the site named in ferst-site.json
6
+ // npx --no-install ferst-modules --site <address> # or ask by the site's address
7
+ // npx --no-install ferst-modules --json # the raw answer
8
+ //
9
+ // Forms and calendars live in the portal, never in the repo: place a form with a
10
+ // `{ "type": "form", "form": "<id>" }` block, and show the calendar by setting
11
+ // calendarSettings.embedUrl to the address printed here.
12
+ import { readFileSync } from 'node:fs';
13
+ import { resolve } from 'node:path';
14
+ import { isDirectInvocation, resolveGitBase } from './cms-config.mjs';
15
+
16
+ /** The site to ask about: `--site <ref>`, else ferst-site.json's siteId, else null. */
17
+ export function moduleRef(argv, siteMeta) {
18
+ const i = argv.indexOf('--site');
19
+ if (i !== -1 && argv[i + 1]) return argv[i + 1];
20
+ return siteMeta && typeof siteMeta.siteId === 'string' && siteMeta.siteId ? siteMeta.siteId : null;
21
+ }
22
+
23
+ /** A readable summary of GET /sites/:ref/modules. Pure — unit-tested. */
24
+ export function formatModules(data) {
25
+ const out = [];
26
+ out.push(`Site: ${data.site.address ?? data.site.id} (${data.site.id})`, '');
27
+
28
+ out.push('Forms');
29
+ if (!data.modules.forms) out.push(' The Forms module is off for this site.');
30
+ else if (data.forms.length === 0) out.push(' No forms yet. They are created in the portal (Forms).');
31
+ for (const f of data.forms) {
32
+ out.push(` ${f.name}`);
33
+ out.push(` place it with: { "type": "form", "form": "${f.id}" }`);
34
+ out.push(` fields: ${f.fields.map((x) => `${x.label}${x.required ? ' *' : ''}`).join(', ') || '(none)'}`);
35
+ out.push(` button: ${f.submitLabel}`);
36
+ }
37
+ out.push('');
38
+
39
+ out.push('Events');
40
+ if (!data.events) out.push(' The Events module is off for this site.');
41
+ else {
42
+ out.push(` calendarSettings.embedUrl = ${data.events.embedUrl}`);
43
+ out.push(
44
+ data.events.calendars.length
45
+ ? ` shows: ${data.events.calendars.map((c) => c.name).join(', ')}`
46
+ : ' No calendars chosen yet. They are connected in the portal (Events).',
47
+ );
48
+ }
49
+ return out.join('\n');
50
+ }
51
+
52
+ function readSiteMeta(cwd) {
53
+ try {
54
+ return JSON.parse(readFileSync(resolve(cwd, 'ferst-site.json'), 'utf8'));
55
+ } catch {
56
+ return null;
57
+ }
58
+ }
59
+
60
+ async function main() {
61
+ const argv = process.argv.slice(2);
62
+ const ref = moduleRef(argv, readSiteMeta(process.cwd()));
63
+ if (!ref) {
64
+ console.error('ferst-modules: no site to ask about. Pass --site <your site address> (e.g. --site example.pages.dev), or add "siteId" to ferst-site.json.');
65
+ process.exit(2);
66
+ }
67
+ const base = resolveGitBase();
68
+ const url = `${base}/sites/${encodeURIComponent(ref)}/modules`;
69
+ let res;
70
+ try {
71
+ res = await fetch(url, { headers: { Accept: 'application/json' } });
72
+ } catch (e) {
73
+ console.error(`ferst-modules: couldn't reach the Ferst platform at ${url}: ${e instanceof Error ? e.message : e}`);
74
+ process.exit(1);
75
+ }
76
+ if (res.status === 404) {
77
+ console.error(`ferst-modules: the platform doesn't know a site "${ref}". Check the address, or ask the core team (a core-request issue).`);
78
+ process.exit(1);
79
+ }
80
+ if (!res.ok) {
81
+ console.error(`ferst-modules: the platform answered ${res.status} for ${url}.`);
82
+ process.exit(1);
83
+ }
84
+ const data = await res.json();
85
+ console.log(argv.includes('--json') ? JSON.stringify(data, null, 2) : formatModules(data));
86
+ }
87
+
88
+ // Run when invoked directly as a bin — including via npm's node_modules/.bin symlink.
89
+ if (isDirectInvocation(process.argv[1])) {
90
+ main();
91
+ }
@@ -26,6 +26,7 @@ import Faq from './recipes/Faq.astro';
26
26
  import Gallery from './recipes/Gallery.astro';
27
27
  import Testimonial from './recipes/Testimonial.astro';
28
28
  import ContactForm from './recipes/ContactForm.astro';
29
+ import Form from './recipes/Form.astro';
29
30
  import Accordion from './recipes/Accordion.astro';
30
31
  import Tiles from './recipes/Tiles.astro';
31
32
  import Banner from './recipes/Banner.astro';
@@ -79,6 +80,7 @@ const registry: Record<BlockType, any> = {
79
80
  gallery: Gallery,
80
81
  testimonial: Testimonial,
81
82
  contactForm: ContactForm,
83
+ form: Form,
82
84
  accordion: Accordion,
83
85
  tiles: Tiles,
84
86
  banner: Banner,
@@ -0,0 +1,26 @@
1
+ ---
2
+ /**
3
+ * ProseParts — renders prose text as paragraphs and lists (lib/prose: blank lines →
4
+ * paragraphs, `- ` / `1. ` lines → lists, inline links / bold / italic, all escaped).
5
+ * The one place this markup lives, shared by prose, document, accordion, mediaText and
6
+ * table intros, so a fix lands everywhere at once.
7
+ *
8
+ * Note for callers: these elements carry THIS component's style scope, so a parent styles
9
+ * them through its own wrapper with `:global(p)`, `:global(ul)` etc.
10
+ */
11
+ import { proseParts } from '../lib/prose';
12
+
13
+ interface Props {
14
+ text: string | undefined | null;
15
+ /** Optional class on each paragraph / list (e.g. a table intro's). */
16
+ class?: string;
17
+ }
18
+ const { text, class: cls } = Astro.props;
19
+ const parts = proseParts(text);
20
+ ---
21
+
22
+ {parts.map((part) =>
23
+ part.kind === 'p' ? <p class={cls} set:html={part.html} />
24
+ : part.kind === 'ul' ? <ul class={cls}>{part.items.map((x) => <li set:html={x} />)}</ul>
25
+ : <ol class={cls}>{part.items.map((x) => <li set:html={x} />)}</ol>
26
+ )}
@@ -1,5 +1,5 @@
1
1
  ---
2
- import { proseParts } from '../../lib/prose';
2
+ import ProseParts from '../ProseParts.astro';
3
3
  interface Props {
4
4
  text: string;
5
5
  variant?: 'body' | 'lead';
@@ -7,40 +7,35 @@ interface Props {
7
7
  const { text, variant = 'body' } = Astro.props;
8
8
  // Blank lines separate paragraphs; `- ` / `1. ` lines make lists; links, bold and
9
9
  // italic are rendered safely (lib/prose.ts → inlineMarkdown).
10
- const parts = proseParts(text);
11
10
  ---
12
11
 
13
12
  <div class="b-prose" data-variant={variant === 'lead' ? 'lead' : undefined}>
14
- {parts.map((part) =>
15
- part.kind === 'p' ? <p set:html={part.html} />
16
- : part.kind === 'ul' ? <ul>{part.items.map((i) => <li set:html={i} />)}</ul>
17
- : <ol>{part.items.map((i) => <li set:html={i} />)}</ol>
18
- )}
13
+ <ProseParts text={text} />
19
14
  </div>
20
15
 
21
16
  <style>
22
17
  .b-prose {
23
18
  color: var(--fg);
24
19
  }
25
- .b-prose p,
26
- .b-prose ul,
27
- .b-prose ol {
20
+ .b-prose :global(p),
21
+ .b-prose :global(ul),
22
+ .b-prose :global(ol) {
28
23
  margin: 0 0 1rem;
29
24
  line-height: 1.7;
30
25
  max-width: var(--max);
31
26
  }
32
- .b-prose ul,
33
- .b-prose ol {
27
+ .b-prose :global(ul),
28
+ .b-prose :global(ol) {
34
29
  padding-inline-start: 1.4em;
35
30
  }
36
- .b-prose li + li {
31
+ .b-prose :global(li + li) {
37
32
  margin-top: 0.25rem;
38
33
  }
39
- .b-prose > :last-child {
34
+ .b-prose > :global(:last-child) {
40
35
  margin-bottom: 0;
41
36
  }
42
37
  /* The page's introduction: larger, quieter, a narrower measure. */
43
- .b-prose[data-variant='lead'] p {
38
+ .b-prose[data-variant='lead'] :global(p) {
44
39
  font-size: clamp(1.125rem, 1.6vw, 1.3125rem);
45
40
  line-height: 1.6;
46
41
  color: var(--muted);
@@ -55,10 +50,10 @@ const parts = proseParts(text);
55
50
  section is centred (or end-aligned) re-anchor it so the text reads as
56
51
  deliberately centred, not centred inside a left column. Text-align itself
57
52
  is inherited from the content-align cascade. */
58
- :global([data-content-align='center']) .b-prose > * {
53
+ :global([data-content-align='center']) .b-prose > :global(*) {
59
54
  margin-inline: auto;
60
55
  }
61
- :global([data-content-align='end']) .b-prose > * {
56
+ :global([data-content-align='end']) .b-prose > :global(*) {
62
57
  margin-inline-start: auto;
63
58
  }
64
59
  </style>
@@ -4,7 +4,7 @@
4
4
  * Native <details>/<summary> — accessible, interactive, zero JavaScript. */
5
5
  import Heading from '../blocks/Heading.astro';
6
6
 
7
- import { proseParts } from '../../lib/prose';
7
+ import ProseParts from '../ProseParts.astro';
8
8
  interface Props {
9
9
  title?: string;
10
10
  items?: { heading: string; body: string }[];
@@ -19,11 +19,7 @@ const { title, items = [] } = Astro.props;
19
19
  <details class="b-accordion__item">
20
20
  <summary class="b-accordion__head">{item.heading}</summary>
21
21
  <div class="b-accordion__body">
22
- {proseParts(item.body).map((part) =>
23
- part.kind === 'p' ? <p set:html={part.html} />
24
- : part.kind === 'ul' ? <ul>{part.items.map((x) => <li set:html={x} />)}</ul>
25
- : <ol>{part.items.map((x) => <li set:html={x} />)}</ol>
26
- )}
22
+ <ProseParts text={item.body} />
27
23
  </div>
28
24
  </details>
29
25
  ))}
@@ -85,7 +81,7 @@ const { title, items = [] } = Astro.props;
85
81
  color: var(--muted);
86
82
  line-height: 1.6;
87
83
  }
88
- .b-accordion__body p {
84
+ .b-accordion__body :global(p) {
89
85
  margin: 0;
90
86
  }
91
87
  </style>
@@ -6,7 +6,7 @@
6
6
  * (links, bold, lists); `items` add a list. Print-friendly: the contents list is
7
7
  * dropped on paper.
8
8
  */
9
- import { proseParts } from '../../lib/prose';
9
+ import ProseParts from '../ProseParts.astro';
10
10
  import { inlineMarkdown } from '../../lib/inline-markdown';
11
11
  import { longDate } from '../../lib/documents';
12
12
  import { pageSlugs, uniqueSlug } from '../../lib/slug';
@@ -44,11 +44,7 @@ const ids = sections.map((s) => uniqueSlug(s.title, used));
44
44
  {sections.map((s, i) => (
45
45
  <section class="b-doc__clause" id={ids[i]}>
46
46
  <h2 id={`clause-${i + 1}`}>{numbered && <span class="b-doc__num">{i + 1}.</span>} {s.title}</h2>
47
- {proseParts(s.body).map((part) =>
48
- part.kind === 'p' ? <p set:html={part.html} />
49
- : part.kind === 'ul' ? <ul>{part.items.map((x) => <li set:html={x} />)}</ul>
50
- : <ol>{part.items.map((x) => <li set:html={x} />)}</ol>
51
- )}
47
+ <ProseParts text={s.body} />
52
48
  {s.items && s.items.length > 0 && <ul>{s.items.map((x) => <li set:html={inlineMarkdown(x)} />)}</ul>}
53
49
  </section>
54
50
  ))}
@@ -135,14 +131,14 @@ const ids = sections.map((s) => uniqueSlug(s.title, used));
135
131
  color: var(--gold);
136
132
  font-variant-numeric: tabular-nums;
137
133
  }
138
- .b-doc__clause p,
139
- .b-doc__clause ul,
140
- .b-doc__clause ol {
134
+ .b-doc__clause :global(p),
135
+ .b-doc__clause :global(ul),
136
+ .b-doc__clause :global(ol) {
141
137
  margin: 0 0 0.75rem;
142
138
  line-height: 1.7;
143
139
  }
144
- .b-doc__clause ul,
145
- .b-doc__clause ol {
140
+ .b-doc__clause :global(ul),
141
+ .b-doc__clause :global(ol) {
146
142
  padding-inline-start: 1.4em;
147
143
  }
148
144
  .b-doc__clause :global(a) {
@@ -0,0 +1,30 @@
1
+ ---
2
+ /**
3
+ * Form — one of the organisation's forms from the Ferst portal, placed by id. Reads the
4
+ * form's fields, button and submit address from the platform at build time (lib/forms)
5
+ * and renders it with the ContactForm recipe, so it looks like every other form and a
6
+ * change made in the portal reaches the site on its next build.
7
+ */
8
+ import ContactForm from './ContactForm.astro';
9
+ import { loadFormDefinition } from '../../lib/forms';
10
+ import { resolveGitBase } from '../../bin/cms-config.mjs';
11
+
12
+ interface Props {
13
+ form: string;
14
+ title?: string;
15
+ intro?: string;
16
+ note?: string;
17
+ }
18
+ const { form, title, intro, note } = Astro.props;
19
+ const def = await loadFormDefinition(form, { base: resolveGitBase() });
20
+ ---
21
+
22
+ <ContactForm
23
+ title={title ?? def.name}
24
+ intro={intro}
25
+ action={def.action}
26
+ method="post"
27
+ submitLabel={def.submitLabel}
28
+ note={note}
29
+ fields={def.fields}
30
+ />
@@ -1,92 +1,88 @@
1
- ---
2
- /**
3
- * MediaText — an image beside its text, on the start or end side; stacks (text, then image)
4
- * on a phone. The text takes prose formatting (paragraphs, lists, links); the image keeps
5
- * its own shape unless `ratio` sets one (cropped to fill). An optional button follows the
6
- * text.
7
- */
8
- import Heading from '../blocks/Heading.astro';
9
- import Button from '../Button.astro';
10
- import { proseParts } from '../../lib/prose';
11
-
12
- interface Props {
13
- title?: string;
14
- text: string;
15
- image: { src: string; alt?: string; caption?: string };
16
- imageSide?: 'start' | 'end';
17
- ratio?: 'auto' | '1/1' | '4/3' | '3/2' | '16/9';
18
- cta?: { label: string; href: string };
19
- }
20
- const { title, text, image, imageSide = 'end', ratio = 'auto', cta } = Astro.props;
21
- ---
22
-
23
- <section class="b-mediatext" data-side={imageSide}>
24
- <div class="b-mediatext__text">
25
- {title && <Heading text={title} level={2} />}
26
- {proseParts(text).map((part) =>
27
- part.kind === 'p' ? <p set:html={part.html} />
28
- : part.kind === 'ul' ? <ul>{part.items.map((x) => <li set:html={x} />)}</ul>
29
- : <ol>{part.items.map((x) => <li set:html={x} />)}</ol>
30
- )}
31
- {cta && <div class="b-mediatext__cta"><Button href={cta.href} variant="primary">{cta.label}</Button></div>}
32
- </div>
33
- <figure class="b-mediatext__media">
34
- <img src={image.src} alt={image.alt ?? ''} loading="lazy" decoding="async" style={ratio !== 'auto' ? `aspect-ratio: ${ratio}; object-fit: cover` : undefined} />
35
- {image.caption && <figcaption>{image.caption}</figcaption>}
36
- </figure>
37
- </section>
38
-
39
- <style>
40
- .b-mediatext {
41
- display: grid;
42
- gap: clamp(1.5rem, 4vw, 3rem);
43
- align-items: center;
44
- width: 100%;
45
- max-width: 72rem;
46
- }
47
- @media (min-width: 48em) {
48
- .b-mediatext {
49
- grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
50
- }
51
- .b-mediatext[data-side='start'] .b-mediatext__media {
52
- order: -1;
53
- }
54
- }
55
- .b-mediatext__text {
56
- display: flex;
57
- flex-direction: column;
58
- gap: 0.9rem;
59
- }
60
- .b-mediatext__text p,
61
- .b-mediatext__text ul,
62
- .b-mediatext__text ol {
63
- margin: 0;
64
- line-height: 1.7;
65
- }
66
- .b-mediatext__text ul,
67
- .b-mediatext__text ol {
68
- padding-inline-start: 1.4em;
69
- }
70
- .b-mediatext__text :global(a:not(.btn)) {
71
- color: var(--accent);
72
- text-decoration: underline;
73
- text-underline-offset: 0.15em;
74
- }
75
- .b-mediatext__cta {
76
- margin-top: 0.4rem;
77
- }
78
- .b-mediatext__media {
79
- margin: 0;
80
- }
81
- .b-mediatext__media img {
82
- display: block;
83
- width: 100%;
84
- height: auto;
85
- border-radius: var(--radius);
86
- }
87
- .b-mediatext__media figcaption {
88
- margin-top: 0.5rem;
89
- font-size: 0.875rem;
90
- color: var(--muted);
91
- }
92
- </style>
1
+ ---
2
+ /**
3
+ * MediaText — an image beside its text, on the start or end side; stacks (text, then image)
4
+ * on a phone. The text takes prose formatting (paragraphs, lists, links); the image keeps
5
+ * its own shape unless `ratio` sets one (cropped to fill). An optional button follows the
6
+ * text.
7
+ */
8
+ import Heading from '../blocks/Heading.astro';
9
+ import Button from '../Button.astro';
10
+ import ProseParts from '../ProseParts.astro';
11
+
12
+ interface Props {
13
+ title?: string;
14
+ text: string;
15
+ image: { src: string; alt?: string; caption?: string };
16
+ imageSide?: 'start' | 'end';
17
+ ratio?: 'auto' | '1/1' | '4/3' | '3/2' | '16/9';
18
+ cta?: { label: string; href: string };
19
+ }
20
+ const { title, text, image, imageSide = 'end', ratio = 'auto', cta } = Astro.props;
21
+ ---
22
+
23
+ <section class="b-mediatext" data-side={imageSide}>
24
+ <div class="b-mediatext__text">
25
+ {title && <Heading text={title} level={2} />}
26
+ <ProseParts text={text} />
27
+ {cta && <div class="b-mediatext__cta"><Button href={cta.href} variant="primary">{cta.label}</Button></div>}
28
+ </div>
29
+ <figure class="b-mediatext__media">
30
+ <img src={image.src} alt={image.alt ?? ''} loading="lazy" decoding="async" style={ratio !== 'auto' ? `aspect-ratio: ${ratio}; object-fit: cover` : undefined} />
31
+ {image.caption && <figcaption>{image.caption}</figcaption>}
32
+ </figure>
33
+ </section>
34
+
35
+ <style>
36
+ .b-mediatext {
37
+ display: grid;
38
+ gap: clamp(1.5rem, 4vw, 3rem);
39
+ align-items: center;
40
+ width: 100%;
41
+ max-width: 72rem;
42
+ }
43
+ @media (min-width: 48em) {
44
+ .b-mediatext {
45
+ grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
46
+ }
47
+ .b-mediatext[data-side='start'] .b-mediatext__media {
48
+ order: -1;
49
+ }
50
+ }
51
+ .b-mediatext__text {
52
+ display: flex;
53
+ flex-direction: column;
54
+ gap: 0.9rem;
55
+ }
56
+ .b-mediatext__text :global(p),
57
+ .b-mediatext__text :global(ul),
58
+ .b-mediatext__text :global(ol) {
59
+ margin: 0;
60
+ line-height: 1.7;
61
+ }
62
+ .b-mediatext__text :global(ul),
63
+ .b-mediatext__text :global(ol) {
64
+ padding-inline-start: 1.4em;
65
+ }
66
+ .b-mediatext__text :global(a:not(.btn)) {
67
+ color: var(--accent);
68
+ text-decoration: underline;
69
+ text-underline-offset: 0.15em;
70
+ }
71
+ .b-mediatext__cta {
72
+ margin-top: 0.4rem;
73
+ }
74
+ .b-mediatext__media {
75
+ margin: 0;
76
+ }
77
+ .b-mediatext__media img {
78
+ display: block;
79
+ width: 100%;
80
+ height: auto;
81
+ border-radius: var(--radius);
82
+ }
83
+ .b-mediatext__media figcaption {
84
+ margin-top: 0.5rem;
85
+ font-size: 0.875rem;
86
+ color: var(--muted);
87
+ }
88
+ </style>
@@ -9,7 +9,7 @@ import Heading from '../blocks/Heading.astro';
9
9
 
10
10
  import { inlineMarkdown } from '../../lib/inline-markdown';
11
11
  import { filledColumns } from '../../lib/table';
12
- import { proseParts } from '../../lib/prose';
12
+ import ProseParts from '../ProseParts.astro';
13
13
  interface Props {
14
14
  title?: string;
15
15
  intro?: string;
@@ -25,7 +25,7 @@ const keep = filledColumns(columns, rows);
25
25
  {(title || intro) && (
26
26
  <div class="b-table__head">
27
27
  {title && <Heading text={title} level={2} />}
28
- {intro && proseParts(intro).map((part) => part.kind === 'p' ? <p class="b-table__intro" set:html={part.html} /> : <ul class="b-table__intro">{part.items.map((x) => <li set:html={x} />)}</ul>)}
28
+ {intro && <ProseParts text={intro} class="b-table__intro" />}
29
29
  </div>
30
30
  )}
31
31
  <div class="b-table__scroll">
@@ -58,7 +58,7 @@ const keep = filledColumns(columns, rows);
58
58
  flex-direction: column;
59
59
  gap: 0.6rem;
60
60
  }
61
- .b-table__intro {
61
+ :global(.b-table__intro) {
62
62
  margin: 0;
63
63
  color: var(--muted);
64
64
  max-width: var(--max);