@mccaskie-labs/workbench-site 0.0.0-stage → 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 +64 -0
- package/README.md +39 -2
- package/dist/builder.d.ts +79 -0
- package/dist/builder.js +828 -0
- package/dist/cli.d.ts +8 -0
- package/dist/cli.js +128 -0
- package/dist/frames.d.ts +91 -0
- package/dist/frames.js +63 -0
- package/dist/html.d.ts +6 -0
- package/dist/html.js +24 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +9 -0
- package/dist/recipe.d.ts +216 -0
- package/dist/recipe.js +166 -0
- package/dist/recipes/admin.d.ts +3 -0
- package/dist/recipes/admin.js +199 -0
- package/dist/recipes/enquiries-kit.d.ts +55 -0
- package/dist/recipes/enquiries-kit.js +235 -0
- package/dist/recipes/every-site.d.ts +3 -0
- package/dist/recipes/every-site.js +293 -0
- package/dist/recipes/index.d.ts +2 -0
- package/dist/recipes/index.js +7 -0
- package/dist/recipes/members.d.ts +3 -0
- package/dist/recipes/members.js +38 -0
- package/dist/samples.d.ts +18 -0
- package/dist/samples.js +69 -0
- package/dist/sections.d.ts +142 -0
- package/dist/sections.js +116 -0
- package/dist/styles.d.ts +33 -0
- package/dist/styles.js +153 -0
- package/package.json +52 -4
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export interface CliDeps {
|
|
3
|
+
log: (line: string) => void;
|
|
4
|
+
error: (line: string) => void;
|
|
5
|
+
/** Runs a command in the project; returns its exit code. */
|
|
6
|
+
run: (cmd: string, args: readonly string[], cwd: string) => number;
|
|
7
|
+
}
|
|
8
|
+
export declare function main(argv: readonly string[], deps?: CliDeps): number;
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `npx workbench-site list`
|
|
3
|
+
// The page recipes this version can build, by group.
|
|
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
|
|
7
|
+
// thin file per page in src/pages/, their words in the strings catalogue,
|
|
8
|
+
// the routes, the menu, a test per page and workbench/site.json. Then it
|
|
9
|
+
// installs this package into the project and regenerates
|
|
10
|
+
// public/styles/workbench.css (`npm install`, `npm run styles`), unless
|
|
11
|
+
// --no-install. A page already built is left alone.
|
|
12
|
+
// `npx workbench-site check [--live] [--dir <project>]` (npm run check:site)
|
|
13
|
+
// workbench/site.json against the page files and the strings catalogue
|
|
14
|
+
// (siteProblems). With --live, before go-live, a built page's word still in
|
|
15
|
+
// [square brackets] fails too.
|
|
16
|
+
import { spawnSync } from "node:child_process";
|
|
17
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
18
|
+
import { dirname, join, resolve } from "node:path";
|
|
19
|
+
import { fileURLToPath } from "node:url";
|
|
20
|
+
import { buildSite, SITE_FILE, siteProblems } from "./builder.js";
|
|
21
|
+
import { GROUPS } from "./recipe.js";
|
|
22
|
+
import { RECIPES } from "./recipes/index.js";
|
|
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" };
|
|
25
|
+
const GROUP_NAMES = { "every-site": "Every site", members: "Members", admin: "Admin", business: "For your business" };
|
|
26
|
+
function version() {
|
|
27
|
+
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
28
|
+
return pkg.version;
|
|
29
|
+
}
|
|
30
|
+
const realDeps = {
|
|
31
|
+
log: (l) => console.log(l),
|
|
32
|
+
error: (l) => console.error(l),
|
|
33
|
+
run: (cmd, args, cwd) => spawnSync(cmd, [...args], { cwd, stdio: "inherit", shell: process.platform === "win32" }).status ?? 1,
|
|
34
|
+
};
|
|
35
|
+
export function main(argv, deps = realDeps) {
|
|
36
|
+
const args = [...argv];
|
|
37
|
+
const take = (name) => {
|
|
38
|
+
const at = args.indexOf(name);
|
|
39
|
+
return at === -1 ? undefined : args.splice(at, 2)[1];
|
|
40
|
+
};
|
|
41
|
+
const flag = (name) => {
|
|
42
|
+
const at = args.indexOf(name);
|
|
43
|
+
if (at !== -1)
|
|
44
|
+
args.splice(at, 1);
|
|
45
|
+
return at !== -1;
|
|
46
|
+
};
|
|
47
|
+
const dir = resolve(take("--dir") ?? ".");
|
|
48
|
+
const noInstall = flag("--no-install");
|
|
49
|
+
const live = flag("--live");
|
|
50
|
+
const [command, ...ids] = args;
|
|
51
|
+
if (command === "list") {
|
|
52
|
+
for (const g of GROUPS) {
|
|
53
|
+
const rs = RECIPES.filter((r) => r.group === g);
|
|
54
|
+
if (!rs.length)
|
|
55
|
+
continue;
|
|
56
|
+
deps.log(`${GROUP_NAMES[g]}:`);
|
|
57
|
+
for (const r of rs)
|
|
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}`);
|
|
59
|
+
}
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
if (command === "check") {
|
|
63
|
+
const read = (p) => JSON.parse(readFileSync(join(dir, p), "utf8"));
|
|
64
|
+
if (!existsSync(join(dir, SITE_FILE))) {
|
|
65
|
+
deps.log(`No ${SITE_FILE}: the site has no built pages yet.`);
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
const pagesDir = join(dir, "src", "pages");
|
|
69
|
+
const files = Object.fromEntries((existsSync(pagesDir) ? readdirSync(pagesDir) : []).filter((f) => f.endsWith(".ts")).map((f) => [`src/pages/${f}`, readFileSync(join(pagesDir, f), "utf8")]));
|
|
70
|
+
let problems;
|
|
71
|
+
try {
|
|
72
|
+
problems = siteProblems({ site: read(SITE_FILE), strings: read("strings/strings.en-AU.json"), files, live });
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
deps.error(`✗ ${e.message}`);
|
|
76
|
+
return 1;
|
|
77
|
+
}
|
|
78
|
+
for (const p of problems)
|
|
79
|
+
deps.error(`✗ ${p}`);
|
|
80
|
+
if (!problems.length)
|
|
81
|
+
deps.log(`✓ ${SITE_FILE} matches the page files and their words${live ? ", and no word waits for the owner" : ""}.`);
|
|
82
|
+
return problems.length ? 1 : 0;
|
|
83
|
+
}
|
|
84
|
+
if (command !== "add" || ids.some((i) => i.startsWith("-"))) {
|
|
85
|
+
deps.error(USAGE);
|
|
86
|
+
return 2;
|
|
87
|
+
}
|
|
88
|
+
const result = buildSite({ read: (p) => (existsSync(join(dir, p)) ? readFileSync(join(dir, p), "utf8") : undefined), add: ids, version: version(), list: (d) => (existsSync(join(dir, d)) ? readdirSync(join(dir, d)) : undefined) });
|
|
89
|
+
if (result.problems.length) {
|
|
90
|
+
for (const p of result.problems)
|
|
91
|
+
deps.error(`✗ ${p}`);
|
|
92
|
+
return 1;
|
|
93
|
+
}
|
|
94
|
+
for (const id of result.already)
|
|
95
|
+
deps.log(`· ${id} is already on the site, so it's left as it is.`);
|
|
96
|
+
for (const [path, text] of Object.entries(result.writes)) {
|
|
97
|
+
mkdirSync(dirname(join(dir, path)), { recursive: true });
|
|
98
|
+
writeFileSync(join(dir, path), text);
|
|
99
|
+
deps.log(`✓ wrote ${path}`);
|
|
100
|
+
}
|
|
101
|
+
if (!result.added.length)
|
|
102
|
+
return 0;
|
|
103
|
+
deps.log(`\nBuilt ${result.added.join(", ")}.`);
|
|
104
|
+
const steps = [
|
|
105
|
+
["npm", ["install", "--no-audit", "--no-fund"]],
|
|
106
|
+
...(result.forms ? [["npm", ["run", "forms"]]] : []),
|
|
107
|
+
["npm", ["run", "styles"]],
|
|
108
|
+
];
|
|
109
|
+
const tables = result.migrations.length
|
|
110
|
+
? `\nThe pages need ${result.migrations.length === 1 ? "a new table" : "new tables"}: apply ${result.migrations.join(", ")} on staging with Workbench Control (sb_migration_apply), then refresh supabase/staging-columns.json (npx workbench-supabase limits-sql, run with sb_query env=staging, piped to npx workbench-supabase limits-save --env staging). Until then check:limits and the forms kit fail.`
|
|
111
|
+
: "";
|
|
112
|
+
if (noInstall) {
|
|
113
|
+
deps.log(`Next: ${steps.map(([c, a]) => `${c} ${a[0] === "run" ? a.join(" ") : a[0]}`).join(", then ")}.${tables}`);
|
|
114
|
+
return 0;
|
|
115
|
+
}
|
|
116
|
+
for (const [cmd, a] of steps) {
|
|
117
|
+
const code = deps.run(cmd, [...a], dir);
|
|
118
|
+
if (code !== 0) {
|
|
119
|
+
deps.error(`✗ ${cmd} ${a.join(" ")} failed (exit ${code}). Run it again in ${dir}.`);
|
|
120
|
+
return 1;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
deps.log(`Done. Each page's words are in the strings catalogue: replace those in [square brackets] with the owner's.${tables}`);
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
|
126
|
+
const self = fileURLToPath(import.meta.url);
|
|
127
|
+
if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(self))
|
|
128
|
+
process.exit(main(process.argv.slice(2)));
|
package/dist/frames.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* - landing: full-width sections, for a home page
|
|
3
|
+
* - column: one centred column of reading width, for about, legal and most pages
|
|
4
|
+
* - two-columns: the first section across the top, the rest in two columns
|
|
5
|
+
*/
|
|
6
|
+
export declare const FRAMES: readonly ["landing", "column", "two-columns"];
|
|
7
|
+
export type FrameName = (typeof FRAMES)[number];
|
|
8
|
+
/**
|
|
9
|
+
* The site layout's header and footer (docs/look-studio.md §6), the first of
|
|
10
|
+
* each the default. They match workbench-ui's SITE_LAYOUT_CHOICES, and the
|
|
11
|
+
* look's site layout (or brand.json's `layout`) picks them; the page width and
|
|
12
|
+
* section spacing are theme tokens (--wb-page-width, --wb-section-space).
|
|
13
|
+
* - menu-right: the name on the left, the menu on the right
|
|
14
|
+
* - centred: the name centred over the menu
|
|
15
|
+
* - menu-centre: the name on the left, the menu in the middle, one button on the right
|
|
16
|
+
*/
|
|
17
|
+
export declare const HEADERS: readonly ["menu-right", "centred", "menu-centre"];
|
|
18
|
+
export type HeaderStyle = (typeof HEADERS)[number];
|
|
19
|
+
/** - line: one line of links; columns: the links and the note side by side; centred: everything centred. */
|
|
20
|
+
export declare const FOOTERS: readonly ["line", "columns", "centred"];
|
|
21
|
+
export type FooterStyle = (typeof FOOTERS)[number];
|
|
22
|
+
/** The parts of a site layout a frame draws. */
|
|
23
|
+
export interface FrameLayout {
|
|
24
|
+
header?: HeaderStyle;
|
|
25
|
+
footer?: FooterStyle;
|
|
26
|
+
}
|
|
27
|
+
export interface MenuLink {
|
|
28
|
+
label: string;
|
|
29
|
+
href: string;
|
|
30
|
+
}
|
|
31
|
+
export interface FrameOptions {
|
|
32
|
+
frame: FrameName;
|
|
33
|
+
/** The page's name for the tab title. Plain text. */
|
|
34
|
+
title: string;
|
|
35
|
+
/** The business's name: the header's first link and the tab title's second half. */
|
|
36
|
+
site: string;
|
|
37
|
+
/** The page's sections, in order (from this package's sections or a tool's). */
|
|
38
|
+
sections: readonly string[];
|
|
39
|
+
/** The site layout's header and footer. Both default to the first choice. */
|
|
40
|
+
layout?: FrameLayout;
|
|
41
|
+
/** One button at the end of the header, such as Book now: the menu-centre header's button. */
|
|
42
|
+
headerAction?: MenuLink;
|
|
43
|
+
/** The header's links. The one whose href is `current` is marked as the page you're on. */
|
|
44
|
+
menu?: readonly MenuLink[];
|
|
45
|
+
/** The footer's links (privacy, terms, contact). */
|
|
46
|
+
footer?: readonly MenuLink[];
|
|
47
|
+
/** A line in the footer, such as the business's name and ABN. */
|
|
48
|
+
footerNote?: string;
|
|
49
|
+
/** This page's path, to mark it in the menu. */
|
|
50
|
+
current?: string;
|
|
51
|
+
/** The page's language, for <html lang>. Defaults to en-AU. */
|
|
52
|
+
lang?: string;
|
|
53
|
+
/** The stylesheet addresses: workbench-ui's STYLESHEETS (workbench.css, then project.css). */
|
|
54
|
+
stylesheets: readonly string[];
|
|
55
|
+
/** More for the <head>, such as the analytics beacon. Trusted HTML. */
|
|
56
|
+
head?: string;
|
|
57
|
+
/** Keeps the page out of search engines: members and admin pages. */
|
|
58
|
+
noindex?: boolean;
|
|
59
|
+
/** An admin page: adds wb-ui-admin to <html>, for the theme's admin look (light, the project's accent and fonts). */
|
|
60
|
+
admin?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Shows the page in the project's light or dark look whatever its own scheme:
|
|
63
|
+
* data-wb-scheme on <html>, which the style guide's sheet (style-guide.css,
|
|
64
|
+
* from workbench-ui) answers. Only the style guide page uses it.
|
|
65
|
+
*/
|
|
66
|
+
scheme?: "light" | "dark";
|
|
67
|
+
/**
|
|
68
|
+
* Shows the page in another look (docs/look-studio.md §5.3): data-wb-look and
|
|
69
|
+
* data-wb-scheme on <html>, and workbench-ui's preview styles (looks.css)
|
|
70
|
+
* after the page's own. From workbench-ui's previewAttributes, which only a
|
|
71
|
+
* signed-in admin or a page outside production may ask for.
|
|
72
|
+
*/
|
|
73
|
+
preview?: {
|
|
74
|
+
look: string;
|
|
75
|
+
scheme: "light" | "dark";
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Design mode (docs/look-studio.md §8): workbench-ui's design script (its
|
|
79
|
+
* DESIGN_FILE.url) at the end of the page, and the preview styles, so an
|
|
80
|
+
* admin can try looks and layouts in place. `keep` is where Keep saves.
|
|
81
|
+
* Never on an admin page.
|
|
82
|
+
*/
|
|
83
|
+
design?: {
|
|
84
|
+
script: string;
|
|
85
|
+
keep?: string;
|
|
86
|
+
};
|
|
87
|
+
/** The environment; anything but production shows a small tag in the header, so a test page is never mistaken for the live one. */
|
|
88
|
+
env?: string;
|
|
89
|
+
}
|
|
90
|
+
/** A whole page: header, the sections in the chosen frame, footer. */
|
|
91
|
+
export declare function frame(o: FrameOptions): string;
|
package/dist/frames.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Page frames: the whole page around a page's sections (docs/site-planner.md
|
|
2
|
+
// §8): the site's header with its menu, the main area laid out one of a few
|
|
3
|
+
// ways, and the footer. A page names its frame in one word, so the project's
|
|
4
|
+
// Claude changes a layout by editing that word.
|
|
5
|
+
// Members and admin pages use the same frames, with noindex; an admin page's
|
|
6
|
+
// header carries the admin menu instead of the site's, and its <html> carries
|
|
7
|
+
// wb-ui-admin, so it takes the project's accent and fonts on Clean's light
|
|
8
|
+
// neutrals (docs/theming.md, Decisions) however dark or bold the public look.
|
|
9
|
+
import { escape, safeHref } from "./html.js";
|
|
10
|
+
/**
|
|
11
|
+
* - landing: full-width sections, for a home page
|
|
12
|
+
* - column: one centred column of reading width, for about, legal and most pages
|
|
13
|
+
* - two-columns: the first section across the top, the rest in two columns
|
|
14
|
+
*/
|
|
15
|
+
export const FRAMES = ["landing", "column", "two-columns"];
|
|
16
|
+
/**
|
|
17
|
+
* The site layout's header and footer (docs/look-studio.md §6), the first of
|
|
18
|
+
* each the default. They match workbench-ui's SITE_LAYOUT_CHOICES, and the
|
|
19
|
+
* look's site layout (or brand.json's `layout`) picks them; the page width and
|
|
20
|
+
* section spacing are theme tokens (--wb-page-width, --wb-section-space).
|
|
21
|
+
* - menu-right: the name on the left, the menu on the right
|
|
22
|
+
* - centred: the name centred over the menu
|
|
23
|
+
* - menu-centre: the name on the left, the menu in the middle, one button on the right
|
|
24
|
+
*/
|
|
25
|
+
export const HEADERS = ["menu-right", "centred", "menu-centre"];
|
|
26
|
+
/** - line: one line of links; columns: the links and the note side by side; centred: everything centred. */
|
|
27
|
+
export const FOOTERS = ["line", "columns", "centred"];
|
|
28
|
+
const links = (items, cls, current) => items
|
|
29
|
+
.map((l) => {
|
|
30
|
+
const href = safeHref(l.href);
|
|
31
|
+
const here = current !== undefined && href === current ? ` aria-current="page"` : "";
|
|
32
|
+
return `<a class="${cls}" href="${escape(href)}"${here}>${escape(l.label)}</a>`;
|
|
33
|
+
})
|
|
34
|
+
.join("");
|
|
35
|
+
/** workbench-ui's preview styles (its PREVIEW_FILE.url): every look a project may choose, as switchable blocks. */
|
|
36
|
+
const PREVIEW_SHEET = "/styles/looks.css";
|
|
37
|
+
const LOOK_ID = /^[a-z][a-z0-9-]{0,39}$/;
|
|
38
|
+
/** A known choice, or the first (the default) for one the frame doesn't know. */
|
|
39
|
+
const pick = (choices, value) => choices.includes(value ?? "") ? value : choices[0];
|
|
40
|
+
/** A whole page: header, the sections in the chosen frame, footer. */
|
|
41
|
+
export function frame(o) {
|
|
42
|
+
const lang = o.lang ?? "en-AU";
|
|
43
|
+
const env = o.env && o.env !== "production" ? `<span class="wb-site-env">${escape(o.env)}</span>` : "";
|
|
44
|
+
const menu = o.menu?.length ? `<nav class="wb-site-menu" aria-label="Main">${links(o.menu, "wb-site-menu-link", o.current)}</nav>` : "";
|
|
45
|
+
const headerStyle = pick(HEADERS, o.layout?.header);
|
|
46
|
+
const footerStyle = pick(FOOTERS, o.layout?.footer);
|
|
47
|
+
const action = o.headerAction ? `<a class="wb-site-button wb-site-header-action" href="${escape(safeHref(o.headerAction.href))}">${escape(o.headerAction.label)}</a>` : "";
|
|
48
|
+
const header = `<header class="wb-site-header" data-header="${headerStyle}"><div class="wb-site-header-row"><a class="wb-site-name" href="/">${escape(o.site)}</a>${env}${menu}${action}</div></header>`;
|
|
49
|
+
const [first = "", ...rest] = o.sections;
|
|
50
|
+
const main = o.frame === "two-columns"
|
|
51
|
+
? `${first}${rest.length ? `<div class="wb-site-columns">${rest.join("")}</div>` : ""}`
|
|
52
|
+
: o.sections.join("");
|
|
53
|
+
const footerLinks = o.footer?.length ? `<nav class="wb-site-footer-links" aria-label="More">${links(o.footer, "wb-site-footer-link", o.current)}</nav>` : "";
|
|
54
|
+
const note = o.footerNote ? `<p class="wb-site-footer-note">${escape(o.footerNote)}</p>` : "";
|
|
55
|
+
const footer = `<footer class="wb-site-footer" data-footer="${footerStyle}">${footerLinks}${note}</footer>`;
|
|
56
|
+
const preview = o.preview && !o.admin && LOOK_ID.test(o.preview.look) ? { look: o.preview.look, scheme: o.preview.scheme === "dark" ? "dark" : "light" } : undefined;
|
|
57
|
+
const scheme = preview ? preview.scheme : o.scheme === "light" || o.scheme === "dark" ? o.scheme : undefined;
|
|
58
|
+
const colours = o.admin ? "light" : scheme;
|
|
59
|
+
const design = o.design && !o.admin && /^\/[A-Za-z0-9/_.-]*$/.test(o.design.script) ? o.design : undefined;
|
|
60
|
+
const sheets = [...o.stylesheets, ...(preview || design ? [PREVIEW_SHEET] : [])].map((href) => `<link rel="stylesheet" href="${escape(href)}">`).join("");
|
|
61
|
+
return `<!doctype html><html lang="${escape(lang)}" class="wb-site${o.admin ? " wb-ui-admin" : ""}"${preview ? ` data-wb-look="${preview.look}"` : ""}${scheme && !o.admin ? ` data-wb-scheme="${scheme}"` : ""}><head><meta charset="utf-8">${colours ? `<meta name="color-scheme" content="${colours}">` : ""}<meta name="viewport" content="width=device-width,initial-scale=1"><title>${escape(o.title)} · ${escape(o.site)}</title>${o.noindex ? '<meta name="robots" content="noindex">' : ""}${sheets}${o.head ?? ""}</head>
|
|
62
|
+
<body class="wb-site-body">${header}<main class="wb-site-main" data-frame="${o.frame}">${main}</main>${footer}${design ? `<script src="${escape(design.script)}"${design.keep ? ` data-keep="${escape(design.keep)}"` : ""}></script>` : ""}</body></html>`;
|
|
63
|
+
}
|
package/dist/html.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Escapes text for HTML content and double-quoted attributes. */
|
|
2
|
+
export declare function escape(text: string): string;
|
|
3
|
+
/** An address a link may use: a path on this site, https, mailto or tel. Anything else becomes "#". */
|
|
4
|
+
export declare function safeHref(href: string): string;
|
|
5
|
+
/** Plain words to paragraphs: a blank line starts a new one. */
|
|
6
|
+
export declare function paragraphs(text: string, cls: string): string;
|
package/dist/html.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Escaping for the HTML the sections and frames draw. Every word a section
|
|
2
|
+
// takes is plain text; only the `body` a frame wraps is HTML (the sections').
|
|
3
|
+
/** Escapes text for HTML content and double-quoted attributes. */
|
|
4
|
+
export function escape(text) {
|
|
5
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
6
|
+
}
|
|
7
|
+
/** An address a link may use: a path on this site, https, mailto or tel. Anything else becomes "#". */
|
|
8
|
+
export function safeHref(href) {
|
|
9
|
+
const h = href.trim();
|
|
10
|
+
if (/^\/(?!\/)/.test(h) || /^#/.test(h))
|
|
11
|
+
return h;
|
|
12
|
+
if (/^(https:\/\/|mailto:|tel:)/i.test(h))
|
|
13
|
+
return h;
|
|
14
|
+
return "#";
|
|
15
|
+
}
|
|
16
|
+
/** Plain words to paragraphs: a blank line starts a new one. */
|
|
17
|
+
export function paragraphs(text, cls) {
|
|
18
|
+
return text
|
|
19
|
+
.split(/\n\s*\n/)
|
|
20
|
+
.map((p) => p.trim())
|
|
21
|
+
.filter(Boolean)
|
|
22
|
+
.map((p) => `<p class="${cls}">${escape(p)}</p>`)
|
|
23
|
+
.join("");
|
|
24
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { frame, FOOTERS, FRAMES, HEADERS, type FooterStyle, type FrameLayout, type FrameName, type FrameOptions, type HeaderStyle, type MenuLink } from "./frames.ts";
|
|
2
|
+
export { escape } from "./html.ts";
|
|
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, TIERS, type ActionSpec, type Area, type Group, type Recipe, type SectionSpec, type Tier } from "./recipe.ts";
|
|
5
|
+
export { RECIPES } from "./recipes/index.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
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @mccaskie-labs/workbench-site: the site's standard pages (docs/site-planner.md).
|
|
2
|
+
// Page recipes (data), the builder that turns them into thin page files in a
|
|
3
|
+
// project, and the page frames and sections those files call.
|
|
4
|
+
export { frame, FOOTERS, FRAMES, HEADERS } from "./frames.js";
|
|
5
|
+
export { escape } from "./html.js";
|
|
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, TIERS } from "./recipe.js";
|
|
8
|
+
export { RECIPES } from "./recipes/index.js";
|
|
9
|
+
export { alwaysSet, buildSite, SITE_FILE, siteProblems } from "./builder.js";
|
package/dist/recipe.d.ts
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { type FrameName } from "./frames.ts";
|
|
2
|
+
import { type HeroArrangement } from "./sections.ts";
|
|
3
|
+
/** A key in the recipe's `words`, such as page.about.hero.heading. */
|
|
4
|
+
export type WordKey = string;
|
|
5
|
+
/**
|
|
6
|
+
* Where a button goes: another recipe's id (the button is left out when that
|
|
7
|
+
* page isn't on the site) or a fixed path on this site ("/").
|
|
8
|
+
*/
|
|
9
|
+
export interface ActionSpec {
|
|
10
|
+
label: WordKey;
|
|
11
|
+
to: string;
|
|
12
|
+
}
|
|
13
|
+
export type SectionSpec = {
|
|
14
|
+
kind: "hero";
|
|
15
|
+
heading: WordKey;
|
|
16
|
+
lead?: WordKey;
|
|
17
|
+
action?: ActionSpec;
|
|
18
|
+
arrangement?: HeroArrangement;
|
|
19
|
+
} | {
|
|
20
|
+
kind: "text";
|
|
21
|
+
heading?: WordKey;
|
|
22
|
+
body: WordKey;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "list";
|
|
25
|
+
heading?: WordKey;
|
|
26
|
+
items: readonly {
|
|
27
|
+
title: WordKey;
|
|
28
|
+
body?: WordKey;
|
|
29
|
+
}[];
|
|
30
|
+
}
|
|
31
|
+
/** Left out when its button's page isn't on the site. */
|
|
32
|
+
| {
|
|
33
|
+
kind: "call";
|
|
34
|
+
heading: WordKey;
|
|
35
|
+
body?: WordKey;
|
|
36
|
+
action: ActionSpec;
|
|
37
|
+
} | {
|
|
38
|
+
kind: "details";
|
|
39
|
+
heading?: WordKey;
|
|
40
|
+
rows: readonly {
|
|
41
|
+
label: WordKey;
|
|
42
|
+
value: WordKey;
|
|
43
|
+
}[];
|
|
44
|
+
}
|
|
45
|
+
/** Who is signed in and a sign-out button: members pages only. `signedIn` holds {email}. */
|
|
46
|
+
| {
|
|
47
|
+
kind: "account";
|
|
48
|
+
heading?: WordKey;
|
|
49
|
+
signedIn: WordKey;
|
|
50
|
+
signOut: WordKey;
|
|
51
|
+
}
|
|
52
|
+
/** Every admin page on the site, each with what it's for: admin pages only. */
|
|
53
|
+
| {
|
|
54
|
+
kind: "admin-menu";
|
|
55
|
+
heading?: WordKey;
|
|
56
|
+
}
|
|
57
|
+
/** The enquiry form (workbench/forms/enquiry.json), or its thank-you once sent: public pages, with the Enquiries page on the site. `send` is the button's key. */
|
|
58
|
+
| {
|
|
59
|
+
kind: "enquiry-form";
|
|
60
|
+
heading: WordKey;
|
|
61
|
+
intro?: WordKey;
|
|
62
|
+
send: WordKey;
|
|
63
|
+
sent: WordKey;
|
|
64
|
+
unavailable: WordKey;
|
|
65
|
+
}
|
|
66
|
+
/** The site's enquiries, newest first, with a delete button each: admin pages only. */
|
|
67
|
+
| {
|
|
68
|
+
kind: "enquiries";
|
|
69
|
+
heading?: WordKey;
|
|
70
|
+
empty: WordKey;
|
|
71
|
+
unavailable: WordKey;
|
|
72
|
+
remove: WordKey;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Every sample of every tool the project uses, in its look, with a switch
|
|
76
|
+
* between light, dark and the admin look (workbench-ui's styleGuide, the
|
|
77
|
+
* project's src/samples.generated.ts): admin pages only.
|
|
78
|
+
*/
|
|
79
|
+
| {
|
|
80
|
+
kind: "style-guide";
|
|
81
|
+
views: WordKey;
|
|
82
|
+
light: WordKey;
|
|
83
|
+
dark: WordKey;
|
|
84
|
+
admin: WordKey;
|
|
85
|
+
empty: WordKey;
|
|
86
|
+
layout: WordKey;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The site's own home page and the first two of its header's pages, in every
|
|
90
|
+
* look it may choose, side by side, light or dark (workbench-ui's lookPreview,
|
|
91
|
+
* docs/look-studio.md §9.1): admin pages only. On the live site, only its own look.
|
|
92
|
+
*/
|
|
93
|
+
/**
|
|
94
|
+
* Design mode's switch (docs/look-studio.md §8): turns it on or off in this
|
|
95
|
+
* browser, on the test site only. Its page takes the switch's POST: admin pages only.
|
|
96
|
+
*/
|
|
97
|
+
| {
|
|
98
|
+
kind: "design-switch";
|
|
99
|
+
on: WordKey;
|
|
100
|
+
off: WordKey;
|
|
101
|
+
turnOn: WordKey;
|
|
102
|
+
turnOff: WordKey;
|
|
103
|
+
live: WordKey;
|
|
104
|
+
} | {
|
|
105
|
+
kind: "look-preview";
|
|
106
|
+
home: WordKey;
|
|
107
|
+
pages: WordKey;
|
|
108
|
+
schemes: WordKey;
|
|
109
|
+
light: WordKey;
|
|
110
|
+
dark: WordKey;
|
|
111
|
+
yours: WordKey;
|
|
112
|
+
inUse: WordKey;
|
|
113
|
+
open: WordKey;
|
|
114
|
+
live: WordKey;
|
|
115
|
+
};
|
|
116
|
+
/** 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. */
|
|
117
|
+
export declare const SECTION_FUNCTIONS: {
|
|
118
|
+
readonly hero: "hero";
|
|
119
|
+
readonly text: "text";
|
|
120
|
+
readonly list: "list";
|
|
121
|
+
readonly call: "callToAction";
|
|
122
|
+
readonly details: "details";
|
|
123
|
+
readonly account: "account";
|
|
124
|
+
readonly "admin-menu": "list";
|
|
125
|
+
readonly "enquiry-form": "enquirySection";
|
|
126
|
+
readonly enquiries: "enquiriesSection";
|
|
127
|
+
readonly "style-guide": "styleGuide";
|
|
128
|
+
readonly "look-preview": "lookPreview";
|
|
129
|
+
readonly "design-switch": "designSwitch";
|
|
130
|
+
};
|
|
131
|
+
/** Sections whose function is in the project's own src/pages/enquiry-store.ts, which the Enquiries recipe writes. */
|
|
132
|
+
export declare const STORE_SECTIONS: ReadonlySet<SectionSpec["kind"]>;
|
|
133
|
+
/** Sections whose function comes from workbench-ui, not this package. */
|
|
134
|
+
export declare const UI_SECTIONS: ReadonlySet<SectionSpec["kind"]>;
|
|
135
|
+
declare const AREAS: readonly ["public", "members", "admin", "legal"];
|
|
136
|
+
export type Area = (typeof AREAS)[number];
|
|
137
|
+
export declare const GROUPS: readonly ["every-site", "members", "admin", "business"];
|
|
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>>;
|
|
149
|
+
export interface Recipe {
|
|
150
|
+
/** Its name in the catalogue and on the command line: lower case and hyphens. */
|
|
151
|
+
id: string;
|
|
152
|
+
/** Bumped when what the builder writes for it changes. */
|
|
153
|
+
version: number;
|
|
154
|
+
/** Its name and what it does, in the owner's words, shown beside its checkbox. */
|
|
155
|
+
title: string;
|
|
156
|
+
does: string;
|
|
157
|
+
group: Group;
|
|
158
|
+
/** Whether the owner is asked about it: always, ticked or offered. */
|
|
159
|
+
tier: Tier;
|
|
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. */
|
|
161
|
+
area: Area;
|
|
162
|
+
/** Its default address. Null for a page no address opens: Not found (status 404) and Something went wrong (status 500). */
|
|
163
|
+
path: string | null;
|
|
164
|
+
/** The answer's status: 404 for Not found, 500 for Something went wrong. Defaults to 200. */
|
|
165
|
+
status?: number;
|
|
166
|
+
/** The frames it can use, its default first. */
|
|
167
|
+
frames: readonly FrameName[];
|
|
168
|
+
/** The tools it is wired to. A recipe is offered only when its tools exist, and built only with tools the owner has said yes to. */
|
|
169
|
+
tools: readonly string[];
|
|
170
|
+
/** Other recipes it can't work without; the builder adds them too. */
|
|
171
|
+
needs: readonly string[];
|
|
172
|
+
/**
|
|
173
|
+
* Its links: in the site's header and footer, and in the admin menu (with
|
|
174
|
+
* `about`, a line on what the page is for), each a place in the order
|
|
175
|
+
* (lower first).
|
|
176
|
+
*/
|
|
177
|
+
menu?: {
|
|
178
|
+
label: WordKey;
|
|
179
|
+
header?: number;
|
|
180
|
+
footer?: number;
|
|
181
|
+
admin?: number;
|
|
182
|
+
about?: WordKey;
|
|
183
|
+
};
|
|
184
|
+
/** Admin menu links to pages the template already has (Brand settings), added when this recipe is built. */
|
|
185
|
+
links?: readonly {
|
|
186
|
+
label: WordKey;
|
|
187
|
+
about: WordKey;
|
|
188
|
+
href: string;
|
|
189
|
+
admin: number;
|
|
190
|
+
}[];
|
|
191
|
+
/** Files it needs besides its page, written only when the project doesn't have them yet (a form's answers file, the code its sections call). */
|
|
192
|
+
files?: Readonly<Record<string, string>>;
|
|
193
|
+
/** Workbench packages its page needs at least this version of (x.y.z): the builder raises the project's to it. */
|
|
194
|
+
packages?: Readonly<Record<string, string>>;
|
|
195
|
+
/** Its table, as a Workbench tool's own migration: supabase/migrations/<stamp>_<name>.sql and its down file, written once. */
|
|
196
|
+
migration?: {
|
|
197
|
+
name: string;
|
|
198
|
+
up: string;
|
|
199
|
+
down: string;
|
|
200
|
+
};
|
|
201
|
+
/** The tab title. */
|
|
202
|
+
pageTitle: WordKey;
|
|
203
|
+
sections: readonly SectionSpec[];
|
|
204
|
+
/** Every word, with its default English. Words in [square brackets] are the owner's to fill in. */
|
|
205
|
+
words: Readonly<Record<WordKey, string>>;
|
|
206
|
+
/** When it fits, for the planner: starter types (empty for "every site") and plain-word signals. */
|
|
207
|
+
suggest: {
|
|
208
|
+
types: readonly string[];
|
|
209
|
+
signals: readonly string[];
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/** Every word key the recipe's page names, in order. */
|
|
213
|
+
export declare function recipeKeys(r: Recipe): WordKey[];
|
|
214
|
+
/** What's wrong with a recipe in a catalogue: empty when it can be built. */
|
|
215
|
+
export declare function recipeProblems(r: Recipe, catalogue: readonly Recipe[]): string[];
|
|
216
|
+
export {};
|