mirror of
https://github.com/bitbaum/sitekit.git
synced 2026-12-04 05:37:31 +01:00
Extracted from substrata's hosted-site model, per orangecat ADR-0003 (the Site Factory). Three things ship: - The closed section union (hero, prose, stats, meter, cards, definitions, index, table) with Zod as the SSOT — every TS type is inferred, and validateSite() returns path-addressed errors a generator can act on. Structural rules are in the schema: hero only first, no duplicate paths, no index entry pointing at a missing anchor. - One set of React renderers emitting semantic utility classes only; no colours, faces or radii ship. The single framework seam is an injectable Link component defaulting to a plain anchor, so static sites and Next apps consume the same package. - Provenance: a sidecar keyed by JSON path (scraped/operator/inferred/ not-found). assertDeliverable() throws on any inferred field, which turns 'we fabricate no facts' from a promise into a check, and not-found makes unknown distinct from empty. Tests import the package by name so a broken exports map fails in CI. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZCNYHwjEeqxNpYCUk6Yna
35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { siteNavItems, pageRendersOwnHeader, sitePageAt, href } from 'sitekit';
|
|
|
|
const PAGES = [
|
|
{ path: '', navLabel: 'Home', title: 'Home', sections: [{ kind: 'hero', statement: 'Hi', lead: [] }] },
|
|
{ path: 'menu', navLabel: 'Menu', title: 'Menu', sections: [{ kind: 'prose', paragraphs: ['x'] }] },
|
|
{ path: 'imprint', title: 'Imprint', sections: [{ kind: 'prose', paragraphs: ['x'] }] },
|
|
];
|
|
|
|
test('nav omits pages without a navLabel', () => {
|
|
assert.deepEqual(siteNavItems(PAGES), [
|
|
{ path: '', label: 'Home' },
|
|
{ path: 'menu', label: 'Menu' },
|
|
]);
|
|
});
|
|
|
|
test('a page opening with a hero renders its own header', () => {
|
|
assert.equal(pageRendersOwnHeader(PAGES[0]), true);
|
|
assert.equal(pageRendersOwnHeader(PAGES[1]), false);
|
|
});
|
|
|
|
test('sitePageAt normalises slashes and misses cleanly', () => {
|
|
assert.equal(sitePageAt(PAGES, '/menu/'), PAGES[1]);
|
|
assert.equal(sitePageAt(PAGES, ''), PAGES[0]);
|
|
assert.equal(sitePageAt(PAGES, 'nope'), null);
|
|
});
|
|
|
|
test('href: root is /, everything else /segment', () => {
|
|
assert.equal(href(), '/');
|
|
assert.equal(href('menu'), '/menu');
|
|
assert.equal(href('/menu/'), '/menu');
|
|
});
|