@cparkerwebm/webmonterey 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/README.md +6 -0
  3. package/dist/webm.mjs +445 -61
  4. package/package.json +5 -3
  5. package/skills/launch/SKILL.md +57 -9
  6. package/skills/start/SKILL.md +66 -12
  7. package/skills/traps/SKILL.md +17 -0
  8. package/src/assets/opengraph-webmaster.png +0 -0
  9. package/src/cli/audit.test.ts +120 -0
  10. package/src/cli/audit.ts +323 -0
  11. package/src/cli/checks.test.ts +46 -6
  12. package/src/cli/checks.ts +52 -12
  13. package/src/cli/doctor.ts +78 -2
  14. package/src/cli/scaffold.test.ts +9 -0
  15. package/src/cli/scaffold.ts +12 -30
  16. package/src/cli/settings.ts +106 -0
  17. package/src/cli/sync.test.ts +61 -0
  18. package/src/cli/sync.ts +64 -1
  19. package/src/emails/footer.ts +3 -3
  20. package/src/includes/cloudflare/r2/media.ts +1 -1
  21. package/src/includes/webmonterey/config.test.ts +51 -0
  22. package/src/includes/webmonterey/config.ts +49 -0
  23. package/src/includes/webmonterey/copy-defaults.ts +20 -0
  24. package/src/includes/webmonterey/webmaster/Webmaster.astro +52 -0
  25. package/src/includes/webmonterey/webmaster/webmaster.test.ts +74 -0
  26. package/src/includes/webmonterey/webmaster/webmaster.ts +89 -0
  27. package/src/integration/index.ts +91 -4
  28. package/src/integration/virtual.d.ts +19 -1
  29. package/src/layouts/base.astro +31 -8
  30. package/src/package.test.ts +20 -0
  31. package/src/pages/robots.txt.ts +14 -0
  32. package/src/pages/webmaster-og.png.ts +31 -0
  33. package/src/pages/webmaster.astro +121 -0
  34. package/template/public/opengraph.png +0 -0
  35. package/template/scripts/test-hooks.mjs +1 -1
  36. package/template/site/CLAUDE.md +25 -2
  37. package/src/includes/webmonterey/credits/Credit.astro +0 -80
  38. package/src/includes/webmonterey/credits/credit.test.ts +0 -111
  39. package/src/includes/webmonterey/credits/credit.ts +0 -59
  40. package/template/public/open-graph.png +0 -0
  41. /package/template/assets/{open-graph.png → opengraph.png} +0 -0
@@ -10,6 +10,7 @@
10
10
  */
11
11
  import { resourceNames } from './slug.ts';
12
12
  import { MCP_NAMES, mcpConfig } from './mcp.ts';
13
+ import { projectSettings } from './settings.ts';
13
14
 
14
15
  export interface ScaffoldOptions {
15
16
  domain: string;
@@ -151,7 +152,7 @@ export function scaffold(options: ScaffoldOptions): Record<string, string> {
151
152
  slug: n.slug,
152
153
  launched: null,
153
154
  '//environment':
154
- "What this deployment is FOR. 'staging' redirects EVERY email the site sends to stagingEmail below, so testing a form on a preview cannot reach the client's real contacts. A new site starts here; /webm:launch flips it to 'production'. Anything served from workers.dev is treated as staging regardless, so a branch preview of a live site is covered too.",
155
+ "What this deployment is FOR. 'staging' makes every build a PREVIEW - every page noindex with no canonical, no sitemap, robots.txt disallowing everything, no Google Tag Manager - on every hostname, main included, so a site that has not launched cannot be indexed before it exists; and it redirects EVERY email the site sends to stagingEmail below, so testing a form on a preview cannot reach the client's real contacts. A new site starts here; /webm:launch flips it to 'production' once the custom domain is live, and that flip is what makes the site indexable. A branch other than main is a preview regardless, and anything served from workers.dev redirects its mail regardless, so a branch preview of a live site is covered too.",
155
156
  environment: 'staging',
156
157
  '//stagingEmail':
157
158
  'Where staging email goes instead of its real recipients. REQUIRED while environment is staging - a staging site with nowhere to send refuses to send rather than guessing. webm doctor checks.',
@@ -250,33 +251,11 @@ export function scaffold(options: ScaffoldOptions): Record<string, string> {
250
251
  2,
251
252
  ) + '\n';
252
253
 
253
- files['.claude/settings.json'] =
254
- JSON.stringify(
255
- {
256
- '//': `Project settings for ${n.repo}.`,
257
- '//mcp':
258
- 'A server declared in .mcp.json is INERT until approved on each machine. Without this line the rules that say consult the Astro and MDN docs before using an API would depend on whoever cloned the repo happening to hit Approve.',
259
- includeCoAuthoredBy: false,
260
- enabledMcpjsonServers: MCP_NAMES,
261
- permissions: {
262
- deny: [
263
- 'Read(**/.dev.vars)',
264
- 'Read(**/.dev.vars.*)',
265
- 'Read(**/.env)',
266
- 'Read(**/.env.*)',
267
- 'Read(**/*.pem)',
268
- 'Read(**/*.key)',
269
- 'Read(**/.npmrc)',
270
- 'Edit(**/.dev.vars)',
271
- 'Edit(**/.env)',
272
- 'Write(**/.dev.vars)',
273
- 'Write(**/.env)',
274
- ],
275
- },
276
- },
277
- null,
278
- 2,
279
- ) + '\n';
254
+ /*
255
+ * The deny list comes from cli/settings.ts, the one place it is declared, so a new site and a
256
+ * `webm sync` on an old one agree about what a session may not touch.
257
+ */
258
+ files['.claude/settings.json'] = JSON.stringify(projectSettings(n.repo), null, 2) + '\n';
280
259
 
281
260
  files['.mcp.json'] = JSON.stringify(mcpConfig(), null, 2) + '\n';
282
261
 
@@ -418,8 +397,11 @@ export function scaffold(options: ScaffoldOptions): Record<string, string> {
418
397
  `domain Chrome could mistake for a lookalike. A second resource of one kind takes a purpose\n` +
419
398
  `suffix - \`${n.slug}-portal\`.\n\n` +
420
399
  `## Deploying\n\n` +
421
- `Push to deploy. A \`wrangler deploy\` from a laptop creates a version no build produced, so\n` +
422
- `history stops describing what is live and the next push reverts it.\n`;
400
+ `The Worker is created ONCE from a laptop - \`npm run build && npx wrangler deploy\` - and the\n` +
401
+ `repo is then connected to it in the dashboard (Worker Settings → Builds). /webm:start does\n` +
402
+ `both. From then on, push to deploy: a \`wrangler deploy\` from a laptop after that creates a\n` +
403
+ `version no build produced, so history stops describing what is live and the next push\n` +
404
+ `reverts it.\n`;
423
405
 
424
406
  return files;
425
407
  }
@@ -0,0 +1,106 @@
1
+ /*
2
+ * The Claude Code project settings a client repo carries, and the one list of what they deny.
3
+ *
4
+ * WHY A MODULE, like mcp.ts. Three places have to agree about these rules: the scaffold writes
5
+ * them into a new site, `webm sync` merges any that are missing into an existing site on every
6
+ * install, and the tests assert both against this list rather than a literal that falls one
7
+ * behind. `.claude/settings.json` is otherwise the site's own - a client adds allow rules to it -
8
+ * so it is MERGED, never replaced: the package's deny rules are added when absent and everything
9
+ * else in the file is left exactly as found.
10
+ *
11
+ * WHAT THE DENY RULES ENFORCE. Two things a session in a client repo must never do, made
12
+ * mechanical rather than advisory:
13
+ *
14
+ * - read a secret. .env, .dev.vars, keys, the npm config.
15
+ * - edit the package. Rule 12 of the site's CLAUDE.md: a session in a client repo never edits
16
+ * the package, not in node_modules and not in its checkout. The deliverable for an upstream
17
+ * problem is a description of the fix, run later in the package repo.
18
+ *
19
+ * THE SYNTAX, verified against code.claude.com/docs/en/permissions rather than recalled:
20
+ *
21
+ * - Read and Edit rules take gitignore patterns. As a DENY rule, `Edit(**\/node_modules/**)`
22
+ * matches a node_modules directory at any depth under the working directory.
23
+ * - `Edit` rules apply to every built-in tool that edits files - Edit, Write, MultiEdit and
24
+ * NotebookEdit. A `Write(...)` rule is accepted, never consulted, and warned about at
25
+ * startup, which is why none appears here and why the two that 1.2.0 scaffolded are removed.
26
+ * - A `Read` deny also blocks Edit and Write on the same path. The Edit rules for the secret
27
+ * files are therefore redundant, and kept: they say what is meant.
28
+ * - THERE IS NO PATTERN FOR "ANY PATH OUTSIDE THE PROJECT". A rule names a path - `//absolute`,
29
+ * `~/home-relative`, `/project-relative`, or cwd-relative - and nothing expresses the
30
+ * complement of one. The package checkout sitting beside a client repo on the same machine
31
+ * cannot be denied by rule without hardcoding where it is, and a public package does not
32
+ * know. Rule 12 in CLAUDE.md carries that half in prose.
33
+ */
34
+
35
+ import { MCP_NAMES } from './mcp.ts';
36
+
37
+ /** Every rule a site's settings must deny. Order is the order they are written. */
38
+ export const DENY_RULES: readonly string[] = [
39
+ 'Read(**/.dev.vars)',
40
+ 'Read(**/.dev.vars.*)',
41
+ 'Read(**/.env)',
42
+ 'Read(**/.env.*)',
43
+ 'Read(**/*.pem)',
44
+ 'Read(**/*.key)',
45
+ 'Read(**/.npmrc)',
46
+ 'Edit(**/.dev.vars)',
47
+ 'Edit(**/.env)',
48
+ 'Edit(**/node_modules/**)',
49
+ ];
50
+
51
+ /**
52
+ * Rules an earlier scaffold wrote that Claude Code never consults and warns about at startup.
53
+ * Removed on sync, by exact string, so a rule the site wrote itself is never touched.
54
+ */
55
+ export const STALE_RULES: readonly string[] = ['Write(**/.dev.vars)', 'Write(**/.env)'];
56
+
57
+ const PERMISSIONS_NOTE =
58
+ 'The deny list is package-managed: `webm sync` adds any rule that is missing on every ' +
59
+ 'install and leaves everything else in this file alone. Edit(**/node_modules/**) is rule 12 ' +
60
+ 'of CLAUDE.md made mechanical - a session in this repo never edits the package.';
61
+
62
+ /** The whole file, for a new site. */
63
+ export function projectSettings(repo: string): Record<string, unknown> {
64
+ return {
65
+ '//': `Project settings for ${repo}.`,
66
+ '//mcp':
67
+ 'A server declared in .mcp.json is INERT until approved on each machine. Without this line the rules that say consult the Astro and MDN docs before using an API would depend on whoever cloned the repo happening to hit Approve.',
68
+ includeCoAuthoredBy: false,
69
+ enabledMcpjsonServers: [...MCP_NAMES],
70
+ '//permissions': PERMISSIONS_NOTE,
71
+ permissions: { deny: [...DENY_RULES] },
72
+ };
73
+ }
74
+
75
+ /**
76
+ * An existing settings file with the package's deny rules present and the stale ones gone.
77
+ *
78
+ * IDEMPOTENT, and additive everywhere else: a second pass reports nothing and changes nothing,
79
+ * and a rule the site added itself - an allow list, a deny of its own - survives untouched. The
80
+ * site's own rules keep their order; the package's are appended in DENY_RULES order.
81
+ */
82
+ export function withDenyRules(settings: Record<string, unknown>): {
83
+ settings: Record<string, unknown>;
84
+ added: string[];
85
+ removed: string[];
86
+ } {
87
+ const permissions =
88
+ settings.permissions && typeof settings.permissions === 'object'
89
+ ? { ...(settings.permissions as Record<string, unknown>) }
90
+ : {};
91
+ const current = Array.isArray(permissions.deny)
92
+ ? (permissions.deny as unknown[]).filter((r): r is string => typeof r === 'string')
93
+ : [];
94
+
95
+ const removed = current.filter((r) => STALE_RULES.includes(r));
96
+ const kept = current.filter((r) => !STALE_RULES.includes(r));
97
+ const added = DENY_RULES.filter((r) => !kept.includes(r));
98
+ if (!added.length && !removed.length) return { settings, added, removed };
99
+
100
+ permissions.deny = [...kept, ...added];
101
+ return {
102
+ settings: { ...settings, '//permissions': PERMISSIONS_NOTE, permissions },
103
+ added,
104
+ removed,
105
+ };
106
+ }
@@ -11,6 +11,7 @@ import {
11
11
  import { tmpdir } from 'node:os';
12
12
  import { join } from 'node:path';
13
13
  import { sync } from './sync.ts';
14
+ import { DENY_RULES, STALE_RULES } from './settings.ts';
14
15
 
15
16
  const site = () => mkdtempSync(join(tmpdir(), 'webm-sync-'));
16
17
 
@@ -135,3 +136,63 @@ test('the migrations README rides along, so the --remote trap is documented in t
135
136
  sync(dir);
136
137
  assert.match(readFileSync(join(dir, 'migrations', 'README.md'), 'utf8'), /--remote/);
137
138
  });
139
+
140
+ test('the package deny rules are MERGED into .claude/settings.json, never replacing it', () => {
141
+ const dir = site();
142
+ mkdirSync(join(dir, '.claude'), { recursive: true });
143
+ const path = join(dir, '.claude/settings.json');
144
+ writeFileSync(
145
+ path,
146
+ JSON.stringify({
147
+ '//': 'theirs',
148
+ enabledMcpjsonServers: ['astro-docs'],
149
+ permissions: {
150
+ allow: ['Bash(npm run *)'],
151
+ deny: ['Read(**/.env)', 'Write(**/.env)', 'Edit(/secrets/**)'],
152
+ },
153
+ }),
154
+ );
155
+
156
+ const first = sync(dir);
157
+ const written = JSON.parse(readFileSync(path, 'utf8'));
158
+ assert.ok(first.settings.added.includes('Edit(**/node_modules/**)'), 'rule 12 lands');
159
+ assert.deepEqual(first.settings.removed, ['Write(**/.env)'], 'the rule Claude Code warns about');
160
+ assert.equal(written['//'], 'theirs');
161
+ assert.deepEqual(written.enabledMcpjsonServers, ['astro-docs'], 'not touched by this');
162
+ assert.deepEqual(
163
+ written.permissions.allow,
164
+ ['Bash(npm run *)'],
165
+ "the site's allow list survives",
166
+ );
167
+ assert.ok(written.permissions.deny.includes('Edit(/secrets/**)'), "the site's own deny survives");
168
+ for (const rule of DENY_RULES) assert.ok(written.permissions.deny.includes(rule), rule);
169
+ for (const rule of STALE_RULES) assert.ok(!written.permissions.deny.includes(rule), rule);
170
+ assert.equal(
171
+ written.permissions.deny.filter((r: string) => r === 'Read(**/.env)').length,
172
+ 1,
173
+ 'a rule already there is not doubled',
174
+ );
175
+
176
+ /* Idempotent: the second pass reports nothing and rewrites nothing. */
177
+ const before = readFileSync(path, 'utf8');
178
+ const second = sync(dir);
179
+ assert.deepEqual(second.settings, { added: [], removed: [], created: false, skipped: null });
180
+ assert.equal(readFileSync(path, 'utf8'), before);
181
+ });
182
+
183
+ test('a site with no settings file gets the scaffold defaults', () => {
184
+ const dir = site();
185
+ const result = sync(dir);
186
+ assert.equal(result.settings.created, true);
187
+ const written = JSON.parse(readFileSync(join(dir, '.claude/settings.json'), 'utf8'));
188
+ assert.deepEqual(written.permissions.deny, [...DENY_RULES]);
189
+ });
190
+
191
+ test('a settings file that will not parse is left alone and reported', () => {
192
+ const dir = site();
193
+ mkdirSync(join(dir, '.claude'), { recursive: true });
194
+ writeFileSync(join(dir, '.claude/settings.json'), '{ not json');
195
+ const result = sync(dir);
196
+ assert.ok(result.settings.skipped);
197
+ assert.equal(readFileSync(join(dir, '.claude/settings.json'), 'utf8'), '{ not json');
198
+ });
package/src/cli/sync.ts CHANGED
@@ -26,6 +26,9 @@
26
26
  * a real D1 database must NEVER change - SQLite has already run
27
27
  * it and wrangler tracks it by name. Later versions add 0002,
28
28
  * they do not rewrite 0001.
29
+ * MERGE .claude/settings.json The package's deny rules are added when absent and the file
30
+ * is otherwise left as found - a client's allow list is theirs.
31
+ * See cli/settings.ts for the rules and why they are rules.
29
32
  * SEED public/, content Written once by `webm new` and then the client's outright.
30
33
  * Not handled here at all - see cli/scaffold.ts.
31
34
  *
@@ -46,8 +49,9 @@ import {
46
49
  writeFileSync,
47
50
  readdirSync,
48
51
  } from 'node:fs';
49
- import { basename, join } from 'node:path';
52
+ import { basename, dirname, join } from 'node:path';
50
53
  import { PACKAGE_ROOT, packageVersion } from './package-root.ts';
54
+ import { DENY_RULES, projectSettings, withDenyRules } from './settings.ts';
51
55
 
52
56
  /**
53
57
  * The namespace. Rule 5's prefix: the CLI is `webm`, the tokens are --webm-*, the classes are
@@ -68,6 +72,11 @@ interface SyncResult {
68
72
  workflows: string[];
69
73
  /** Migrations copied because the site did not have them. Never includes an existing file. */
70
74
  migrations: string[];
75
+ /**
76
+ * What changed in .claude/settings.json: deny rules added, stale ones removed, the file
77
+ * created when there was none, or why it was left alone.
78
+ */
79
+ settings: { added: string[]; removed: string[]; created: boolean; skipped: string | null };
71
80
  }
72
81
 
73
82
  /**
@@ -119,6 +128,46 @@ function addMissing(source: string, target: string): string[] {
119
128
  return added.sort();
120
129
  }
121
130
 
131
+ /**
132
+ * MERGE. The package's deny rules into the site's settings, and nothing else.
133
+ *
134
+ * `.claude/settings.json` is the site's: a client adds allow rules to it, and a full replace would
135
+ * throw those away on the next install. So the file is read, the rules in cli/settings.ts are
136
+ * added where absent, the two rules Claude Code warns about at startup are dropped, and the file
137
+ * is written back only when that changed something - a second pass is a no-op. A file that will
138
+ * not parse is left exactly as it is and reported: Claude Code cannot read it either, and
139
+ * rewriting it would hide that.
140
+ *
141
+ * Created from the scaffold's defaults when there is none, so a site that predates the file gets
142
+ * the rules on its next install rather than never.
143
+ */
144
+ function ensureSettings(siteRoot: string): SyncResult['settings'] {
145
+ const path = join(siteRoot, '.claude', 'settings.json');
146
+ if (!existsSync(path)) {
147
+ mkdirSync(dirname(path), { recursive: true });
148
+ writeFileSync(path, JSON.stringify(projectSettings(basename(siteRoot)), null, 2) + '\n');
149
+ return { added: [...DENY_RULES], removed: [], created: true, skipped: null };
150
+ }
151
+
152
+ let parsed: Record<string, unknown>;
153
+ try {
154
+ parsed = JSON.parse(readFileSync(path, 'utf8')) as Record<string, unknown>;
155
+ } catch {
156
+ return {
157
+ added: [],
158
+ removed: [],
159
+ created: false,
160
+ skipped: '.claude/settings.json is not valid JSON, so it was left alone',
161
+ };
162
+ }
163
+
164
+ const { settings, added, removed } = withDenyRules(parsed);
165
+ if (added.length || removed.length) {
166
+ writeFileSync(path, JSON.stringify(settings, null, 2) + '\n');
167
+ }
168
+ return { added, removed, created: false, skipped: null };
169
+ }
170
+
122
171
  function listSkills(dir: string): string[] {
123
172
  if (!existsSync(dir)) return [];
124
173
  return readdirSync(dir, { withFileTypes: true })
@@ -207,6 +256,7 @@ export function sync(siteRoot: string): SyncResult {
207
256
  */
208
257
  workflows: syncDir(join(template, 'workflows'), join(siteRoot, '.github/workflows')),
209
258
  migrations: addMissing(join(template, 'migrations'), join(siteRoot, 'migrations')),
259
+ settings: ensureSettings(siteRoot),
210
260
  };
211
261
  }
212
262
 
@@ -245,6 +295,19 @@ export function run(argv: string[]): number {
245
295
  for (const m of result.migrations) {
246
296
  console.log(` + migrations/${m} (apply it: npx wrangler d1 migrations apply <DB> --remote)`);
247
297
  }
298
+ if (result.settings.created) {
299
+ console.log(` + .claude/settings.json`);
300
+ } else if (result.settings.skipped) {
301
+ console.log(` ${result.settings.skipped}`);
302
+ } else if (result.settings.added.length || result.settings.removed.length) {
303
+ const parts = [
304
+ result.settings.added.length && `+${result.settings.added.length} deny`,
305
+ result.settings.removed.length && `-${result.settings.removed.length} stale`,
306
+ ].filter(Boolean);
307
+ console.log(
308
+ ` .claude/settings.json: ${parts.join(', ')} (package-managed rules; yours are kept)`,
309
+ );
310
+ }
248
311
 
249
312
  if (ensureGitignored(siteRoot)) {
250
313
  console.log(` gitignored .claude/skills/${NAMESPACE}/`);
@@ -14,7 +14,7 @@
14
14
  * constant — and a caller that has to remember to pass the year eventually forgets, which
15
15
  * shows up as a stale copyright the following January.
16
16
  */
17
- import { CREDIT_TEXT, creditUrl } from '../includes/webmonterey/credits/credit.ts';
17
+ import { CREDIT_TEXT, creditUrl } from '../includes/webmonterey/webmaster/webmaster.ts';
18
18
  import { DEFAULT_COPY, fill } from '../includes/webmonterey/copy-defaults.ts';
19
19
 
20
20
  export interface EmailFooterInput {
@@ -75,13 +75,13 @@ export function renderFooterHtml(input: EmailFooterInput): string {
75
75
  * in a browser is the expected behavior, so the warning would be noise about something no
76
76
  * reader was surprised by. Nothing is lost that email a11y actually asks for.
77
77
  *
78
- * `title` is absent from both links ON PURPOSE, here and in Credit.astro. It is not reliably
78
+ * `title` is absent from both links ON PURPOSE, here and in Webmaster.astro. It is not reliably
79
79
  * announced by screen readers, is unreachable by keyboard and touch entirely, and either
80
80
  * duplicates the link text or competes with it for the accessible name. The link text is the
81
81
  * accessible name; that is the mechanism that works.
82
82
  *
83
83
  * `rel="noopener"` without `noreferrer`, also on purpose: the referrer IS the attribution.
84
- * Stripping it would leave only utm_content. See credit.ts.
84
+ * Stripping it would leave only utm_content. See webmaster.ts.
85
85
  */
86
86
  return ` <div style="max-width:640px;margin:0 auto;padding:24px 32px 8px;text-align:center;font-size:13px;line-height:1.6;color:#3f3f3f;">
87
87
  <p style="margin:0;">&copy; ${year} ${escapeHtml(input.client)}</p>
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * src/assets/ images the DESIGN uses — imported, hashed, optimised at build by sharp.
7
7
  * A logo, an icon, a hero shot. These belong in the repo.
8
- * public/ small fixed files that need a stable URL (favicons, open-graph.png).
8
+ * public/ small fixed files that need a stable URL (favicons, opengraph.png).
9
9
  * R2 (here) everything too large or too numerous to sit in git: video, audio, PDFs,
10
10
  * photo galleries, downloads, anything migrated wholesale off a WordPress
11
11
  * uploads folder.
@@ -3,9 +3,11 @@ import assert from 'node:assert/strict';
3
3
  import {
4
4
  APP_DIR,
5
5
  isConfigured,
6
+ isPreviewBuild,
6
7
  isStagingDeployment,
7
8
  isValidTimeZone,
8
9
  PLACEHOLDER,
10
+ previewReason,
9
11
  resolveAppPath,
10
12
  resolveDisplayName,
11
13
  workerFirstPaths,
@@ -92,3 +94,52 @@ test('shortName falls back to the display name when unset', () => {
92
94
  assert.equal(isConfigured('FoML'), true);
93
95
  assert.equal(isConfigured(''), false);
94
96
  });
97
+
98
+ /* --- preview builds ------------------------------------------------------ */
99
+
100
+ test('a staging site is a preview with no branch at all - the laptop build', () => {
101
+ assert.equal(isPreviewBuild({ environment: 'staging', branch: null }), true);
102
+ assert.equal(previewReason({ environment: 'staging', branch: null }), 'staging');
103
+ });
104
+
105
+ test('a staging site is a preview on main - the case that was crawlable', () => {
106
+ /* autire.webmonterey.workers.dev: main on Workers Builds, environment staging, and indexable
107
+ * because only a non-production BRANCH used to be a preview. */
108
+ assert.equal(isPreviewBuild({ environment: 'staging', branch: 'main' }), true);
109
+ assert.equal(previewReason({ environment: 'staging', branch: 'main' }), 'staging');
110
+ });
111
+
112
+ test('a production site with no branch is production output', () => {
113
+ assert.equal(isPreviewBuild({ environment: 'production', branch: null }), false);
114
+ assert.equal(previewReason({ environment: 'production', branch: null }), null);
115
+ });
116
+
117
+ test('a production site on main is production output', () => {
118
+ assert.equal(isPreviewBuild({ environment: 'production', branch: 'main' }), false);
119
+ });
120
+
121
+ test('a feature branch of a production site is still a preview', () => {
122
+ /* webmonterey.json is committed, so the branch inherits production from main. The branch rule
123
+ * is what keeps a launched site's review links out of the index. */
124
+ assert.equal(isPreviewBuild({ environment: 'production', branch: 'feature/x' }), true);
125
+ assert.equal(previewReason({ environment: 'production', branch: 'feature/x' }), 'branch');
126
+ });
127
+
128
+ test('productionBranch renames which branch is production', () => {
129
+ const on = { environment: 'production', productionBranch: 'release' } as const;
130
+ assert.equal(isPreviewBuild({ ...on, branch: 'release' }), false);
131
+ assert.equal(isPreviewBuild({ ...on, branch: 'main' }), true);
132
+ });
133
+
134
+ test('staging wins over the production branch, whatever it is called', () => {
135
+ assert.equal(
136
+ previewReason({ environment: 'staging', branch: 'release', productionBranch: 'release' }),
137
+ 'staging',
138
+ );
139
+ });
140
+
141
+ test('an unset environment is production, so a site predating the field builds as before', () => {
142
+ assert.equal(isPreviewBuild({ environment: undefined, branch: null }), false);
143
+ assert.equal(isPreviewBuild({ environment: undefined, branch: 'main' }), false);
144
+ assert.equal(isPreviewBuild({ environment: undefined, branch: 'feature/x' }), true);
145
+ });
@@ -125,6 +125,14 @@ export interface SiteConfig {
125
125
  * Read it anywhere via `environment`, `isStaging` and `isProduction` from webmonterey/site.
126
126
  * The first consumer is transactional email, which redirects every recipient to `stagingEmail`
127
127
  * on a staging deployment rather than mailing the client's real contacts from a preview.
128
+ *
129
+ * THE SECOND CONSUMER IS INDEXABILITY. A staging site is a PREVIEW BUILD on every hostname and
130
+ * in every build - laptop, `main` on Workers Builds, anywhere: every page is noindex with no
131
+ * canonical, there is no sitemap, robots.txt disallows everything, and Google Tag Manager does
132
+ * not load. Until this switch existed a site that had not launched was crawlable on its
133
+ * workers.dev URL the moment `main` deployed, because only a non-production BRANCH was a
134
+ * preview. See `isPreviewBuild`. Flipping this to production is therefore what makes a site
135
+ * indexable, which is why /webm:launch does it only once the custom domain is live.
128
136
  */
129
137
  environment?: 'production' | 'staging';
130
138
 
@@ -344,3 +352,44 @@ export function isStagingDeployment(
344
352
  /* Match the label, not a substring: a client domain ending "notworkers.dev" is not a preview. */
345
353
  return Boolean(hostname && /(^|\.)workers\.dev$/i.test(hostname));
346
354
  }
355
+
356
+ /** Which signal made a build a preview, or null for production output. */
357
+ export type PreviewReason = 'staging' | 'branch' | null;
358
+
359
+ /**
360
+ * Why this build is a preview - noindex on every page, no canonical, no sitemap, robots.txt
361
+ * disallowing everything, no analytics - or null when it is production output.
362
+ *
363
+ * TWO INDEPENDENT SIGNALS, for the same reason `isStagingDeployment` has two.
364
+ *
365
+ * `environment` is what the deployment is FOR. A site that has not launched says `staging`, and
366
+ * a site that has not launched must not be indexable ANYWHERE: not on a feature branch, not on
367
+ * `main`, not from a laptop. Before this signal existed only a non-production branch was a
368
+ * preview, so `main` on Workers Builds was production output for every site that had not gone
369
+ * live yet - indexable pages with a canonical, a sitemap and `Allow: /` on a public workers.dev
370
+ * hostname. autire.webmonterey.workers.dev was crawlable that way.
371
+ *
372
+ * The branch covers the opposite case: webmonterey.json is committed, so a feature branch of a
373
+ * LAUNCHED site inherits `production` from main and would build indexable pages under a review
374
+ * URL. Workers Builds injects WORKERS_CI_BRANCH; anything other than the production branch is a
375
+ * preview whatever the config says.
376
+ *
377
+ * An unset environment is production, as it is everywhere else - see SiteConfig.environment for
378
+ * why that default is the safe one - so a site predating the field builds exactly as before.
379
+ * `branch` is null when nothing injected one, which is every laptop build.
380
+ */
381
+ export function previewReason(input: {
382
+ environment: SiteConfig['environment'] | undefined;
383
+ branch: string | null | undefined;
384
+ productionBranch?: string;
385
+ }): PreviewReason {
386
+ if (input.environment === 'staging') return 'staging';
387
+ const branch = input.branch ?? null;
388
+ if (branch !== null && branch !== (input.productionBranch ?? 'main')) return 'branch';
389
+ return null;
390
+ }
391
+
392
+ /** Whether this build is a preview. `previewReason` says which signal decided it. */
393
+ export function isPreviewBuild(input: Parameters<typeof previewReason>[0]): boolean {
394
+ return previewReason(input) !== null;
395
+ }
@@ -67,6 +67,13 @@ export interface Copy {
67
67
  /** `{domain}` is replaced with the site's domain. */
68
68
  footerNotice: string;
69
69
  };
70
+ /** The /webmaster page. `intro` wraps the agency link: `before` <a>WebMonterey</a> `after`. */
71
+ webmaster: {
72
+ title: string;
73
+ description: string;
74
+ intro: { before: string; after: string };
75
+ body: string[];
76
+ };
70
77
  }
71
78
 
72
79
  /*
@@ -125,6 +132,19 @@ export const DEFAULT_COPY: Copy = {
125
132
  reference: 'Reference: #{id}',
126
133
  footerNotice: 'This is an automated notification for your account at the {domain} website.',
127
134
  },
135
+ webmaster: {
136
+ title: 'Our Webmaster',
137
+ description:
138
+ 'This website was designed, built and managed by WebMonterey, a webmaster maintenance service in Monterey, California.',
139
+ intro: {
140
+ before: 'This website was designed, built and managed by',
141
+ after:
142
+ ', a webmaster maintenance service in Monterey, California. WebMonterey handles the hosting, security, updates and ongoing care of the site so that we can focus on what we do.',
143
+ },
144
+ body: [
145
+ "If you have a question about this website, notice something that isn't working, or have trouble using a page, please let WebMonterey know and they will take care of it.",
146
+ ],
147
+ },
128
148
  };
129
149
 
130
150
  /** Merge the site's overrides over the defaults, key by key, at any depth. */
@@ -0,0 +1,52 @@
1
+ ---
2
+ /*
3
+ * The webmaster credit. Goes in the site footer.
4
+ *
5
+ * <Webmaster /> -> Powered by WebMonterey
6
+ *
7
+ * AN INTERNAL LINK. It points at the site's own /webmaster page, which the package injects on
8
+ * every site - so the visitor stays on the client's site, and the page they land on says who
9
+ * built it and who to contact when something is wrong. The outbound link to the agency lives on
10
+ * that page, once, with its UTM parameters. See webmaster.ts for why.
11
+ *
12
+ * No target, no rel: this is an ordinary same-site link and it navigates like one. The old
13
+ * outbound credit opened a new tab; an internal link that did would be a bug.
14
+ *
15
+ * NO `title` ATTRIBUTE, and that is the correct state rather than an omission. `title` is not
16
+ * reliably announced by screen readers, is unreachable by keyboard and touch entirely, and either
17
+ * duplicates the link text or competes with it for the accessible name.
18
+ */
19
+ import { CREDIT_TEXT, WEBMASTER_PATH } from './webmaster.ts';
20
+
21
+ interface Props {
22
+ class?: string;
23
+ }
24
+
25
+ const { class: className } = Astro.props;
26
+ ---
27
+
28
+ <p class:list={['webm-credit', className]}>
29
+ <a href={WEBMASTER_PATH}>{CREDIT_TEXT}</a>
30
+ </p>
31
+
32
+ <style>
33
+ @layer webm.components.core {
34
+ .webm-credit {
35
+ font-size: var(--webm-font-size-xs);
36
+ color: var(--webm-text-muted);
37
+ }
38
+
39
+ /*
40
+ * Underline at the text's own color. An underline in --webm-border-subtle is ~1.3:1 on
41
+ * white - effectively invisible, leaving nothing to mark the link as clickable.
42
+ */
43
+ .webm-credit a {
44
+ color: inherit;
45
+ text-decoration-color: currentColor;
46
+ }
47
+
48
+ .webm-credit a:hover {
49
+ color: var(--webm-link-hover);
50
+ }
51
+ }
52
+ </style>