@nulib/canopy 0.0.0 → 2.0.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/bin/canopy.js +16 -0
- package/lib/AGENTS.md +107 -0
- package/lib/base-path.js +67 -0
- package/lib/build/appearance.js +76 -0
- package/lib/build/assets.js +30 -0
- package/lib/build/build.js +350 -0
- package/lib/build/dev.js +1355 -0
- package/lib/build/devtoast.config.json +6 -0
- package/lib/build/devtoast.css +14 -0
- package/lib/build/facets.js +19 -0
- package/lib/build/fonts.js +105 -0
- package/lib/build/iiif.js +2990 -0
- package/lib/build/log.js +31 -0
- package/lib/build/mdx.js +1967 -0
- package/lib/build/package-names.js +111 -0
- package/lib/build/pages.js +420 -0
- package/lib/build/rehype-task-list-labels.js +54 -0
- package/lib/build/runtimes.js +141 -0
- package/lib/build/search-index.js +55 -0
- package/lib/build/search-text.js +160 -0
- package/lib/build/search-workflow.js +72 -0
- package/lib/build/search.js +302 -0
- package/lib/build/sitemap.js +197 -0
- package/lib/build/styles.js +140 -0
- package/lib/build/theme-tokens.js +78 -0
- package/lib/build/ui-styles.js +25 -0
- package/lib/build/upgrade-notices.js +121 -0
- package/lib/cli.js +64 -0
- package/lib/common.js +580 -0
- package/lib/components/bibliography.js +197 -0
- package/lib/components/featured.js +237 -0
- package/lib/components/hero-slider-runtime.js +215 -0
- package/lib/components/image-story-runtime-entry.js +249 -0
- package/lib/components/map-runtime.js +114 -0
- package/lib/components/metadata-index.js +32 -0
- package/lib/components/nav-place.js +227 -0
- package/lib/components/navigation.js +381 -0
- package/lib/components/referenced.js +217 -0
- package/lib/components/slider-runtime-entry.js +106 -0
- package/lib/components/timeline-runtime.js +80 -0
- package/lib/components/viewer-runtime-entry.js +88 -0
- package/lib/config-path.js +78 -0
- package/lib/default-locale.js +113 -0
- package/lib/discovery/browser-loader.js +107 -0
- package/lib/discovery/browser.js +115 -0
- package/lib/discovery/config.js +25 -0
- package/lib/discovery/envelope.js +124 -0
- package/lib/discovery/export.js +226 -0
- package/lib/discovery/ingestion.js +62 -0
- package/lib/discovery/pagination.js +66 -0
- package/lib/discovery/provenance.js +79 -0
- package/lib/discovery/search.js +81 -0
- package/lib/discovery/tools.js +155 -0
- package/lib/discovery/validation.js +121 -0
- package/lib/head.js +154 -0
- package/lib/iiif/thumbnail.js +402 -0
- package/lib/index.js +9 -0
- package/lib/locale-runtime.js +69 -0
- package/lib/locales.js +203 -0
- package/lib/orchestrator.js +231 -0
- package/lib/page-context.js +24 -0
- package/lib/search/bundle.js +25 -0
- package/lib/search/data.js +202 -0
- package/lib/search/engine.js +86 -0
- package/lib/search/index-cache.js +95 -0
- package/lib/search/search-app.jsx +835 -0
- package/lib/search/search-engine-runtime.js +44 -0
- package/lib/search/search-form-runtime.js +462 -0
- package/lib/search/search.js +676 -0
- package/package.json +109 -3
- package/types/base-path.d.ts +4 -0
- package/types/orchestrator.d.ts +17 -0
- package/ui/dist/index.mjs +7358 -0
- package/ui/dist/index.mjs.map +7 -0
- package/ui/dist/server.mjs +12731 -0
- package/ui/dist/server.mjs.map +7 -0
- package/ui/fonts/OFL.txt +98 -0
- package/ui/fonts/google-sans-flex-latin-ext.woff2 +0 -0
- package/ui/fonts/google-sans-flex-latin.woff2 +0 -0
- package/ui/fonts/source-serif-4-italic-latin-ext.woff2 +0 -0
- package/ui/fonts/source-serif-4-italic-latin.woff2 +0 -0
- package/ui/fonts/source-serif-4-latin-ext.woff2 +0 -0
- package/ui/fonts/source-serif-4-latin.woff2 +0 -0
- package/ui/styles/base/_common.scss +97 -0
- package/ui/styles/base/_heading.scss +61 -0
- package/ui/styles/base/_markdown.scss +188 -0
- package/ui/styles/base/_type.scss +51 -0
- package/ui/styles/base/_utilities.scss +7 -0
- package/ui/styles/base/index.scss +5 -0
- package/ui/styles/components/_article-card.scss +108 -0
- package/ui/styles/components/_band.scss +104 -0
- package/ui/styles/components/_bibliography.scss +88 -0
- package/ui/styles/components/_buttons.scss +143 -0
- package/ui/styles/components/_card.scss +109 -0
- package/ui/styles/components/_diagram.scss +76 -0
- package/ui/styles/components/_feature.scss +66 -0
- package/ui/styles/components/_footer.scss +136 -0
- package/ui/styles/components/_gallery.scss +476 -0
- package/ui/styles/components/_image-story.scss +56 -0
- package/ui/styles/components/_interstitial-hero.scss +625 -0
- package/ui/styles/components/_layout.scss +83 -0
- package/ui/styles/components/_map.scss +296 -0
- package/ui/styles/components/_metadata-index.scss +68 -0
- package/ui/styles/components/_nav-tree.scss +80 -0
- package/ui/styles/components/_referenced-items.scss +69 -0
- package/ui/styles/components/_sub-navigation.scss +208 -0
- package/ui/styles/components/_swoosh.scss +50 -0
- package/ui/styles/components/_timeline.scss +350 -0
- package/ui/styles/components/_work.scss +71 -0
- package/ui/styles/components/header/_header.scss +294 -0
- package/ui/styles/components/header/_logo.scss +99 -0
- package/ui/styles/components/header/_navbar.scss +143 -0
- package/ui/styles/components/header/index.scss +3 -0
- package/ui/styles/components/iiif/_image.scss +32 -0
- package/ui/styles/components/iiif/_slider.scss +5 -0
- package/ui/styles/components/iiif/index.scss +2 -0
- package/ui/styles/components/index.scss +25 -0
- package/ui/styles/components/modal/_modal.scss +130 -0
- package/ui/styles/components/modal/index.scss +1 -0
- package/ui/styles/components/search/_filters.scss +259 -0
- package/ui/styles/components/search/_form.scss +187 -0
- package/ui/styles/components/search/_panel.scss +7 -0
- package/ui/styles/components/search/_results.scss +241 -0
- package/ui/styles/components/search/_tabs.scss +60 -0
- package/ui/styles/components/search/index.scss +4 -0
- package/ui/styles/index.css +5007 -0
- package/ui/styles/index.scss +11 -0
- package/ui/styles/settings/_breakpoints.scss +7 -0
- package/ui/styles/settings/_focus.scss +15 -0
- package/ui/styles/settings/_tokens.scss +170 -0
- package/ui/styles/settings/_type.scss +126 -0
- package/ui/styles/version-parity.css +116 -0
- package/ui/tailwind-canopy-iiif-plugin.js +39 -0
- package/ui/tailwind-canopy-iiif-preset.js +32 -0
- package/ui/tailwind-config.d.ts +29 -0
- package/ui/tailwind-config.js +159 -0
- package/ui/tailwind-default.config.mjs +4 -0
- package/ui/theme-color.js +130 -0
- package/ui/theme-palette.js +337 -0
- package/ui/theme.js +153 -0
- package/README.md +0 -3
package/bin/canopy.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// `canopy build` and `canopy dev` (`lib/cli.js`).
|
|
5
|
+
const {run} = require('../lib/cli');
|
|
6
|
+
|
|
7
|
+
run(process.argv.slice(2)).then(
|
|
8
|
+
(code) => {
|
|
9
|
+
if (code) process.exitCode = code;
|
|
10
|
+
},
|
|
11
|
+
(error) => {
|
|
12
|
+
const message = (error && (error.stack || error.message)) || String(error);
|
|
13
|
+
console.error(`[canopy][error] ${message}`);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
},
|
|
16
|
+
);
|
package/lib/AGENTS.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Lib Agent Notes
|
|
2
|
+
===============
|
|
3
|
+
|
|
4
|
+
Prime directive: WCAG 2.2 AA
|
|
5
|
+
----------------------------
|
|
6
|
+
- The HTML the builder writes and every runtime it bundles conform to WCAG 2.2 at Level AA, and that outranks every note below. The rules are in `packages/app/DESIGN.md` §0; known failures are in `ACCESSIBILITY.md`.
|
|
7
|
+
- The HTML shell owns the page's `lang`, its landmarks and its skip link. A runtime never moves focus, reorders content or drops a name when it mounts.
|
|
8
|
+
|
|
9
|
+
Mission
|
|
10
|
+
-------
|
|
11
|
+
- Provides the Node-side builder, SSR utilities, and client runtime bundles consumed by the static site.
|
|
12
|
+
- Owns IIIF ingestion, MDX compilation, site generation, and search indexing.
|
|
13
|
+
|
|
14
|
+
Core Areas
|
|
15
|
+
----------
|
|
16
|
+
- `build/`: Orchestrates the site build pipeline (MDX, assets, search, IIIF).
|
|
17
|
+
- `components/`: Shared SSR-ready React components (MDX placeholders, layout helpers).
|
|
18
|
+
- `iiif/`: Fetching, caching, and normalizing Presentation 3 manifests.
|
|
19
|
+
- `search/`: the index writer (`search.js`), the search engine both runtimes share (`engine.js`, FlexSearch 0.8 behind it), their data loader and IndexedDB cache (`data.js`, `index-cache.js`), and the runtimes: the search page's (`search-app.jsx`), the header field's (`search-form-runtime.js`) and the engine it loads when used (`search-engine-runtime.js`).
|
|
20
|
+
- `discovery/`: IIIF catalog exports, resource retrieval, and the WebMCP browser runtime.
|
|
21
|
+
- `common.js` / `index.js`: Entry points that wire CLI commands `build()` and `dev()`.
|
|
22
|
+
|
|
23
|
+
Invariants
|
|
24
|
+
----------
|
|
25
|
+
- Server code must import UI through `@nulib/canopy/ui/server`; never pull browser-only modules into SSR paths.
|
|
26
|
+
- The package refers to itself by path, or by `PACKAGE_NAME` (`build/package-names.js`), never by a written name. Wherever a site's code is compiled or bundled, an import of either name (`@nulib/canopy`, or `@canopy-iiif/app` from 1.x) is read through `package-names.js`: `recmaPackageImports` for MDX, `esbuildPackageNames()` for browser bundles, `esbuildServerPackageNames()` for server bundles.
|
|
27
|
+
- Bundled runtimes rely on browser React globals from `site/scripts/react-globals.js`; maintain esbuild shims for `react`, `react-dom`, `react-dom/client`, and any new browser deps the UI marks external. FlexSearch is bundled, not shimmed: the search runtimes take its compact build through `search/bundle.js`'s `flexSearchPlugin()`.
|
|
28
|
+
- Only `search/engine.js` knows FlexSearch. A change to how words match changes `ENGINE_ID` and `tests/unit/search/engine.test.js` together.
|
|
29
|
+
- Keep IIIF cache writes confined to `.cache/iiif/`; document any format changes here before implementation.
|
|
30
|
+
|
|
31
|
+
Active Cleanup Goals
|
|
32
|
+
--------------------
|
|
33
|
+
1. Document and untangle build orchestration in `build/` (identify stages, shared utilities, and intended extension points).
|
|
34
|
+
2. Expand search indexing to include MDX page records per repository guidelines; ensure `writeSearchIndex` receives unified records.
|
|
35
|
+
3. Audit IIIF pipeline error handling and retry logic; capture gaps or performance tweaks in this log.
|
|
36
|
+
4. Establish targeted unit/integration tests around MDX rendering and search runtime bundling once baseline docs exist.
|
|
37
|
+
|
|
38
|
+
Current Focus
|
|
39
|
+
-------------
|
|
40
|
+
- Build pipeline map: diagram the flow from `build/index.js` through MDX compilation, asset sync, IIIF generation, and search index writes; note which steps run during `dev` versus `build`.
|
|
41
|
+
- Search index expansion: confirm where MDX pages are collected, identify reserved filenames to exclude, and outline the data contract passed to `writeSearchIndex`.
|
|
42
|
+
- Runtime bundling: review `search/search.js` for esbuild config drift (externals, shims); list required adjustments if UI adds new hydrated components.
|
|
43
|
+
- Cache hygiene: document when `.cache/mdx` vs `.cache/iiif` are pruned and add TODOs if cleanup relies on manual intervention.
|
|
44
|
+
|
|
45
|
+
### Interstitial hero support
|
|
46
|
+
- Featured manifests come from `canopy.yml → featured`; `lib/components/featured.js` normalizes IDs, resolves slugs from `.cache/iiif/index.json`, and surfaces thumbnails (`heroThumbnail*` when the IIIF build computed representative images).
|
|
47
|
+
- `build/iiif.js` now writes `heroThumbnail`, `heroThumbnailWidth`, and `heroThumbnailHeight` alongside standard thumbnails so the UI hero can display consistent crops.
|
|
48
|
+
- `build/mdx.js` → `ensureHeroRuntime()` bundles `packages/app/lib/components/hero-slider-runtime.js` to `site/scripts/canopy-hero-slider.js`. The runtime has no dependencies since 2.x Phase 4 (Embla gone); mirror any esbuild option changes in the UI workspace docs.
|
|
49
|
+
|
|
50
|
+
Risks & Watchpoints
|
|
51
|
+
-------------------
|
|
52
|
+
- Long reruns: if `dev` mode clears `.cache/iiif` too aggressively it slows iteration; capture triggers before modifying cleanup behavior.
|
|
53
|
+
- SSR safety: any import path change that reaches into `ui/src` instead of `ui/server` will break builds on platforms without DOM. Flag code locations handling UI imports.
|
|
54
|
+
- Partial failures: build stages lack retry/backoff; note hotspots (network IIIF fetches, MDX parsing) so we can stage resilience work.
|
|
55
|
+
|
|
56
|
+
Session Ritual
|
|
57
|
+
--------------
|
|
58
|
+
- Start by checking `build/index.js` for any ad-hoc logic that should be modularised.
|
|
59
|
+
- When touching bundler configs, record the rationale plus command to verify (e.g., `npm run build`, targeted script).
|
|
60
|
+
- Log open TODOs with references back to this document (`// TODO: see packages/app/lib/AGENTS.md#...`).
|
|
61
|
+
|
|
62
|
+
Logbook Template
|
|
63
|
+
----------------
|
|
64
|
+
- Date / engineer
|
|
65
|
+
- Stage(s) touched (build, mdx, iiif, search, runtime)
|
|
66
|
+
- Changes made / findings (link to sections above)
|
|
67
|
+
- Follow-ups created (reference numbered goals)
|
|
68
|
+
|
|
69
|
+
Logbook
|
|
70
|
+
-------
|
|
71
|
+
- 2026-11-16 / claude (2.x Phase 7): `build/search.js`'s `pageSearchRecord` reads the search front matter the docs promise (`searchType`, `searchSummary`, `searchSummaryMarkdown`, `description`, `image`) into a page's record; `build/search-index.js` passes its `thumbnail` on. `build/pages.js` takes a page's derived meta description from `extractSearchText`'s `excerpt`.
|
|
72
|
+
- 2026-11-16 / claude (2.x Phase 7): an MDX page's search text and excerpt come from `build/search-text.js` (the MDX parser with GFM, required as ESM, which Node 24 does and Jest 29 cannot, so its tests run in a child process), through `mdx.js`'s new `extractSearchText`; `extractPlainText` and `extractMarkdownSummary` remain its fallback, the former's link pattern fixed (it wrote "$1"). `build/search.js`'s `collectMdxPageRecords` uses it.
|
|
73
|
+
- 2026-11-16 / claude (2.x Phase 7): search, rebuilt on FlexSearch 0.8 behind `search/engine.js` (`packages/app/AGENTS.md`, "Search"). `search.js` bundles FlexSearch's compact build into `site/scripts/search.js`, minified, and writes no `flexsearch-globals.js`; `build/runtimes.js` builds `site/scripts/canopy-search-engine.js` for the header's field, which loads it when first used. `writeSearchIndex` logs through `../build/log` (its `./log` had not resolved since 2025) and no longer writes the index's version into `.cache/iiif/index.json` (its `./iiif` never resolved; nothing read it); the version covers the annotations too. `build/build.js` holds the IIIF records and ids it reuses between builds on `globalThis`: `dev.js` reloads the app's modules after a change under `lib/`, and a reloaded `build.js` without them indexed the pages alone and wrote them alone to the sitemap. Its discovery data stays the module's own, as a fresh module keeps the catalog already published (`tests/unit/discovery/build.test.js`). Verified: `npm test`, `npm run lint:a11y`, `npm run test:a11y`.
|
|
74
|
+
- 2026-11-13 / claude: `build/mdx.js` adds `build/rehype-task-list-labels.js` to every compile through `buildCompileOptions()`, which names Markdown task lists' checkboxes (ACCESSIBILITY.md C15); an override's `rehypePlugins` run after it. Tested in `tests/unit/mdx/task-list-labels.test.js`.
|
|
75
|
+
- 2026-11-15 / claude (2.x Phase 6): `build/fonts.js` copies Google Sans Flex (`ui/fonts/`, with `OFL.txt`) to `site/styles/fonts/` and declares its faces in the injected block, after Tailwind runs, so their relative `url()`s hold under any base path (`injectThemeTokens`, build and dev). `build/ui-styles.js` holds the Clover imports both `ui/scripts/build-ui.mjs` and dev's `rebuildUiStyles()` write atop `ui/styles/index.css`; dev's copy had none since Phase 2, so `npm run dev` drew Clover unstyled. The search form runtime fills in the ⌘K (Ctrl K) hint and the input's `aria-keyshortcuts`.
|
|
76
|
+
- 2026-11-13 / claude: 2.x Phase 0 (WCAG 2.2 AA prime directive; see the root `AGENTS.md` and `ACCESSIBILITY.md`).
|
|
77
|
+
- `build/iiif.js` exposes `upgradeIiifResource` and `ensurePresentation3Manifest` on `__TESTING__`. `tests/unit/iiif/upgrade.test.js` covers the Presentation 2 → 3 upgrade, and fails if `@iiif/parser/upgrader` stops resolving.
|
|
78
|
+
- Today `@iiif/parser` arrives only through `@samvera/clover-iiif` and `@iiif/helpers`. The build's fallback, `normalizeToV3`, calls `toPresentation3`, `normalize` and `upgradeToV3`, none of which `@iiif/helpers` exports, so a missing upgrader passes P2 through unconverted.
|
|
79
|
+
- `tests/a11y/build-fixture.mjs` builds each template offline with `build/build.js`, serving the fixture's own IIIF at `CANOPY_BASE_URL` while it builds (featured Manifests are read by URL).
|
|
80
|
+
- Verified: `npm test` (243 tests in 23 suites), `npm run test:a11y`, `npm run lint:a11y`.
|
|
81
|
+
- 2026-10-02 / claude: `build/pages.js` no longer links `scripts/canopy-hero-slider.css`. The file stopped existing when the hero moved from Swiper to Embla (`02be285`, 2026-05-06): its CSS came from the runtime's `swiper/css` imports, and Embla ships none. Every page with a hero had 404'd on it since then. The hero's layout styles live in `ui/styles/components/_interstitial-hero.scss`.
|
|
82
|
+
- 2026-10-02 / claude: Tailwind v4 cleanup in `build/styles.js` and `build/dev.js`:
|
|
83
|
+
- Dropped the `tailwind.config.*` lookup and the `-c` flag. Tailwind v4's CLI has no such flag and loads a JS config only through `@config`, so neither the lookup nor the built-in default config was ever applied.
|
|
84
|
+
- Dev no longer watches the preset/plugin/config files.
|
|
85
|
+
- Stopped stripping Tailwind's `@layer theme`. `theme-tokens.js` now emits `@layer theme, properties;` inside the injected block, so Tailwind's defaults rank below Canopy's tokens and `app/styles` overrides instead of being deleted.
|
|
86
|
+
- Stripping had broken every utility that reads a theme variable (`space-y-*`, `p-1`, `text-sm`, `transition`, `text-slate-*`) and any site-level `@theme` variable. It also forced `code`/`pre` onto fallback fonts.
|
|
87
|
+
- Verified with a full computed-style diff of every element on six docs pages and four Northwestern pages. The only changes were `pre`/`code` now using the site's monospace font and the search summary picking up `text-sm` and the muted gray. `tests/unit/build/theme-tokens.test.js` covers a site's `@theme` values and Tailwind's spacing scale surviving.
|
|
88
|
+
- 2026-10-02 / claude: The generated `canopy.yml` theme now goes at the start of `site/styles/styles.css` (after the Tailwind banner and any `@charset`/`@import`/`@layer`/`@namespace` statements) instead of the end. Author overrides in `@layer properties` now win by source order, so they no longer need `!important`; existing `!important` still works. Placement lives in `build/theme-tokens.js` (`withThemeBlock`). The old marker regex never matched, so re-injection stacked copies; the new one is escaped, and `injectThemeTokens()` skips no-op writes so the dev watcher doesn't loop. Dev's `rebuildUiStyles()` and `ui/scripts/build-ui.mjs` (`CANOPY_EMBED_THEME`) no longer bake the theme into the package's `ui/styles/index.css`. A baked copy there outlives `canopy.yml` edits and, once imported, would override the fresh theme. Verified with `tests/unit/build/theme-tokens.test.js` and in-browser snapshots of a Northwestern template build: old pipeline with `!important` = new pipeline with or without it, in both build and dev (0 differences). Old pipeline without `!important`: 53 differences.
|
|
89
|
+
- 2026-09-10 / Codex: Updated the root Clover dependency from `^3.7.0` to npm's current stable `^3.16.0` and refreshed `package-lock.json`. All 202 tests across 17 suites now pass against the installed release, including the real Clover and custom TSX bundling fixtures; type checking, dependency-file formatting, and a network-enabled full site build pass. npm reports React peer warnings in Clover's transitive Radix packages and a critical MapLibre audit advisory (`GHSA-jrc7-96c5-q579`); its suggested Clover downgrade was not applied because the requested version is latest.
|
|
90
|
+
- 2026-09-10 / Codex: Browser runtime bundlers in `build/mdx.js`, `build/runtimes.js`, and `search/search.js` now target ES2020 because Clover's bundled MapLibre decoder uses native BigInt. `prepareAllRuntimes()` propagates labeled failures with their original cause and checks the cached custom component runtime result so page-level catches cannot hide a broken bundle. Verified the published Clover 3.16.0 in a temporary directory: both built-in and custom bundlers fail at ES2018 and pass at ES2020 without changing repository dependencies. Validation: `npm test` (202 tests across 17 suites), `npm run typecheck`, and targeted ESLint pass. Regression fixtures cover BigInt TSX output and a nonzero build exit for an unresolved custom dependency. The network-enabled `npm run build` also passed. The documented `packages/helpers/verify-build.js` command is stale; that helper is absent.
|
|
91
|
+
- 2026-09-09 / Codex: Reproduced the WebMCP build fixture's CI citation failure by removing `ui/dist`: missing SSR components prevented the work page and search record from being generated, leaving the source URL as the citation fallback. Root `pretest:unit` now builds UI assets before Jest, and the Tests workflow reads Node 24 from `.nvmrc`. The fixture reports rendering failures with child-process logs. Validation: all 193 tests across 15 suites pass starting without `ui/dist`; targeted ESLint and workflow YAML checks pass.
|
|
92
|
+
- 2026-09-08 / Codex: IIIF and AI tools use WebMCP with static catalog and resource files. Source version, retrieval time, and normalization history are stored separately under `.cache/iiif/provenance/<sha256-resource-id>.json`; IIIF JSON stays unchanged. Older cache entries report unknown provenance. The browser bundle has no React dependency and is injected by the shared HTML shell. Verify with discovery fixture tests and a network-enabled build.
|
|
93
|
+
- 2026-09-08 / Codex: The internal `createDiscoveryTools` helper supplies schema 1.0 IIIF responses to the browser. Responses have a 64 KiB data limit, versioned pagination, explicit partial summaries, and strict input validation. Discovery references resolve source aliases without changing snapshots; skipped IIIF builds retain the previous export. The tools require no separately hosted service or server SDK. Repository-wide lint still includes generated bundles and template previews with existing configuration errors.
|
|
94
|
+
- 2026-09-08 / Codex: WebMCP validation passed: 176 tests across 14 suites, type checking, targeted lint, formatting, package inspection, and a network-enabled static build with 175 Manifests and three Collections. Browser tests also verify the bundled script and WebMCP annotations. This feature adds no package dependencies or CLI commands.
|
|
95
|
+
- 2026-09-09 / Codex: A single root setting, `webmcp`, controls browser registration and static exports. It defaults to `true`; `webmcp: false` disables both. Removed the separate discovery settings. Configuration tests cover missing settings, explicit booleans, invalid values, and YAML errors. The build fixture verifies default enablement, explicit enablement, retained snapshots, and disabled cleanup. Validation: 193 tests across 15 suites, type checking, targeted lint, formatting, and a network-enabled build passed.
|
|
96
|
+
- 2026-04-26 / mat: Added local file path support to the manifest fetch worker in `build/iiif.js`. Previously, the worker branched on `https?://` and `file://` and SKIPped everything else; relative paths (e.g., `assets/iiif/example.json`) were silently dropped. Added a third branch that catches any value with no URI scheme (regex: no `[scheme]:` prefix) and routes it through `readJsonFromUri()`, which already resolves relative paths against `process.cwd()`. Collection-root URIs were already handled correctly via `readJsonFromUri()`; only the manifest worker needed the fix.
|
|
97
|
+
- 2025-09-26 / chatgpt: Hardened runtime bundlers to throw when esbuild or source compilation fails and required `content/works/_layout.mdx`; build now aborts instead of silently writing placeholder assets.
|
|
98
|
+
- 2025-09-26 / chatgpt: Replaced the legacy command runtime stub with an esbuild-bundled runtime (`search/search-form-runtime.js`); `prepareSearchFormRuntime()` now builds `site/scripts/canopy-search-form.js` and fails if esbuild is missing.
|
|
99
|
+
- 2025-09-27 / chatgpt: Documented Tailwind token flow in `app/styles/tailwind.config.mts`, compiled UI Sass variables during config load, and exposed `stylesheetHref`/`Stylesheet` helpers via `@canopy-iiif/app/head` so `_app.mdx` can reference the generated CSS directly.
|
|
100
|
+
- 2025-09-27 / chatgpt: Expanded search indexing to harvest MDX pages (respecting frontmatter/layout types), injected BASE_PATH hydration data into search.html, and reworked `mdx.extractTitle()` so generated records surface real headings instead of `Untitled`.
|
|
101
|
+
- 2025-10-19 / chatgpt: Embedded the Tailwind preset/plugin in a packaged config so dev/build fall back automatically; removed `app/styles/tailwind.config.*` from the default app and switched the public stylesheet to Tailwind’s CSS-first (`@import 'tailwindcss'; @theme { ... }`) workflow.
|
|
102
|
+
- 2025-10-20 / chatgpt: Added `lib/config-path.js` to resolve `canopy.yml` from the workspace root (preferring `options.cwd`, then npm `INIT_CWD`, then `process.cwd()`) and updated all loaders (theme, common base URL, search metadata, IIIF builder, featured manifests) to use it so hosted builds and Tailwind runs inside `node_modules/@canopy-iiif/app/ui` pick up user theme settings.
|
|
103
|
+
|
|
104
|
+
Verification Commands
|
|
105
|
+
---------------------
|
|
106
|
+
- Full pipeline: `npm run build`
|
|
107
|
+
- Dev/watch validation: `npm run dev`
|
package/lib/base-path.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function normalizeBasePath(value) {
|
|
4
|
+
if (value == null) return '';
|
|
5
|
+
const raw = String(value).trim();
|
|
6
|
+
if (!raw) return '';
|
|
7
|
+
const prefixed = raw.startsWith('/') ? raw : `/${raw}`;
|
|
8
|
+
const cleaned = prefixed.replace(/\/+$/, '');
|
|
9
|
+
return cleaned === '/' ? '' : cleaned;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let cachedBasePath = null;
|
|
13
|
+
|
|
14
|
+
function readBasePath(options = {}) {
|
|
15
|
+
const {force = false} = options;
|
|
16
|
+
if (!force && cachedBasePath !== null) return cachedBasePath;
|
|
17
|
+
const candidates = [];
|
|
18
|
+
try {
|
|
19
|
+
if (typeof window !== 'undefined' && window.CANOPY_BASE_PATH != null) {
|
|
20
|
+
candidates.push(window.CANOPY_BASE_PATH);
|
|
21
|
+
}
|
|
22
|
+
} catch (_) {}
|
|
23
|
+
try {
|
|
24
|
+
if (typeof globalThis !== 'undefined' && globalThis.CANOPY_BASE_PATH != null) {
|
|
25
|
+
candidates.push(globalThis.CANOPY_BASE_PATH);
|
|
26
|
+
}
|
|
27
|
+
} catch (_) {}
|
|
28
|
+
try {
|
|
29
|
+
if (typeof process !== 'undefined' && process.env && process.env.CANOPY_BASE_PATH) {
|
|
30
|
+
candidates.push(process.env.CANOPY_BASE_PATH);
|
|
31
|
+
}
|
|
32
|
+
} catch (_) {}
|
|
33
|
+
|
|
34
|
+
for (const candidate of candidates) {
|
|
35
|
+
const normalized = normalizeBasePath(candidate);
|
|
36
|
+
if (normalized || normalized === '') {
|
|
37
|
+
cachedBasePath = normalized;
|
|
38
|
+
return cachedBasePath;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
cachedBasePath = '';
|
|
43
|
+
return cachedBasePath;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function withBasePath(href) {
|
|
47
|
+
if (typeof href !== 'string') return href;
|
|
48
|
+
const raw = href.trim();
|
|
49
|
+
if (!raw) return href;
|
|
50
|
+
if (/^(?:[a-z][a-z0-9+.-]*:|\/\/|#)/i.test(raw)) return raw;
|
|
51
|
+
if (!raw.startsWith('/')) return raw;
|
|
52
|
+
const base = readBasePath();
|
|
53
|
+
if (!base || base === '/') return raw;
|
|
54
|
+
if (raw === base || raw.startsWith(`${base}/`)) return raw;
|
|
55
|
+
return `${base}${raw}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function clearBasePathCache() {
|
|
59
|
+
cachedBasePath = null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = {
|
|
63
|
+
normalizeBasePath,
|
|
64
|
+
readBasePath,
|
|
65
|
+
withBasePath,
|
|
66
|
+
clearBasePathCache,
|
|
67
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// `theme.appearance: auto` in canopy.yml: a page follows the visitor's system setting,
|
|
2
|
+
// and the footer's switch (`AppearanceToggle`) lets them choose Light or Dark instead.
|
|
3
|
+
//
|
|
4
|
+
// The script is inline in every page's <head>, ahead of the stylesheet, so a page is
|
|
5
|
+
// drawn in its appearance from the first paint, never light first. It sets `light` or
|
|
6
|
+
// `dark` on <html>, which the theme's tokens follow (`appearanceVariablesToCss`,
|
|
7
|
+
// ui/theme-palette.js), as do the rules written for `html.dark`. Without it the tokens
|
|
8
|
+
// still follow `prefers-color-scheme`, and the switch stays hidden: it does nothing
|
|
9
|
+
// without a script.
|
|
10
|
+
//
|
|
11
|
+
// The choice is kept per site: sites on one origin (GitHub Pages' project sites) each
|
|
12
|
+
// keep their own, by the site's base path.
|
|
13
|
+
|
|
14
|
+
const STORAGE_PREFIX = 'canopy-appearance:';
|
|
15
|
+
|
|
16
|
+
function appearanceStorageKey(basePath) {
|
|
17
|
+
const base = typeof basePath === 'string' && basePath.trim() ? basePath.trim() : '/';
|
|
18
|
+
return `${STORAGE_PREFIX}${base}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function appearanceScript(basePath) {
|
|
22
|
+
const key = JSON.stringify(appearanceStorageKey(basePath));
|
|
23
|
+
return `(function () {
|
|
24
|
+
var KEY = ${key};
|
|
25
|
+
var root = document.documentElement;
|
|
26
|
+
var media = window.matchMedia ? window.matchMedia("(prefers-color-scheme: dark)") : null;
|
|
27
|
+
function stored() {
|
|
28
|
+
try {
|
|
29
|
+
var value = window.localStorage.getItem(KEY);
|
|
30
|
+
return value === "light" || value === "dark" ? value : "system";
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return "system";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function apply(choice) {
|
|
36
|
+
var dark = choice === "dark" || (choice === "system" && !!(media && media.matches));
|
|
37
|
+
root.classList.toggle("dark", dark);
|
|
38
|
+
root.classList.toggle("light", !dark);
|
|
39
|
+
}
|
|
40
|
+
function sync() {
|
|
41
|
+
var choice = stored();
|
|
42
|
+
var switches = document.querySelectorAll("[data-canopy-appearance]");
|
|
43
|
+
for (var i = 0; i < switches.length; i += 1) {
|
|
44
|
+
var select = switches[i].querySelector("select");
|
|
45
|
+
if (select) select.value = choice;
|
|
46
|
+
switches[i].hidden = false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
apply(stored());
|
|
50
|
+
if (media && media.addEventListener) {
|
|
51
|
+
media.addEventListener("change", function () {
|
|
52
|
+
if (stored() === "system") apply("system");
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
document.addEventListener("change", function (event) {
|
|
56
|
+
var select = event.target;
|
|
57
|
+
if (!select || !select.closest || !select.closest("[data-canopy-appearance]")) return;
|
|
58
|
+
var choice = select.value === "light" || select.value === "dark" ? select.value : "system";
|
|
59
|
+
try {
|
|
60
|
+
if (choice === "system") window.localStorage.removeItem(KEY);
|
|
61
|
+
else window.localStorage.setItem(KEY, choice);
|
|
62
|
+
} catch (error) {}
|
|
63
|
+
apply(choice);
|
|
64
|
+
sync();
|
|
65
|
+
});
|
|
66
|
+
window.addEventListener("storage", function (event) {
|
|
67
|
+
if (event.key !== KEY) return;
|
|
68
|
+
apply(stored());
|
|
69
|
+
sync();
|
|
70
|
+
});
|
|
71
|
+
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", sync);
|
|
72
|
+
else sync();
|
|
73
|
+
})();`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = { appearanceScript, appearanceStorageKey };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { fs, fsp, path, ASSETS_DIR, OUT_DIR, ensureDirSync } = require('../common');
|
|
2
|
+
const { logLine } = require('./log');
|
|
3
|
+
|
|
4
|
+
async function copyAssets() {
|
|
5
|
+
try {
|
|
6
|
+
if (!fs.existsSync(ASSETS_DIR)) return;
|
|
7
|
+
} catch (_) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
async function walk(dir) {
|
|
11
|
+
const entries = await fsp.readdir(dir, { withFileTypes: true });
|
|
12
|
+
for (const e of entries) {
|
|
13
|
+
const src = path.join(dir, e.name);
|
|
14
|
+
const rel = path.relative(ASSETS_DIR, src);
|
|
15
|
+
const dest = path.join(OUT_DIR, rel);
|
|
16
|
+
if (e.isDirectory()) { ensureDirSync(dest); await walk(src); }
|
|
17
|
+
else if (e.isFile()) {
|
|
18
|
+
ensureDirSync(path.dirname(dest));
|
|
19
|
+
await fsp.copyFile(src, dest);
|
|
20
|
+
try { logLine(`• Asset ${path.relative(process.cwd(), dest)}`, 'cyan', { dim: true }); } catch (_) {}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
try { logLine('• Copying assets...', 'blue', { bright: true }); } catch (_) {}
|
|
25
|
+
await walk(ASSETS_DIR);
|
|
26
|
+
try { logLine('✓ Assets copied', 'green'); } catch (_) {}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = { copyAssets };
|
|
30
|
+
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
const {
|
|
2
|
+
fs,
|
|
3
|
+
fsp,
|
|
4
|
+
path,
|
|
5
|
+
CONTENT_DIR,
|
|
6
|
+
OUT_DIR,
|
|
7
|
+
absoluteUrl,
|
|
8
|
+
ensureDirSync,
|
|
9
|
+
cleanDir,
|
|
10
|
+
} = require("../common");
|
|
11
|
+
const { exportDiscovery } = require("../discovery/export");
|
|
12
|
+
const { webMcpEnabled } = require("../discovery/config");
|
|
13
|
+
const mdx = require("./mdx");
|
|
14
|
+
const iiif = require("./iiif");
|
|
15
|
+
const pages = require("./pages");
|
|
16
|
+
const searchBuild = require("./search");
|
|
17
|
+
const {buildSearchIndex} = require("./search-index");
|
|
18
|
+
const runtimes = require("./runtimes");
|
|
19
|
+
const {writeSitemap} = require("./sitemap");
|
|
20
|
+
const {ensureSearchInitialized, finalizeSearch} = require("./search-workflow");
|
|
21
|
+
const {ensureStyles} = require("./styles");
|
|
22
|
+
const {copyAssets} = require("./assets");
|
|
23
|
+
const {logLine} = require("./log");
|
|
24
|
+
const navigation = require("../components/navigation");
|
|
25
|
+
const referenced = require("../components/referenced");
|
|
26
|
+
const bibliography = require("../components/bibliography");
|
|
27
|
+
const {printUpgradeNotices} = require("./upgrade-notices");
|
|
28
|
+
|
|
29
|
+
// The IIIF records and ids a rebuild that skips IIIF reuses. On `globalThis`, so that
|
|
30
|
+
// `npm run dev` reloading this module after a change under `lib/` (`dev.js`) keeps them:
|
|
31
|
+
// a reloaded module with none indexed the pages alone, and wrote them alone to the
|
|
32
|
+
// sitemap. The discovery data stays the module's own: a fresh module keeps the catalog
|
|
33
|
+
// already published (`tests/unit/discovery/build.test.js`).
|
|
34
|
+
const held =
|
|
35
|
+
globalThis.__CANOPY_BUILD_HELD__ ||
|
|
36
|
+
(globalThis.__CANOPY_BUILD_HELD__ = {
|
|
37
|
+
iiifRecords: [],
|
|
38
|
+
manifestIds: [],
|
|
39
|
+
collectionIds: [],
|
|
40
|
+
});
|
|
41
|
+
let pageRecords = [];
|
|
42
|
+
let discoveryCache = null;
|
|
43
|
+
|
|
44
|
+
function nowMs() {
|
|
45
|
+
try {
|
|
46
|
+
return Number(process.hrtime.bigint()) / 1e6;
|
|
47
|
+
} catch (_) {
|
|
48
|
+
return Date.now();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function formatDuration(ms) {
|
|
53
|
+
if (!Number.isFinite(ms) || ms < 0) return "0ms";
|
|
54
|
+
if (ms >= 1000) return `${(ms / 1000).toFixed(1)}s`;
|
|
55
|
+
return `${Math.round(ms)}ms`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function timeStage(label, store, fn) {
|
|
59
|
+
const start = nowMs();
|
|
60
|
+
try {
|
|
61
|
+
return await fn();
|
|
62
|
+
} finally {
|
|
63
|
+
const durationMs = nowMs() - start;
|
|
64
|
+
if (Array.isArray(store)) store.push({label, durationMs});
|
|
65
|
+
try {
|
|
66
|
+
logLine(
|
|
67
|
+
`⏱ ${label} completed in ${formatDuration(durationMs)}`,
|
|
68
|
+
"cyan",
|
|
69
|
+
{
|
|
70
|
+
dim: true,
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
} catch (_) {}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function ensureNoJekyllMarker() {
|
|
78
|
+
try {
|
|
79
|
+
await fsp.mkdir(OUT_DIR, {recursive: true});
|
|
80
|
+
const markerPath = path.join(OUT_DIR, ".nojekyll");
|
|
81
|
+
await fsp.writeFile(markerPath, "", "utf8");
|
|
82
|
+
} catch (_) {}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function build(options = {}) {
|
|
86
|
+
const skipIiif = !!(
|
|
87
|
+
options?.skipIiif ||
|
|
88
|
+
process.env.CANOPY_SKIP_IIIF === "1" ||
|
|
89
|
+
process.env.CANOPY_SKIP_IIIF === "true"
|
|
90
|
+
);
|
|
91
|
+
if (!fs.existsSync(CONTENT_DIR)) {
|
|
92
|
+
console.error("No content directory found at", CONTENT_DIR);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
// What a site made before 2.0 can drop or rename, said once.
|
|
96
|
+
printUpgradeNotices();
|
|
97
|
+
const stageTimings = [];
|
|
98
|
+
const buildStart = nowMs();
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Clean and prepare output directory
|
|
102
|
+
*/
|
|
103
|
+
await timeStage("Clean and prepare directories", stageTimings, async () => {
|
|
104
|
+
logLine("\nClean and prepare directories", "magenta", {
|
|
105
|
+
bright: true,
|
|
106
|
+
underscore: true,
|
|
107
|
+
});
|
|
108
|
+
logLine("• Reset MDX cache", "blue", {dim: true});
|
|
109
|
+
mdx?.resetMdxCaches();
|
|
110
|
+
navigation?.resetNavigationCache?.();
|
|
111
|
+
referenced?.resetReferenceIndex?.();
|
|
112
|
+
bibliography?.resetBibliographyIndex?.();
|
|
113
|
+
if (!skipIiif) {
|
|
114
|
+
await cleanDir(OUT_DIR);
|
|
115
|
+
await ensureNoJekyllMarker();
|
|
116
|
+
logLine(`• Cleaned output directory`, "blue", {dim: true});
|
|
117
|
+
} else {
|
|
118
|
+
logLine("• Retaining cache (skipping IIIF rebuild)", "blue", {dim: true});
|
|
119
|
+
}
|
|
120
|
+
if (skipIiif) {
|
|
121
|
+
await ensureNoJekyllMarker();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Build IIIF Collection content from configured source(s).
|
|
127
|
+
* This includes building IIIF manifests for works and collections,
|
|
128
|
+
* as well as collecting search records for works.
|
|
129
|
+
*/
|
|
130
|
+
let iiifRecords = [];
|
|
131
|
+
let CONFIG;
|
|
132
|
+
let currentManifestIds = [];
|
|
133
|
+
let currentCollectionIds = [];
|
|
134
|
+
await timeStage("Build IIIF Collection content", stageTimings, async () => {
|
|
135
|
+
logLine("\nBuild IIIF Collection content", "magenta", {
|
|
136
|
+
bright: true,
|
|
137
|
+
underscore: true,
|
|
138
|
+
});
|
|
139
|
+
CONFIG = await iiif.loadConfig();
|
|
140
|
+
const sources = iiif.resolveIiifSources(CONFIG);
|
|
141
|
+
const hasIiifSources =
|
|
142
|
+
Array.isArray(sources?.collections) && sources.collections.length
|
|
143
|
+
? true
|
|
144
|
+
: Array.isArray(sources?.manifests) && sources.manifests.length > 0;
|
|
145
|
+
if (!skipIiif && hasIiifSources) {
|
|
146
|
+
const results = await iiif.buildIiifCollectionPages(CONFIG);
|
|
147
|
+
iiifRecords = results?.iiifRecords;
|
|
148
|
+
discoveryCache = webMcpEnabled(CONFIG) ? results?.discovery || {} : null;
|
|
149
|
+
held.iiifRecords = Array.isArray(iiifRecords) ? iiifRecords : [];
|
|
150
|
+
currentManifestIds = Array.isArray(results?.manifestIds)
|
|
151
|
+
? results.manifestIds
|
|
152
|
+
: [];
|
|
153
|
+
currentCollectionIds = Array.isArray(results?.collectionIds)
|
|
154
|
+
? results.collectionIds
|
|
155
|
+
: [];
|
|
156
|
+
held.manifestIds = currentManifestIds;
|
|
157
|
+
held.collectionIds = currentCollectionIds;
|
|
158
|
+
logLine(
|
|
159
|
+
`• IIIF records collected: ${Array.isArray(iiifRecords) ? iiifRecords.length : 0}`,
|
|
160
|
+
"blue",
|
|
161
|
+
{dim: true},
|
|
162
|
+
);
|
|
163
|
+
} else if (!skipIiif && !hasIiifSources) {
|
|
164
|
+
iiifRecords = [];
|
|
165
|
+
held.iiifRecords = [];
|
|
166
|
+
discoveryCache = {};
|
|
167
|
+
currentManifestIds = [];
|
|
168
|
+
currentCollectionIds = [];
|
|
169
|
+
held.manifestIds = [];
|
|
170
|
+
held.collectionIds = [];
|
|
171
|
+
logLine("• No IIIF sources configured; skipping", "blue", {dim: true});
|
|
172
|
+
} else {
|
|
173
|
+
iiifRecords = Array.isArray(held.iiifRecords) ? held.iiifRecords : [];
|
|
174
|
+
currentManifestIds = Array.isArray(held.manifestIds)
|
|
175
|
+
? held.manifestIds
|
|
176
|
+
: [];
|
|
177
|
+
currentCollectionIds = Array.isArray(held.collectionIds)
|
|
178
|
+
? held.collectionIds
|
|
179
|
+
: [];
|
|
180
|
+
logLine(
|
|
181
|
+
`• Reusing cached IIIF search records (${iiifRecords.length})`,
|
|
182
|
+
"blue",
|
|
183
|
+
{dim: true},
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
// Ensure any configured featured manifests are cached (and thumbnails computed)
|
|
187
|
+
// so SSR interstitials can resolve items even if they are not part of
|
|
188
|
+
// the traversed collection or when IIIF build is skipped during incremental rebuilds.
|
|
189
|
+
try {
|
|
190
|
+
await iiif.ensureFeaturedInCache(CONFIG);
|
|
191
|
+
} catch (_) {}
|
|
192
|
+
if (!skipIiif && hasIiifSources && currentManifestIds.length) {
|
|
193
|
+
try {
|
|
194
|
+
const featuredKeepIds = Array.isArray(CONFIG?.featured)
|
|
195
|
+
? CONFIG.featured
|
|
196
|
+
: [];
|
|
197
|
+
await iiif.cleanupIiifCache({
|
|
198
|
+
allowedManifestIds: currentManifestIds,
|
|
199
|
+
allowedCollectionIds: currentCollectionIds,
|
|
200
|
+
keepManifestIds: featuredKeepIds,
|
|
201
|
+
});
|
|
202
|
+
} catch (_) {}
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Build contextual MDX content from the content directory.
|
|
208
|
+
* This includes collecting page metadata for sitemap and search index,
|
|
209
|
+
* as well as building all MDX pages to HTML.
|
|
210
|
+
*/
|
|
211
|
+
await timeStage(
|
|
212
|
+
"Build contextual content from Markdown pages",
|
|
213
|
+
stageTimings,
|
|
214
|
+
async () => {
|
|
215
|
+
logLine("\nBuild contextual content from Markdown pages", "magenta", {
|
|
216
|
+
bright: true,
|
|
217
|
+
underscore: true,
|
|
218
|
+
});
|
|
219
|
+
// Interstitials read directly from the local IIIF cache; no API file needed
|
|
220
|
+
try {
|
|
221
|
+
bibliography?.buildBibliographyIndexSync?.();
|
|
222
|
+
} catch (err) {
|
|
223
|
+
logLine(
|
|
224
|
+
"• Failed to build bibliography index: " +
|
|
225
|
+
String(err && err.message ? err.message : err),
|
|
226
|
+
"red",
|
|
227
|
+
{dim: true},
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
pageRecords = await searchBuild.collectMdxPageRecords();
|
|
231
|
+
await pages.buildContentTree(CONTENT_DIR, pageRecords);
|
|
232
|
+
logLine("✓ MDX pages built", "green");
|
|
233
|
+
},
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Build search index from IIIF and MDX records, then build or update
|
|
238
|
+
* the search.html page and search runtime bundle.
|
|
239
|
+
* This is done after all content is built so that the index is comprehensive.
|
|
240
|
+
*/
|
|
241
|
+
await timeStage("Create search indices", stageTimings, async () => {
|
|
242
|
+
logLine("\nCreate search indices", "magenta", {
|
|
243
|
+
bright: true,
|
|
244
|
+
underscore: true,
|
|
245
|
+
});
|
|
246
|
+
try {
|
|
247
|
+
await ensureSearchInitialized();
|
|
248
|
+
const combined = await buildSearchIndex(iiifRecords, pageRecords);
|
|
249
|
+
await finalizeSearch(combined);
|
|
250
|
+
} catch (e) {
|
|
251
|
+
logLine("✗ Search index creation failed", "red", {bright: true});
|
|
252
|
+
logLine(" " + String(e), "red");
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
await timeStage("Export IIIF discovery data", stageTimings, async () => {
|
|
257
|
+
if (skipIiif && discoveryCache === null && webMcpEnabled(CONFIG)) {
|
|
258
|
+
const catalogPath = path.join(OUT_DIR, "api", "discovery", "index.json");
|
|
259
|
+
if (!fs.existsSync(catalogPath)) {
|
|
260
|
+
throw new Error("IIIF discovery needs a full build before IIIF can be skipped.");
|
|
261
|
+
}
|
|
262
|
+
logLine(
|
|
263
|
+
"• Retaining published IIIF discovery data (skipping IIIF rebuild)",
|
|
264
|
+
"blue",
|
|
265
|
+
{dim: true},
|
|
266
|
+
);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
await exportDiscovery({
|
|
270
|
+
config: CONFIG,
|
|
271
|
+
...discoveryCache,
|
|
272
|
+
records: iiifRecords,
|
|
273
|
+
outDir: OUT_DIR,
|
|
274
|
+
absoluteUrl,
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Generate a sitemap so static hosts can discover every rendered page.
|
|
280
|
+
*/
|
|
281
|
+
await timeStage("Write sitemap", stageTimings, async () => {
|
|
282
|
+
logLine("\nWrite sitemap", "magenta", {
|
|
283
|
+
bright: true,
|
|
284
|
+
underscore: true,
|
|
285
|
+
});
|
|
286
|
+
try {
|
|
287
|
+
await writeSitemap(iiifRecords, pageRecords);
|
|
288
|
+
} catch (e) {
|
|
289
|
+
logLine("✗ Failed to write sitemap.xml", "red", {bright: true});
|
|
290
|
+
logLine(" " + String(e), "red");
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// No-op: Featured API file no longer written (SSR reads from cache directly)
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Prepare client runtimes (e.g. search) by bundling with esbuild.
|
|
298
|
+
* This is done early so that MDX content can reference runtime assets if needed.
|
|
299
|
+
*/
|
|
300
|
+
await timeStage(
|
|
301
|
+
"Prepare client runtimes and stylesheets",
|
|
302
|
+
stageTimings,
|
|
303
|
+
async () => {
|
|
304
|
+
logLine("\nPrepare client runtimes and stylesheets", "magenta", {
|
|
305
|
+
bright: true,
|
|
306
|
+
underscore: true,
|
|
307
|
+
});
|
|
308
|
+
const tasks = [];
|
|
309
|
+
if (!process.env.CANOPY_SKIP_STYLES) {
|
|
310
|
+
tasks.push(
|
|
311
|
+
(async () => {
|
|
312
|
+
await ensureStyles();
|
|
313
|
+
logLine("✓ Wrote styles.css", "cyan");
|
|
314
|
+
})(),
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
tasks.push(runtimes.prepareAllRuntimes());
|
|
318
|
+
await Promise.all(tasks);
|
|
319
|
+
},
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Copy static assets from the assets directory to the output directory.
|
|
324
|
+
*/
|
|
325
|
+
await timeStage("Copy static assets", stageTimings, async () => {
|
|
326
|
+
logLine("\nCopy static assets", "magenta", {
|
|
327
|
+
bright: true,
|
|
328
|
+
underscore: true,
|
|
329
|
+
});
|
|
330
|
+
await copyAssets();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
const totalMs = nowMs() - buildStart;
|
|
334
|
+
logLine("\nBuild phase timings", "magenta", {bright: true, underscore: true});
|
|
335
|
+
for (const {label, durationMs} of stageTimings) {
|
|
336
|
+
logLine(`• ${label}: ${formatDuration(durationMs)}`, "blue", {dim: true});
|
|
337
|
+
}
|
|
338
|
+
logLine(`Total build time: ${formatDuration(totalMs)}`, "green", {
|
|
339
|
+
bright: true,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
module.exports = {build};
|
|
344
|
+
|
|
345
|
+
if (require.main === module) {
|
|
346
|
+
build().catch((e) => {
|
|
347
|
+
console.error(e);
|
|
348
|
+
process.exit(1);
|
|
349
|
+
});
|
|
350
|
+
}
|