Skip to content

Commit

Permalink
DEL-110 - Top level collection customisations
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenwf committed Jan 10, 2025
1 parent 29f0053 commit 0dc0df0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 20 deletions.
8 changes: 8 additions & 0 deletions .iiifrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ run:
- folder-collections
- typesense-manifests

collections:
index:
label: { "en": "My great top level collection" }
summary: { "en": "This is a summary of the collection" }
manifests:
label: { "en": "Manifests" }
summary: { "en": "A list of all manifests in the collection" }

generators:
sts-shuttles:
type: nasa-generator
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"typings": "lib/scripts.d.ts",
"scripts": {
"dev": "bun run ./src/entrypoint.ts",
"dev-cli": "bun run ./src/index.ts serve",
"dev-cli": "bun run ./src/index.ts",
"build": "pnpm run build:cli && pnpm run build:server && pnpm run build:client && pnpm run build:node-client",
"build:cli": "tsup-node src/index.ts --no-splitting --outDir build --format esm --env.NODE_ENV production",
"build:server": "tsup-node src/entrypoint.ts --no-splitting --outDir build/server --format esm --env.NODE_ENV production",
Expand Down
18 changes: 11 additions & 7 deletions src/commands/build/5-indices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ export async function indices(

if (indexCollection) {
const baseTopicTypeCollectionSnippet = createCollection({
label: "Topics",
...(config.collections?.topics || {}),
configUrl,
slug: "topics",
label: "Topics",
});

topLevelCollection.push(baseTopicTypeCollectionSnippet);
Expand Down Expand Up @@ -154,7 +155,7 @@ export async function indices(

indexCollection[topicTypeMeta.slug] = topicTypeCollectionSnippet;
topLevelCollection.push(topicTypeCollectionSnippet);
baseTopicTypeCollection.items.push(topicTypeCollectionSnippet);
baseTopicTypeCollection.items.push(topicTypeCollectionSnippet as any);

const topicTypeCollection: Collection = {
...topicTypeCollectionSnippet,
Expand Down Expand Up @@ -189,7 +190,7 @@ export async function indices(
label: topicMeta.label,
});

topicTypeCollection.items.push(topicCollectionSnippet);
topicTypeCollection.items.push(topicCollectionSnippet as any);

indexCollection[topicMeta.slug] = topicCollectionSnippet;

Expand Down Expand Up @@ -234,9 +235,10 @@ export async function indices(

if (indexCollection) {
const indexCollectionJson = createCollection({
label: "Index",
...(config.collections?.index || {}),
configUrl,
slug: "",
label: "Index",
}) as Collection;

indexCollectionJson.items = Object.values(indexCollection);
Expand All @@ -246,9 +248,10 @@ export async function indices(

if (manifestCollection) {
const manifestCollectionJson = createCollection({
label: "Manifests",
...(config.collections?.index || {}),
configUrl,
slug: "manifests",
label: "Manifests",
}) as Collection;

manifestCollectionJson.items = manifestCollection;
Expand Down Expand Up @@ -276,9 +279,10 @@ export async function indices(
});

const topLevelCollectionJson = createCollection({
configUrl,
slug: "collections",
label: "Collections",
...(config.collections?.collections || {}),
slug: "collections",
configUrl,
}) as Collection;
topLevelCollectionJson.items = topLevelCollection;
await files.mkdir(join(buildDir, "collections"));
Expand Down
32 changes: 20 additions & 12 deletions src/util/create-collection.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import type { Collection } from "@iiif/presentation-3";
import type { Collection, InternationalString } from "@iiif/presentation-3";

export function createCollection(opts: {
export function createCollection({
configUrl,
slug,
label,
items: _, // Not allowed.
...collection
}: {
configUrl?: string;
slug?: string;
label: string;
}): Omit<Collection, "items">;
export function createCollection(opts: {
configUrl?: string;
slug?: string;
label: string;
}): Omit<Collection, "items"> {
label: string | InternationalString;
summary?: string | InternationalString;
} & Partial<Omit<Collection, "label" | "sumary">>): Omit<Collection, "items"> {
return {
"@context": "http://iiif.io/api/presentation/3/context.json",
id: `${opts.configUrl}/${opts.slug}/collection.json`,
id: `${configUrl}/${slug}/collection.json`,
type: "Collection" as const,
label: { en: [opts.label] },
"hss:slug": opts.slug,
label: typeof label === "string" ? { en: [label] } : label,
summary: collection.summary
? typeof collection.summary === "string"
? { en: [collection.summary] }
: collection.summary
: undefined,
"hss:slug": slug,
...collection,
} as any;
}
7 changes: 7 additions & 0 deletions src/util/get-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "node:fs";
import { join } from "node:path";
import { cwd } from "node:process";
import type { Collection } from "@iiif/presentation-3";
import { parse } from "yaml";
import type { SlugConfig } from "./slug-engine.ts";

Expand All @@ -13,6 +14,12 @@ export interface IIIFRC {
stores: Record<string, GenericStore>;
slugs?: Record<string, SlugConfig>;
config?: Record<string, any>;
collections?: {
index?: Partial<Collection>;
manifests?: Partial<Collection>;
collections?: Record<string, Partial<Collection>>;
topics?: Record<string, Partial<Collection>>;
};
}

export interface GenericStore {
Expand Down

0 comments on commit 0dc0df0

Please sign in to comment.