Skip to content

Commit

Permalink
Add seeAlso.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathewjordan committed Jul 23, 2024
1 parent 2e6af8f commit 2bc9dc6
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 40 deletions.
43 changes: 33 additions & 10 deletions node/src/api/response/iiif/collection.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { dcApiEndpoint, dcUrl } = require("../../../environment");
const { transformError } = require("../error");
const { provider, nulLogo } = require("./presentation-api/provider");

async function transform(response, pager) {
if (response.statusCode === 200) {
Expand Down Expand Up @@ -36,13 +37,37 @@ async function buildCollection(responseBody, pageInfo) {
*/
const { pathname } = new URL(query_url);
const isTopCollection = pathname.split("/").pop() === "collections";
const apiLink = `${dcApiEndpoint()}/collections`;
const collectionId = parseCollectionId(pageInfo.query_url);

let result = {
"@context": ["http://iiif.io/api/presentation/3/context.json"],
id: collectionId(pageInfo),
id: iiifCollectionId(pageInfo),
type: "Collection",
label: { none: [collectionLabel] },
summary: { none: [collectionSummary] },
items: getItems(responseBody?.hits?.hits, pageInfo, isTopCollection),
provider: [provider],
logo: [nulLogo],
requiredStatement: {
label: {
none: ["Attribution"],
},
value: {
none: ["Courtesy of Northwestern University Libraries"],
},
},
seeAlso: [
{
pageInfo,
id: isTopCollection ? apiLink : `${apiLink}/${collectionId}`,
type: "Dataset",
format: "application/json",
label: {
none: ["Northwestern University Libraries Digital Collections API"],
},
},
],
homepage: [
{
id: isTopCollection ? dcUrl() : homepageUrl(pageInfo),
Expand All @@ -53,13 +78,9 @@ async function buildCollection(responseBody, pageInfo) {
},
},
],
items: getItems(responseBody?.hits?.hits, pageInfo, isTopCollection),
};

if (pageInfo.options?.parameterOverrides) {
const collectionId = new URL(pageInfo.query_url).pathname
.split("/")
.reverse()[0];
if (!isTopCollection && pageInfo.options?.parameterOverrides) {
const thumbnailId = `${dcApiEndpoint()}/collections/${collectionId}/thumbnail`;
result.thumbnail = [
{
Expand Down Expand Up @@ -92,21 +113,23 @@ function getItems(hits, pageInfo, isTopCollection) {
return items;
}

function collectionId(pageInfo) {
function iiifCollectionId(pageInfo) {
let collectionId = new URL(pageInfo.query_url);
if (pageInfo.current_page > 1) {
collectionId.searchParams.set("page", pageInfo.current_page);
}
return collectionId;
}

function parseCollectionId(query_url) {
return new URL(query_url).pathname.split("/").reverse()[0];
}

function homepageUrl(pageInfo) {
let result;

if (pageInfo.options?.parameterOverrides) {
const collectionId = new URL(pageInfo.query_url).pathname
.split("/")
.reverse()[0];
const collectionId = parseCollectionId(pageInfo.query_url);
result = new URL(`/collections/${collectionId}`, dcUrl());
} else {
result = new URL("/search", dcUrl());
Expand Down
32 changes: 2 additions & 30 deletions node/src/api/response/iiif/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { metadataLabelFields } = require("./presentation-api/metadata");
const {
buildPlaceholderCanvas,
} = require("./presentation-api/placeholder-canvas");
const { nulLogo, provider } = require("./presentation-api/provider");

function transform(response) {
if (response.statusCode === 200) {
Expand Down Expand Up @@ -260,37 +261,8 @@ function transform(response) {
}
}

/** Add logo manually (w/o IIIF Builder) */
const nulLogo = {
id: "https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000003/full/pct:50/0/default.webp",
type: "Image",
format: "image/webp",
height: 139,
width: 1190,
};
jsonManifest.logo = [nulLogo];

/** Add provider manually (w/o IIIF Builder) */
const provider = {
id: "https://www.library.northwestern.edu/",
type: "Agent",
label: { none: ["Northwestern University Libraries"] },
homepage: [
{
id: "https://dc.library.northwestern.edu/",
type: "Text",
label: {
none: [
"Northwestern University Libraries Digital Collections Homepage",
],
},
format: "text/html",
language: ["en"],
},
],
logo: [nulLogo],
};
jsonManifest.provider = [provider];
jsonManifest.logo = [nulLogo];

return {
statusCode: 200,
Expand Down
29 changes: 29 additions & 0 deletions node/src/api/response/iiif/presentation-api/provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const nulLogo = {
id: "https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000003/full/pct:50/0/default.webp",
type: "Image",
format: "image/webp",
height: 139,
width: 1190,
};

const provider = {
id: "https://www.library.northwestern.edu/",
type: "Agent",
label: { none: ["Northwestern University Libraries"] },
homepage: [
{
id: "https://dc.library.northwestern.edu/",
type: "Text",
label: {
none: [
"Northwestern University Libraries Digital Collections Homepage",
],
},
format: "text/html",
language: ["en"],
},
],
logo: [nulLogo],
};

module.exports = { nulLogo, provider };
40 changes: 40 additions & 0 deletions node/test/unit/api/response/iiif/presentation-api/provider.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use strict";

const chai = require("chai");
const expect = chai.expect;

const { provider, nulLogo } = requireSource(
"api/response/iiif/presentation-api/provider"
);

describe("IIIF response presentation API provider and logo", () => {
it("outputs a IIIF provider property", async () => {
expect(provider.id).to.contain("https://www.library.northwestern.edu");
expect(provider.type).to.eq("Agent");
expect(provider.label.none[0]).to.eq("Northwestern University Libraries");
expect(provider.homepage[0].id).to.contain(
"https://dc.library.northwestern.edu"
);
expect(provider.homepage[0].label.none[0]).to.eq(
"Northwestern University Libraries Digital Collections Homepage"
);
expect(provider.logo).to.be.an("array");
expect(provider.logo[0].id).to.contain(
"https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000003/full/pct:50/0/default.webp"
);
expect(provider.logo[0].type).to.eq("Image");
expect(provider.logo[0].format).to.eq("image/webp");
expect(provider.logo[0].height).to.be.a("number");
expect(provider.logo[0].width).to.be.a("number");
});

it("outputs a IIIF logo property", async () => {
expect(nulLogo.id).to.contain(
"https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000003/full/pct:50/0/default.webp"
);
expect(nulLogo.type).to.eq("Image");
expect(nulLogo.format).to.eq("image/webp");
expect(nulLogo.height).to.be.a("number");
expect(nulLogo.width).to.be.a("number");
});
});

0 comments on commit 2bc9dc6

Please sign in to comment.