@mccaskie-labs/workbench-site 0.13.0 → 0.14.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @mccaskie-labs/workbench-site
2
2
 
3
+ ## 0.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ded9a98: Your pages' words (rule B10): Contact's opening hours, address, phone and email, and the answers on Questions and answers, are owner settings on the app's Settings page (`SITE_SETTINGS`, `siteSettings(site)`, `siteAnswers`), so the owner changes them with no rebuild. A recipe names its owner's words (`Recipe.owner`); a page with any reads the owner's changes when drawn through the generated `src/pages/owner-words.ts` and hands them to the site helper's new `words` option, which uses them over the catalogue's. Contact is recipe version 3 and Questions and answers version 2.
8
+
9
+ ## 0.13.1
10
+
11
+ ### Patch Changes
12
+
13
+ - A page with a tool's own section imports `../lib/wiring.ts`, the template's tools wiring registry, which installs itself on import. A tool's section function reads its settings and database client from there, even when the page is drawn directly (as the generated pages test does). Pages without a tool section are unchanged.
14
+
3
15
  ## 0.13.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -21,10 +21,30 @@ Admin home is the admins' dashboard: what needs them now (each page with a "need
21
21
  | `src/pages/<page>.ts` | One thin file per page: its frame, its sections in order and its words' keys. The project's own from then on |
22
22
  | `src/pages/site.ts` | The shared page wrapper (words, frame, header and footer). Written once |
23
23
  | `src/pages/index.ts`, `src/pages/nav.ts` | The routes and the header and footer links, rewritten on each add |
24
+ | `src/pages/owner-words.ts` | Reads the words the owner changed on the Settings page ("Your pages' words"), rewritten on each add |
24
25
  | `strings/strings.en-AU.json` | Each page's words. Words in `[square brackets]` are the owner's to fill in |
25
26
  | `test/pages.test.ts` | Every page answers, in the project's look, and is owner-only on staging |
26
27
  | `workbench/site.json` | Each page, its recipe and version, its frame, and its state (`built`, `checked`, `changed`) |
27
28
 
29
+ ## Your pages' words
30
+
31
+ Some words on a page are the owner's to keep up to date after launch: Contact's opening hours, address, phone and email, and the answers on Questions and answers (where you are and when you're open, your prices, what you offer, how to start, how to get in touch). Each recipe lists its own (`Recipe.owner`). They are settings on the app's Settings page (workbench-settings), in a section called "Your pages' words", so the owner changes them with no rebuild:
32
+
33
+ ```ts
34
+ // src/lib/settings-page.ts
35
+ import { siteAnswers, siteSettings } from "@mccaskie-labs/workbench-site";
36
+ import site from "../../workbench/site.json";
37
+ import strings from "../../strings/strings.en-AU.json";
38
+
39
+ const SITE = siteSettings(site, undefined, LANGUAGES.length); // with more than one, each word's help says "shown in every language"
40
+ export const SETTINGS_TOOLS = [EMAIL_SETTINGS, ...(SITE ? [SITE] : [])];
41
+ export const SETTINGS_ANSWERS = { ...siteAnswers(SITE, strings) };
42
+ ```
43
+
44
+ A page with any of these words reads the owner's changes when it is drawn (`src/pages/owner-words.ts`, through the project's `settingsFor`) and uses them over the catalogue's, in every language. A word the owner hasn't changed stays the catalogue's, in the visitor's language. Until the project has a Settings page, the pages use the catalogue's words. Only the words the Settings page shows are used: once a page is marked `changed` in `workbench/site.json`, its words go back to the catalogue's. A line break the owner types stays a line break on the page; phone and email are one line.
45
+
46
+ Later: an owner's word per language. For now one word is shown in every language.
47
+
28
48
  Then it runs `npm install` and `npm run styles` (skip with `--no-install`). A page already in `workbench/site.json` is left alone. It also adds `npm run check:site`.
29
49
 
30
50
  Pages come in three areas. Public pages are for anyone. Members pages (Account) need a sign-in, and admin pages (Admin home) need one of the site's admins; both are never indexed or cached and carry no analytics beacon. On staging every page is owner-only, as the rest of the project is.
package/dist/builder.js CHANGED
@@ -113,6 +113,7 @@ export function buildSite(o) {
113
113
  writes["src/pages/site.ts"] = SITE_HELPER;
114
114
  writes["src/pages/index.ts"] = indexFile(pages, byId);
115
115
  writes["src/pages/nav.ts"] = navFile(pages, byId);
116
+ writes["src/pages/owner-words.ts"] = ownerWordsFile(o.read("src/lib/settings-page.ts")?.includes("export function settingsFor(") ?? false);
116
117
  const dashboard = pages.some((p) => byId.get(p.recipe)?.sections.some((x) => x.kind === "needs-you"));
117
118
  if (dashboard)
118
119
  writes["src/pages/needs.ts"] = needsFile(pages, byId);
@@ -319,14 +320,16 @@ function pageFile(r, version, base, pathOf) {
319
320
  const looks = sections.some(([s]) => s.kind === "look-preview");
320
321
  const design = sections.some(([s]) => s.kind === "design-switch");
321
322
  const needs = sections.some(([s]) => s.kind === "needs-you");
323
+ const owned = (r.owner?.length ?? 0) > 0;
322
324
  const pre = [
323
325
  ...(list ? [" const enquiries = await listEnquiries(env, ctx);"] : []),
324
326
  ...(needs ? [" // Each tool's count, read at once (src/pages/needs.ts).", " const needs = await readNeeds(env, ctx);"] : []),
325
327
  ...(guide ? [" // ?view=light, dark or admin: the switch at the top of the guide.", " const view = guideView(request.url);"] : []),
326
328
  ...tools.map((t) => ` const ${t.name} = await ${t.fn}(request, env, ctx);`),
329
+ ...(owned ? [" // The words the owner changed on the Settings page (\"Your pages' words\").", " const words = await ownerWords(env);"] : []),
327
330
  ];
328
331
  const block = pre.length > 0;
329
- const waits = list || needs || tools.length > 0;
332
+ const waits = list || needs || owned || tools.length > 0;
330
333
  const toolImports = [...new Set(tools.map((t) => t.from))].sort().map((from) => `import { ${[...new Set(tools.filter((t) => t.from === from).map((t) => t.fn))].sort().join(", ")} } from "${from}";`);
331
334
  const area = r.area === "members" || r.area === "admin" ? `, area: ${JSON.stringify(r.area)}` : "";
332
335
  const prefix = `page.${r.id.replace(/-/g, "_")}.`;
@@ -344,6 +347,8 @@ function pageFile(r, version, base, pathOf) {
344
347
  "",
345
348
  ...(used.length ? [`import { ${used.join(", ")} } from "${PACKAGE}";`] : []),
346
349
  ...toolImports,
350
+ // The tools' wiring registry (the template's src/lib/wiring.ts installs it on import), which a tool's section reads.
351
+ ...(tools.length ? [`import "../lib/wiring.ts";`] : []),
347
352
  ...(store.length ? [`import { ${store.join(", ")} } from "./enquiry-store.ts";`] : []),
348
353
  ...(guide ? [`import { guideView, styleGuide } from "@mccaskie-labs/workbench-ui";`, `import { SAMPLES } from "../samples.generated.ts";`] : []),
349
354
  ...(looks ? [`import { lookPreview } from "@mccaskie-labs/workbench-ui";`] : []),
@@ -351,14 +356,15 @@ function pageFile(r, version, base, pathOf) {
351
356
  ...(looks ? [`import { BRAND } from "../lib/brand.ts";`] : []),
352
357
  ...(usesMenu || looks ? [`import { ${[...(usesMenu ? ["ADMIN_MENU"] : []), ...(looks ? ["MENU"] : [])].join(", ")} } from "./nav.ts";`] : []),
353
358
  ...(needs ? [`import { readNeeds } from "./needs.ts";`] : []),
359
+ ...(owned ? [`import { ownerWords } from "./owner-words.ts";`] : []),
354
360
  `import { sitePage, type SitePage } from "./site.ts";`,
355
361
  "",
356
362
  `export const ${camel(r.id)}: SitePage = {`,
357
363
  ` recipe: ${JSON.stringify(r.id)},`,
358
364
  ` path: ${JSON.stringify(r.path)},`,
359
365
  ` access: ${JSON.stringify(r.area === "legal" ? "public" : r.area)},`,
360
- ...(block ? [` render: ${waits ? "async " : ""}(request, env${usesCtx || waits ? ", ctx" : ""}) => {`, ...pre] : [` render: (request, env${usesCtx ? ", ctx" : ""}) =>`]),
361
- ` ${block ? "return " : ""}sitePage(request, env, { frame: ${JSON.stringify(frame)}, title: ${JSON.stringify(r.pageTitle)}${r.status && r.status !== 200 ? `, status: ${r.status}` : ""}${area}${guide ? `, view, stylesheets: [${JSON.stringify(GUIDE_SHEET)}]` : ""} }, (w) => [`,
366
+ ...(block ? [` render: ${waits ? "async " : ""}(request, env${usesCtx || list || needs || tools.length > 0 ? ", ctx" : ""}) => {`, ...pre] : [` render: (request, env${usesCtx ? ", ctx" : ""}) =>`]),
367
+ ` ${block ? "return " : ""}sitePage(request, env, { frame: ${JSON.stringify(frame)}, title: ${JSON.stringify(r.pageTitle)}${r.status && r.status !== 200 ? `, status: ${r.status}` : ""}${area}${guide ? `, view, stylesheets: [${JSON.stringify(GUIDE_SHEET)}]` : ""}${owned ? ", words" : ""} }, (w) => [`,
362
368
  ...sections.map(([, code]) => ` ${code},`),
363
369
  block ? " ]);\n }," : " ]),",
364
370
  ...(form ? [` // The form's POST: checked, stored, then back to the thank-you.`, ` post: (request, env, ctx) => takeEnquiry(request, env, ctx, ${camel(r.id)}),`] : []),
@@ -494,6 +500,47 @@ function needsFile(pages, byId) {
494
500
  "",
495
501
  ].join("\n");
496
502
  }
503
+ /**
504
+ * src/pages/owner-words.ts: the words the owner changed on the Settings page,
505
+ * for the pages that have them. Read through the project's Settings page
506
+ * (src/lib/settings-page.ts) once it has one; until then, none.
507
+ */
508
+ function ownerWordsFile(settings) {
509
+ return [
510
+ `// Generated by ${PACKAGE}: \`npx workbench-site add <page>\` rewrites it. The`,
511
+ "// words the owner keeps up to date on the Settings page (\"Your pages' words\":",
512
+ "// opening hours, prices, answers to common questions), read when a page is",
513
+ "// drawn, so a change shows with no rebuild.",
514
+ ...(settings
515
+ ? [
516
+ "//",
517
+ "// The Settings page shows them once src/lib/settings-page.ts lists",
518
+ `// siteSettings(site) in SETTINGS_TOOLS, with siteAnswers(...) in its answers.`,
519
+ "",
520
+ `import { readOwnerWords, siteSettings } from "${PACKAGE}";`,
521
+ `import site from "../../workbench/site.json";`,
522
+ `import { settingsFor } from "../lib/settings-page.ts";`,
523
+ "",
524
+ "/** The owner's words by word key; none while settings are off. */",
525
+ "export async function ownerWords(env: Env): Promise<Readonly<Record<string, string>>> {",
526
+ " // Only the words the Settings page shows: a page the project changed by hand has none.",
527
+ " return readOwnerWords(settingsFor(env), siteSettings(site));",
528
+ "}",
529
+ ]
530
+ : [
531
+ "//",
532
+ "// This project has no Settings page yet (src/lib/settings-page.ts, from",
533
+ "// the template's workbench-settings), so the pages use the catalogue's",
534
+ "// words. Update the project, then run add again.",
535
+ "",
536
+ "/** The owner's words by word key: none until the project has a Settings page. */",
537
+ "export async function ownerWords(_env: Env): Promise<Readonly<Record<string, string>>> {",
538
+ " return {};",
539
+ "}",
540
+ ]),
541
+ "",
542
+ ].join("\n");
543
+ }
497
544
  function navFile(pages, byId) {
498
545
  const entries = (place) => pages
499
546
  .map((p) => ({ p, menu: byId.get(p.recipe)?.menu }))
@@ -756,7 +803,7 @@ describe("enquiries", () => {
756
803
  }
757
804
  /** src/pages/site.ts: written once, then the project's. */
758
805
  /** Each helper an earlier workbench-site wrote, by its FNV-1a hash: a project still holding one unchanged gets the newest. */
759
- const PAST_HELPERS = new Set(["dcf7ed6a", "ccd7d6a5", "c1d44c4f", "ffc5d608", "ee2ade9e", "9ee82f4f"]);
806
+ const PAST_HELPERS = new Set(["dcf7ed6a", "ccd7d6a5", "c1d44c4f", "ffc5d608", "ee2ade9e", "9ee82f4f", "80cd163b"]);
760
807
  /** FNV-1a, 32 bits: enough to know a file is one of a few texts, never a check of who wrote it. */
761
808
  function fnv(s) {
762
809
  let h = 0x811c9dc5;
@@ -831,6 +878,8 @@ export interface PageOptions {
831
878
  view?: "light" | "dark" | "admin";
832
879
  /** Stylesheets after the site's own, such as the style guide's. */
833
880
  stylesheets?: readonly string[];
881
+ /** The words the owner changed on the Settings page (src/pages/owner-words.ts), used over the catalogue's in every language. */
882
+ words?: Readonly<Record<string, string>>;
834
883
  }
835
884
 
836
885
  /** A whole page: its sections, in its frame, with the site's header and footer. */
@@ -839,7 +888,7 @@ export function sitePage(request: Request, env: Env, o: PageOptions, sections: (
839
888
  // The kit's typed keys aren't needed here: each page names its own words.
840
889
  const strings = stringsFor(env) as unknown as { detect(request: Request): { locale: string }; t(locale: string, key: string, values?: Record<string, string>): string };
841
890
  const { locale } = strings.detect(request);
842
- const w: Words = (key, values) => strings.t(locale, key, values);
891
+ const w: Words = (key, values) => o.words?.[key] ?? strings.t(locale, key, values);
843
892
  const link = ([label, href]: readonly [string, string, ...string[]]) => ({ label: w(label), href });
844
893
  // ?wb-look= and ?wb-scheme=: a public page in another look, for the look
845
894
  // previewer. Never on the live site, and never on a members or admin page.
package/dist/html.d.ts CHANGED
@@ -2,5 +2,5 @@
2
2
  export declare function escape(text: string): string;
3
3
  /** An address a link may use: a path on this site, https, mailto or tel. Anything else becomes "#". */
4
4
  export declare function safeHref(href: string): string;
5
- /** Plain words to paragraphs: a blank line starts a new one. */
5
+ /** Plain words to paragraphs: a blank line starts a new one, and a single line break stays one. */
6
6
  export declare function paragraphs(text: string, cls: string): string;
package/dist/html.js CHANGED
@@ -13,12 +13,12 @@ export function safeHref(href) {
13
13
  return h;
14
14
  return "#";
15
15
  }
16
- /** Plain words to paragraphs: a blank line starts a new one. */
16
+ /** Plain words to paragraphs: a blank line starts a new one, and a single line break stays one. */
17
17
  export function paragraphs(text, cls) {
18
18
  return text
19
19
  .split(/\n\s*\n/)
20
20
  .map((p) => p.trim())
21
21
  .filter(Boolean)
22
- .map((p) => `<p class="${cls}">${escape(p)}</p>`)
22
+ .map((p) => `<p class="${cls}">${escape(p).replace(/\s*\n\s*/g, "<br>")}</p>`)
23
23
  .join("");
24
24
  }
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { escape } from "./html.ts";
3
3
  export { account, callToAction, DESIGN_COOKIE, designModeOn, designModePost, designSwitch, details, enquiryList, needsYou, formSection, hero, HERO_ARRANGEMENTS, list, picture, text, type AccountOptions, type Action, type CallToActionOptions, type DesignSwitchOptions, type DetailRow, type DetailsOptions, type Enquiry, type EnquiryListOptions, type NeedsYouItem, type NeedsYouOptions, type FormSectionOptions, type HeroArrangement, type HeroOptions, type ListItem, type ListOptions, type Picture, type PictureOptions, type TextOptions, } from "./sections.ts";
4
4
  export { recipeKeys, recipeProblems, TIERS, type ActionSpec, type Area, type Group, type PageWords, type Recipe, type SectionSpec, type Tier, type ToolSectionFunction } from "./recipe.ts";
5
5
  export { RECIPES } from "./recipes/index.ts";
6
+ export { MAX_OWNER_LINE, MAX_OWNER_WORD, ownerWordKey, readOwnerWords, SITE_SETTINGS, siteAnswers, siteSettings, type OwnerWordsReader, type SiteOwnerSettings } from "./owner-words.ts";
6
7
  export { gatherRecipes, RECIPES_EXPORT, type GatheredRecipes, type RecipeSource } from "./gather.ts";
7
8
  export { alwaysSet, buildSite, SITE_FILE, siteProblems, type BuildOptions, type BuildResult, type SiteCheckInput, type SitePageRecord, type SiteRecord } from "./builder.ts";
8
9
  export { askedPages, fromAnswers, SITE_ANSWER_IDS, SiteAnswersError, siteAnswersProblems, type ProjectFacts as SiteProjectFacts, type SiteAnswersResult, type ToolAnswers as SiteToolAnswers } from "./from-answers.ts";
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ export { escape } from "./html.js";
6
6
  export { account, callToAction, DESIGN_COOKIE, designModeOn, designModePost, designSwitch, details, enquiryList, needsYou, formSection, hero, HERO_ARRANGEMENTS, list, picture, text, } from "./sections.js";
7
7
  export { recipeKeys, recipeProblems, TIERS } from "./recipe.js";
8
8
  export { RECIPES } from "./recipes/index.js";
9
+ export { MAX_OWNER_LINE, MAX_OWNER_WORD, ownerWordKey, readOwnerWords, SITE_SETTINGS, siteAnswers, siteSettings } from "./owner-words.js";
9
10
  export { gatherRecipes, RECIPES_EXPORT } from "./gather.js";
10
11
  export { alwaysSet, buildSite, SITE_FILE, siteProblems } from "./builder.js";
11
12
  export { askedPages, fromAnswers, SITE_ANSWER_IDS, SiteAnswersError, siteAnswersProblems } from "./from-answers.js";
@@ -0,0 +1,73 @@
1
+ import type { Recipe } from "./recipe.ts";
2
+ import type { SiteRecord } from "./builder.ts";
3
+ export { MAX_OWNER_LINE, MAX_OWNER_WORD, ownerWordKey } from "./recipe.ts";
4
+ interface OwnerWordSetting {
5
+ key: string;
6
+ type: "text";
7
+ lines: boolean;
8
+ kind: "live";
9
+ max: number;
10
+ answers: string;
11
+ label: {
12
+ en: string;
13
+ tl?: string;
14
+ taglish?: string;
15
+ };
16
+ help: {
17
+ en: string;
18
+ tl: string;
19
+ taglish: string;
20
+ };
21
+ }
22
+ /** The Settings page's section for the owner's words on these pages, as workbench-settings takes it (a ToolSettings). */
23
+ export interface SiteOwnerSettings {
24
+ format: 1;
25
+ tool: "site";
26
+ title: {
27
+ en: string;
28
+ tl: string;
29
+ taglish: string;
30
+ };
31
+ about: {
32
+ en: string;
33
+ tl: string;
34
+ taglish: string;
35
+ };
36
+ settings: readonly OwnerWordSetting[];
37
+ }
38
+ /** Every owner's word in Workbench's recipes: what the manifest declares. A site shows only its own pages' (siteSettings). */
39
+ export declare const SITE_SETTINGS: SiteOwnerSettings;
40
+ /**
41
+ * The Settings page's section for this site's pages (workbench/site.json, or
42
+ * the recipe ids on it), or null when none of them has words the owner keeps
43
+ * up to date. A page the project changed is left out: its words may no longer
44
+ * be on it. With more than one language, each word's help says it is shown
45
+ * in every language (one owner's word per word for now).
46
+ */
47
+ export declare function siteSettings(site: SiteRecord | readonly string[], catalogue?: readonly Recipe[], languages?: number): SiteOwnerSettings | null;
48
+ /**
49
+ * The words the pages were built with, as the Settings page's answers
50
+ * (`createSettings({ answers })`), so each shows "set when the app was built"
51
+ * with the page's words until the owner changes it.
52
+ */
53
+ export declare function siteAnswers(declared: SiteOwnerSettings | null, strings: Readonly<Record<string, string>>, catalogue?: readonly Recipe[]): {
54
+ site: Readonly<Record<string, string>>;
55
+ };
56
+ /** The part of workbench-settings' createSettings(...) the pages read. */
57
+ export interface OwnerWordsReader {
58
+ states(): Promise<readonly {
59
+ tool: string;
60
+ key: string;
61
+ value: unknown;
62
+ from: string;
63
+ }[]>;
64
+ }
65
+ /**
66
+ * The words the owner changed on the Settings page, by word key, for
67
+ * sitePage's `words`. Only the owner's own: a word they haven't changed stays
68
+ * the strings catalogue's, in the visitor's language. A read that fails gives
69
+ * none, so the page still draws, and a line says so. Only the words the
70
+ * Settings page shows (`declared`, from siteSettings) are used, so a word on a
71
+ * page the project has since changed can't stay on with no way to see or undo it.
72
+ */
73
+ export declare function readOwnerWords(settings: OwnerWordsReader | null, declared: SiteOwnerSettings | null, catalogue?: readonly Recipe[]): Promise<Readonly<Record<string, string>>>;
@@ -0,0 +1,90 @@
1
+ // "Your pages' words" (rule B10 of docs/builder-ready.md): the words on the
2
+ // site's pages that the owner keeps up to date after launch, such as opening
3
+ // hours, prices and answers to common questions, changed on the app's own
4
+ // Settings page (workbench-settings) with no rebuild. Each recipe names its
5
+ // own (Recipe.owner); these turn them into the Settings page's declarations,
6
+ // and read back what the owner changed for the pages to draw.
7
+ import { RECIPES } from "./recipes/index.js";
8
+ export { MAX_OWNER_LINE, MAX_OWNER_WORD, ownerWordKey } from "./recipe.js";
9
+ import { MAX_OWNER_LINE, MAX_OWNER_WORD, ownerWordKey } from "./recipe.js";
10
+ const HELP = {
11
+ en: "Shown on your site as you type it here, with no rebuild. Put back shows the words the page was built with.",
12
+ tl: "Ipinapakita sa site mo gaya ng pagkaka-type mo rito, nang hindi na ginagawa ulit ang site. Ibinabalik ng Put back ang mga salitang ginamit noong ginawa ang pahina.",
13
+ taglish: "Lalabas sa site mo as you type it here, walang rebuild. Ibabalik ng Put back ang words na ginamit noong ginawa ang page.",
14
+ };
15
+ const MANY_LANGUAGES = {
16
+ en: `${HELP.en} Shown in every language on your site.`,
17
+ tl: `${HELP.tl} Ipinapakita sa lahat ng wika sa site mo.`,
18
+ taglish: `${HELP.taglish} Lalabas sa lahat ng languages ng site mo.`,
19
+ };
20
+ function declare(recipes, multi = false) {
21
+ return {
22
+ format: 1,
23
+ tool: "site",
24
+ title: { en: "Your pages' words", tl: "Mga salita sa mga pahina mo", taglish: "Words sa pages mo" },
25
+ about: {
26
+ en: "The words on your site you keep up to date, such as your opening hours, prices and answers to common questions.",
27
+ tl: "Ang mga salita sa site mo na pinapanatili mong bago, gaya ng oras ng bukas, presyo at sagot sa mga karaniwang tanong.",
28
+ taglish: "Ang words sa site mo na kina-keep mong updated, like opening hours, prices at answers sa common questions.",
29
+ },
30
+ settings: recipes.flatMap((r) => (r.owner ?? []).map((o) => ({ key: ownerWordKey(o.word), type: "text", lines: o.lines !== false, kind: "live", max: o.lines === false ? MAX_OWNER_LINE : MAX_OWNER_WORD, answers: ownerWordKey(o.word), label: o.label, help: multi ? MANY_LANGUAGES : HELP }))),
31
+ };
32
+ }
33
+ /** Every owner's word in Workbench's recipes: what the manifest declares. A site shows only its own pages' (siteSettings). */
34
+ export const SITE_SETTINGS = declare(RECIPES);
35
+ /**
36
+ * The Settings page's section for this site's pages (workbench/site.json, or
37
+ * the recipe ids on it), or null when none of them has words the owner keeps
38
+ * up to date. A page the project changed is left out: its words may no longer
39
+ * be on it. With more than one language, each word's help says it is shown
40
+ * in every language (one owner's word per word for now).
41
+ */
42
+ export function siteSettings(site, catalogue = RECIPES, languages = 1) {
43
+ const ids = new Set(Array.isArray(site) ? site : site.pages.filter((p) => p.state !== "changed").map((p) => p.recipe));
44
+ const d = declare(catalogue.filter((r) => ids.has(r.id)), languages > 1);
45
+ return d.settings.length ? d : null;
46
+ }
47
+ /**
48
+ * The words the pages were built with, as the Settings page's answers
49
+ * (`createSettings({ answers })`), so each shows "set when the app was built"
50
+ * with the page's words until the owner changes it.
51
+ */
52
+ export function siteAnswers(declared, strings, catalogue = RECIPES) {
53
+ const out = {};
54
+ const words = new Map(catalogue.flatMap((r) => (r.owner ?? []).map((o) => [ownerWordKey(o.word), o.word])));
55
+ for (const s of declared?.settings ?? []) {
56
+ const w = strings[words.get(s.key) ?? ""];
57
+ if (typeof w === "string" && w.trim())
58
+ out[s.key] = w;
59
+ }
60
+ return { site: out };
61
+ }
62
+ /**
63
+ * The words the owner changed on the Settings page, by word key, for
64
+ * sitePage's `words`. Only the owner's own: a word they haven't changed stays
65
+ * the strings catalogue's, in the visitor's language. A read that fails gives
66
+ * none, so the page still draws, and a line says so. Only the words the
67
+ * Settings page shows (`declared`, from siteSettings) are used, so a word on a
68
+ * page the project has since changed can't stay on with no way to see or undo it.
69
+ */
70
+ export async function readOwnerWords(settings, declared, catalogue = RECIPES) {
71
+ if (!settings || !declared)
72
+ return {};
73
+ const shown = new Set(declared.settings.map((s) => s.key));
74
+ let states;
75
+ try {
76
+ states = await settings.states();
77
+ }
78
+ catch {
79
+ console.warn(JSON.stringify({ event: "owner_settings_read_failed", tool: "site" }));
80
+ return {};
81
+ }
82
+ const words = new Map(catalogue.flatMap((r) => (r.owner ?? []).map((o) => [ownerWordKey(o.word), o.word])));
83
+ const out = {};
84
+ for (const s of states) {
85
+ const word = words.get(s.key);
86
+ if (s.tool === "site" && s.from === "owner" && word && shown.has(s.key) && typeof s.value === "string" && s.value.trim())
87
+ out[word] = s.value;
88
+ }
89
+ return out;
90
+ }
package/dist/recipe.d.ts CHANGED
@@ -1,5 +1,11 @@
1
1
  import { type FrameName } from "./frames.ts";
2
2
  import { type HeroArrangement } from "./sections.ts";
3
+ /** The longest an owner's word may be, on the Settings page and as the page is built with it. */
4
+ export declare const MAX_OWNER_WORD = 2000;
5
+ /** The longest a one-line owner's word (a phone number or email address) may be. */
6
+ export declare const MAX_OWNER_LINE = 200;
7
+ /** The Settings page's key for one of a page's words: page.contact.visit.hours.value is contact_visit_hours_value. */
8
+ export declare function ownerWordKey(word: string): string;
3
9
  /** A key in the recipe's `words`, such as page.about.hero.heading. */
4
10
  export type WordKey = string;
5
11
  /**
@@ -241,6 +247,22 @@ export interface Recipe {
241
247
  file: string;
242
248
  fn: string;
243
249
  };
250
+ /**
251
+ * The words on its page the owner keeps up to date after launch (opening
252
+ * hours, prices, answers to common questions), in the order shown on the
253
+ * Settings page's "Your pages' words" (rule B10 of docs/builder-ready.md).
254
+ * Each is one of its words, and `label` names it for the owner. Public
255
+ * pages only.
256
+ */
257
+ owner?: readonly {
258
+ word: WordKey;
259
+ label: {
260
+ en: string;
261
+ tl?: string;
262
+ taglish?: string;
263
+ };
264
+ lines?: false;
265
+ }[];
244
266
  /** Its table, as a Workbench tool's own migration: supabase/migrations/<stamp>_<name>.sql and its down file, written once. */
245
267
  migration?: {
246
268
  name: string;
package/dist/recipe.js CHANGED
@@ -5,6 +5,14 @@
5
5
  // the Translations page already work.
6
6
  import { FRAMES } from "./frames.js";
7
7
  import { HERO_ARRANGEMENTS } from "./sections.js";
8
+ /** The longest an owner's word may be, on the Settings page and as the page is built with it. */
9
+ export const MAX_OWNER_WORD = 2000;
10
+ /** The longest a one-line owner's word (a phone number or email address) may be. */
11
+ export const MAX_OWNER_LINE = 200;
12
+ /** The Settings page's key for one of a page's words: page.contact.visit.hours.value is contact_visit_hours_value. */
13
+ export function ownerWordKey(word) {
14
+ return word.replace(/^page\./, "").replace(/[^a-z0-9]+/g, "_");
15
+ }
8
16
  /** The section functions a page file calls, by kind. Those in STORE_SECTIONS come from the project's src/pages/enquiry-store.ts, the rest from this package. */
9
17
  export const SECTION_FUNCTIONS = { hero: "hero", text: "text", list: "list", call: "callToAction", details: "details", account: "account", "admin-menu": "list", "needs-you": "needsYou", "enquiry-form": "enquirySection", enquiries: "enquiriesSection", "style-guide": "styleGuide", "look-preview": "lookPreview", "design-switch": "designSwitch", tool: "" };
10
18
  /** Sections whose function is in the project's own src/pages/enquiry-store.ts, which the Enquiries recipe writes. */
@@ -170,6 +178,26 @@ export function recipeProblems(r, catalogue) {
170
178
  if (!/^[a-z][A-Za-z0-9]*$/.test(r.needsYou.fn) || !(r.files?.[r.needsYou.file] ?? "").includes(`export async function ${r.needsYou.fn}(`))
171
179
  p(`its needs-you file must export async function ${r.needsYou.fn}`);
172
180
  }
181
+ const ownWords = new Set();
182
+ for (const o of r.owner ?? []) {
183
+ if (!keys.includes(o.word))
184
+ p(`its owner's word ${o.word} isn't one of its page's words`);
185
+ if (ownWords.has(o.word))
186
+ p(`its owner's word ${o.word} is listed twice`);
187
+ ownWords.add(o.word);
188
+ if (!o.label?.en?.trim() || o.label.en.length > 80)
189
+ p(`its owner's word ${o.word} needs a label, up to 80 characters`);
190
+ if (valuesFor(r, o.word).length)
191
+ p(`its owner's word ${o.word} takes values, so the owner can't change it`);
192
+ const other = catalogue.find((c) => c.id !== r.id && (c.owner ?? []).some((x) => ownerWordKey(x.word) === ownerWordKey(o.word)));
193
+ if (other)
194
+ p(`its owner's word ${o.word} has the same Settings key as one on ${other.id}`);
195
+ const most = o.lines === false ? MAX_OWNER_LINE : MAX_OWNER_WORD;
196
+ if ((r.words[o.word] ?? "").length > most)
197
+ p(`its owner's word ${o.word} is longer than ${most} characters, the most an owner can save`);
198
+ }
199
+ if (r.owner?.length && r.area !== "public")
200
+ p("only a public page has words the owner keeps up to date");
173
201
  if (r.migration && !/^workbench_site_[a-z0-9_]+$/.test(r.migration.name))
174
202
  p("a migration is named workbench_site_<what>, so Control treats it as a Workbench tool's own");
175
203
  for (const [name, v] of Object.entries(r.packages ?? {}))
@@ -88,7 +88,7 @@ const about = {
88
88
  };
89
89
  const contact = {
90
90
  id: "contact",
91
- version: 2,
91
+ version: 3,
92
92
  title: "Contact",
93
93
  does: "How to reach you: email, phone, where you are and when you're open, and a form to send you a message.",
94
94
  group: "every-site",
@@ -99,6 +99,12 @@ const contact = {
99
99
  tools: [],
100
100
  needs: ["enquiries"],
101
101
  menu: { label: "page.contact.menu", header: 90, footer: 10 },
102
+ owner: [
103
+ { word: "page.contact.visit.hours.value", label: { en: "Opening hours, on the Contact page", tl: "Oras ng bukas, sa pahinang Contact", taglish: "Opening hours, sa Contact page" } },
104
+ { word: "page.contact.visit.address.value", label: { en: "Address, on the Contact page", tl: "Address, sa pahinang Contact", taglish: "Address, sa Contact page" } },
105
+ { word: "page.contact.reach.phone.value", label: { en: "Phone number, on the Contact page", tl: "Numero ng telepono, sa pahinang Contact", taglish: "Phone number, sa Contact page" }, lines: false },
106
+ { word: "page.contact.reach.email.value", label: { en: "Email address, on the Contact page", tl: "Email address, sa pahinang Contact", taglish: "Email address, sa Contact page" }, lines: false },
107
+ ],
102
108
  pageTitle: "page.contact.title",
103
109
  sections: [
104
110
  { kind: "hero", heading: "page.contact.hero.heading", lead: "page.contact.hero.lead" },
@@ -145,7 +151,7 @@ const contact = {
145
151
  };
146
152
  const faq = {
147
153
  id: "faq",
148
- version: 1,
154
+ version: 2,
149
155
  title: "Questions and answers",
150
156
  does: "The questions people ask you most, each with your answer, so they needn't message you to find out.",
151
157
  group: "every-site",
@@ -156,6 +162,13 @@ const faq = {
156
162
  tools: [],
157
163
  needs: [],
158
164
  menu: { label: "page.faq.menu", footer: 20 },
165
+ owner: [
166
+ { word: "page.faq.where.answer", label: { en: "Where you are and when you're open, on Questions and answers", tl: "Nasaan kayo at kailan bukas, sa Mga tanong at sagot", taglish: "Nasaan kayo at kailan open, sa Questions and answers" } },
167
+ { word: "page.faq.cost.answer", label: { en: "Your prices, on Questions and answers", tl: "Ang mga presyo mo, sa Mga tanong at sagot", taglish: "Ang prices mo, sa Questions and answers" } },
168
+ { word: "page.faq.offer.answer", label: { en: "What you offer, on Questions and answers", tl: "Ang inaalok mo, sa Mga tanong at sagot", taglish: "Ang ino-offer mo, sa Questions and answers" } },
169
+ { word: "page.faq.start.answer", label: { en: "How to get started, on Questions and answers", tl: "Paano magsimula, sa Mga tanong at sagot", taglish: "Paano mag-start, sa Questions and answers" } },
170
+ { word: "page.faq.contact.answer", label: { en: "How to get in touch, on Questions and answers", tl: "Paano makipag-ugnayan, sa Mga tanong at sagot", taglish: "Paano mag-contact, sa Questions and answers" } },
171
+ ],
159
172
  pageTitle: "page.faq.title",
160
173
  sections: [
161
174
  { kind: "hero", heading: "page.faq.hero.heading", lead: "page.faq.hero.lead" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mccaskie-labs/workbench-site",
3
- "version": "0.13.0",
3
+ "version": "0.14.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",