Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the largest thumbnail size in the resource meta file. #35

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/iiif/.iiifrc-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ run:
- extract-slug-source
- delft-extract-labels
- extract-part-of-collection
- extract-thumbnail
- extract-thumbnail-local
- manifest-sqlite
- metadata-analysis
- site-collections
- delft-image-source
- typesense-manifests

config:
extract-thumbnail-local:
width: 1080
height: 1080

stores:
collective-access:
type: iiif-json
Expand Down
56 changes: 56 additions & 0 deletions apps/iiif/scripts/extract-thumbnail-local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { createThumbnailHelper } from "@iiif/helpers";
import { extract } from "iiif-hss";

extract({
id: "extract-thumbnail-local",
name: "Extract Thumbnail",
types: ["Manifest"],
invalidate: async (resource, api, config) => {
const cache = await api.caches.value;
return !cache.extractThumbnail && cache.extractThumbnail !== false;
}},
async (resource, api, config) => {
const vault = resource.vault;
const helper = createThumbnailHelper(vault);
const thumbnail = await helper.getBestThumbnailAtSize(
api.resource,
config.width
? {
width: config.width,
height: config.height || config.width,
}
: {
width: 256,
height: 256,
},
config.dereference || false
);

if (thumbnail?.best) {
return {
meta: { thumbnail: thumbnail.best },
caches: { extractThumbnail: true },
};
}
else {
const thumbnail = await helper.getBestThumbnailAtSize(
api.resource, {
width: 256,
height: 256,
},
config.dereference || false
);

if (thumbnail?.best) {
return {
meta: { thumbnail: thumbnail.best },
caches: { extractThumbnail: true },
};
}
}

return {
caches: { extractThumbnail: false },
};
},
)
4 changes: 3 additions & 1 deletion apps/static-site/src/iiif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export async function loadCollection(slug: string) {

export async function loadCollectionMeta(slug: string) {
const resp = await fetch(`${IIIF_URL}${slug}/meta.json`);

if (resp.ok) {
return resp.json();
const json = await resp.json();
return json;
}
}

Expand Down
Loading