@canopy-iiif/app 1.6.11 → 1.6.13

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.
Files changed (2) hide show
  1. package/lib/build/iiif.js +17 -10
  2. package/package.json +1 -1
package/lib/build/iiif.js CHANGED
@@ -498,7 +498,7 @@ function collectTextualBody(body, out) {
498
498
  if (body.text !== undefined) collectTextualBody(body.text, out);
499
499
  }
500
500
 
501
- function extractAnnotationText(manifest, options = {}) {
501
+ async function extractAnnotationText(manifest, options = {}) {
502
502
  if (!manifest || typeof manifest !== "object") return "";
503
503
  if (!options.enabled) return "";
504
504
  const motivations =
@@ -524,7 +524,7 @@ function extractAnnotationText(manifest, options = {}) {
524
524
  }
525
525
  }
526
526
 
527
- function handleAnnotation(annotation) {
527
+ async function handleAnnotation(annotation) {
528
528
  if (!annotation || typeof annotation !== "object") return;
529
529
  if (!matchesMotivation(annotation.motivation)) return;
530
530
  const body = annotation.body;
@@ -538,10 +538,10 @@ function extractAnnotationText(manifest, options = {}) {
538
538
  }
539
539
  }
540
540
 
541
- function walk(value) {
541
+ async function walk(value) {
542
542
  if (!value) return;
543
543
  if (Array.isArray(value)) {
544
- for (const entry of value) walk(entry);
544
+ for (const entry of value) await walk(entry);
545
545
  return;
546
546
  }
547
547
  if (typeof value !== "object") return;
@@ -549,22 +549,29 @@ function extractAnnotationText(manifest, options = {}) {
549
549
  seenNodes.add(value);
550
550
  if (Array.isArray(value.annotations)) {
551
551
  for (const page of value.annotations) {
552
- if (page && Array.isArray(page.items)) {
552
+ if (page && typeof page.id === 'string' && !page.items){
553
+ const fetchedPage = await readJsonFromUri(page.id, { log: true });
554
+ if (fetchedPage && Array.isArray(fetchedPage.items)) {
555
+ for (const item of fetchedPage.items){
556
+ handleAnnotation(item)
557
+ }
558
+ }
559
+ } else if (page && Array.isArray(page.items)) {
553
560
  for (const item of page.items) handleAnnotation(item);
554
561
  }
555
- walk(page);
562
+ await walk(page);
556
563
  }
557
564
  }
558
565
  if (Array.isArray(value.items)) {
559
- for (const item of value.items) walk(item);
566
+ for (const item of value.items) await walk(item);
560
567
  }
561
568
  for (const key of Object.keys(value)) {
562
569
  if (key === "annotations" || key === "items") continue;
563
- walk(value[key]);
570
+ await walk(value[key]);
564
571
  }
565
572
  }
566
573
 
567
- walk(manifest);
574
+ await walk(manifest);
568
575
  if (!results.length) return "";
569
576
  return results.join(" ");
570
577
  }
@@ -2342,7 +2349,7 @@ async function buildIiifCollectionPages(CONFIG) {
2342
2349
  }
2343
2350
  if (annotationsOptions && annotationsOptions.enabled) {
2344
2351
  try {
2345
- annotationValue = extractAnnotationText(
2352
+ annotationValue = await extractAnnotationText(
2346
2353
  manifest,
2347
2354
  annotationsOptions,
2348
2355
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopy-iiif/app",
3
- "version": "1.6.11",
3
+ "version": "1.6.13",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "Mat Jordan <mat@northwestern.edu>",