@mccaskie-labs/workbench-site 0.9.0 → 0.10.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.
- package/CHANGELOG.md +8 -0
- package/README.md +5 -2
- package/dist/builder.d.ts +8 -2
- package/dist/builder.js +81 -22
- package/dist/cli.js +7 -5
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/recipe.d.ts +14 -2
- package/dist/recipe.js +18 -3
- package/dist/recipes/admin.js +5 -0
- package/dist/recipes/every-site.js +130 -3
- package/dist/recipes/members.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @mccaskie-labs/workbench-site
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Default pages step 1 (`docs/default-pages.md`): three new recipes, Questions and answers (`faq`, `/faq`), Accessibility (`accessibility`, `/accessibility`) and Something went wrong (`error`, no address, status 500).
|
|
8
|
+
- Every recipe has a `tier`: `always` (built without asking), `ticked` (suggested) or `offered` (shown unticked). Only About, Questions and answers and Accessibility are not always. `npx workbench-site add` with no pages named builds the always set (`alwaysSet()`), members pages left out; `list` shows each page's tier.
|
|
9
|
+
- `src/pages/index.ts` exports `errorPage(request, env)`, which draws Something went wrong in the site's look with status 500, never cached. The template's `src/index.ts` calls it when answering throws, and its starter `src/pages/index.ts` has it too: a project on an older template keeps its plain error until it takes the template update. The generated pages test checks a page that throws shows it.
|
|
10
|
+
|
|
3
11
|
## 0.9.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -3,12 +3,15 @@
|
|
|
3
3
|
A Workbench project's standard pages (`docs/site-planner.md`). Workbench builds the pages; the project's Claude goes over them with the owner and changes what they want.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
npx workbench-site list # the pages it can build
|
|
7
|
-
npx workbench-site add
|
|
6
|
+
npx workbench-site list # the pages it can build, and which are asked about
|
|
7
|
+
npx workbench-site add # build the pages every project has, without asking
|
|
8
|
+
npx workbench-site add about faq # and the ones the owner kept
|
|
8
9
|
npx workbench-site check # site.json matches the pages, every word is there
|
|
9
10
|
npx workbench-site check --live # and no [fill-in] is left, before going live
|
|
10
11
|
```
|
|
11
12
|
|
|
13
|
+
Every page has a tier (`docs/default-pages.md` §3). Always pages are built without asking: Home, Contact, Not found, Something went wrong (the site's own error page, shown when a page breaks), Admin home, Enquiries, Style guide, Looks and Design mode. The owner is asked about three: About and Questions and answers (ticked) and Accessibility (not ticked).
|
|
14
|
+
|
|
12
15
|
`add` writes, in a project made from Workbench's template:
|
|
13
16
|
|
|
14
17
|
| File | What it is |
|
package/dist/builder.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface BuildOptions {
|
|
|
25
25
|
read: (path: string) => string | undefined;
|
|
26
26
|
/** Lists a project folder's file names; undefined or empty when it doesn't exist. */
|
|
27
27
|
list?: (dir: string) => readonly string[] | undefined;
|
|
28
|
-
/** The recipe ids to add. */
|
|
28
|
+
/** The recipe ids to add. Empty builds the always set (alwaysSet). */
|
|
29
29
|
add: readonly string[];
|
|
30
30
|
/** This package's version, written into the page files and the project's dependency. */
|
|
31
31
|
version: string;
|
|
@@ -49,7 +49,13 @@ export interface BuildResult {
|
|
|
49
49
|
/** True when a form's answers file was written, so `npm run forms` must run. */
|
|
50
50
|
forms: boolean;
|
|
51
51
|
}
|
|
52
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* The pages every project gets without being asked (docs/default-pages.md §3):
|
|
54
|
+
* the always tier, members pages left out (they come when the project has
|
|
55
|
+
* members, default pages step 4).
|
|
56
|
+
*/
|
|
57
|
+
export declare function alwaysSet(catalogue?: readonly Recipe[]): string[];
|
|
58
|
+
/** Builds the chosen recipes into the project; with none chosen, the always set. */
|
|
53
59
|
export declare function buildSite(o: BuildOptions): BuildResult;
|
|
54
60
|
/** One problem with the site's record, its page files or their words. */
|
|
55
61
|
export interface SiteCheckInput {
|
package/dist/builder.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// It reads the project's files through `read` and returns what to write; the
|
|
8
8
|
// CLI (cli.ts) does the disk. A page already in workbench/site.json is never
|
|
9
9
|
// written again: once built, it is the project's.
|
|
10
|
-
import { recipeKeys, recipeProblems, SECTION_FUNCTIONS, STORE_SECTIONS, UI_SECTIONS } from "./recipe.js";
|
|
10
|
+
import { recipeKeys, recipeProblems, SECTION_FUNCTIONS, STORE_SECTIONS, UI_SECTIONS, UNADDRESSED } from "./recipe.js";
|
|
11
11
|
import { RECIPES } from "./recipes/index.js";
|
|
12
12
|
export const SITE_FILE = "workbench/site.json";
|
|
13
13
|
const PACKAGE = "@mccaskie-labs/workbench-site";
|
|
@@ -20,7 +20,15 @@ function readJson(read, path) {
|
|
|
20
20
|
return undefined;
|
|
21
21
|
return JSON.parse(text);
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* The pages every project gets without being asked (docs/default-pages.md §3):
|
|
25
|
+
* the always tier, members pages left out (they come when the project has
|
|
26
|
+
* members, default pages step 4).
|
|
27
|
+
*/
|
|
28
|
+
export function alwaysSet(catalogue = RECIPES) {
|
|
29
|
+
return catalogue.filter((r) => r.tier === "always" && r.area !== "members" && r.area !== "legal").map((r) => r.id);
|
|
30
|
+
}
|
|
31
|
+
/** Builds the chosen recipes into the project; with none chosen, the always set. */
|
|
24
32
|
export function buildSite(o) {
|
|
25
33
|
const catalogue = o.catalogue ?? RECIPES;
|
|
26
34
|
const base = o.base ?? "en-AU";
|
|
@@ -71,8 +79,8 @@ export function buildSite(o) {
|
|
|
71
79
|
}
|
|
72
80
|
added.push(id);
|
|
73
81
|
};
|
|
74
|
-
for (const id of o.add)
|
|
75
|
-
visit(id,
|
|
82
|
+
for (const id of o.add.length ? o.add : alwaysSet(catalogue))
|
|
83
|
+
visit(id, o.add.length > 0);
|
|
76
84
|
if (problems.length)
|
|
77
85
|
return fail();
|
|
78
86
|
const pages = [...site.pages];
|
|
@@ -82,8 +90,9 @@ export function buildSite(o) {
|
|
|
82
90
|
problems.push(`${id} would be at ${r.path}, where ${pages.find((p) => p.path === r.path).recipe} already is.`);
|
|
83
91
|
continue;
|
|
84
92
|
}
|
|
85
|
-
|
|
86
|
-
|
|
93
|
+
const same = r.path === null ? pages.find((p) => p.path === null && (byId.get(p.recipe)?.status ?? 404) === r.status) : undefined;
|
|
94
|
+
if (same) {
|
|
95
|
+
problems.push(`${id} would be the ${UNADDRESSED[r.status]} page, which ${same.recipe} already is.`);
|
|
87
96
|
continue;
|
|
88
97
|
}
|
|
89
98
|
if (o.read(fileOf(id)) !== undefined) {
|
|
@@ -102,9 +111,9 @@ export function buildSite(o) {
|
|
|
102
111
|
const helper = o.read("src/pages/site.ts");
|
|
103
112
|
if (helper === undefined || (helper !== SITE_HELPER && PAST_HELPERS.has(fnv(helper))))
|
|
104
113
|
writes["src/pages/site.ts"] = SITE_HELPER;
|
|
105
|
-
writes["src/pages/index.ts"] = indexFile(pages);
|
|
114
|
+
writes["src/pages/index.ts"] = indexFile(pages, byId);
|
|
106
115
|
writes["src/pages/nav.ts"] = navFile(pages, byId);
|
|
107
|
-
writes["test/pages.test.ts"] = testFile(base, pages);
|
|
116
|
+
writes["test/pages.test.ts"] = testFile(base, pages, byId);
|
|
108
117
|
// What the pages need besides their files: each written once, then the project's.
|
|
109
118
|
let forms = false;
|
|
110
119
|
const migrations = [];
|
|
@@ -324,15 +333,19 @@ function pageFile(r, version, base, pathOf) {
|
|
|
324
333
|
];
|
|
325
334
|
return lines.join("\n");
|
|
326
335
|
}
|
|
327
|
-
|
|
336
|
+
/** The page with no address that answers with this status (Not found's 404, Something went wrong's 500). */
|
|
337
|
+
const unaddressed = (pages, byId, status) => pages.find((p) => p.path === null && (byId.get(p.recipe)?.status ?? 404) === status);
|
|
338
|
+
function indexFile(pages, byId) {
|
|
339
|
+
const notFound = unaddressed(pages, byId, 404);
|
|
340
|
+
const broken = unaddressed(pages, byId, 500);
|
|
328
341
|
const sorted = [...pages].sort((a, b) => (a.recipe < b.recipe ? -1 : a.recipe > b.recipe ? 1 : 0));
|
|
329
342
|
const members = pages.some((p) => p.access !== "public");
|
|
330
343
|
const admin = pages.some((p) => p.access === "admin");
|
|
331
344
|
return [
|
|
332
345
|
`// Generated by ${PACKAGE} from workbench/site.json: \`npx workbench-site add <page>\``,
|
|
333
346
|
"// rewrites it. Each page's own file is the project's. src/index.ts hands",
|
|
334
|
-
"// every request the app's own routes didn't answer to sitePages,
|
|
335
|
-
"// page answers to notFoundPage. A page's access is checked here, before it",
|
|
347
|
+
"// every request the app's own routes didn't answer to sitePages, one no",
|
|
348
|
+
"// page answers to notFoundPage, and one that threw to errorPage. A page's access is checked here, before it",
|
|
336
349
|
"// is drawn: members pages need the app's sign-in, admin pages one of the",
|
|
337
350
|
"// app's admins (the same check as Brand settings).",
|
|
338
351
|
"",
|
|
@@ -354,10 +367,29 @@ function indexFile(pages) {
|
|
|
354
367
|
"}",
|
|
355
368
|
"",
|
|
356
369
|
"/** The page shown when no other answers (its status is 404); null when the site has none. */",
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
370
|
+
`export async function notFoundPage(${notFound ? "request" : "_request"}: Request, ${notFound ? "env" : "_env"}: Env, _url: URL): Promise<Response | null> {`,
|
|
371
|
+
...(notFound
|
|
372
|
+
? [' if (request.method !== "GET" && request.method !== "HEAD") return null;', ` return serve(${camel(notFound.recipe)}, request, env);`]
|
|
373
|
+
: [" return null;"]),
|
|
374
|
+
"}",
|
|
375
|
+
"",
|
|
376
|
+
"/**",
|
|
377
|
+
" * The page shown when answering threw (its status is 500), for any method; null",
|
|
378
|
+
" * when the site has none, or it can't be drawn either. Never kept by a cache.",
|
|
379
|
+
" */",
|
|
380
|
+
`export async function errorPage(${broken ? "request" : "_request"}: Request, ${broken ? "env" : "_env"}: Env): Promise<Response | null> {`,
|
|
381
|
+
...(broken
|
|
382
|
+
? [
|
|
383
|
+
" try {",
|
|
384
|
+
` const res = await ${camel(broken.recipe)}.render(new Request(request.url, { headers: request.headers }), env, { user: null });`,
|
|
385
|
+
" const headers = new Headers(res.headers);",
|
|
386
|
+
' headers.set("cache-control", "private, no-store");',
|
|
387
|
+
" return new Response(res.body, { status: 500, headers });",
|
|
388
|
+
" } catch {",
|
|
389
|
+
" return null;",
|
|
390
|
+
" }",
|
|
391
|
+
]
|
|
392
|
+
: [" return null;"]),
|
|
361
393
|
"}",
|
|
362
394
|
"",
|
|
363
395
|
"/** Checks who may open the page, then draws it, or takes its form's POST. */",
|
|
@@ -422,7 +454,10 @@ function navFile(pages, byId) {
|
|
|
422
454
|
"",
|
|
423
455
|
].join("\n");
|
|
424
456
|
}
|
|
425
|
-
function testFile(base, pages) {
|
|
457
|
+
function testFile(base, pages, byId) {
|
|
458
|
+
const status = Object.fromEntries(pages.filter((p) => p.path === null).map((p) => [p.recipe, byId.get(p.recipe)?.status ?? 404]));
|
|
459
|
+
const broken = unaddressed(pages, byId, 500);
|
|
460
|
+
const sample = pages.find((p) => p.access === "public" && p.path !== null);
|
|
426
461
|
const enquiries = pages.some((p) => p.recipe === "enquiries");
|
|
427
462
|
const form = pages.find((p) => p.access === "public" && p.path !== null && p.recipe === "contact");
|
|
428
463
|
const guide = pages.find((p) => p.recipe === "style-guide" && p.path !== null);
|
|
@@ -432,7 +467,7 @@ function testFile(base, pages) {
|
|
|
432
467
|
// workbench/site.json matches the page files (check:site).
|
|
433
468
|
|
|
434
469
|
import { siteProblems } from "${PACKAGE}";
|
|
435
|
-
import { ${enquiries ? "beforeEach, " : ""}describe, expect, it${enquiries ? ", vi" : ""} } from "vitest";
|
|
470
|
+
import { ${enquiries ? "beforeEach, " : ""}describe, expect, it${enquiries || (broken && sample) ? ", vi" : ""} } from "vitest";
|
|
436
471
|
import worker from "../src/index.ts";
|
|
437
472
|
${enquiries ? 'import { enquiryStore } from "../src/pages/enquiry-store.ts";\n' : ""}import { PAGES } from "../src/pages/index.ts";
|
|
438
473
|
import { SITE_LAYOUT as LAYOUT } from "../src/site-layout.generated.ts";
|
|
@@ -447,6 +482,8 @@ const SESSION_SECRET = "s".repeat(43);
|
|
|
447
482
|
const production = () => testEnv({ WORKBENCH_ENV: "production", WORKBENCH_GATEWAY_KEY: FAKE.prdKey, ACCESS_AUD: AUD, SESSION_SECRET });
|
|
448
483
|
const staging = () => testEnv({ WORKBENCH_ENV: "staging", WORKBENCH_GATEWAY_KEY: FAKE.stgKey, ACCESS_AUD: AUD, SESSION_SECRET });
|
|
449
484
|
const MISSING = "/no-page-is-here-" + "x".repeat(8);
|
|
485
|
+
/** What each page answers with: 200, but 404 for Not found and 500 for Something went wrong. */
|
|
486
|
+
const STATUS: Readonly<Record<string, number>> = ${JSON.stringify(status)};
|
|
450
487
|
const files = import.meta.glob<string>("../src/pages/*.ts", { query: "?raw", import: "default", eager: true });
|
|
451
488
|
|
|
452
489
|
describe("site pages", () => {
|
|
@@ -457,10 +494,11 @@ ${enquiries ? " // The enquiries table isn't reached: each test says what it ho
|
|
|
457
494
|
|
|
458
495
|
for (const page of PAGES) {
|
|
459
496
|
const path = page.path ?? MISSING;
|
|
497
|
+
const status = STATUS[page.recipe] ?? 200;
|
|
460
498
|
it(\`\${page.recipe} draws in the project's look\`, async () => {
|
|
461
499
|
const user = page.access === "public" ? null : { id: "user-1", email: "sam@example.com" };
|
|
462
500
|
const res = await page.render(new Request(\`https://example.com\${path}\`), production(), user ? { user, accessToken: "token" } : { user });
|
|
463
|
-
expect(res.status).toBe(
|
|
501
|
+
expect(res.status).toBe(status);
|
|
464
502
|
expect(res.headers.get("content-type")).toContain("text/html");
|
|
465
503
|
const html = await res.text();
|
|
466
504
|
expect(html).toMatch(/<html [^>]*class="wb-site[ "]/);
|
|
@@ -476,9 +514,12 @@ ${enquiries ? " // The enquiries table isn't reached: each test says what it ho
|
|
|
476
514
|
expect(html.includes("wb-ui-admin")).toBe(page.access === "admin" && page.recipe !== "style-guide");
|
|
477
515
|
});
|
|
478
516
|
|
|
517
|
+
// No address opens Something went wrong: its own test is below.
|
|
518
|
+
if (status === 500) continue;
|
|
519
|
+
|
|
479
520
|
it(\`\${page.recipe} answers at \${path} to whoever may open it\`, async () => {
|
|
480
521
|
const res = await get(path, production());
|
|
481
|
-
if (page.access === "public") expect(res.status).toBe(
|
|
522
|
+
if (page.access === "public") expect(res.status).toBe(status);
|
|
482
523
|
else {
|
|
483
524
|
// Signed out: sent to sign in, and back here afterwards.
|
|
484
525
|
expect(res.status).toBe(303);
|
|
@@ -490,12 +531,30 @@ ${enquiries ? " // The enquiries table isn't reached: each test says what it ho
|
|
|
490
531
|
useTestTeam();
|
|
491
532
|
expect((await get(path, staging())).status).toBe(403);
|
|
492
533
|
const res = await get(path, staging(), { "Cf-Access-Jwt-Assertion": await accessToken() });
|
|
493
|
-
expect(res.status).toBe(page.access !== "public" ? 303 :
|
|
534
|
+
expect(res.status).toBe(page.access !== "public" ? 303 : status);
|
|
494
535
|
expect(res.headers.get("cache-control")).toBe("private, no-store");
|
|
495
536
|
});
|
|
496
537
|
}
|
|
497
538
|
});
|
|
498
|
-
${enquiries && form ? enquiryTests(form.path) : ""}${guide ? guideTests(guide.path) : ""}`;
|
|
539
|
+
${enquiries && form ? enquiryTests(form.path) : ""}${guide ? guideTests(guide.path) : ""}${broken && sample ? errorTests(sample.recipe, sample.path) : ""}`;
|
|
540
|
+
}
|
|
541
|
+
/** Something went wrong's own test, when the site has it and a public page to break. */
|
|
542
|
+
function errorTests(recipe, path) {
|
|
543
|
+
return `
|
|
544
|
+
describe("something went wrong", () => {
|
|
545
|
+
it("a page that throws shows the site's own error page, never the error", async () => {
|
|
546
|
+
const page = PAGES.find((p) => p.recipe === ${JSON.stringify(recipe)})!;
|
|
547
|
+
const render = vi.spyOn(page, "render").mockRejectedValue(new Error("a secret detail"));
|
|
548
|
+
const log = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
549
|
+
const res = await get(${JSON.stringify(path)}, production()).finally(() => (render.mockRestore(), log.mockRestore()));
|
|
550
|
+
expect(res.status).toBe(500);
|
|
551
|
+
expect(res.headers.get("cache-control")).toBe("private, no-store");
|
|
552
|
+
const html = await res.text();
|
|
553
|
+
expect(html).toMatch(/<html [^>]*class="wb-site[ "]/);
|
|
554
|
+
expect(html).not.toContain("a secret detail");
|
|
555
|
+
});
|
|
556
|
+
});
|
|
557
|
+
`;
|
|
499
558
|
}
|
|
500
559
|
/** The style guide's own tests, when the site has it. */
|
|
501
560
|
function guideTests(path) {
|
|
@@ -743,7 +802,7 @@ export function siteProblems(i) {
|
|
|
743
802
|
out.push(`${where}: its file ${p.file} is missing`);
|
|
744
803
|
if (!["built", "checked", "changed"].includes(p.state))
|
|
745
804
|
out.push(`${where}: state ${String(p.state)} isn't built, checked or changed`);
|
|
746
|
-
const key = p.path ??
|
|
805
|
+
const key = p.path ?? `(${UNADDRESSED[byId.get(p.recipe)?.status ?? 404] ?? "no address"})`;
|
|
747
806
|
if (seen.has(key))
|
|
748
807
|
out.push(`${where}: ${key} is also ${seen.get(key)}'s address`);
|
|
749
808
|
seen.set(key, p.recipe);
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// `npx workbench-site list`
|
|
3
3
|
// The page recipes this version can build, by group.
|
|
4
|
-
// `npx workbench-site add <page>... [--dir <project>] [--no-install]`
|
|
5
|
-
//
|
|
4
|
+
// `npx workbench-site add [<page>...] [--dir <project>] [--no-install]`
|
|
5
|
+
// With no pages named, builds the pages every project has without being
|
|
6
|
+
// asked (the always tier, docs/default-pages.md §3). Builds the pages into the project (the current folder by default): one
|
|
6
7
|
// thin file per page in src/pages/, their words in the strings catalogue,
|
|
7
8
|
// the routes, the menu, a test per page and workbench/site.json. Then it
|
|
8
9
|
// installs this package into the project and regenerates
|
|
@@ -19,7 +20,8 @@ import { fileURLToPath } from "node:url";
|
|
|
19
20
|
import { buildSite, SITE_FILE, siteProblems } from "./builder.js";
|
|
20
21
|
import { GROUPS } from "./recipe.js";
|
|
21
22
|
import { RECIPES } from "./recipes/index.js";
|
|
22
|
-
const USAGE = ["Usage: workbench-site list", " workbench-site add <page>... [--dir <project>] [--no-install]", " workbench-site check [--live] [--dir <project>]"].join("\n");
|
|
23
|
+
const USAGE = ["Usage: workbench-site list", " workbench-site add [<page>...] [--dir <project>] [--no-install]", " workbench-site check [--live] [--dir <project>]"].join("\n");
|
|
24
|
+
const TIER_NAMES = { always: "always built", ticked: "ask, ticked", offered: "ask, not ticked" };
|
|
23
25
|
const GROUP_NAMES = { "every-site": "Every site", members: "Members", admin: "Admin", business: "For your business" };
|
|
24
26
|
function version() {
|
|
25
27
|
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
@@ -53,7 +55,7 @@ export function main(argv, deps = realDeps) {
|
|
|
53
55
|
continue;
|
|
54
56
|
deps.log(`${GROUP_NAMES[g]}:`);
|
|
55
57
|
for (const r of rs)
|
|
56
|
-
deps.log(` ${r.id.padEnd(
|
|
58
|
+
deps.log(` ${r.id.padEnd(14)} ${(r.path ?? (r.status === 500 ? "(when a page breaks)" : "(any missing address)")).padEnd(20)} ${TIER_NAMES[r.tier].padEnd(16)} ${r.does}`);
|
|
57
59
|
}
|
|
58
60
|
return 0;
|
|
59
61
|
}
|
|
@@ -79,7 +81,7 @@ export function main(argv, deps = realDeps) {
|
|
|
79
81
|
deps.log(`✓ ${SITE_FILE} matches the page files and their words${live ? ", and no word waits for the owner" : ""}.`);
|
|
80
82
|
return problems.length ? 1 : 0;
|
|
81
83
|
}
|
|
82
|
-
if (command !== "add" ||
|
|
84
|
+
if (command !== "add" || ids.some((i) => i.startsWith("-"))) {
|
|
83
85
|
deps.error(USAGE);
|
|
84
86
|
return 2;
|
|
85
87
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { frame, FOOTERS, FRAMES, HEADERS, type FooterStyle, type FrameLayout, type FrameName, type FrameOptions, type HeaderStyle, type MenuLink } from "./frames.ts";
|
|
2
2
|
export { escape } from "./html.ts";
|
|
3
3
|
export { account, callToAction, DESIGN_COOKIE, designModeOn, designModePost, designSwitch, details, enquiryList, formSection, hero, HERO_ARRANGEMENTS, list, picture, text, type AccountOptions, type Action, type CallToActionOptions, type DesignSwitchOptions, type DetailRow, type DetailsOptions, type Enquiry, type EnquiryListOptions, type FormSectionOptions, type HeroArrangement, type HeroOptions, type ListItem, type ListOptions, type Picture, type PictureOptions, type TextOptions, } from "./sections.ts";
|
|
4
|
-
export { recipeKeys, recipeProblems, type ActionSpec, type Area, type Group, type Recipe, type SectionSpec } from "./recipe.ts";
|
|
4
|
+
export { recipeKeys, recipeProblems, TIERS, type ActionSpec, type Area, type Group, type Recipe, type SectionSpec, type Tier } from "./recipe.ts";
|
|
5
5
|
export { RECIPES } from "./recipes/index.ts";
|
|
6
|
-
export { buildSite, SITE_FILE, siteProblems, type BuildOptions, type BuildResult, type SiteCheckInput, type SitePageRecord, type SiteRecord } from "./builder.ts";
|
|
6
|
+
export { alwaysSet, buildSite, SITE_FILE, siteProblems, type BuildOptions, type BuildResult, type SiteCheckInput, type SitePageRecord, type SiteRecord } from "./builder.ts";
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
export { frame, FOOTERS, FRAMES, HEADERS } from "./frames.js";
|
|
5
5
|
export { escape } from "./html.js";
|
|
6
6
|
export { account, callToAction, DESIGN_COOKIE, designModeOn, designModePost, designSwitch, details, enquiryList, formSection, hero, HERO_ARRANGEMENTS, list, picture, text, } from "./sections.js";
|
|
7
|
-
export { recipeKeys, recipeProblems } from "./recipe.js";
|
|
7
|
+
export { recipeKeys, recipeProblems, TIERS } from "./recipe.js";
|
|
8
8
|
export { RECIPES } from "./recipes/index.js";
|
|
9
|
-
export { buildSite, SITE_FILE, siteProblems } from "./builder.js";
|
|
9
|
+
export { alwaysSet, buildSite, SITE_FILE, siteProblems } from "./builder.js";
|
package/dist/recipe.d.ts
CHANGED
|
@@ -136,6 +136,16 @@ declare const AREAS: readonly ["public", "members", "admin", "legal"];
|
|
|
136
136
|
export type Area = (typeof AREAS)[number];
|
|
137
137
|
export declare const GROUPS: readonly ["every-site", "members", "admin", "business"];
|
|
138
138
|
export type Group = (typeof GROUPS)[number];
|
|
139
|
+
/**
|
|
140
|
+
* Whether the owner is asked (docs/default-pages.md §3): always pages are built
|
|
141
|
+
* without asking (`npx workbench-site add` with no pages named builds them),
|
|
142
|
+
* ticked pages are suggested and may be unticked, offered pages are shown
|
|
143
|
+
* unticked.
|
|
144
|
+
*/
|
|
145
|
+
export declare const TIERS: readonly ["always", "ticked", "offered"];
|
|
146
|
+
export type Tier = (typeof TIERS)[number];
|
|
147
|
+
/** The statuses a page with no address can answer with: Not found's, and Something went wrong's. */
|
|
148
|
+
export declare const UNADDRESSED: Readonly<Record<number, string>>;
|
|
139
149
|
export interface Recipe {
|
|
140
150
|
/** Its name in the catalogue and on the command line: lower case and hyphens. */
|
|
141
151
|
id: string;
|
|
@@ -145,11 +155,13 @@ export interface Recipe {
|
|
|
145
155
|
title: string;
|
|
146
156
|
does: string;
|
|
147
157
|
group: Group;
|
|
158
|
+
/** Whether the owner is asked about it: always, ticked or offered. */
|
|
159
|
+
tier: Tier;
|
|
148
160
|
/** Sets the access rule the builder writes: public, members (signed in) or admin (signed in and one of the app's admins). Legal pages come with step 4. */
|
|
149
161
|
area: Area;
|
|
150
|
-
/** Its default address. Null for
|
|
162
|
+
/** Its default address. Null for a page no address opens: Not found (status 404) and Something went wrong (status 500). */
|
|
151
163
|
path: string | null;
|
|
152
|
-
/** The answer's status: 404 for Not found. Defaults to 200. */
|
|
164
|
+
/** The answer's status: 404 for Not found, 500 for Something went wrong. Defaults to 200. */
|
|
153
165
|
status?: number;
|
|
154
166
|
/** The frames it can use, its default first. */
|
|
155
167
|
frames: readonly FrameName[];
|
package/dist/recipe.js
CHANGED
|
@@ -13,6 +13,15 @@ export const STORE_SECTIONS = new Set(["enquiry-form", "enquiries"]);
|
|
|
13
13
|
export const UI_SECTIONS = new Set(["style-guide", "look-preview"]);
|
|
14
14
|
const AREAS = ["public", "members", "admin", "legal"];
|
|
15
15
|
export const GROUPS = ["every-site", "members", "admin", "business"];
|
|
16
|
+
/**
|
|
17
|
+
* Whether the owner is asked (docs/default-pages.md §3): always pages are built
|
|
18
|
+
* without asking (`npx workbench-site add` with no pages named builds them),
|
|
19
|
+
* ticked pages are suggested and may be unticked, offered pages are shown
|
|
20
|
+
* unticked.
|
|
21
|
+
*/
|
|
22
|
+
export const TIERS = ["always", "ticked", "offered"];
|
|
23
|
+
/** The statuses a page with no address can answer with: Not found's, and Something went wrong's. */
|
|
24
|
+
export const UNADDRESSED = { 404: "Not found", 500: "Something went wrong" };
|
|
16
25
|
/** Every word key a section names. */
|
|
17
26
|
function sectionKeys(s) {
|
|
18
27
|
switch (s.kind) {
|
|
@@ -70,8 +79,14 @@ export function recipeProblems(r, catalogue) {
|
|
|
70
79
|
p(`area ${r.area} isn't one of ${AREAS.join(", ")}`);
|
|
71
80
|
if (r.path !== null && !/^\/([a-z0-9-]+(\/[a-z0-9-]+)*)?$/.test(r.path))
|
|
72
81
|
p(`path ${r.path} must be / or /lower-case-words`);
|
|
73
|
-
if (
|
|
74
|
-
p(
|
|
82
|
+
if (!TIERS.includes(r.tier))
|
|
83
|
+
p(`tier ${r.tier} isn't one of ${TIERS.join(", ")}`);
|
|
84
|
+
if (r.path === null && !(r.status !== undefined && r.status in UNADDRESSED))
|
|
85
|
+
p("a page with no path is Not found (status 404) or Something went wrong (status 500)");
|
|
86
|
+
if (r.path !== null && r.status !== undefined && r.status !== 200)
|
|
87
|
+
p("a page with an address answers 200");
|
|
88
|
+
if (r.path === null && catalogue.some((c) => c.id !== r.id && c.path === null && c.status === r.status))
|
|
89
|
+
p(`another recipe is already the ${UNADDRESSED[r.status] ?? "unaddressed"} page`);
|
|
75
90
|
if (!r.frames.length || r.frames.some((f) => !FRAMES.includes(f)))
|
|
76
91
|
p(`frames must be some of ${FRAMES.join(", ")}`);
|
|
77
92
|
for (const n of r.needs)
|
|
@@ -117,7 +132,7 @@ export function recipeProblems(r, catalogue) {
|
|
|
117
132
|
if (r.area === "admin" && (r.path === null || !/^\/admin(\/|$)/.test(r.path)))
|
|
118
133
|
p("an admin page's address starts /admin");
|
|
119
134
|
if (r.area !== "public" && r.path === null)
|
|
120
|
-
p("
|
|
135
|
+
p("a page with no path is public");
|
|
121
136
|
for (const s of r.sections) {
|
|
122
137
|
if (s.kind === "account" && r.area !== "members")
|
|
123
138
|
p("the account section is for members pages");
|
package/dist/recipes/admin.js
CHANGED
|
@@ -9,6 +9,7 @@ const adminHome = {
|
|
|
9
9
|
title: "Admin home",
|
|
10
10
|
does: "One page with a link to everything the business's admins look after.",
|
|
11
11
|
group: "admin",
|
|
12
|
+
tier: "always",
|
|
12
13
|
area: "admin",
|
|
13
14
|
path: "/admin",
|
|
14
15
|
frames: ["column"],
|
|
@@ -39,6 +40,7 @@ const enquiries = {
|
|
|
39
40
|
title: "Enquiries",
|
|
40
41
|
does: "Every message sent from the Contact page, newest first, with a way to reply.",
|
|
41
42
|
group: "admin",
|
|
43
|
+
tier: "always",
|
|
42
44
|
area: "admin",
|
|
43
45
|
path: "/admin/enquiries",
|
|
44
46
|
frames: ["column"],
|
|
@@ -73,6 +75,7 @@ const styleGuide = {
|
|
|
73
75
|
title: "Style guide",
|
|
74
76
|
does: "Every part of the site on one page, in its look, light and dark, so a change of colours or fonts can be checked at a glance.",
|
|
75
77
|
group: "admin",
|
|
78
|
+
tier: "always",
|
|
76
79
|
area: "admin",
|
|
77
80
|
path: "/admin/style-guide",
|
|
78
81
|
frames: ["column"],
|
|
@@ -115,6 +118,7 @@ const look = {
|
|
|
115
118
|
title: "Looks",
|
|
116
119
|
does: "The site's own pages in every look it may choose, side by side, light or dark, so an owner can see a new look on their real words and pictures before choosing it.",
|
|
117
120
|
group: "admin",
|
|
121
|
+
tier: "always",
|
|
118
122
|
area: "admin",
|
|
119
123
|
path: "/admin/look",
|
|
120
124
|
frames: ["column"],
|
|
@@ -163,6 +167,7 @@ const design = {
|
|
|
163
167
|
title: "Design mode",
|
|
164
168
|
does: "Turns design mode on in this browser, on the test site: a bar on every page to try looks, light or dark and the site layout, and a badge on each tool to try its layouts, on the real pages.",
|
|
165
169
|
group: "admin",
|
|
170
|
+
tier: "always",
|
|
166
171
|
area: "admin",
|
|
167
172
|
path: "/admin/design",
|
|
168
173
|
frames: ["column"],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The "Every site" recipes (docs/site-planner.md §5): the pages most sites
|
|
2
|
-
// have. Privacy and Terms join them with their
|
|
3
|
-
// (
|
|
2
|
+
// have (docs/default-pages.md §3). Privacy and Terms join them with their
|
|
3
|
+
// written clauses per country (default pages step 3). Contact's enquiry form needs the Enquiries admin
|
|
4
4
|
// list, so no enquiry is taken before there is somewhere to read it. Words in [square brackets] are the owner's to fill in: Workbench
|
|
5
5
|
// never makes up a price, an address, an opening hour or a person.
|
|
6
6
|
const home = {
|
|
@@ -9,6 +9,7 @@ const home = {
|
|
|
9
9
|
title: "Home",
|
|
10
10
|
does: "The first page people see: what you do, who for, and how to get in touch.",
|
|
11
11
|
group: "every-site",
|
|
12
|
+
tier: "always",
|
|
12
13
|
area: "public",
|
|
13
14
|
path: "/",
|
|
14
15
|
frames: ["landing", "column"],
|
|
@@ -57,6 +58,7 @@ const about = {
|
|
|
57
58
|
title: "About",
|
|
58
59
|
does: "Your story: who you are, why you started and what you care about.",
|
|
59
60
|
group: "every-site",
|
|
61
|
+
tier: "ticked",
|
|
60
62
|
area: "public",
|
|
61
63
|
path: "/about",
|
|
62
64
|
frames: ["column", "landing"],
|
|
@@ -90,6 +92,7 @@ const contact = {
|
|
|
90
92
|
title: "Contact",
|
|
91
93
|
does: "How to reach you: email, phone, where you are and when you're open, and a form to send you a message.",
|
|
92
94
|
group: "every-site",
|
|
95
|
+
tier: "always",
|
|
93
96
|
area: "public",
|
|
94
97
|
path: "/contact",
|
|
95
98
|
frames: ["two-columns", "column"],
|
|
@@ -140,12 +143,113 @@ const contact = {
|
|
|
140
143
|
},
|
|
141
144
|
suggest: { types: [], signals: ["every site"] },
|
|
142
145
|
};
|
|
146
|
+
const faq = {
|
|
147
|
+
id: "faq",
|
|
148
|
+
version: 1,
|
|
149
|
+
title: "Questions and answers",
|
|
150
|
+
does: "The questions people ask you most, each with your answer, so they needn't message you to find out.",
|
|
151
|
+
group: "every-site",
|
|
152
|
+
tier: "ticked",
|
|
153
|
+
area: "public",
|
|
154
|
+
path: "/faq",
|
|
155
|
+
frames: ["column"],
|
|
156
|
+
tools: [],
|
|
157
|
+
needs: [],
|
|
158
|
+
menu: { label: "page.faq.menu", footer: 20 },
|
|
159
|
+
pageTitle: "page.faq.title",
|
|
160
|
+
sections: [
|
|
161
|
+
{ kind: "hero", heading: "page.faq.hero.heading", lead: "page.faq.hero.lead" },
|
|
162
|
+
{
|
|
163
|
+
kind: "list",
|
|
164
|
+
items: [
|
|
165
|
+
{ title: "page.faq.offer.question", body: "page.faq.offer.answer" },
|
|
166
|
+
{ title: "page.faq.where.question", body: "page.faq.where.answer" },
|
|
167
|
+
{ title: "page.faq.cost.question", body: "page.faq.cost.answer" },
|
|
168
|
+
{ title: "page.faq.start.question", body: "page.faq.start.answer" },
|
|
169
|
+
{ title: "page.faq.contact.question", body: "page.faq.contact.answer" },
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
{ kind: "call", heading: "page.faq.call.heading", body: "page.faq.call.body", action: { label: "page.faq.call.action", to: "contact" } },
|
|
173
|
+
],
|
|
174
|
+
words: {
|
|
175
|
+
"page.faq.menu": "Questions and answers",
|
|
176
|
+
"page.faq.title": "Questions and answers",
|
|
177
|
+
"page.faq.hero.heading": "Questions and answers",
|
|
178
|
+
"page.faq.hero.lead": "The things people ask us most.",
|
|
179
|
+
"page.faq.offer.question": "What do you offer?",
|
|
180
|
+
"page.faq.offer.answer": "[A sentence or two on what you offer, and who it's for.]",
|
|
181
|
+
"page.faq.where.question": "Where are you, and when are you open?",
|
|
182
|
+
"page.faq.where.answer": "[Where to find you, or the area you cover, and your opening hours.]",
|
|
183
|
+
"page.faq.cost.question": "How much does it cost?",
|
|
184
|
+
"page.faq.cost.answer": "[Your prices, or how you work out a price.]",
|
|
185
|
+
"page.faq.start.question": "How do I get started?",
|
|
186
|
+
"page.faq.start.answer": "[How people book, order or start with you.]",
|
|
187
|
+
"page.faq.contact.question": "How do I get in touch?",
|
|
188
|
+
"page.faq.contact.answer": "Send us a message from the Contact page and we'll reply by email.",
|
|
189
|
+
"page.faq.call.heading": "Still have a question?",
|
|
190
|
+
"page.faq.call.body": "Ask us, and we'll get back to you.",
|
|
191
|
+
"page.faq.call.action": "Ask a question",
|
|
192
|
+
},
|
|
193
|
+
suggest: { types: [], signals: ["every site", "people ask the same questions"] },
|
|
194
|
+
};
|
|
195
|
+
const accessibility = {
|
|
196
|
+
id: "accessibility",
|
|
197
|
+
version: 1,
|
|
198
|
+
title: "Accessibility",
|
|
199
|
+
does: "What you do so everyone can use your site, anything that doesn't work well yet, and how to tell you when something is hard to use.",
|
|
200
|
+
group: "every-site",
|
|
201
|
+
tier: "offered",
|
|
202
|
+
area: "public",
|
|
203
|
+
path: "/accessibility",
|
|
204
|
+
frames: ["column"],
|
|
205
|
+
tools: [],
|
|
206
|
+
needs: [],
|
|
207
|
+
menu: { label: "page.accessibility.menu", footer: 40 },
|
|
208
|
+
pageTitle: "page.accessibility.title",
|
|
209
|
+
sections: [
|
|
210
|
+
{ kind: "hero", heading: "page.accessibility.hero.heading", lead: "page.accessibility.hero.lead" },
|
|
211
|
+
{ kind: "text", heading: "page.accessibility.aim.heading", body: "page.accessibility.aim.body" },
|
|
212
|
+
{
|
|
213
|
+
kind: "list",
|
|
214
|
+
heading: "page.accessibility.done.heading",
|
|
215
|
+
items: [
|
|
216
|
+
{ title: "page.accessibility.done.read.title", body: "page.accessibility.done.read.body" },
|
|
217
|
+
{ title: "page.accessibility.done.keys.title", body: "page.accessibility.done.keys.body" },
|
|
218
|
+
{ title: "page.accessibility.done.forms.title", body: "page.accessibility.done.forms.body" },
|
|
219
|
+
],
|
|
220
|
+
},
|
|
221
|
+
{ kind: "text", heading: "page.accessibility.known.heading", body: "page.accessibility.known.body" },
|
|
222
|
+
{ kind: "call", heading: "page.accessibility.call.heading", body: "page.accessibility.call.body", action: { label: "page.accessibility.call.action", to: "contact" } },
|
|
223
|
+
],
|
|
224
|
+
words: {
|
|
225
|
+
"page.accessibility.menu": "Accessibility",
|
|
226
|
+
"page.accessibility.title": "Accessibility",
|
|
227
|
+
"page.accessibility.hero.heading": "Accessibility",
|
|
228
|
+
"page.accessibility.hero.lead": "We want everyone to be able to use this site.",
|
|
229
|
+
"page.accessibility.aim.heading": "What we aim for",
|
|
230
|
+
"page.accessibility.aim.body": "We aim to meet the Web Content Accessibility Guidelines (WCAG) 2.2 at level AA.",
|
|
231
|
+
"page.accessibility.done.heading": "What we've done",
|
|
232
|
+
"page.accessibility.done.read.title": "Easy to read",
|
|
233
|
+
"page.accessibility.done.read.body": "Text and buttons have strong contrast in light and dark, and the pages still work when you make the text bigger.",
|
|
234
|
+
"page.accessibility.done.keys.title": "No mouse needed",
|
|
235
|
+
"page.accessibility.done.keys.body": "Every link, button and form works with a keyboard, and with screen readers.",
|
|
236
|
+
"page.accessibility.done.forms.title": "Clear forms",
|
|
237
|
+
"page.accessibility.done.forms.body": "Every field has a label, and a problem with an answer is said in words, not only in colour.",
|
|
238
|
+
"page.accessibility.known.heading": "What doesn't work well yet",
|
|
239
|
+
"page.accessibility.known.body": "[Anything on the site that is hard to use, such as a video without captions or a PDF, and when you'll fix it. If you know of nothing, say so.]",
|
|
240
|
+
"page.accessibility.call.heading": "Something hard to use?",
|
|
241
|
+
"page.accessibility.call.body": "Tell us what you were trying to do, and we'll help you and fix it.",
|
|
242
|
+
"page.accessibility.call.action": "Tell us",
|
|
243
|
+
},
|
|
244
|
+
suggest: { types: [], signals: ["every site", "government or community funding", "older or disabled customers"] },
|
|
245
|
+
};
|
|
143
246
|
const notFound = {
|
|
144
247
|
id: "not-found",
|
|
145
248
|
version: 1,
|
|
146
249
|
title: "Not found",
|
|
147
250
|
does: "What people see when an address on your site doesn't exist, with a way back.",
|
|
148
251
|
group: "every-site",
|
|
252
|
+
tier: "always",
|
|
149
253
|
area: "public",
|
|
150
254
|
path: null,
|
|
151
255
|
status: 404,
|
|
@@ -162,5 +266,28 @@ const notFound = {
|
|
|
162
266
|
},
|
|
163
267
|
suggest: { types: [], signals: ["every site"] },
|
|
164
268
|
};
|
|
269
|
+
const error = {
|
|
270
|
+
id: "error",
|
|
271
|
+
version: 1,
|
|
272
|
+
title: "Something went wrong",
|
|
273
|
+
does: "What people see, in your site's look, when a page breaks, instead of a blank error.",
|
|
274
|
+
group: "every-site",
|
|
275
|
+
tier: "always",
|
|
276
|
+
area: "public",
|
|
277
|
+
path: null,
|
|
278
|
+
status: 500,
|
|
279
|
+
frames: ["column"],
|
|
280
|
+
tools: [],
|
|
281
|
+
needs: [],
|
|
282
|
+
pageTitle: "page.error.title",
|
|
283
|
+
sections: [{ kind: "hero", heading: "page.error.hero.heading", lead: "page.error.hero.lead", action: { label: "page.error.hero.action", to: "/" } }],
|
|
284
|
+
words: {
|
|
285
|
+
"page.error.title": "Something went wrong",
|
|
286
|
+
"page.error.hero.heading": "Something went wrong",
|
|
287
|
+
"page.error.hero.lead": "That's our fault, not yours. Please try again in a minute.",
|
|
288
|
+
"page.error.hero.action": "Go to the home page",
|
|
289
|
+
},
|
|
290
|
+
suggest: { types: [], signals: ["every site"] },
|
|
291
|
+
};
|
|
165
292
|
/** The "Every site" group, in the order they're offered. */
|
|
166
|
-
export const EVERY_SITE = [home, about, contact, notFound];
|
|
293
|
+
export const EVERY_SITE = [home, about, contact, faq, accessibility, notFound, error];
|
package/dist/recipes/members.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mccaskie-labs/workbench-site",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "A Workbench project's standard pages: page recipes, the builder that turns them into thin page files calling Workbench's tools, and the page frames and sections they are drawn with (wb-site-*, restylable, on the project's theme tokens).",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|