@canopy-iiif/app 0.9.3 → 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 +18 -8
- package/package.json +1 -1
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
|
|
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
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
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,
|
|
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:
|
|
949
|
+
tasks.push({id: entryId, parent: collectionKey});
|
|
940
950
|
} else if (t === "collection") {
|
|
941
|
-
await gatherFromCollection(entryId,
|
|
951
|
+
await gatherFromCollection(entryId, collectionKey);
|
|
942
952
|
}
|
|
943
953
|
}
|
|
944
954
|
// Traverse strictly by parent/child hierarchy (Presentation 3): items → Manifest or Collection
|