@canopy-iiif/app 0.9.2 → 0.9.4

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/lib/build/iiif.js CHANGED
@@ -912,7 +912,10 @@ async function buildIiifCollectionPages(CONFIG) {
912
912
  };
913
913
  async function gatherFromCollection(colLike, parentId) {
914
914
  try {
915
- // Resolve uri/id
915
+ // Resolve the URI we were asked to fetch. Some providers (e.g. Internet Archive)
916
+ // return paged collections where the JSON payload's `id` does not match the
917
+ // URI that served it. We rely on the requested URI as the stable, unique key
918
+ // so pagination continues even when `id` flips back to the root collection.
916
919
  const uri =
917
920
  typeof colLike === "string"
918
921
  ? colLike
@@ -923,12 +926,19 @@ async function buildIiifCollectionPages(CONFIG) {
923
926
  : await readJsonFromUri(uri, {log: true});
924
927
  if (!col) return;
925
928
  const ncol = await normalizeToV3(col);
926
- const colId = String((ncol && (ncol.id || uri)) || uri);
927
- const nid = norm(colId);
928
- if (visitedCollections.has(nid)) return; // avoid cycles
929
- visitedCollections.add(nid);
929
+ const reportedId = String(
930
+ (ncol && (ncol.id || ncol["@id"])) ||
931
+ (typeof colLike === "object" &&
932
+ (colLike.id || colLike["@id"])) ||
933
+ ""
934
+ );
935
+ const effectiveId = String(uri || reportedId || "");
936
+ const collectionKey = effectiveId || reportedId || uri || "";
937
+ const visitKey = norm(collectionKey) || collectionKey;
938
+ if (visitedCollections.has(visitKey)) return; // avoid cycles
939
+ visitedCollections.add(visitKey);
930
940
  try {
931
- await saveCachedCollection(ncol, colId, parentId || "");
941
+ await saveCachedCollection(ncol, collectionKey, parentId || "");
932
942
  } catch (_) {}
933
943
  const itemsArr = Array.isArray(ncol.items) ? ncol.items : [];
934
944
  for (const entry of itemsArr) {
@@ -936,9 +946,9 @@ async function buildIiifCollectionPages(CONFIG) {
936
946
  const t = String(entry.type || entry["@type"] || "").toLowerCase();
937
947
  const entryId = entry.id || entry["@id"] || "";
938
948
  if (t === "manifest") {
939
- tasks.push({id: entryId, parent: colId});
949
+ tasks.push({id: entryId, parent: collectionKey});
940
950
  } else if (t === "collection") {
941
- await gatherFromCollection(entryId, colId);
951
+ await gatherFromCollection(entryId, collectionKey);
942
952
  }
943
953
  }
944
954
  // Traverse strictly by parent/child hierarchy (Presentation 3): items → Manifest or Collection
package/lib/build/mdx.js CHANGED
@@ -11,6 +11,42 @@ const {
11
11
  ensureDirSync,
12
12
  withBase,
13
13
  } = require("../common");
14
+
15
+ const EXTRA_REMARK_PLUGINS = (() => {
16
+ try {
17
+ const absPath = path.resolve(process.cwd(), "packages/helpers/docs/remark-code-meta.js");
18
+ if (fs.existsSync(absPath)) {
19
+ const plugin = require(absPath);
20
+ if (typeof plugin === "function") return [plugin];
21
+ }
22
+ } catch (_) {}
23
+ return [];
24
+ })();
25
+
26
+ function buildCompileOptions(overrides = {}) {
27
+ const base = {
28
+ jsx: false,
29
+ development: false,
30
+ providerImportSource: "@mdx-js/react",
31
+ jsxImportSource: "react",
32
+ format: "mdx",
33
+ };
34
+ const remarkPlugins = [];
35
+ if (overrides && Array.isArray(overrides.remarkPlugins)) {
36
+ remarkPlugins.push(...overrides.remarkPlugins);
37
+ }
38
+ if (EXTRA_REMARK_PLUGINS.length) {
39
+ remarkPlugins.push(...EXTRA_REMARK_PLUGINS);
40
+ }
41
+ if (remarkPlugins.length) {
42
+ base.remarkPlugins = remarkPlugins;
43
+ }
44
+ if (overrides && typeof overrides === "object") {
45
+ const { remarkPlugins: _omit, ...rest } = overrides;
46
+ Object.assign(base, rest);
47
+ }
48
+ return base;
49
+ }
14
50
  const yaml = require("js-yaml");
15
51
  const { getPageContext } = require("../page-context");
16
52
 
@@ -255,15 +291,7 @@ async function loadAppWrapper() {
255
291
  const { compile } = await import("@mdx-js/mdx");
256
292
  const raw = await fsp.readFile(appPath, "utf8");
257
293
  const { content: source } = parseFrontmatter(raw);
258
- let code = String(
259
- await compile(source, {
260
- jsx: false,
261
- development: false,
262
- providerImportSource: "@mdx-js/react",
263
- jsxImportSource: "react",
264
- format: "mdx",
265
- })
266
- );
294
+ let code = String(await compile(source, buildCompileOptions()));
267
295
  // MDX v3 default export (MDXContent) does not forward external children.
268
296
  // When present, expose the underlying layout function as __MDXLayout for wrapping.
269
297
  if (
@@ -307,13 +335,7 @@ async function compileMdxFile(filePath, outPath, Layout, extraProps = {}) {
307
335
  const { compile } = await import("@mdx-js/mdx");
308
336
  const raw = await fsp.readFile(filePath, "utf8");
309
337
  const { content: source } = parseFrontmatter(raw);
310
- const compiled = await compile(source, {
311
- jsx: false,
312
- development: false,
313
- providerImportSource: "@mdx-js/react",
314
- jsxImportSource: "react",
315
- format: "mdx",
316
- });
338
+ const compiled = await compile(source, buildCompileOptions());
317
339
  const code = String(compiled);
318
340
  ensureDirSync(CACHE_DIR);
319
341
  const relCacheName =
@@ -449,13 +471,7 @@ async function compileMdxToComponent(filePath) {
449
471
  const { compile } = await import("@mdx-js/mdx");
450
472
  const raw = await fsp.readFile(filePath, "utf8");
451
473
  const { content: source } = parseFrontmatter(raw);
452
- const compiled = await compile(source, {
453
- jsx: false,
454
- development: false,
455
- providerImportSource: "@mdx-js/react",
456
- jsxImportSource: "react",
457
- format: "mdx",
458
- });
474
+ const compiled = await compile(source, buildCompileOptions());
459
475
  const code = String(compiled);
460
476
  ensureDirSync(CACHE_DIR);
461
477
  const relCacheName =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopy-iiif/app",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "Mat Jordan <mat@northwestern.edu>",
@@ -22,7 +22,8 @@
22
22
  "import": "./lib/orchestrator.js",
23
23
  "require": "./lib/orchestrator.js",
24
24
  "default": "./lib/orchestrator.js"
25
- }
25
+ },
26
+ "./docs-legacy-compat": "./docs-legacy-compat.mjs"
26
27
  },
27
28
  "files": [
28
29
  "lib/**",