ferst-core 0.10.0 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env node
2
+ // Ferst page allowance guard (myai4-webdev #119): a release never puts more pages on the live
3
+ // site than the site's plan publishes. The platform writes the plan's allowance into
4
+ // ferst-site.json (`pages`: a number, or null/absent for no limit); a page is published unless
5
+ // it says `"draft": true`. Home counts; the "page not found" page (`404`) never does.
6
+ // Run by the site's `guard` check on a release: `ferst-check-pages [siteRoot]` (defaults to .).
7
+ import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs';
8
+ import { join, relative } from 'node:path';
9
+ import { pathToFileURL } from 'node:url';
10
+
11
+ const PAGES_DIR = 'src/content/pages';
12
+ const NOT_FOUND = '404';
13
+
14
+ function* walk(dir) {
15
+ for (const name of readdirSync(dir)) {
16
+ const p = join(dir, name);
17
+ if (statSync(p).isDirectory()) yield* walk(p);
18
+ else if (name.endsWith('.json')) yield p;
19
+ }
20
+ }
21
+
22
+ function readJson(path) {
23
+ try {
24
+ return JSON.parse(readFileSync(path, 'utf8'));
25
+ } catch {
26
+ return null;
27
+ }
28
+ }
29
+
30
+ /** The plan's allowance and the published pages (their slugs, sorted); `over` is how many too
31
+ * many are published (0 when within the plan or there's no limit). Pure apart from reading. */
32
+ export function checkPages(root = '.') {
33
+ const meta = readJson(join(root, 'ferst-site.json'));
34
+ const allowance = meta && typeof meta.pages === 'number' ? meta.pages : null;
35
+ const dir = join(root, PAGES_DIR);
36
+ const published = [];
37
+ if (existsSync(dir)) {
38
+ for (const file of walk(dir)) {
39
+ const slug = relative(dir, file).replace(/\\/g, '/').replace(/\.json$/, '');
40
+ if (slug === NOT_FOUND) continue;
41
+ const data = readJson(file);
42
+ // A page that can't be read counts as published: the build reports the broken file.
43
+ if (data && data.draft === true) continue;
44
+ published.push(slug);
45
+ }
46
+ }
47
+ published.sort();
48
+ const over = allowance == null ? 0 : Math.max(0, published.length - allowance);
49
+ return { allowance, published, over };
50
+ }
51
+
52
+ function main() {
53
+ const r = checkPages(process.argv[2] ?? '.');
54
+ if (r.allowance == null) {
55
+ console.log(`ferst-check-pages: ${r.published.length} pages published; the plan has no page limit.`);
56
+ return;
57
+ }
58
+ if (r.over > 0) {
59
+ console.error(`::error::The plan publishes ${r.allowance} pages, and this release would publish ${r.published.length}:`);
60
+ for (const p of r.published) console.error(` ${p === 'index' ? 'index (home)' : p}`);
61
+ console.error(`Make ${r.over} of them a draft ("draft": true), or the site's owner chooses a bigger plan in the portal.`);
62
+ process.exit(1);
63
+ }
64
+ console.log(`ferst-check-pages: ${r.published.length} of ${r.allowance} pages published.`);
65
+ }
66
+
67
+ /** True when run as a CLI, also through npm's `node_modules/.bin` symlink (see check-thin.mjs:
68
+ * it has to compare THIS file's URL, so it can't be shared). */
69
+ function isDirectInvocation(argv1) {
70
+ if (!argv1) return false;
71
+ if (import.meta.url === pathToFileURL(argv1).href) return true;
72
+ try {
73
+ return import.meta.url === pathToFileURL(realpathSync(argv1)).href;
74
+ } catch {
75
+ return false;
76
+ }
77
+ }
78
+
79
+ if (isDirectInvocation(process.argv[1])) main();
@@ -70,7 +70,7 @@ const MANAGED_OWNER = 'myai4webdev';
70
70
 
71
71
  /** The Pages collection's description on each plan. */
72
72
  const PAGES_DESCRIPTION = {
73
- basic: "See each page and request a change — our team makes it and sends it back for you to check. You don't edit the page layout here.",
73
+ basic: "See each page and request a change — our team makes it and sends it back for you to check. You don't edit the page layout here. To add a new page, or publish one, use the Pages tab in your Ferst portal.",
74
74
  free: "You're on the free plan: you look after this site yourself and change its pages in your own repository. Asking the Ferst team to make changes for you comes with the Basic plan.",
75
75
  };
76
76
 
@@ -20,49 +20,8 @@ collections:
20
20
  - name: settings
21
21
  label: Site settings
22
22
  files:
23
- - name: theme
24
- label: Design tokens
25
- file: src/content/themeSettings/index.json
26
- icon: palette
27
- description: "Edit your brand in the Theme Studio, where you preview changes live before publishing — open portal.ferst.co.uk, choose this site, then the Design tab. The fields here still work as a fallback."
28
- fields:
29
- - { name: brand, label: Brand colour, widget: color, default: '#0E4D4A', hint: Buttons, links, icons, highlights. }
30
- - { name: ink, label: Ink colour, widget: color, default: '#0C2123', hint: Headings and body text. }
31
- - { name: surface, label: Surface colour, widget: color, default: '#FFFFFF', hint: Page background. }
32
- - name: fonts
33
- label: Typography
34
- widget: object
35
- collapsed: false
36
- fields:
37
- - name: heading
38
- label: Heading font
39
- widget: select
40
- required: false
41
- default: ''
42
- options: &fonts
43
- - { label: 'Default (theme)', value: '' }
44
- - { label: 'Poppins', value: 'Poppins, system-ui, sans-serif' }
45
- - { label: 'Inter', value: 'Inter, system-ui, sans-serif' }
46
- - { label: 'Playfair Display', value: "'Playfair Display', Georgia, serif" }
47
- - { label: 'Georgia', value: "Georgia, 'Times New Roman', serif" }
48
- - { label: 'System', value: 'system-ui, sans-serif' }
49
- - { name: body, label: Body font, widget: select, required: false, default: '', options: *fonts }
50
- - { name: display, label: Display font, widget: select, required: false, default: '', options: *fonts }
51
- - { name: corners, label: Corners, widget: select, default: rounded, options: [{ label: Sharp, value: sharp }, { label: Rounded, value: rounded }, { label: Soft, value: soft }] }
52
- - { name: elevation, label: Elevation, widget: select, default: raised, options: [{ label: Raised, value: raised }, { label: Flat, value: flat }] }
53
- - { name: stroke, label: Card stroke, widget: select, default: 'on', options: [{ label: 'On', value: 'on' }, { label: 'Off', value: 'off' }] }
54
- - { name: fields, label: Input fields, widget: select, default: boxed, options: [{ label: Boxed, value: boxed }, { label: Filled, value: filled }, { label: Underline, value: underline }] }
55
- - { name: darkDepth, label: Dark depth, widget: number, value_type: float, min: 0.14, max: 0.34, step: 0.01, default: 0.21 }
56
- - { name: darkChroma, label: Dark colour intensity, widget: number, value_type: float, min: 0, max: 0.15, step: 0.01, default: 0.05 }
57
- - name: darkOverrides
58
- label: Dark colour overrides (optional)
59
- widget: object
60
- collapsed: true
61
- fields:
62
- - { name: ground, label: Ground, widget: string, required: false }
63
- - { name: text, label: Text, widget: string, required: false }
64
- - { name: accent, label: Accent, widget: string, required: false }
65
-
23
+ # No design tokens pane: a site's look is set in the portal, on its Design tab, for every
24
+ # site and branch (myai4-webdev #119). The themeSettings file is the portal's to write.
66
25
  - name: identity
67
26
  label: Identity & contact
68
27
  file: src/content/siteSettings/index.json
@@ -240,6 +199,10 @@ collections:
240
199
  extension: json
241
200
  format: json
242
201
  icon: description
202
+ # Pages are added, published and made drafts on the portal's Pages tab, within the site's
203
+ # plan (myai4-webdev #119): the CMS shows each page, for its people to request changes.
204
+ create: false
205
+ delete: false
243
206
  nested: { depth: 3, summary: "{{title}}" }
244
207
  summary: "{{title}}"
245
208
  identifier_field: title
@@ -1,260 +1,260 @@
1
- ---
2
- interface Props {
3
- href?: string;
4
- type?: 'button' | 'submit' | 'reset';
5
- variant?: 'primary' | 'secondary' | 'cta' | 'compact' | 'ghost';
6
- size?: 'sm' | 'md';
7
- disabled?: boolean;
8
- [x: string]: any;
9
- }
10
-
11
- const {
12
- href,
13
- type = 'button',
14
- variant = 'primary',
15
- size = 'md',
16
- disabled = false,
17
- ...rest
18
- } = Astro.props;
19
- ---
20
-
21
- {href ? (
22
- <a
23
- href={href}
24
- class:list={['btn', `btn--${variant}`, size === 'sm' && 'btn--sm']}
25
- {...rest}
26
- >
27
- <slot />
28
- </a>
29
- ) : (
30
- <button
31
- type={type}
32
- disabled={disabled}
33
- class:list={['btn', `btn--${variant}`, size === 'sm' && 'btn--sm']}
34
- {...rest}
35
- >
36
- <slot />
37
- </button>
38
- )}
39
-
40
- <style>
41
- /* Mobile-first base: smaller. Desktop ≥64em scales up for visual presence on big screens. */
42
- .btn {
43
- display: inline-flex;
44
- align-items: center;
45
- justify-content: center;
46
- background: transparent;
47
- border: 2px solid var(--fg);
48
- border-radius: var(--radius-sm);
49
- color: var(--fg);
50
- font-family: var(--font-heading);
51
- font-size: 0.75rem;
52
- font-weight: 600;
53
- text-transform: uppercase;
54
- letter-spacing: 0.12em;
55
- height: auto;
56
- min-height: 44px;
57
- padding: 0 0.95rem;
58
- min-width: 116px;
59
- text-decoration: none;
60
- cursor: pointer;
61
- transition: border-color 0.3s, color 0.3s;
62
- user-select: none;
63
- touch-action: manipulation;
64
- box-sizing: border-box;
65
- white-space: nowrap;
66
- }
67
- @media (min-width: 64em) {
68
- .btn {
69
- height: 44px;
70
- padding: 0 1.1rem;
71
- font-size: 0.8125rem;
72
- min-width: 124px;
73
- }
74
- }
75
-
76
- .btn:hover {
77
- border-color: var(--gold);
78
- color: var(--gold);
79
- }
80
- .btn:focus-visible {
81
- outline: 2px solid var(--gold);
82
- outline-offset: 2px;
83
- border-color: var(--gold);
84
- color: var(--gold);
85
- }
86
-
87
- .btn:disabled {
88
- opacity: 0.5;
89
- cursor: not-allowed;
90
- }
91
-
92
- /* Role distinction: primary = filled (high emphasis), secondary = the base
93
- outline (medium). Filled beats the base outline-hover, so override it. */
94
- .btn--primary {
95
- background: var(--gold);
96
- border-color: var(--gold);
97
- color: var(--on-brand);
98
- }
99
- .btn--primary:hover,
100
- .btn--primary:focus-visible {
101
- background: color-mix(in srgb, var(--gold) 85%, #000);
102
- border-color: color-mix(in srgb, var(--gold) 85%, #000);
103
- color: var(--on-brand);
104
- }
105
- .btn--primary:focus-visible {
106
- outline: 2px solid var(--gold);
107
- outline-offset: 2px;
108
- }
109
-
110
- .btn--sm {
111
- height: auto;
112
- min-height: 40px;
113
- padding: 0 0.7rem;
114
- min-width: auto;
115
- }
116
- @media (min-width: 64em) {
117
- .btn--sm { height: 40px; padding: 0 0.85rem; }
118
- }
119
-
120
- /* CTA / compact variants — a filled button in the brand accent. Token-driven
121
- (was a hardcoded brand green) so it recolours with the site palette; hover
122
- darkens the accent via color-mix, which works for any brand colour. */
123
- .btn--cta {
124
- background: var(--gold);
125
- color: var(--on-brand);
126
- border: none;
127
- border-radius: 8px;
128
- font-family: var(--font-body);
129
- font-size: 0.75rem;
130
- font-weight: 600;
131
- letter-spacing: 0.1em;
132
- text-transform: uppercase;
133
- padding: 0.45rem 0.85rem;
134
- min-height: 44px;
135
- min-width: auto;
136
- transition: background 0.18s ease;
137
- }
138
- @media (min-width: 64em) {
139
- .btn--cta {
140
- min-height: 44px;
141
- padding: 0.625rem 1rem;
142
- font-size: 0.8125rem;
143
- }
144
- }
145
-
146
- .btn--cta:hover {
147
- background: color-mix(in srgb, var(--gold) 85%, #000);
148
- color: var(--on-brand);
149
- }
150
- .btn--cta:focus-visible {
151
- background: color-mix(in srgb, var(--gold) 85%, #000);
152
- color: var(--on-brand);
153
- outline: 2px solid var(--gold);
154
- outline-offset: 2px;
155
- }
156
-
157
- .btn--compact {
158
- display: inline-flex;
159
- align-items: center;
160
- justify-content: center;
161
- margin-top: auto;
162
- align-self: var(--content-self, flex-start);
163
- background: var(--gold);
164
- color: var(--on-brand);
165
- border: none;
166
- border-radius: 8px;
167
- font-family: var(--font-body);
168
- font-size: 0.75rem;
169
- font-weight: 600;
170
- letter-spacing: 0.1em;
171
- text-transform: uppercase;
172
- padding: 0.45rem 0.75rem;
173
- min-width: auto;
174
- min-height: 44px;
175
- transition: background 0.18s ease;
176
- }
177
- @media (min-width: 64em) {
178
- .btn--compact {
179
- min-height: 44px;
180
- padding: 0.5rem 0.85rem;
181
- font-size: 0.8125rem;
182
- }
183
- }
184
-
185
- .btn--compact:hover {
186
- background: color-mix(in srgb, var(--gold) 85%, #000);
187
- color: var(--on-brand);
188
- }
189
- .btn--compact:focus-visible {
190
- background: color-mix(in srgb, var(--gold) 85%, #000);
191
- color: var(--on-brand);
192
- outline: 2px solid var(--gold);
193
- outline-offset: 2px;
194
- }
195
-
196
- /* Ghost — a quiet, borderless text button for tertiary actions. */
197
- .btn--ghost {
198
- background: transparent;
199
- border: 2px solid transparent;
200
- color: var(--gold);
201
- min-width: auto;
202
- padding: 0 0.6rem;
203
- }
204
- .btn--ghost:hover {
205
- color: var(--gold);
206
- border-color: transparent;
207
- background: var(--gold-light);
208
- }
209
- .btn--ghost:focus-visible {
210
- color: var(--gold);
211
- border-color: transparent;
212
- background: var(--gold-light);
213
- outline: 2px solid var(--gold);
214
- outline-offset: 2px;
215
- }
216
-
217
- /* Dark mode support */
218
- :global([data-theme="dark"]) .btn {
219
- border-color: var(--text-light);
220
- color: var(--text-light);
221
- }
222
-
223
- :global([data-theme="dark"]) .btn--ghost {
224
- border-color: transparent;
225
- color: var(--gold);
226
- }
227
- :global([data-theme="dark"]) .btn--ghost:hover,
228
- :global([data-theme="dark"]) .btn--ghost:focus-visible {
229
- border-color: transparent;
230
- color: var(--gold);
231
- background: var(--gold-light);
232
- }
233
-
234
- :global([data-theme="dark"]) .btn:hover,
235
- :global([data-theme="dark"]) .btn:focus-visible {
236
- border-color: var(--gold);
237
- color: var(--gold);
238
- }
239
-
240
- /* In dark mode --gold is a light accent, so dark text reads best on it, and
241
- hover lightens (mix toward white) rather than darkens. */
242
- :global([data-theme="dark"]) .btn--cta,
243
- :global([data-theme="dark"]) .btn--compact,
244
- :global([data-theme="dark"]) .btn--primary {
245
- background: var(--gold);
246
- border-color: var(--gold);
247
- color: var(--dark-bg);
248
- }
249
-
250
- :global([data-theme="dark"]) .btn--cta:hover,
251
- :global([data-theme="dark"]) .btn--cta:focus-visible,
252
- :global([data-theme="dark"]) .btn--compact:hover,
253
- :global([data-theme="dark"]) .btn--compact:focus-visible,
254
- :global([data-theme="dark"]) .btn--primary:hover,
255
- :global([data-theme="dark"]) .btn--primary:focus-visible {
256
- background: color-mix(in srgb, var(--gold) 85%, #fff);
257
- border-color: color-mix(in srgb, var(--gold) 85%, #fff);
258
- color: var(--dark-bg);
259
- }
1
+ ---
2
+ interface Props {
3
+ href?: string;
4
+ type?: 'button' | 'submit' | 'reset';
5
+ variant?: 'primary' | 'secondary' | 'cta' | 'compact' | 'ghost';
6
+ size?: 'sm' | 'md';
7
+ disabled?: boolean;
8
+ [x: string]: any;
9
+ }
10
+
11
+ const {
12
+ href,
13
+ type = 'button',
14
+ variant = 'primary',
15
+ size = 'md',
16
+ disabled = false,
17
+ ...rest
18
+ } = Astro.props;
19
+ ---
20
+
21
+ {href ? (
22
+ <a
23
+ href={href}
24
+ class:list={['btn', `btn--${variant}`, size === 'sm' && 'btn--sm']}
25
+ {...rest}
26
+ >
27
+ <slot />
28
+ </a>
29
+ ) : (
30
+ <button
31
+ type={type}
32
+ disabled={disabled}
33
+ class:list={['btn', `btn--${variant}`, size === 'sm' && 'btn--sm']}
34
+ {...rest}
35
+ >
36
+ <slot />
37
+ </button>
38
+ )}
39
+
40
+ <style>
41
+ /* Mobile-first base: smaller. Desktop ≥64em scales up for visual presence on big screens. */
42
+ .btn {
43
+ display: inline-flex;
44
+ align-items: center;
45
+ justify-content: center;
46
+ background: transparent;
47
+ border: 2px solid var(--fg);
48
+ border-radius: var(--radius-sm);
49
+ color: var(--fg);
50
+ font-family: var(--font-heading);
51
+ font-size: 0.75rem;
52
+ font-weight: 600;
53
+ text-transform: uppercase;
54
+ letter-spacing: 0.12em;
55
+ height: auto;
56
+ min-height: 44px;
57
+ padding: 0 0.95rem;
58
+ min-width: 116px;
59
+ text-decoration: none;
60
+ cursor: pointer;
61
+ transition: border-color 0.3s, color 0.3s;
62
+ user-select: none;
63
+ touch-action: manipulation;
64
+ box-sizing: border-box;
65
+ white-space: nowrap;
66
+ }
67
+ @media (min-width: 64em) {
68
+ .btn {
69
+ height: 44px;
70
+ padding: 0 1.1rem;
71
+ font-size: 0.8125rem;
72
+ min-width: 124px;
73
+ }
74
+ }
75
+
76
+ .btn:hover {
77
+ border-color: var(--gold);
78
+ color: var(--gold);
79
+ }
80
+ .btn:focus-visible {
81
+ outline: 2px solid var(--gold);
82
+ outline-offset: 2px;
83
+ border-color: var(--gold);
84
+ color: var(--gold);
85
+ }
86
+
87
+ .btn:disabled {
88
+ opacity: 0.5;
89
+ cursor: not-allowed;
90
+ }
91
+
92
+ /* Role distinction: primary = filled (high emphasis), secondary = the base
93
+ outline (medium). Filled beats the base outline-hover, so override it. */
94
+ .btn--primary {
95
+ background: var(--gold);
96
+ border-color: var(--gold);
97
+ color: var(--on-brand);
98
+ }
99
+ .btn--primary:hover,
100
+ .btn--primary:focus-visible {
101
+ background: color-mix(in srgb, var(--gold) 85%, #000);
102
+ border-color: color-mix(in srgb, var(--gold) 85%, #000);
103
+ color: var(--on-brand);
104
+ }
105
+ .btn--primary:focus-visible {
106
+ outline: 2px solid var(--gold);
107
+ outline-offset: 2px;
108
+ }
109
+
110
+ .btn--sm {
111
+ height: auto;
112
+ min-height: 40px;
113
+ padding: 0 0.7rem;
114
+ min-width: auto;
115
+ }
116
+ @media (min-width: 64em) {
117
+ .btn--sm { height: 40px; padding: 0 0.85rem; }
118
+ }
119
+
120
+ /* CTA / compact variants — a filled button in the brand accent. Token-driven
121
+ (was a hardcoded brand green) so it recolours with the site palette; hover
122
+ darkens the accent via color-mix, which works for any brand colour. */
123
+ .btn--cta {
124
+ background: var(--gold);
125
+ color: var(--on-brand);
126
+ border: none;
127
+ border-radius: var(--radius-sm);
128
+ font-family: var(--font-body);
129
+ font-size: 0.75rem;
130
+ font-weight: 600;
131
+ letter-spacing: 0.1em;
132
+ text-transform: uppercase;
133
+ padding: 0.45rem 0.85rem;
134
+ min-height: 44px;
135
+ min-width: auto;
136
+ transition: background 0.18s ease;
137
+ }
138
+ @media (min-width: 64em) {
139
+ .btn--cta {
140
+ min-height: 44px;
141
+ padding: 0.625rem 1rem;
142
+ font-size: 0.8125rem;
143
+ }
144
+ }
145
+
146
+ .btn--cta:hover {
147
+ background: color-mix(in srgb, var(--gold) 85%, #000);
148
+ color: var(--on-brand);
149
+ }
150
+ .btn--cta:focus-visible {
151
+ background: color-mix(in srgb, var(--gold) 85%, #000);
152
+ color: var(--on-brand);
153
+ outline: 2px solid var(--gold);
154
+ outline-offset: 2px;
155
+ }
156
+
157
+ .btn--compact {
158
+ display: inline-flex;
159
+ align-items: center;
160
+ justify-content: center;
161
+ margin-top: auto;
162
+ align-self: var(--content-self, flex-start);
163
+ background: var(--gold);
164
+ color: var(--on-brand);
165
+ border: none;
166
+ border-radius: var(--radius-sm);
167
+ font-family: var(--font-body);
168
+ font-size: 0.75rem;
169
+ font-weight: 600;
170
+ letter-spacing: 0.1em;
171
+ text-transform: uppercase;
172
+ padding: 0.45rem 0.75rem;
173
+ min-width: auto;
174
+ min-height: 44px;
175
+ transition: background 0.18s ease;
176
+ }
177
+ @media (min-width: 64em) {
178
+ .btn--compact {
179
+ min-height: 44px;
180
+ padding: 0.5rem 0.85rem;
181
+ font-size: 0.8125rem;
182
+ }
183
+ }
184
+
185
+ .btn--compact:hover {
186
+ background: color-mix(in srgb, var(--gold) 85%, #000);
187
+ color: var(--on-brand);
188
+ }
189
+ .btn--compact:focus-visible {
190
+ background: color-mix(in srgb, var(--gold) 85%, #000);
191
+ color: var(--on-brand);
192
+ outline: 2px solid var(--gold);
193
+ outline-offset: 2px;
194
+ }
195
+
196
+ /* Ghost — a quiet, borderless text button for tertiary actions. */
197
+ .btn--ghost {
198
+ background: transparent;
199
+ border: 2px solid transparent;
200
+ color: var(--gold);
201
+ min-width: auto;
202
+ padding: 0 0.6rem;
203
+ }
204
+ .btn--ghost:hover {
205
+ color: var(--gold);
206
+ border-color: transparent;
207
+ background: var(--gold-light);
208
+ }
209
+ .btn--ghost:focus-visible {
210
+ color: var(--gold);
211
+ border-color: transparent;
212
+ background: var(--gold-light);
213
+ outline: 2px solid var(--gold);
214
+ outline-offset: 2px;
215
+ }
216
+
217
+ /* Dark mode support */
218
+ :global([data-theme="dark"]) .btn {
219
+ border-color: var(--text-light);
220
+ color: var(--text-light);
221
+ }
222
+
223
+ :global([data-theme="dark"]) .btn--ghost {
224
+ border-color: transparent;
225
+ color: var(--gold);
226
+ }
227
+ :global([data-theme="dark"]) .btn--ghost:hover,
228
+ :global([data-theme="dark"]) .btn--ghost:focus-visible {
229
+ border-color: transparent;
230
+ color: var(--gold);
231
+ background: var(--gold-light);
232
+ }
233
+
234
+ :global([data-theme="dark"]) .btn:hover,
235
+ :global([data-theme="dark"]) .btn:focus-visible {
236
+ border-color: var(--gold);
237
+ color: var(--gold);
238
+ }
239
+
240
+ /* In dark mode --gold is a light accent, so dark text reads best on it, and
241
+ hover lightens (mix toward white) rather than darkens. */
242
+ :global([data-theme="dark"]) .btn--cta,
243
+ :global([data-theme="dark"]) .btn--compact,
244
+ :global([data-theme="dark"]) .btn--primary {
245
+ background: var(--gold);
246
+ border-color: var(--gold);
247
+ color: var(--dark-bg);
248
+ }
249
+
250
+ :global([data-theme="dark"]) .btn--cta:hover,
251
+ :global([data-theme="dark"]) .btn--cta:focus-visible,
252
+ :global([data-theme="dark"]) .btn--compact:hover,
253
+ :global([data-theme="dark"]) .btn--compact:focus-visible,
254
+ :global([data-theme="dark"]) .btn--primary:hover,
255
+ :global([data-theme="dark"]) .btn--primary:focus-visible {
256
+ background: color-mix(in srgb, var(--gold) 85%, #fff);
257
+ border-color: color-mix(in srgb, var(--gold) 85%, #fff);
258
+ color: var(--dark-bg);
259
+ }
260
260
  </style>
@@ -0,0 +1,65 @@
1
+ /**
2
+ * A page can be a draft (`draft: true`): kept in the repo, but not on the site. A menu link to
3
+ * a draft would lead to "page not found", so the menu leaves those links out, and publishing
4
+ * the page brings its link back without anyone editing the menu (myai4-webdev #119).
5
+ *
6
+ * Pure, so it is unit-tested without an Astro content context; `lib/siteSettings` applies it.
7
+ */
8
+ import type { NavGroup, NavLink } from '../content/schemas';
9
+
10
+ export interface Navigation {
11
+ primary: NavLink[];
12
+ footer: NavLink[];
13
+ footerGroups: Array<{ heading: string; links: NavLink[] }>;
14
+ dropdown?: NavGroup;
15
+ cta: { label: string; href: string } | null;
16
+ }
17
+
18
+ /** The address of a `pages` entry: `index` is home (`/`), any other id is `/<id>`. */
19
+ function addressOf(id: string): string {
20
+ return id === 'index' ? '/' : `/${id}`;
21
+ }
22
+
23
+ /** The addresses of the draft pages (no trailing slash; home is `/`). */
24
+ export function draftAddresses(pages: Array<{ id: string; data: { draft?: boolean } }>): Set<string> {
25
+ return new Set(pages.filter((p) => p.data.draft === true).map((p) => addressOf(p.id)));
26
+ }
27
+
28
+ /** A link's address on this site, normalised to compare with draftAddresses; null when it
29
+ * leads off the site (another domain, mailto:, tel:, an in-page #anchor). */
30
+ function siteAddress(href: string): string | null {
31
+ if (!href.startsWith('/') || href.startsWith('//')) return null;
32
+ const path = href.split(/[?#]/)[0];
33
+ return path.length > 1 ? path.replace(/\/+$/, '') : '/';
34
+ }
35
+
36
+ /** The navigation with every link to a draft page left out. */
37
+ export function hideDraftLinks<N extends Navigation>(nav: N, drafts: Set<string>): N {
38
+ if (!drafts.size) return nav;
39
+ const live = (href: string) => {
40
+ const a = siteAddress(href);
41
+ return a === null || !drafts.has(a);
42
+ };
43
+ const keep = (links: NavLink[]) => links.filter((l) => live(l.href));
44
+
45
+ let dropdown = nav.dropdown;
46
+ if (dropdown) {
47
+ const items = dropdown.items.filter((i) => live(i.href));
48
+ if (live(dropdown.href)) dropdown = { ...dropdown, items };
49
+ else dropdown = items.length ? { ...dropdown, href: items[0].href, items } : undefined;
50
+ }
51
+
52
+ let cta = nav.cta;
53
+ if (cta && !live(cta.href)) cta = live('/contact/') ? { label: 'Contact', href: '/contact/' } : null;
54
+
55
+ return {
56
+ ...nav,
57
+ primary: keep(nav.primary),
58
+ footer: keep(nav.footer),
59
+ footerGroups: nav.footerGroups
60
+ .map((g) => ({ ...g, links: keep(g.links) }))
61
+ .filter((g) => g.links.length > 0),
62
+ dropdown,
63
+ cta,
64
+ };
65
+ }
@@ -11,7 +11,8 @@
11
11
  * `schema.parse()` does. We re-parse each entry through its own schema so nested
12
12
  * defaults are fully populated, including when a file is missing.
13
13
  */
14
- import { getEntry } from 'astro:content';
14
+ import { getCollection, getEntry } from 'astro:content';
15
+ import { draftAddresses, hideDraftLinks } from './draft-links';
15
16
  import {
16
17
  footerSettingsSchema,
17
18
  logoSettingsSchema,
@@ -37,24 +38,29 @@ let cached: LoadedSiteSettings | null = null;
37
38
  export async function loadSiteSettings(): Promise<LoadedSiteSettings> {
38
39
  if (cached) return cached;
39
40
 
40
- const [siteSettingsEntry, logoEntry, navbarEntry, footerEntry, themeEntry] = await Promise.all([
41
+ const [siteSettingsEntry, logoEntry, navbarEntry, footerEntry, themeEntry, pageEntries] = await Promise.all([
41
42
  getEntry('siteSettings', 'index'),
42
43
  getEntry('logoSettings', 'index'),
43
44
  getEntry('navbarSettings', 'index'),
44
45
  getEntry('footerSettings', 'index'),
45
46
  getEntry('themeSettings', 'index'),
47
+ // Draft pages aren't on the site, so the menu leaves out links to them (lib/draft-links).
48
+ getCollection('pages').catch(() => []),
46
49
  ]);
47
50
 
48
51
  cached = {
49
52
  ...siteSettingsSchema.parse(siteSettingsEntry?.data ?? {}),
50
53
  ...logoSettingsSchema.parse(logoEntry?.data ?? {}),
51
- navigation: {
52
- primary: navbarSettingsSchema.parse(navbarEntry?.data ?? {}).primary,
53
- footer: footerSettingsSchema.parse(footerEntry?.data ?? {}).footer,
54
- footerGroups: footerSettingsSchema.parse(footerEntry?.data ?? {}).groups,
55
- dropdown: navbarSettingsSchema.parse(navbarEntry?.data ?? {}).dropdown,
56
- cta: navbarSettingsSchema.parse(navbarEntry?.data ?? {}).cta,
57
- },
54
+ navigation: hideDraftLinks(
55
+ {
56
+ primary: navbarSettingsSchema.parse(navbarEntry?.data ?? {}).primary,
57
+ footer: footerSettingsSchema.parse(footerEntry?.data ?? {}).footer,
58
+ footerGroups: footerSettingsSchema.parse(footerEntry?.data ?? {}).groups,
59
+ dropdown: navbarSettingsSchema.parse(navbarEntry?.data ?? {}).dropdown,
60
+ cta: navbarSettingsSchema.parse(navbarEntry?.data ?? {}).cta,
61
+ },
62
+ draftAddresses(pageEntries as Array<{ id: string; data: { draft?: boolean } }>),
63
+ ),
58
64
  theme: themeSettingsSchema.parse(themeEntry?.data ?? {}),
59
65
  };
60
66
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ferst-core",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
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",
@@ -50,6 +50,7 @@
50
50
  ],
51
51
  "bin": {
52
52
  "ferst-check-thin": "bin/check-thin.mjs",
53
+ "ferst-check-pages": "bin/check-pages.mjs",
53
54
  "ferst-set-cms-branch": "bin/set-cms-branch.mjs",
54
55
  "ferst-cms-config": "bin/cms-config.mjs",
55
56
  "ferst-update": "bin/ferst-update.mjs",
@@ -1,108 +0,0 @@
1
- /**
2
- * CMS design-tokens live preview (PDLC Phase 1 / WS4) — SPIKE artifact.
3
- *
4
- * Registers a Sveltia/Decap preview template for the `theme` file collection that
5
- * embeds an iframe of the live site (?preview=1) and pushes the editor's CURRENT
6
- * (unsaved) token values to it over postMessage — same-origin, since /admin and
7
- * the site share the client domain. Re-themes live via ferst-core's site-side
8
- * listener (lib/theme-preview.ts). Save is the CMS's existing git-proxy write.
9
- *
10
- * STATUS: unverified against the deployed Sveltia (pre-1.0; docs warn of Decap
11
- * preview-template compat gaps). It is fully GUARDED — if the API isn't present or
12
- * differs, it logs once and no-ops, so it can never break the CMS. The portal
13
- * Theme Studio is the guaranteed token surface until the dev spike confirms this.
14
- *
15
- * Include from a client's public/admin/index.html AFTER the Sveltia bundle:
16
- * <script src="/ferst/theme-preview.js"></script> (copied from ferst-core/cms)
17
- */
18
- (function () {
19
- 'use strict';
20
-
21
- var MSG = { theme: 'ferst:preview:theme', ready: 'ferst:preview:ready' };
22
- // Match the CMS theme collection's fields (config.yml `theme` file).
23
- var FIELDS = ['brand', 'ink', 'surface', 'corners', 'elevation', 'stroke', 'fields', 'darkDepth', 'darkChroma'];
24
-
25
- function log(msg) {
26
- try {
27
- console.info('[ferst theme-preview] ' + msg);
28
- } catch (_) {}
29
- }
30
-
31
- // Read the live entry into a themeSettings-shaped draft (Immutable Map API).
32
- function draftFromEntry(entry) {
33
- var get = function (k) {
34
- try {
35
- return entry && entry.getIn ? entry.getIn(['data', k]) : undefined;
36
- } catch (_) {
37
- return undefined;
38
- }
39
- };
40
- var fonts = get('fonts') || {};
41
- var ov = get('darkOverrides') || {};
42
- var pick = function (o, k) {
43
- return o && typeof o.get === 'function' ? o.get(k) : o ? o[k] : '';
44
- };
45
- return {
46
- brand: get('brand') || '',
47
- ink: get('ink') || '',
48
- surface: get('surface') || '',
49
- fonts: { heading: pick(fonts, 'heading') || '', body: pick(fonts, 'body') || '', display: pick(fonts, 'display') || '' },
50
- corners: get('corners') || 'rounded',
51
- elevation: get('elevation') || 'raised',
52
- stroke: get('stroke') || 'on',
53
- fields: get('fields') || 'boxed',
54
- darkDepth: typeof get('darkDepth') === 'number' ? get('darkDepth') : 0.21,
55
- darkChroma: typeof get('darkChroma') === 'number' ? get('darkChroma') : 0.05,
56
- darkOverrides: { ground: pick(ov, 'ground') || '', text: pick(ov, 'text') || '', accent: pick(ov, 'accent') || '' },
57
- };
58
- }
59
-
60
- function register(CMS, React) {
61
- var Preview = function (props) {
62
- // Keep one iframe of the live site in the preview pane; push the draft on
63
- // every render (Sveltia re-renders as the editor types) and on ready.
64
- var doc = props.document || document;
65
- var frame = doc.getElementById('ferst-preview-frame');
66
- if (!frame) {
67
- frame = doc.createElement('iframe');
68
- frame.id = 'ferst-preview-frame';
69
- frame.src = '/?preview=1';
70
- frame.style.cssText = 'width:100%;height:100%;min-height:80vh;border:0';
71
- (doc.body || doc.documentElement).appendChild(frame);
72
- (props.window || window).addEventListener('message', function (e) {
73
- if (e && e.data && e.data.type === MSG.ready) postDraft();
74
- });
75
- }
76
- function postDraft() {
77
- try {
78
- frame.contentWindow.postMessage({ type: MSG.theme, theme: draftFromEntry(props.entry) }, window.location.origin);
79
- } catch (_) {}
80
- }
81
- postDraft();
82
- // Render nothing of our own into React's tree — we own the iframe directly.
83
- return React && React.createElement ? React.createElement('div', { style: { display: 'none' } }) : null;
84
- };
85
- CMS.registerPreviewTemplate('theme', Preview);
86
- log('registered live preview for the theme collection');
87
- void FIELDS; // documents the fields this mirrors
88
- }
89
-
90
- var tries = 0;
91
- (function wait() {
92
- var CMS = window.CMS;
93
- var React = window.React || window.h || (CMS && CMS.React);
94
- if (CMS && typeof CMS.registerPreviewTemplate === 'function') {
95
- try {
96
- register(CMS, React);
97
- } catch (err) {
98
- log('registerPreviewTemplate failed — in-pane preview disabled (use the portal Theme Studio). ' + (err && err.message));
99
- }
100
- return;
101
- }
102
- if (tries++ < 40) {
103
- setTimeout(wait, 250); // CMS loads async as an ES module
104
- } else {
105
- log('CMS.registerPreviewTemplate not found — in-pane preview unavailable in this CMS build.');
106
- }
107
- })();
108
- })();