@luhtech/site-template 0.24.1 → 0.25.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/README.md +46 -0
- package/bin/lib/assetBank.mjs +74 -0
- package/bin/lib/ground.mjs +99 -0
- package/bin/luhtech-sync-boards.mjs +170 -0
- package/bin/luhtech-sync-icons.mjs +28 -11
- package/bin/luhtech-sync-mark-set.mjs +166 -0
- package/bin/luhtech-tokens.mjs +75 -28
- package/package.json +5 -1
- package/src/components/AssetRequestForm.astro +1 -1
- package/src/components/Block.astro +1 -1
- package/src/components/Board.astro +46 -0
- package/src/components/CtaLink.astro +1 -1
- package/src/components/Diagram.astro +2 -0
- package/src/components/Figure.astro +1 -1
- package/src/components/LeadCaptureForm.astro +5 -5
- package/src/components/Mark.astro +21 -0
- package/src/components/PaperLanding.astro +2 -2
- package/src/components/SplashHero.astro +6 -6
- package/src/components/ToolCalculator.astro +6 -6
- package/src/components/VentureCard.astro +1 -1
- package/src/components/sections/Audiences.astro +1 -1
- package/src/content/figures.ts +12 -1
- package/src/layouts/SiteLayout.astro +17 -11
- package/src/lib/boards.ts +123 -0
- package/src/lib/markSet.ts +72 -0
- package/src/lib/seoHead.ts +18 -3
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// A banked board on a site (0.25.0, d-2026-12-04-lb-site-ground-and-marks OUT-8), drawn the way the deck's
|
|
2
|
+
// board layout draws it, by the deck's own rule.
|
|
3
|
+
//
|
|
4
|
+
// bin/luhtech-sync-boards.mjs verifies each board's bytes against its asset-bank record and writes them with a
|
|
5
|
+
// manifest that carries the rule as schema-registry's channel-renders deck-react meta.boardLayout states it (the
|
|
6
|
+
// fit, the aspect tolerance, the legibility floor, the content budget). Nothing here restates those numbers.
|
|
7
|
+
//
|
|
8
|
+
// The legibility floor at the width a board is drawn: a board drawn at the fit width (1x) has its own stated
|
|
9
|
+
// minTextScale; drawn at width W its smallest type scales by W / fitWidth. So a board is legible at W when
|
|
10
|
+
// minTextScale * W / fitWidth >= the floor, and Board.astro draws it no narrower than that -- at its own aspect,
|
|
11
|
+
// scrolling sideways inside its figure where the column is narrower (as ConnectionGraph does on a phone).
|
|
12
|
+
import { createHash } from 'node:crypto';
|
|
13
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
|
|
16
|
+
export const BOARDS_MANIFEST = 'src/generated/boards/manifest.json';
|
|
17
|
+
|
|
18
|
+
export interface BoardRule {
|
|
19
|
+
source: string;
|
|
20
|
+
fitWidth: number;
|
|
21
|
+
fitHeight: number;
|
|
22
|
+
aspectTolerance: number;
|
|
23
|
+
minTextScaleFloor: number;
|
|
24
|
+
contentBudget: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface BoardEntry {
|
|
28
|
+
assetId: string;
|
|
29
|
+
sha256: string;
|
|
30
|
+
mimeType: string;
|
|
31
|
+
width: number;
|
|
32
|
+
height: number;
|
|
33
|
+
src: string;
|
|
34
|
+
rule: BoardRule;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type BoardText = string | { role?: string; value: string };
|
|
38
|
+
|
|
39
|
+
const cache = new Map<string, { rule: BoardRule; boards: Record<string, BoardEntry> }>();
|
|
40
|
+
|
|
41
|
+
/** The site's synced boards, the bytes re-hashed against the manifest. */
|
|
42
|
+
export function loadBoards(siteRoot: string = process.cwd()): { rule: BoardRule; boards: Record<string, BoardEntry> } {
|
|
43
|
+
const hit = cache.get(siteRoot);
|
|
44
|
+
if (hit) return hit;
|
|
45
|
+
const path = join(siteRoot, BOARDS_MANIFEST);
|
|
46
|
+
if (!existsSync(path)) throw new Error(`no boards at ${path}: run luhtech-sync-boards in the site's prebuild`);
|
|
47
|
+
const manifest = JSON.parse(readFileSync(path, 'utf-8'));
|
|
48
|
+
const rule: BoardRule = manifest.rule;
|
|
49
|
+
const boards: Record<string, BoardEntry> = {};
|
|
50
|
+
for (const [assetId, b] of Object.entries<any>(manifest.boards ?? {})) {
|
|
51
|
+
const got = createHash('sha256').update(readFileSync(join(siteRoot, manifest.out, b.file))).digest('hex');
|
|
52
|
+
if (got !== b.sha256) throw new Error(`board ${assetId}: ${b.file} hashes to ${got}, the manifest says ${b.sha256} -- re-run luhtech-sync-boards`);
|
|
53
|
+
boards[assetId] = { assetId, sha256: b.sha256, mimeType: b.mimeType, width: b.width, height: b.height, src: b.src, rule };
|
|
54
|
+
}
|
|
55
|
+
const out = { rule, boards };
|
|
56
|
+
cache.set(siteRoot, out);
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function boardFor(assetId: string, siteRoot?: string): BoardEntry {
|
|
61
|
+
const { boards } = loadBoards(siteRoot);
|
|
62
|
+
const b = boards[assetId];
|
|
63
|
+
if (!b) throw new Error(`Board: ${assetId} is not among this site's synced boards (${Object.keys(boards).sort().join(', ') || 'none'})`);
|
|
64
|
+
return b;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The board's smallest type, over the deck body type, when the board is drawn `drawnWidth` wide. */
|
|
68
|
+
export function scaleAt(rule: BoardRule, minTextScale: number, drawnWidth: number): number {
|
|
69
|
+
return (minTextScale * drawnWidth) / rule.fitWidth;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The narrowest width (CSS px, whole) at which the board's smallest type still meets the floor. */
|
|
73
|
+
export function legibleWidth(rule: BoardRule, minTextScale: number): number {
|
|
74
|
+
return Math.ceil((rule.fitWidth * rule.minTextScaleFloor) / minTextScale - 1e-9);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** budget(board) = floor(contentBudget / minTextScale^2), the deck's rule. */
|
|
78
|
+
export function wordBudget(rule: BoardRule, minTextScale: number): number {
|
|
79
|
+
return Math.floor(rule.contentBudget / minTextScale ** 2);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const wordCount = (text: BoardText[]): number =>
|
|
83
|
+
text.reduce((n, t) => n + (typeof t === 'string' ? t : t.value).split(/\s+/).filter(Boolean).length, 0);
|
|
84
|
+
|
|
85
|
+
/** What Board.astro refuses at build: no alt, no words, a scale below the floor, words over the budget. */
|
|
86
|
+
export function boardAuthoringProblems(b: BoardEntry, alt: string, text: BoardText[], minTextScale: number): string[] {
|
|
87
|
+
const out: string[] = [];
|
|
88
|
+
if (!alt?.trim()) out.push(`${b.assetId}: no alt`);
|
|
89
|
+
if (!Array.isArray(text) || text.length === 0) out.push(`${b.assetId}: no words -- the board's words are data on the page`);
|
|
90
|
+
if (!(typeof minTextScale === 'number' && minTextScale > 0)) {
|
|
91
|
+
out.push(`${b.assetId}: no minTextScale -- the board's smallest type over the deck body type, from its deck record`);
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
if (minTextScale < b.rule.minTextScaleFloor) {
|
|
95
|
+
out.push(`${b.assetId}: minTextScale ${minTextScale} is below the legibility floor ${b.rule.minTextScaleFloor} (${b.rule.source})`);
|
|
96
|
+
}
|
|
97
|
+
const words = Array.isArray(text) ? wordCount(text) : 0;
|
|
98
|
+
const budget = wordBudget(b.rule, minTextScale);
|
|
99
|
+
if (words > budget) out.push(`${b.assetId}: ${words} words, budget ${budget} at minTextScale ${minTextScale} (${b.rule.source})`);
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The page check's judgement of a board as drawn (a site measures the <img> in a browser): its drawn aspect off
|
|
105
|
+
* the fit's by more than the tolerance, or its smallest type below the floor at the width it is drawn.
|
|
106
|
+
*/
|
|
107
|
+
export function boardDrawnProblems(
|
|
108
|
+
b: BoardEntry,
|
|
109
|
+
minTextScale: number,
|
|
110
|
+
drawn: { width: number; height: number },
|
|
111
|
+
): string[] {
|
|
112
|
+
const out: string[] = [];
|
|
113
|
+
const fit = b.rule.fitWidth / b.rule.fitHeight;
|
|
114
|
+
const aspect = drawn.width / drawn.height;
|
|
115
|
+
if (Math.abs(aspect - fit) / fit > b.rule.aspectTolerance) {
|
|
116
|
+
out.push(`${b.assetId}: drawn at aspect ${aspect.toFixed(4)}, the board fit is ${fit.toFixed(4)} -- stretched or cropped`);
|
|
117
|
+
}
|
|
118
|
+
const s = scaleAt(b.rule, minTextScale, drawn.width);
|
|
119
|
+
if (s + 1e-9 < b.rule.minTextScaleFloor) {
|
|
120
|
+
out.push(`${b.assetId}: drawn ${Math.round(drawn.width)} wide its smallest type is ${s.toFixed(4)} of the body, below the floor ${b.rule.minTextScaleFloor}`);
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// The site's mark set at build (0.25.0, d-2026-12-04-lb-site-ground-and-marks OUT-3).
|
|
2
|
+
//
|
|
3
|
+
// bin/luhtech-sync-mark-set.mjs writes the verified bytes of each approved member and a manifest into the site
|
|
4
|
+
// (src/generated/mark-set by default). Mark.astro reads them here: the bytes are hashed again against the
|
|
5
|
+
// manifest, so what is inlined is what the asset-bank record names, and an unknown markId fails the build.
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
|
|
10
|
+
export const MARK_SET_DIR = 'src/generated/mark-set';
|
|
11
|
+
|
|
12
|
+
export interface MarkEntry {
|
|
13
|
+
markId: string;
|
|
14
|
+
assetId: string;
|
|
15
|
+
sha256: string;
|
|
16
|
+
viewBox: string;
|
|
17
|
+
/** The member's sheet line: what the mark stands for, in plain words. */
|
|
18
|
+
line: string;
|
|
19
|
+
/** The verified bytes, unaltered. */
|
|
20
|
+
markup: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const cache = new Map<string, Record<string, MarkEntry>>();
|
|
24
|
+
|
|
25
|
+
/** Every mark in the site's synced set, keyed by markId; the bytes re-hashed against the manifest. */
|
|
26
|
+
export function loadMarkSet(dir: string = join(process.cwd(), MARK_SET_DIR)): Record<string, MarkEntry> {
|
|
27
|
+
const hit = cache.get(dir);
|
|
28
|
+
if (hit) return hit;
|
|
29
|
+
const manifestPath = join(dir, 'manifest.json');
|
|
30
|
+
if (!existsSync(manifestPath)) {
|
|
31
|
+
throw new Error(`no mark set at ${dir}: run luhtech-sync-mark-set in the site's prebuild`);
|
|
32
|
+
}
|
|
33
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
34
|
+
const out: Record<string, MarkEntry> = {};
|
|
35
|
+
for (const [markId, m] of Object.entries<any>(manifest.marks ?? {})) {
|
|
36
|
+
const bytes = readFileSync(join(dir, m.file));
|
|
37
|
+
const got = createHash('sha256').update(bytes).digest('hex');
|
|
38
|
+
if (got !== m.sha256) {
|
|
39
|
+
throw new Error(`mark ${markId}: ${m.file} hashes to ${got}, the manifest says ${m.sha256} -- re-run luhtech-sync-mark-set`);
|
|
40
|
+
}
|
|
41
|
+
out[markId] = { markId, assetId: m.assetId, sha256: m.sha256, viewBox: m.viewBox, line: m.line, markup: bytes.toString('utf-8') };
|
|
42
|
+
}
|
|
43
|
+
cache.set(dir, out);
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** One mark by markId; an unknown markId is an authoring error and fails the build. */
|
|
48
|
+
export function markFor(markId: string, dir?: string): MarkEntry {
|
|
49
|
+
const set = loadMarkSet(dir);
|
|
50
|
+
const mark = set[markId];
|
|
51
|
+
if (!mark) {
|
|
52
|
+
throw new Error(`Mark: markId ${markId} is not in this site's mark set (${Object.keys(set).sort().join(', ') || 'empty'})`);
|
|
53
|
+
}
|
|
54
|
+
return mark;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* OUT-6's proof on a built page: every mark Mark.astro inlined (the markup inside a [data-mark] wrapper) hashes
|
|
59
|
+
* to its manifest entry. Returns the problems, one per mark; an empty list when every inlined mark is the
|
|
60
|
+
* asset-bank record's bytes.
|
|
61
|
+
*/
|
|
62
|
+
export function inlinedMarkProblems(html: string, set: Record<string, MarkEntry>): string[] {
|
|
63
|
+
const out: string[] = [];
|
|
64
|
+
for (const m of html.matchAll(/<span\b[^>]*\sdata-mark="([^"]+)"[^>]*>([\s\S]*?)<\/span>/g)) {
|
|
65
|
+
const [, markId, inner] = m;
|
|
66
|
+
const entry = set[markId];
|
|
67
|
+
if (!entry) { out.push(`${markId}: inlined but not in the mark set`); continue; }
|
|
68
|
+
const got = createHash('sha256').update(inner, 'utf8').digest('hex');
|
|
69
|
+
if (got !== entry.sha256) out.push(`${markId}: inlined markup hashes to ${got}, its asset-bank record says ${entry.sha256}`);
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
package/src/lib/seoHead.ts
CHANGED
|
@@ -24,7 +24,20 @@ export type IconFile = (typeof ICON_FILES)[keyof typeof ICON_FILES];
|
|
|
24
24
|
|
|
25
25
|
export interface BrandLike {
|
|
26
26
|
identity?: { name?: string };
|
|
27
|
-
|
|
27
|
+
brandId?: string;
|
|
28
|
+
color?: {
|
|
29
|
+
foundation?: { ink?: { hex?: string }; canvas?: { hex?: string } };
|
|
30
|
+
/** brand-identity color.dark (0.25.0): the ground every site stands on. */
|
|
31
|
+
dark?: { canvas?: { hex?: string } };
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The ground's hex (0.25.0, d-2026-12-04-lb-site-ground-and-marks OUT-2): the brand's own color.dark.canvas, or
|
|
37
|
+
* -- for a brand that carries none -- that of the ground record the site names (luhtech-tokens --ground).
|
|
38
|
+
*/
|
|
39
|
+
export function groundCanvasHex(brand?: BrandLike, ground?: BrandLike): string | null {
|
|
40
|
+
return brand?.color?.dark?.canvas?.hex ?? ground?.color?.dark?.canvas?.hex ?? null;
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
export interface SeoHeadInput {
|
|
@@ -33,6 +46,8 @@ export interface SeoHeadInput {
|
|
|
33
46
|
/** Astro.url.pathname for the page being rendered. */
|
|
34
47
|
pathname: string;
|
|
35
48
|
brand?: BrandLike;
|
|
49
|
+
/** The ground record, for a brand that carries no color.dark (the file luhtech-tokens --ground reads). */
|
|
50
|
+
ground?: BrandLike;
|
|
36
51
|
/** Which ICON_FILES exist in the consuming site's public/ directory. */
|
|
37
52
|
publicFiles: ReadonlySet<string>;
|
|
38
53
|
locale?: string;
|
|
@@ -97,8 +112,8 @@ export function buildSeoHead(input: SeoHeadInput): SeoHead {
|
|
|
97
112
|
canonical,
|
|
98
113
|
siteName,
|
|
99
114
|
locale: input.locale ?? 'en_US',
|
|
100
|
-
//
|
|
101
|
-
themeColor: brand
|
|
115
|
+
// 0.25.0: the header stands on the ground, so the browser chrome matches it.
|
|
116
|
+
themeColor: groundCanvasHex(brand, input.ground),
|
|
102
117
|
links,
|
|
103
118
|
metas,
|
|
104
119
|
};
|