create-website-build-kit 0.1.16 → 0.1.17
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-website-build-kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "Scaffold a production marketing site \u2014 Astro on Cloudflare Workers, with the gates, the migration playbook and the accessibility work already wired.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
package/template/CLAUDE.md
CHANGED
|
@@ -111,6 +111,11 @@ weakened scrim.** On a real site two of three regions could not fail at any phot
|
|
|
111
111
|
exposure was a scrim lightened from 92% to 62% so a client's photography could show its colour.
|
|
112
112
|
This check is what makes weakening one safe.
|
|
113
113
|
|
|
114
|
+
**Navigation may be CMS-managed; redirects may not.** `check:cms` resolves every internal path in
|
|
115
|
+
CMS-managed data against `src/pages`, so a menu item pointing at a missing page fails the build
|
|
116
|
+
rather than 404ing for a visitor. A redirect has no such check — a client toggling one off is
|
|
117
|
+
silent traffic loss — so it stays in code.
|
|
118
|
+
|
|
114
119
|
⚠ **A CMS DELETES EVERY KEY ITS SCHEMA FORGOT.** It rewrites the whole file from the schema, so
|
|
115
120
|
anything undeclared is absent from what it writes back — the client changes one field, saves, and
|
|
116
121
|
the rest is gone, looking like an ordinary content commit. `npm run check:cms` refuses a
|
|
@@ -42,6 +42,7 @@ import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
|
42
42
|
import { join, relative, sep } from 'node:path';
|
|
43
43
|
import { parse } from 'yaml';
|
|
44
44
|
import { literalImages } from './lib/literal-images.mjs';
|
|
45
|
+
import { routeExists, routesFromPages } from './lib/routes.mjs';
|
|
45
46
|
|
|
46
47
|
const RESET = '\x1b[0m';
|
|
47
48
|
const RED = '\x1b[31m';
|
|
@@ -322,6 +323,83 @@ for (const entry of entries) {
|
|
|
322
323
|
}
|
|
323
324
|
}
|
|
324
325
|
|
|
326
|
+
/* ── internal links a client can type ────────────────────────────────────── */
|
|
327
|
+
|
|
328
|
+
/*
|
|
329
|
+
* ⚠ THIS IS WHAT MAKES NAVIGATION SAFE TO PUT IN A CMS.
|
|
330
|
+
*
|
|
331
|
+
* `stacks.md` kept nav out of the CMS for a good reason — a bad value should
|
|
332
|
+
* fail the build, not publish. A typo'd path gives a menu item leading to a
|
|
333
|
+
* 404: the page renders, nothing errors, and only a visitor finds it.
|
|
334
|
+
*
|
|
335
|
+
* But navigation was missing from all five audited sites, so every client had
|
|
336
|
+
* to ask for a menu change. That is not a rule being respected, it is a gap
|
|
337
|
+
* the rule creates. The answer is not to forbid the field, it is to verify
|
|
338
|
+
* it — before the build, while somebody is still looking at the config.
|
|
339
|
+
*
|
|
340
|
+
* ⚠ A DYNAMIC ROUTE IS A PATTERN. `[slug].astro` serves every legal page, so
|
|
341
|
+
* treating routes as literal strings would report most of a site as broken.
|
|
342
|
+
* `routesFromPages` returns patterns for those and `routeExists` matches them.
|
|
343
|
+
*
|
|
344
|
+
* External links, `mailto:`, `tel:` and bare anchors are somebody else's
|
|
345
|
+
* problem — `verify` checks those against the deployed site, where they can
|
|
346
|
+
* actually be resolved.
|
|
347
|
+
*/
|
|
348
|
+
const LINKISH = /(^|\.)(href|url|link|to|target|destination)$/i;
|
|
349
|
+
const routes = routesFromPages();
|
|
350
|
+
const brokenLinks = [];
|
|
351
|
+
|
|
352
|
+
if (routes.static.size || routes.dynamic.length) {
|
|
353
|
+
for (const entry of entries) {
|
|
354
|
+
const documents = [];
|
|
355
|
+
if (entry?.type === 'collection' && existsSync(entry.path ?? '')) {
|
|
356
|
+
const walk = (d) =>
|
|
357
|
+
readdirSync(d).flatMap((e) => {
|
|
358
|
+
const full = join(d, e);
|
|
359
|
+
return statSync(full).isDirectory() ? walk(full) : [full];
|
|
360
|
+
});
|
|
361
|
+
for (const file of walk(entry.path).filter((f) => /\.mdx?$/.test(f))) {
|
|
362
|
+
const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(readFileSync(file, 'utf8'));
|
|
363
|
+
if (!m) continue;
|
|
364
|
+
try {
|
|
365
|
+
documents.push({ where: rel(file), data: parse(m[1]) ?? {} });
|
|
366
|
+
} catch {
|
|
367
|
+
/* reported elsewhere */
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
} else if (/\.json$/.test(entry?.path ?? '') && existsSync(entry.path)) {
|
|
371
|
+
try {
|
|
372
|
+
documents.push({ where: rel(entry.path), data: JSON.parse(readFileSync(entry.path, 'utf8')) });
|
|
373
|
+
} catch {
|
|
374
|
+
/* reported above */
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
for (const doc of documents) {
|
|
379
|
+
const visit = (value, path) => {
|
|
380
|
+
if (Array.isArray(value)) return value.forEach((v) => visit(v, path));
|
|
381
|
+
if (value && typeof value === 'object') {
|
|
382
|
+
for (const [k, v] of Object.entries(value)) visit(v, path ? `${path}.${k}` : k);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
if (typeof value !== 'string' || !LINKISH.test(path)) return;
|
|
386
|
+
if (!value.startsWith('/')) return; // external, mailto:, tel:, #anchor
|
|
387
|
+
if (routeExists(value, routes)) return;
|
|
388
|
+
brokenLinks.push({ where: doc.where, path, value });
|
|
389
|
+
};
|
|
390
|
+
visit(doc.data, '');
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (brokenLinks.length) {
|
|
396
|
+
problems.push({
|
|
397
|
+
label: 'internal links',
|
|
398
|
+
why: `${brokenLinks.length} point at a page this site does not serve`,
|
|
399
|
+
links: brokenLinks,
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
325
403
|
/* ── coverage, and secrets ───────────────────────────────────────────────── */
|
|
326
404
|
|
|
327
405
|
/*
|
|
@@ -483,6 +561,16 @@ for (const p of problems) {
|
|
|
483
561
|
` the client will never touch — or move them out of a CMS-managed file.${RESET}`,
|
|
484
562
|
);
|
|
485
563
|
}
|
|
564
|
+
if (p.links) {
|
|
565
|
+
for (const l of p.links.slice(0, 8)) {
|
|
566
|
+
console.error(` ${DIM}${l.where} ${l.path} = ${JSON.stringify(l.value)}${RESET}`);
|
|
567
|
+
}
|
|
568
|
+
console.error(
|
|
569
|
+
` ${DIM}A menu item pointing at a missing page renders perfectly and 404s only\n` +
|
|
570
|
+
` for a visitor. This is what lets navigation be a CMS field at all: the\n` +
|
|
571
|
+
` value is checked before the build rather than trusted.${RESET}`,
|
|
572
|
+
);
|
|
573
|
+
}
|
|
486
574
|
if (p.picker) {
|
|
487
575
|
console.error(
|
|
488
576
|
` ${DIM}The site still renders this: <Img> accepts a manifest key as well as a\n` +
|
|
@@ -96,3 +96,70 @@ export async function discoverRoutes(origin, fetcher = fetch) {
|
|
|
96
96
|
|
|
97
97
|
return { routes: [], source: 'nothing — no sitemap and no dist/' };
|
|
98
98
|
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Routes derived from `src/pages`, without building anything.
|
|
102
|
+
*
|
|
103
|
+
* ── WHY NOT routesFromDist ─────────────────────────────────────────────────
|
|
104
|
+
* `check-cms.mjs` runs BEFORE the build, so `dist/` does not exist yet. The
|
|
105
|
+
* point of checking a navigation target early is to fail while somebody is
|
|
106
|
+
* still looking at the config, not after a deploy.
|
|
107
|
+
*
|
|
108
|
+
* Returns `{ static: Set<string>, dynamic: RegExp[] }`.
|
|
109
|
+
*
|
|
110
|
+
* ⚠ A DYNAMIC ROUTE IS A PATTERN, NOT A ROUTE. `[slug].astro` serves every
|
|
111
|
+
* legal page and `[...path].astro` serves any depth. Treating those as
|
|
112
|
+
* literal strings would report every real link through them as broken, which
|
|
113
|
+
* on a site with a `[slug]` catch-all is *most of the site* — a check that
|
|
114
|
+
* confident and that wrong gets switched off within a day.
|
|
115
|
+
*
|
|
116
|
+
* ⚠ ENDPOINTS ARE NOT PAGES. `robots.txt.ts` and `api/contact.ts` produce
|
|
117
|
+
* responses, never navigable pages, so they are excluded — nobody puts them
|
|
118
|
+
* in a menu and reporting them as available would be noise.
|
|
119
|
+
*/
|
|
120
|
+
export function routesFromPages(dir = 'src/pages') {
|
|
121
|
+
const out = { static: new Set(), dynamic: [] };
|
|
122
|
+
if (!existsSync(dir)) return out;
|
|
123
|
+
|
|
124
|
+
const walk = (d) =>
|
|
125
|
+
readdirSync(d, { withFileTypes: true }).flatMap((e) => {
|
|
126
|
+
const full = join(d, e.name);
|
|
127
|
+
return e.isDirectory() ? walk(full) : [full];
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
for (const file of walk(dir)) {
|
|
131
|
+
const rel = relative(dir, file).split(sep).join('/');
|
|
132
|
+
/* `_` prefixed files and directories are not routed by Astro. */
|
|
133
|
+
if (rel.split('/').some((part) => part.startsWith('_'))) continue;
|
|
134
|
+
if (!/\.(astro|md|mdx)$/.test(rel)) continue; // .ts endpoints are not pages
|
|
135
|
+
|
|
136
|
+
const path =
|
|
137
|
+
'/' +
|
|
138
|
+
rel
|
|
139
|
+
.replace(/\.(astro|md|mdx)$/, '')
|
|
140
|
+
.replace(/(^|\/)index$/, '$1')
|
|
141
|
+
.replace(/\/$/, '');
|
|
142
|
+
const route = path === '/' ? '/' : `${path}/`.replace(/\/+/g, '/');
|
|
143
|
+
|
|
144
|
+
if (route.includes('[')) {
|
|
145
|
+
/* [...rest] matches any depth; [slug] matches one segment. */
|
|
146
|
+
const pattern = route
|
|
147
|
+
.replace(/[.*+?^${}()|\\]/g, '\\$&')
|
|
148
|
+
.replace(/\[\.\.\.[^\]]+\]/g, '.+')
|
|
149
|
+
.replace(/\[[^\]]+\]/g, '[^/]+');
|
|
150
|
+
out.dynamic.push(new RegExp(`^${pattern}$`));
|
|
151
|
+
} else {
|
|
152
|
+
out.static.add(route);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return out;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Does `href` correspond to a page this site serves? */
|
|
160
|
+
export function routeExists(href, routes) {
|
|
161
|
+
const path = href.split('#')[0].split('?')[0];
|
|
162
|
+
const normalised = path.endsWith('/') || path === '' ? path || '/' : `${path}/`;
|
|
163
|
+
if (routes.static.has(normalised)) return true;
|
|
164
|
+
return routes.dynamic.some((re) => re.test(normalised));
|
|
165
|
+
}
|