@digitalculture/ochre-sdk 0.6.6 → 0.7.1
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/dist/index.cjs +8 -2742
- package/dist/index.d.cts +11 -8
- package/dist/index.d.ts +11 -8
- package/dist/index.js +8 -2667
- package/package.json +8 -7
package/dist/index.js
CHANGED
|
@@ -1,2672 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var websiteSchema = z.object({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"traditional",
|
|
8
|
-
"digital-collection",
|
|
9
|
-
"plum",
|
|
10
|
-
"cedar",
|
|
11
|
-
"elm",
|
|
12
|
-
"maple",
|
|
13
|
-
"oak",
|
|
14
|
-
"palm"
|
|
15
|
-
],
|
|
16
|
-
{ message: "Invalid website type" }
|
|
17
|
-
),
|
|
18
|
-
status: z.enum(
|
|
19
|
-
["development", "preview", "production"],
|
|
20
|
-
{ message: "Invalid website status" }
|
|
21
|
-
),
|
|
22
|
-
privacy: z.enum(
|
|
23
|
-
["public", "password", "private"],
|
|
24
|
-
{ message: "Invalid website privacy" }
|
|
25
|
-
)
|
|
26
|
-
});
|
|
27
|
-
var componentSchema = z.enum(
|
|
28
|
-
[
|
|
29
|
-
"annotated-document",
|
|
30
|
-
"annotated-image",
|
|
31
|
-
"bibliography",
|
|
32
|
-
"blog",
|
|
33
|
-
"button",
|
|
34
|
-
"collection",
|
|
35
|
-
"empty-space",
|
|
36
|
-
"filter-categories",
|
|
37
|
-
"iframe",
|
|
38
|
-
"iiif-viewer",
|
|
39
|
-
"image",
|
|
40
|
-
"image-gallery",
|
|
41
|
-
"n-columns",
|
|
42
|
-
"n-rows",
|
|
43
|
-
"network-graph",
|
|
44
|
-
"search-bar",
|
|
45
|
-
"table",
|
|
46
|
-
"text",
|
|
47
|
-
"timeline",
|
|
48
|
-
"video"
|
|
49
|
-
],
|
|
50
|
-
{ message: "Invalid component" }
|
|
51
|
-
);
|
|
52
|
-
var categorySchema = z.enum([
|
|
53
|
-
"resource",
|
|
54
|
-
"spatialUnit",
|
|
55
|
-
"concept",
|
|
56
|
-
"period",
|
|
57
|
-
"bibliography",
|
|
58
|
-
"person",
|
|
59
|
-
"propertyValue",
|
|
60
|
-
"set",
|
|
61
|
-
"tree"
|
|
62
|
-
]);
|
|
63
|
-
var gallerySchema = z.object({
|
|
64
|
-
uuid: z.string().uuid({ message: "Invalid UUID" }),
|
|
65
|
-
filter: z.string().optional(),
|
|
66
|
-
page: z.number().positive({ message: "Page must be positive" }),
|
|
67
|
-
perPage: z.number().positive({ message: "Per page must be positive" })
|
|
68
|
-
}).strict();
|
|
69
|
-
var renderOptionsSchema = z.string().transform((str) => str.split(" ")).pipe(
|
|
70
|
-
z.array(
|
|
71
|
-
z.enum([
|
|
72
|
-
"bold",
|
|
73
|
-
"italic",
|
|
74
|
-
"underline"
|
|
75
|
-
])
|
|
76
|
-
)
|
|
77
|
-
);
|
|
78
|
-
var whitespaceSchema = z.string().transform((str) => str.split(" ")).pipe(
|
|
79
|
-
z.array(
|
|
80
|
-
z.enum([
|
|
81
|
-
"newline",
|
|
82
|
-
"trailing",
|
|
83
|
-
"leading"
|
|
84
|
-
])
|
|
85
|
-
)
|
|
86
|
-
);
|
|
87
|
-
var emailSchema = z.string().email({ message: "Invalid email" });
|
|
88
|
-
|
|
89
|
-
// src/utils/getters.ts
|
|
90
|
-
var DEFAULT_OPTIONS = {
|
|
91
|
-
searchNestedProperties: false
|
|
92
|
-
};
|
|
93
|
-
function getPropertyByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
94
|
-
const { searchNestedProperties } = options;
|
|
95
|
-
const property = properties.find((property2) => property2.label === label);
|
|
96
|
-
if (property) {
|
|
97
|
-
return property;
|
|
98
|
-
}
|
|
99
|
-
if (searchNestedProperties) {
|
|
100
|
-
for (const property2 of properties) {
|
|
101
|
-
if (property2.properties.length > 0) {
|
|
102
|
-
const nestedResult = getPropertyByLabel(property2.properties, label, {
|
|
103
|
-
searchNestedProperties
|
|
104
|
-
});
|
|
105
|
-
if (nestedResult) {
|
|
106
|
-
return nestedResult;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
function getPropertyValuesByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
114
|
-
const { searchNestedProperties } = options;
|
|
115
|
-
const property = properties.find((property2) => property2.label === label);
|
|
116
|
-
if (property) {
|
|
117
|
-
return property.values.map((value) => value.content);
|
|
118
|
-
}
|
|
119
|
-
if (searchNestedProperties) {
|
|
120
|
-
for (const property2 of properties) {
|
|
121
|
-
if (property2.properties.length > 0) {
|
|
122
|
-
const nestedResult = getPropertyValuesByLabel(
|
|
123
|
-
property2.properties,
|
|
124
|
-
label,
|
|
125
|
-
{ searchNestedProperties }
|
|
126
|
-
);
|
|
127
|
-
if (nestedResult) {
|
|
128
|
-
return nestedResult;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
function getPropertyValueByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
136
|
-
const { searchNestedProperties } = options;
|
|
137
|
-
const values = getPropertyValuesByLabel(properties, label, {
|
|
138
|
-
searchNestedProperties
|
|
139
|
-
});
|
|
140
|
-
if (values !== null && values.length > 0) {
|
|
141
|
-
return values[0];
|
|
142
|
-
}
|
|
143
|
-
if (searchNestedProperties) {
|
|
144
|
-
for (const property of properties) {
|
|
145
|
-
if (property.properties.length > 0) {
|
|
146
|
-
const nestedResult = getPropertyValueByLabel(
|
|
147
|
-
property.properties,
|
|
148
|
-
label,
|
|
149
|
-
{ searchNestedProperties }
|
|
150
|
-
);
|
|
151
|
-
if (nestedResult !== null) {
|
|
152
|
-
return nestedResult;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
function getAllPropertyLabels(properties, options = DEFAULT_OPTIONS) {
|
|
160
|
-
const { searchNestedProperties } = options;
|
|
161
|
-
const labels = /* @__PURE__ */ new Set();
|
|
162
|
-
for (const property of properties) {
|
|
163
|
-
labels.add(property.label);
|
|
164
|
-
if (property.properties.length > 0 && searchNestedProperties) {
|
|
165
|
-
const nestedLabels = getAllPropertyLabels(property.properties, {
|
|
166
|
-
searchNestedProperties: true
|
|
167
|
-
});
|
|
168
|
-
for (const label of nestedLabels) {
|
|
169
|
-
labels.add(label);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return [...labels];
|
|
174
|
-
}
|
|
175
|
-
function filterProperties(property, filter, options = DEFAULT_OPTIONS) {
|
|
176
|
-
const { searchNestedProperties } = options;
|
|
177
|
-
const isAllFields = filter.label.toLocaleLowerCase("en-US") === "all fields";
|
|
178
|
-
if (isAllFields || property.label.toLocaleLowerCase("en-US") === filter.label.toLocaleLowerCase("en-US")) {
|
|
179
|
-
let isFound = property.values.some((value) => {
|
|
180
|
-
if (value.content === null) {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
if (typeof value.content === "string") {
|
|
184
|
-
if (typeof filter.value !== "string") {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
return value.content.toLocaleLowerCase("en-US").includes(filter.value.toLocaleLowerCase("en-US"));
|
|
188
|
-
}
|
|
189
|
-
if (typeof value.content === "number") {
|
|
190
|
-
if (typeof filter.value !== "number") {
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
return value.content === filter.value;
|
|
194
|
-
}
|
|
195
|
-
if (typeof value.content === "boolean") {
|
|
196
|
-
if (typeof filter.value !== "boolean") {
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
return value.booleanValue === filter.value;
|
|
200
|
-
}
|
|
201
|
-
if (value.content instanceof Date) {
|
|
202
|
-
if (!(filter.value instanceof Date)) {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
return value.content.getTime() === filter.value.getTime();
|
|
206
|
-
}
|
|
207
|
-
return false;
|
|
208
|
-
});
|
|
209
|
-
if (!isFound && searchNestedProperties) {
|
|
210
|
-
isFound = property.properties.some(
|
|
211
|
-
(property2) => filterProperties(property2, filter, { searchNestedProperties: true })
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
return isFound;
|
|
215
|
-
}
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// src/utils/string.ts
|
|
220
|
-
function getStringItemByLanguage(content, language) {
|
|
221
|
-
const stringItemToFind = content.find((item) => item.lang === language);
|
|
222
|
-
return stringItemToFind ?? null;
|
|
223
|
-
}
|
|
224
|
-
function parseEmail(string) {
|
|
225
|
-
const splitString = string.split(" ");
|
|
226
|
-
const returnSplitString = [];
|
|
227
|
-
for (const string2 of splitString) {
|
|
228
|
-
const cleanString = string2.replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g, "").replace(/[!),.:;?\]]$/, "");
|
|
229
|
-
const index = string2.indexOf(cleanString);
|
|
230
|
-
const before = string2.slice(0, index);
|
|
231
|
-
const after = string2.slice(index + cleanString.length);
|
|
232
|
-
const isEmail = emailSchema.safeParse(cleanString).success;
|
|
233
|
-
if (isEmail) {
|
|
234
|
-
returnSplitString.push(
|
|
235
|
-
before,
|
|
236
|
-
`${before}<ExternalLink href="mailto:${cleanString}">${cleanString}</ExternalLink>${after}`
|
|
237
|
-
);
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
returnSplitString.push(string2);
|
|
241
|
-
}
|
|
242
|
-
return returnSplitString.join(" ");
|
|
243
|
-
}
|
|
244
|
-
function parseRenderOptions(contentString, renderString) {
|
|
245
|
-
let returnString = contentString;
|
|
246
|
-
const result = renderOptionsSchema.safeParse(renderString);
|
|
247
|
-
if (!result.success) {
|
|
248
|
-
console.warn(`Invalid render options string provided: \u201C${renderString}\u201D`);
|
|
249
|
-
return contentString;
|
|
250
|
-
}
|
|
251
|
-
for (const option of result.data) {
|
|
252
|
-
switch (option) {
|
|
253
|
-
case "bold": {
|
|
254
|
-
returnString = `**${returnString}**`;
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
257
|
-
case "italic": {
|
|
258
|
-
returnString = `*${returnString}*`;
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
case "underline": {
|
|
262
|
-
returnString = `_${returnString}_`;
|
|
263
|
-
break;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return returnString.replaceAll("'", "'");
|
|
268
|
-
}
|
|
269
|
-
function parseWhitespace(contentString, whitespace) {
|
|
270
|
-
let returnString = contentString;
|
|
271
|
-
const result = whitespaceSchema.safeParse(whitespace);
|
|
272
|
-
if (!result.success) {
|
|
273
|
-
console.warn(`Invalid whitespace string provided: \u201C${whitespace}\u201D`);
|
|
274
|
-
return contentString;
|
|
275
|
-
}
|
|
276
|
-
for (const option of result.data) {
|
|
277
|
-
switch (option) {
|
|
278
|
-
case "newline": {
|
|
279
|
-
returnString = `<br />
|
|
280
|
-
${returnString}`;
|
|
281
|
-
break;
|
|
282
|
-
}
|
|
283
|
-
case "trailing": {
|
|
284
|
-
returnString = `${returnString} `;
|
|
285
|
-
break;
|
|
286
|
-
}
|
|
287
|
-
case "leading": {
|
|
288
|
-
returnString = ` ${returnString}`;
|
|
289
|
-
break;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return returnString.replaceAll("'", "'");
|
|
294
|
-
}
|
|
295
|
-
function parseFakeString(string) {
|
|
296
|
-
let returnString = "";
|
|
297
|
-
if (typeof string === "string") {
|
|
298
|
-
returnString = string;
|
|
299
|
-
} else if (typeof string === "number") {
|
|
300
|
-
returnString = string.toString();
|
|
301
|
-
} else if (typeof string === "boolean") {
|
|
302
|
-
returnString = string ? "Yes" : "No";
|
|
303
|
-
}
|
|
304
|
-
return returnString.replaceAll("'", "'").replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
|
|
305
|
-
}
|
|
306
|
-
function parseStringItem(item) {
|
|
307
|
-
let returnString = "";
|
|
308
|
-
switch (typeof item.string) {
|
|
309
|
-
case "string": {
|
|
310
|
-
returnString = item.string;
|
|
311
|
-
break;
|
|
312
|
-
}
|
|
313
|
-
case "number":
|
|
314
|
-
case "boolean": {
|
|
315
|
-
returnString = parseFakeString(item.string);
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
case "object": {
|
|
319
|
-
const stringItems = Array.isArray(item.string) ? item.string : [item.string];
|
|
320
|
-
for (const stringItem of stringItems) {
|
|
321
|
-
if (typeof stringItem === "string" || typeof stringItem === "number" || typeof stringItem === "boolean") {
|
|
322
|
-
returnString += parseFakeString(stringItem);
|
|
323
|
-
} else {
|
|
324
|
-
const renderedText = stringItem.rend != null ? parseRenderOptions(
|
|
325
|
-
parseFakeString(stringItem.content),
|
|
326
|
-
stringItem.rend
|
|
327
|
-
) : parseFakeString(stringItem.content);
|
|
328
|
-
const whitespacedText = stringItem.whitespace != null ? parseWhitespace(renderedText, stringItem.whitespace) : renderedText;
|
|
329
|
-
returnString += whitespacedText;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
break;
|
|
333
|
-
}
|
|
334
|
-
default: {
|
|
335
|
-
returnString = "";
|
|
336
|
-
break;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return returnString.replaceAll("'", "'").replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
|
|
340
|
-
}
|
|
341
|
-
function parseStringDocumentItem(item, footnotes) {
|
|
342
|
-
if (typeof item === "string" || typeof item === "number" || typeof item === "boolean") {
|
|
343
|
-
return parseEmail(parseFakeString(item));
|
|
344
|
-
}
|
|
345
|
-
if ("whitespace" in item && !("content" in item) && !("string" in item)) {
|
|
346
|
-
if (item.whitespace === "newline") {
|
|
347
|
-
return " \n";
|
|
348
|
-
} else {
|
|
349
|
-
return "";
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
if ("links" in item) {
|
|
353
|
-
let itemString = "";
|
|
354
|
-
if (typeof item.string === "object") {
|
|
355
|
-
itemString = parseStringContent(item.string);
|
|
356
|
-
} else {
|
|
357
|
-
itemString = parseFakeString(item.string).replaceAll("<", String.raw`\<`).replaceAll("{", String.raw`\{`);
|
|
358
|
-
}
|
|
359
|
-
const itemLinks = Array.isArray(item.links) ? item.links : [item.links];
|
|
360
|
-
for (const link of itemLinks) {
|
|
361
|
-
if ("resource" in link) {
|
|
362
|
-
const linkResource = Array.isArray(link.resource) ? link.resource[0] : link.resource;
|
|
363
|
-
let linkContent = null;
|
|
364
|
-
if (linkResource.content != null) {
|
|
365
|
-
linkContent = parseFakeString(linkResource.content).replaceAll("<", String.raw`\<`).replaceAll("{", String.raw`\{`);
|
|
366
|
-
}
|
|
367
|
-
switch (linkResource.type) {
|
|
368
|
-
case "image": {
|
|
369
|
-
if (linkResource.rend === "inline") {
|
|
370
|
-
return `<InlineImage uuid="${linkResource.uuid}" ${linkContent !== null ? `content="${linkContent}"` : ""} height={${linkResource.height?.toString() ?? "null"}} width={${linkResource.width?.toString() ?? "null"}} />`;
|
|
371
|
-
} else if (linkResource.publicationDateTime != null) {
|
|
372
|
-
return `<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${linkResource.uuid}" type="image"${linkContent !== null ? ` content="${linkContent}"` : ""}>${itemString}</ExternalLink>`;
|
|
373
|
-
} else {
|
|
374
|
-
return `<TooltipSpan type="image" ${linkContent !== null ? `content="${linkContent}"` : ""}>${itemString}</TooltipSpan>`;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
case "internalDocument": {
|
|
378
|
-
const isFootnote = linkContent?.toLocaleLowerCase("en-US").includes("footnote");
|
|
379
|
-
if (isFootnote) {
|
|
380
|
-
if (footnotes) {
|
|
381
|
-
footnotes.push({
|
|
382
|
-
uuid: linkResource.uuid,
|
|
383
|
-
label: itemString,
|
|
384
|
-
content: ""
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
return ` <Footnote uuid="${linkResource.uuid}"${itemString ? ` label="${itemString}"` : ""}${linkContent !== null ? ` content="${linkContent}"` : ""} />`;
|
|
388
|
-
} else {
|
|
389
|
-
return `<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${linkResource.uuid}" type="internalDocument" ${linkContent !== null ? `content="${linkContent}"` : ""}>${itemString}</ExternalLink>`;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
case "externalDocument": {
|
|
393
|
-
if (linkResource.publicationDateTime != null) {
|
|
394
|
-
return `<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${linkResource.uuid}" type="externalDocument" ${linkContent !== null ? `content="${linkContent}"` : ""}>${itemString}</ExternalLink>`;
|
|
395
|
-
} else {
|
|
396
|
-
return `<TooltipSpan type="externalDocument" ${linkContent !== null ? `content="${linkContent}"` : ""}>${itemString}</TooltipSpan>`;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
case "webpage": {
|
|
400
|
-
return `<ExternalLink href="${linkResource.href}" type="webpage" ${linkContent !== null ? `content="${linkContent}"` : ""}>${itemString}</ExternalLink>`;
|
|
401
|
-
}
|
|
402
|
-
default: {
|
|
403
|
-
return "";
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
} else if ("concept" in link) {
|
|
407
|
-
const linkConcept = Array.isArray(link.concept) ? link.concept[0] : link.concept;
|
|
408
|
-
if (linkConcept.publicationDateTime != null) {
|
|
409
|
-
return `<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${linkConcept.uuid}" type="concept">${itemString}</ExternalLink>`;
|
|
410
|
-
} else {
|
|
411
|
-
return `<TooltipSpan type="concept">${itemString}</TooltipSpan>`;
|
|
412
|
-
}
|
|
413
|
-
} else if ("set" in link) {
|
|
414
|
-
const linkSet = Array.isArray(link.set) ? link.set[0] : link.set;
|
|
415
|
-
if (linkSet.publicationDateTime != null) {
|
|
416
|
-
return `<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${linkSet.uuid}" type="set">${itemString}</ExternalLink>`;
|
|
417
|
-
} else {
|
|
418
|
-
return `<TooltipSpan type="set">${itemString}</TooltipSpan>`;
|
|
419
|
-
}
|
|
420
|
-
} else if ("person" in link) {
|
|
421
|
-
const linkPerson = Array.isArray(link.person) ? link.person[0] : link.person;
|
|
422
|
-
const linkContent = linkPerson.identification ? ["string", "number", "boolean"].includes(
|
|
423
|
-
typeof linkPerson.identification.label
|
|
424
|
-
) ? parseFakeString(linkPerson.identification.label) : parseStringContent(
|
|
425
|
-
linkPerson.identification.label
|
|
426
|
-
) : null;
|
|
427
|
-
if (linkPerson.publicationDateTime != null) {
|
|
428
|
-
return `<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${linkPerson.uuid}" type="${linkPerson.type ?? "person"}" ${linkContent !== null ? `content="${linkContent}"` : ""}>${itemString}</ExternalLink>`;
|
|
429
|
-
} else {
|
|
430
|
-
return `<TooltipSpan type="${linkPerson.type ?? "person"}" ${linkContent !== null ? `content="${linkContent}"` : ""}>${itemString}</TooltipSpan>`;
|
|
431
|
-
}
|
|
432
|
-
} else if ("bibliography" in link) {
|
|
433
|
-
const linkBibliography = Array.isArray(link.bibliography) ? link.bibliography[0] : link.bibliography;
|
|
434
|
-
if (linkBibliography.publicationDateTime != null) {
|
|
435
|
-
return `<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${linkBibliography.uuid}" type="${linkBibliography.type ?? "bibliography"}">${itemString}</ExternalLink>`;
|
|
436
|
-
} else {
|
|
437
|
-
return `<TooltipSpan type="bibliography">${itemString}</TooltipSpan>`;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
let returnString = "";
|
|
443
|
-
if ("string" in item) {
|
|
444
|
-
const stringItems = Array.isArray(item.string) ? item.string : [item.string];
|
|
445
|
-
for (const stringItem of stringItems) {
|
|
446
|
-
returnString += parseStringDocumentItem(stringItem, footnotes);
|
|
447
|
-
}
|
|
448
|
-
if ("whitespace" in item && item.whitespace != null) {
|
|
449
|
-
returnString = parseWhitespace(parseEmail(returnString), item.whitespace);
|
|
450
|
-
}
|
|
451
|
-
return returnString.replaceAll("'", "'").replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
|
|
452
|
-
} else {
|
|
453
|
-
returnString = parseFakeString(item.content);
|
|
454
|
-
if (item.rend != null) {
|
|
455
|
-
returnString = parseRenderOptions(parseEmail(returnString), item.rend);
|
|
456
|
-
}
|
|
457
|
-
if (item.whitespace != null) {
|
|
458
|
-
returnString = parseWhitespace(parseEmail(returnString), item.whitespace);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
return returnString.replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
|
|
462
|
-
}
|
|
463
|
-
function parseStringContent(content, language = "eng") {
|
|
464
|
-
switch (typeof content.content) {
|
|
465
|
-
case "string":
|
|
466
|
-
case "number":
|
|
467
|
-
case "boolean": {
|
|
468
|
-
return parseFakeString(content.content);
|
|
469
|
-
}
|
|
470
|
-
case "object": {
|
|
471
|
-
if (Array.isArray(content.content)) {
|
|
472
|
-
const stringItem = getStringItemByLanguage(content.content, language);
|
|
473
|
-
if (stringItem) {
|
|
474
|
-
return parseStringItem(stringItem);
|
|
475
|
-
} else {
|
|
476
|
-
const returnStringItem = content.content[0];
|
|
477
|
-
if (!returnStringItem) {
|
|
478
|
-
throw new Error(
|
|
479
|
-
`No string item found for language \u201C${language}\u201D in the following content:
|
|
480
|
-
${JSON.stringify(
|
|
481
|
-
content.content
|
|
482
|
-
)}.`
|
|
483
|
-
);
|
|
484
|
-
}
|
|
485
|
-
return parseStringItem(returnStringItem);
|
|
486
|
-
}
|
|
487
|
-
} else {
|
|
488
|
-
return parseStringItem(content.content);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
default: {
|
|
492
|
-
return String(content.content).replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
// src/utils/helpers.ts
|
|
498
|
-
function getItemCategory(keys) {
|
|
499
|
-
const categoryFound = keys.find(
|
|
500
|
-
(key) => categorySchema.safeParse(key).success
|
|
501
|
-
);
|
|
502
|
-
if (!categoryFound) {
|
|
503
|
-
const unknownKey = keys.find(
|
|
504
|
-
(key) => ![
|
|
505
|
-
"uuid",
|
|
506
|
-
"uuidBelongsTo",
|
|
507
|
-
"belongsTo",
|
|
508
|
-
"publicationDateTime",
|
|
509
|
-
"metadata",
|
|
510
|
-
"languages"
|
|
511
|
-
].includes(key)
|
|
512
|
-
);
|
|
513
|
-
throw new Error(`Invalid OCHRE data; found unexpected "${unknownKey}" key`);
|
|
514
|
-
}
|
|
515
|
-
const categoryKey = categorySchema.parse(categoryFound);
|
|
516
|
-
return categoryKey;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
// src/utils/fetchers/uuid.ts
|
|
520
|
-
async function fetchByUuid(uuid) {
|
|
521
|
-
try {
|
|
522
|
-
const parsedUuid = uuidSchema.parse(uuid);
|
|
523
|
-
const response = await fetch(
|
|
524
|
-
`https://ochre.lib.uchicago.edu/ochre?uuid=${parsedUuid}&format=json&lang="*"`
|
|
525
|
-
);
|
|
526
|
-
if (!response.ok) {
|
|
527
|
-
throw new Error("Failed to fetch OCHRE data");
|
|
528
|
-
}
|
|
529
|
-
const dataRaw = await response.json();
|
|
530
|
-
if (!("ochre" in dataRaw)) {
|
|
531
|
-
throw new Error("Invalid OCHRE data: API response missing 'ochre' key");
|
|
532
|
-
}
|
|
533
|
-
return [null, dataRaw];
|
|
534
|
-
} catch (error) {
|
|
535
|
-
return [error instanceof Error ? error.message : "Unknown error", null];
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
// src/utils/fetchers/item.ts
|
|
540
|
-
async function fetchItem(uuid, category) {
|
|
541
|
-
try {
|
|
542
|
-
const [error, data] = await fetchByUuid(uuid);
|
|
543
|
-
if (error !== null) {
|
|
544
|
-
throw new Error(error);
|
|
545
|
-
}
|
|
546
|
-
const categoryKey = getItemCategory(Object.keys(data.ochre));
|
|
547
|
-
let item;
|
|
548
|
-
switch (categoryKey) {
|
|
549
|
-
case "resource": {
|
|
550
|
-
if (!("resource" in data.ochre)) {
|
|
551
|
-
throw new Error(
|
|
552
|
-
"Invalid OCHRE data: API response missing 'resource' key"
|
|
553
|
-
);
|
|
554
|
-
}
|
|
555
|
-
item = parseResource(data.ochre.resource);
|
|
556
|
-
break;
|
|
557
|
-
}
|
|
558
|
-
case "spatialUnit": {
|
|
559
|
-
if (!("spatialUnit" in data.ochre)) {
|
|
560
|
-
throw new Error(
|
|
561
|
-
"Invalid OCHRE data: API response missing 'spatialUnit' key"
|
|
562
|
-
);
|
|
563
|
-
}
|
|
564
|
-
item = parseSpatialUnit(data.ochre.spatialUnit);
|
|
565
|
-
break;
|
|
566
|
-
}
|
|
567
|
-
case "concept": {
|
|
568
|
-
if (!("concept" in data.ochre)) {
|
|
569
|
-
throw new Error(
|
|
570
|
-
"Invalid OCHRE data: API response missing 'concept' key"
|
|
571
|
-
);
|
|
572
|
-
}
|
|
573
|
-
item = parseConcept(data.ochre.concept);
|
|
574
|
-
break;
|
|
575
|
-
}
|
|
576
|
-
case "period": {
|
|
577
|
-
if (!("period" in data.ochre)) {
|
|
578
|
-
throw new Error(
|
|
579
|
-
"Invalid OCHRE data: API response missing 'period' key"
|
|
580
|
-
);
|
|
581
|
-
}
|
|
582
|
-
item = parsePeriod(data.ochre.period);
|
|
583
|
-
break;
|
|
584
|
-
}
|
|
585
|
-
case "bibliography": {
|
|
586
|
-
if (!("bibliography" in data.ochre)) {
|
|
587
|
-
throw new Error(
|
|
588
|
-
"Invalid OCHRE data: API response missing 'bibliography' key"
|
|
589
|
-
);
|
|
590
|
-
}
|
|
591
|
-
item = parseBibliography(data.ochre.bibliography);
|
|
592
|
-
break;
|
|
593
|
-
}
|
|
594
|
-
case "person": {
|
|
595
|
-
if (!("person" in data.ochre)) {
|
|
596
|
-
throw new Error(
|
|
597
|
-
"Invalid OCHRE data: API response missing 'person' key"
|
|
598
|
-
);
|
|
599
|
-
}
|
|
600
|
-
item = parsePerson(data.ochre.person);
|
|
601
|
-
break;
|
|
602
|
-
}
|
|
603
|
-
case "propertyValue": {
|
|
604
|
-
if (!("propertyValue" in data.ochre)) {
|
|
605
|
-
throw new Error(
|
|
606
|
-
"Invalid OCHRE data: API response missing 'propertyValue' key"
|
|
607
|
-
);
|
|
608
|
-
}
|
|
609
|
-
item = parsePropertyValue(data.ochre.propertyValue);
|
|
610
|
-
break;
|
|
611
|
-
}
|
|
612
|
-
case "set": {
|
|
613
|
-
if (!("set" in data.ochre)) {
|
|
614
|
-
throw new Error("Invalid OCHRE data: API response missing 'set' key");
|
|
615
|
-
}
|
|
616
|
-
item = parseSet(data.ochre.set);
|
|
617
|
-
break;
|
|
618
|
-
}
|
|
619
|
-
case "tree": {
|
|
620
|
-
if (!("tree" in data.ochre)) {
|
|
621
|
-
throw new Error(
|
|
622
|
-
"Invalid OCHRE data: API response missing 'tree' key"
|
|
623
|
-
);
|
|
624
|
-
}
|
|
625
|
-
item = parseTree(data.ochre.tree);
|
|
626
|
-
break;
|
|
627
|
-
}
|
|
628
|
-
default: {
|
|
629
|
-
throw new Error("Invalid category");
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
const metadata = parseMetadata(data.ochre.metadata);
|
|
633
|
-
const belongsTo = {
|
|
634
|
-
uuid: data.ochre.uuidBelongsTo,
|
|
635
|
-
abbreviation: parseFakeString(data.ochre.belongsTo)
|
|
636
|
-
};
|
|
637
|
-
return {
|
|
638
|
-
error: null,
|
|
639
|
-
metadata,
|
|
640
|
-
belongsTo,
|
|
641
|
-
item,
|
|
642
|
-
category
|
|
643
|
-
};
|
|
644
|
-
} catch (error) {
|
|
645
|
-
return {
|
|
646
|
-
error: error instanceof Error ? error.message : "Unknown error",
|
|
647
|
-
metadata: void 0,
|
|
648
|
-
belongsTo: void 0,
|
|
649
|
-
item: void 0,
|
|
650
|
-
category: void 0
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
// src/utils/parse.ts
|
|
656
|
-
function parseIdentification(identification) {
|
|
657
|
-
try {
|
|
658
|
-
const returnIdentification = {
|
|
659
|
-
label: ["string", "number", "boolean"].includes(typeof identification.label) ? parseFakeString(identification.label) : parseStringContent(identification.label),
|
|
660
|
-
abbreviation: ""
|
|
661
|
-
};
|
|
662
|
-
for (const key of Object.keys(identification).filter(
|
|
663
|
-
(key2) => key2 !== "label"
|
|
664
|
-
)) {
|
|
665
|
-
returnIdentification[key] = parseStringContent(
|
|
666
|
-
identification[key]
|
|
667
|
-
);
|
|
668
|
-
}
|
|
669
|
-
return returnIdentification;
|
|
670
|
-
} catch (error) {
|
|
671
|
-
console.error(error);
|
|
672
|
-
return {
|
|
673
|
-
label: "",
|
|
674
|
-
abbreviation: ""
|
|
675
|
-
};
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
function parseLanguages(language) {
|
|
679
|
-
if (language == null) {
|
|
680
|
-
return ["eng"];
|
|
681
|
-
}
|
|
682
|
-
if (Array.isArray(language)) {
|
|
683
|
-
return language.map((lang) => parseStringContent(lang));
|
|
684
|
-
} else {
|
|
685
|
-
return [parseStringContent(language)];
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
function parseMetadata(metadata) {
|
|
689
|
-
let identification = {
|
|
690
|
-
label: "",
|
|
691
|
-
abbreviation: ""
|
|
692
|
-
};
|
|
693
|
-
if (metadata.item) {
|
|
694
|
-
if (metadata.item.label || metadata.item.abbreviation) {
|
|
695
|
-
let label = "";
|
|
696
|
-
let abbreviation = "";
|
|
697
|
-
if (metadata.item.label) {
|
|
698
|
-
label = parseStringContent(metadata.item.label);
|
|
699
|
-
}
|
|
700
|
-
if (metadata.item.abbreviation) {
|
|
701
|
-
abbreviation = parseStringContent(metadata.item.abbreviation);
|
|
702
|
-
}
|
|
703
|
-
identification = { label, abbreviation };
|
|
704
|
-
} else {
|
|
705
|
-
identification = parseIdentification(metadata.item.identification);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
let projectIdentification = null;
|
|
709
|
-
const baseProjectIdentification = metadata.project?.identification ? parseIdentification(metadata.project.identification) : null;
|
|
710
|
-
if (baseProjectIdentification) {
|
|
711
|
-
projectIdentification = {
|
|
712
|
-
...baseProjectIdentification,
|
|
713
|
-
website: metadata.project?.identification.website ?? null
|
|
714
|
-
};
|
|
715
|
-
}
|
|
716
|
-
return {
|
|
717
|
-
project: projectIdentification ? { identification: projectIdentification } : null,
|
|
718
|
-
item: metadata.item ? {
|
|
719
|
-
identification,
|
|
720
|
-
category: metadata.item.category,
|
|
721
|
-
type: metadata.item.type,
|
|
722
|
-
maxLength: metadata.item.maxLength ?? null
|
|
723
|
-
} : null,
|
|
724
|
-
dataset: parseStringContent(metadata.dataset),
|
|
725
|
-
publisher: parseStringContent(metadata.publisher),
|
|
726
|
-
languages: parseLanguages(metadata.language),
|
|
727
|
-
identifier: parseStringContent(metadata.identifier),
|
|
728
|
-
description: parseStringContent(metadata.description)
|
|
729
|
-
};
|
|
730
|
-
}
|
|
731
|
-
function parseContextItem(contextItem) {
|
|
732
|
-
return {
|
|
733
|
-
uuid: contextItem.uuid,
|
|
734
|
-
publicationDateTime: contextItem.publicationDateTime != null ? new Date(contextItem.publicationDateTime) : null,
|
|
735
|
-
number: contextItem.n,
|
|
736
|
-
content: parseFakeString(contextItem.content)
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
|
-
function parseContext(context) {
|
|
740
|
-
const contexts = Array.isArray(context.context) ? context.context : [context.context];
|
|
741
|
-
const returnContexts = {
|
|
742
|
-
nodes: contexts.map((context2) => {
|
|
743
|
-
const spatialUnit = [];
|
|
744
|
-
if ("spatialUnit" in context2 && context2.spatialUnit) {
|
|
745
|
-
const contextsToParse = Array.isArray(context2.spatialUnit) ? context2.spatialUnit : [context2.spatialUnit];
|
|
746
|
-
for (const contextItem of contextsToParse) {
|
|
747
|
-
spatialUnit.push(parseContextItem(contextItem));
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
return {
|
|
751
|
-
tree: parseContextItem(context2.tree),
|
|
752
|
-
project: parseContextItem(context2.project),
|
|
753
|
-
spatialUnit
|
|
754
|
-
};
|
|
755
|
-
}),
|
|
756
|
-
displayPath: context.displayPath
|
|
757
|
-
};
|
|
758
|
-
return returnContexts;
|
|
759
|
-
}
|
|
760
|
-
function parseLicense(license) {
|
|
761
|
-
if (typeof license.license === "string") {
|
|
762
|
-
return null;
|
|
763
|
-
}
|
|
764
|
-
return {
|
|
765
|
-
content: license.license.content,
|
|
766
|
-
url: license.license.target
|
|
767
|
-
};
|
|
768
|
-
}
|
|
769
|
-
function parsePerson(person) {
|
|
770
|
-
return {
|
|
771
|
-
uuid: person.uuid,
|
|
772
|
-
category: "person",
|
|
773
|
-
publicationDateTime: person.publicationDateTime != null ? new Date(person.publicationDateTime) : null,
|
|
774
|
-
type: person.type ?? null,
|
|
775
|
-
date: person.date != null ? new Date(person.date) : null,
|
|
776
|
-
identification: person.identification ? parseIdentification(person.identification) : null,
|
|
777
|
-
content: person.content != null ? parseFakeString(person.content) : null
|
|
778
|
-
};
|
|
779
|
-
}
|
|
780
|
-
function parsePersons(persons) {
|
|
781
|
-
const returnPersons = [];
|
|
782
|
-
for (const person of persons) {
|
|
783
|
-
returnPersons.push(parsePerson(person));
|
|
784
|
-
}
|
|
785
|
-
return returnPersons;
|
|
786
|
-
}
|
|
787
|
-
function parseLink(linkRaw) {
|
|
788
|
-
const links = "resource" in linkRaw ? linkRaw.resource : "spatialUnit" in linkRaw ? linkRaw.spatialUnit : "concept" in linkRaw ? linkRaw.concept : "set" in linkRaw ? linkRaw.set : "tree" in linkRaw ? linkRaw.tree : "person" in linkRaw ? linkRaw.person : "bibliography" in linkRaw ? linkRaw.bibliography : "epigraphicUnit" in linkRaw ? linkRaw.epigraphicUnit : "propertyValue" in linkRaw ? linkRaw.propertyValue : null;
|
|
789
|
-
if (!links) {
|
|
790
|
-
throw new Error(
|
|
791
|
-
`Invalid link provided: ${JSON.stringify(linkRaw, null, 2)}`
|
|
792
|
-
);
|
|
793
|
-
}
|
|
794
|
-
const linksToParse = Array.isArray(links) ? links : [links];
|
|
795
|
-
const returnLinks = [];
|
|
796
|
-
for (const link of linksToParse) {
|
|
797
|
-
const returnLink = {
|
|
798
|
-
category: "resource" in linkRaw ? "resource" : "spatialUnit" in linkRaw ? "spatialUnit" : "concept" in linkRaw ? "concept" : "set" in linkRaw ? "set" : "person" in linkRaw ? "person" : "tree" in linkRaw ? "tree" : "bibliography" in linkRaw ? "bibliography" : "epigraphicUnit" in linkRaw ? "epigraphicUnit" : "propertyValue" in linkRaw ? "propertyValue" : null,
|
|
799
|
-
content: "content" in link ? link.content != null ? parseFakeString(link.content) : null : null,
|
|
800
|
-
href: "href" in link && link.href != null ? link.href : null,
|
|
801
|
-
uuid: link.uuid,
|
|
802
|
-
type: link.type ?? null,
|
|
803
|
-
identification: link.identification ? parseIdentification(link.identification) : null,
|
|
804
|
-
image: null,
|
|
805
|
-
bibliographies: "bibliography" in linkRaw ? parseBibliographies(
|
|
806
|
-
Array.isArray(linkRaw.bibliography) ? linkRaw.bibliography : [linkRaw.bibliography]
|
|
807
|
-
) : null,
|
|
808
|
-
publicationDateTime: link.publicationDateTime != null ? new Date(link.publicationDateTime) : null
|
|
809
|
-
};
|
|
810
|
-
if ("height" in link && link.height != null && link.width != null && link.heightPreview != null && link.widthPreview != null) {
|
|
811
|
-
returnLink.image = {
|
|
812
|
-
isInline: link.rend === "inline",
|
|
813
|
-
isPrimary: link.isPrimary ?? false,
|
|
814
|
-
heightPreview: link.heightPreview,
|
|
815
|
-
widthPreview: link.widthPreview,
|
|
816
|
-
height: link.height,
|
|
817
|
-
width: link.width
|
|
818
|
-
};
|
|
819
|
-
}
|
|
820
|
-
returnLinks.push(returnLink);
|
|
821
|
-
}
|
|
822
|
-
return returnLinks;
|
|
823
|
-
}
|
|
824
|
-
function parseLinks(links) {
|
|
825
|
-
const returnLinks = [];
|
|
826
|
-
for (const link of links) {
|
|
827
|
-
returnLinks.push(...parseLink(link));
|
|
828
|
-
}
|
|
829
|
-
return returnLinks;
|
|
830
|
-
}
|
|
831
|
-
function parseDocument(document, language = "eng") {
|
|
832
|
-
let returnString = "";
|
|
833
|
-
const footnotes = [];
|
|
834
|
-
const documentWithLanguage = Array.isArray(document) ? document.find((doc) => doc.lang === language) : document;
|
|
835
|
-
if (typeof documentWithLanguage.string === "string" || typeof documentWithLanguage.string === "number" || typeof documentWithLanguage.string === "boolean") {
|
|
836
|
-
returnString += parseEmail(parseFakeString(documentWithLanguage.string));
|
|
837
|
-
} else {
|
|
838
|
-
const documentItems = Array.isArray(documentWithLanguage.string) ? documentWithLanguage.string : [documentWithLanguage.string];
|
|
839
|
-
for (const item of documentItems) {
|
|
840
|
-
returnString += parseStringDocumentItem(item, footnotes);
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
return { content: returnString, footnotes };
|
|
844
|
-
}
|
|
845
|
-
function parseImage(image) {
|
|
846
|
-
return {
|
|
847
|
-
publicationDateTime: image.publicationDateTime != null ? new Date(image.publicationDateTime) : null,
|
|
848
|
-
identification: image.identification ? parseIdentification(image.identification) : null,
|
|
849
|
-
url: image.href ?? (image.htmlImgSrcPrefix == null && image.content != null ? parseFakeString(image.content) : null),
|
|
850
|
-
htmlPrefix: image.htmlImgSrcPrefix ?? null,
|
|
851
|
-
content: image.htmlImgSrcPrefix != null && image.content != null ? parseFakeString(image.content) : null,
|
|
852
|
-
widthPreview: image.widthPreview ?? null,
|
|
853
|
-
heightPreview: image.heightPreview ?? null,
|
|
854
|
-
width: image.width ?? null,
|
|
855
|
-
height: image.height ?? null
|
|
856
|
-
};
|
|
857
|
-
}
|
|
858
|
-
function parseNotes(notes, language = "eng") {
|
|
859
|
-
const returnNotes = [];
|
|
860
|
-
for (const note of notes) {
|
|
861
|
-
if (typeof note === "string") {
|
|
862
|
-
if (note === "") {
|
|
863
|
-
continue;
|
|
864
|
-
}
|
|
865
|
-
returnNotes.push({
|
|
866
|
-
number: -1,
|
|
867
|
-
title: null,
|
|
868
|
-
content: note
|
|
869
|
-
});
|
|
870
|
-
continue;
|
|
871
|
-
}
|
|
872
|
-
let content = "";
|
|
873
|
-
const notesToParse = Array.isArray(note.content) ? note.content : [note.content];
|
|
874
|
-
let noteWithLanguage = notesToParse.find((item) => item.lang === language);
|
|
875
|
-
if (!noteWithLanguage) {
|
|
876
|
-
noteWithLanguage = notesToParse[0];
|
|
877
|
-
if (!noteWithLanguage) {
|
|
878
|
-
throw new Error(
|
|
879
|
-
`Note does not have a valid content item: ${JSON.stringify(
|
|
880
|
-
note,
|
|
881
|
-
null,
|
|
882
|
-
2
|
|
883
|
-
)}`
|
|
884
|
-
);
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
if (typeof noteWithLanguage.string === "string" || typeof noteWithLanguage.string === "number" || typeof noteWithLanguage.string === "boolean") {
|
|
888
|
-
content = parseEmail(parseFakeString(noteWithLanguage.string));
|
|
889
|
-
} else {
|
|
890
|
-
content = parseEmail(parseDocument(noteWithLanguage).content);
|
|
891
|
-
}
|
|
892
|
-
returnNotes.push({
|
|
893
|
-
number: note.noteNo,
|
|
894
|
-
title: noteWithLanguage.title != null ? parseFakeString(noteWithLanguage.title) : null,
|
|
895
|
-
content
|
|
896
|
-
});
|
|
897
|
-
}
|
|
898
|
-
return returnNotes;
|
|
899
|
-
}
|
|
900
|
-
function parseCoordinates(coordinates) {
|
|
901
|
-
return {
|
|
902
|
-
latitude: coordinates.latitude,
|
|
903
|
-
longitude: coordinates.longitude,
|
|
904
|
-
type: coordinates.coord?.coordType ?? null,
|
|
905
|
-
label: coordinates.coord?.coordLabel != null ? parseFakeString(coordinates.coord.coordLabel) : null
|
|
906
|
-
};
|
|
907
|
-
}
|
|
908
|
-
function parseObservation(observation) {
|
|
909
|
-
return {
|
|
910
|
-
number: observation.observationNo,
|
|
911
|
-
date: observation.date != null ? new Date(observation.date) : null,
|
|
912
|
-
observers: observation.observers != null ? parseFakeString(observation.observers).split(";").map((observer) => observer.trim()) : [],
|
|
913
|
-
notes: observation.notes ? parseNotes(
|
|
914
|
-
Array.isArray(observation.notes.note) ? observation.notes.note : [observation.notes.note]
|
|
915
|
-
) : [],
|
|
916
|
-
links: observation.links ? parseLinks(
|
|
917
|
-
Array.isArray(observation.links) ? observation.links : [observation.links]
|
|
918
|
-
) : [],
|
|
919
|
-
properties: observation.properties ? parseProperties(
|
|
920
|
-
Array.isArray(observation.properties.property) ? observation.properties.property : [observation.properties.property]
|
|
921
|
-
) : []
|
|
922
|
-
};
|
|
923
|
-
}
|
|
924
|
-
function parseObservations(observations) {
|
|
925
|
-
const returnObservations = [];
|
|
926
|
-
for (const observation of observations) {
|
|
927
|
-
returnObservations.push(parseObservation(observation));
|
|
928
|
-
}
|
|
929
|
-
return returnObservations;
|
|
930
|
-
}
|
|
931
|
-
function parseEvents(events) {
|
|
932
|
-
const returnEvents = [];
|
|
933
|
-
for (const event of events) {
|
|
934
|
-
returnEvents.push({
|
|
935
|
-
date: event.dateTime != null ? new Date(event.dateTime) : null,
|
|
936
|
-
label: parseStringContent(event.label),
|
|
937
|
-
agent: event.agent ? {
|
|
938
|
-
uuid: event.agent.uuid,
|
|
939
|
-
content: parseFakeString(event.agent.content)
|
|
940
|
-
} : null
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
|
-
return returnEvents;
|
|
944
|
-
}
|
|
945
|
-
function parseProperty(property, type, language = "eng") {
|
|
946
|
-
const valuesToParse = "value" in property && property.value ? Array.isArray(property.value) ? property.value : [property.value] : [];
|
|
947
|
-
const values = valuesToParse.map((value) => {
|
|
948
|
-
let content = null;
|
|
949
|
-
let booleanValue = null;
|
|
950
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
951
|
-
content = parseFakeString(value);
|
|
952
|
-
const returnValue = {
|
|
953
|
-
content,
|
|
954
|
-
booleanValue,
|
|
955
|
-
type,
|
|
956
|
-
category: "value",
|
|
957
|
-
uuid: null,
|
|
958
|
-
publicationDateTime: null
|
|
959
|
-
};
|
|
960
|
-
return returnValue;
|
|
961
|
-
} else {
|
|
962
|
-
switch (type) {
|
|
963
|
-
case "integer":
|
|
964
|
-
case "decimal": {
|
|
965
|
-
content = Number(value.content);
|
|
966
|
-
break;
|
|
967
|
-
}
|
|
968
|
-
case "dateTime": {
|
|
969
|
-
content = value.content ? typeof value.content === "string" ? new Date(value.content) : new Date(parseStringContent({ content: value.content })) : null;
|
|
970
|
-
break;
|
|
971
|
-
}
|
|
972
|
-
default: {
|
|
973
|
-
if ("slug" in value && value.slug != null) {
|
|
974
|
-
content = parseFakeString(value.slug);
|
|
975
|
-
} else if (value.content != null) {
|
|
976
|
-
content = parseStringContent({ content: value.content });
|
|
977
|
-
}
|
|
978
|
-
if (type === "boolean") {
|
|
979
|
-
booleanValue = value.booleanValue ?? null;
|
|
980
|
-
}
|
|
981
|
-
break;
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
const returnValue = {
|
|
985
|
-
content,
|
|
986
|
-
booleanValue,
|
|
987
|
-
type,
|
|
988
|
-
category: value.category ?? "value",
|
|
989
|
-
uuid: value.uuid ?? null,
|
|
990
|
-
publicationDateTime: value.publicationDateTime != null ? new Date(value.publicationDateTime) : null
|
|
991
|
-
};
|
|
992
|
-
return returnValue;
|
|
993
|
-
}
|
|
994
|
-
});
|
|
995
|
-
return {
|
|
996
|
-
label: parseStringContent(property.label, language).replace(/\s*\.{3}$/, "").trim(),
|
|
997
|
-
values,
|
|
998
|
-
comment: property.comment != null ? parseFakeString(property.comment) : null,
|
|
999
|
-
properties: property.property ? parseProperties(
|
|
1000
|
-
Array.isArray(property.property) ? property.property : [property.property]
|
|
1001
|
-
) : []
|
|
1002
|
-
};
|
|
1003
|
-
}
|
|
1004
|
-
function parseProperties(properties, language = "eng") {
|
|
1005
|
-
const returnProperties = [];
|
|
1006
|
-
for (const property of properties) {
|
|
1007
|
-
returnProperties.push(
|
|
1008
|
-
parseProperty(property, "string", language)
|
|
1009
|
-
);
|
|
1010
|
-
}
|
|
1011
|
-
return returnProperties;
|
|
1012
|
-
}
|
|
1013
|
-
function parseInterpretations(interpretations) {
|
|
1014
|
-
const returnInterpretations = [];
|
|
1015
|
-
for (const interpretation of interpretations) {
|
|
1016
|
-
returnInterpretations.push({
|
|
1017
|
-
date: new Date(interpretation.date),
|
|
1018
|
-
number: interpretation.interpretationNo,
|
|
1019
|
-
properties: interpretation.properties ? parseProperties(
|
|
1020
|
-
Array.isArray(interpretation.properties.property) ? interpretation.properties.property : [interpretation.properties.property]
|
|
1021
|
-
) : []
|
|
1022
|
-
});
|
|
1023
|
-
}
|
|
1024
|
-
return returnInterpretations;
|
|
1025
|
-
}
|
|
1026
|
-
function parseImageMap(imageMap) {
|
|
1027
|
-
const returnImageMap = {
|
|
1028
|
-
area: [],
|
|
1029
|
-
width: imageMap.width,
|
|
1030
|
-
height: imageMap.height
|
|
1031
|
-
};
|
|
1032
|
-
const imageMapAreasToParse = Array.isArray(imageMap.area) ? imageMap.area : [imageMap.area];
|
|
1033
|
-
for (const area of imageMapAreasToParse) {
|
|
1034
|
-
returnImageMap.area.push({
|
|
1035
|
-
uuid: area.uuid,
|
|
1036
|
-
publicationDateTime: area.publicationDateTime != null ? new Date(area.publicationDateTime) : null,
|
|
1037
|
-
type: area.type,
|
|
1038
|
-
title: parseFakeString(area.title),
|
|
1039
|
-
shape: area.shape === "rect" ? "rectangle" : "polygon",
|
|
1040
|
-
coords: area.coords.split(",").map((coord) => Number.parseInt(coord))
|
|
1041
|
-
});
|
|
1042
|
-
}
|
|
1043
|
-
return returnImageMap;
|
|
1044
|
-
}
|
|
1045
|
-
function parsePeriod(period) {
|
|
1046
|
-
return {
|
|
1047
|
-
uuid: period.uuid,
|
|
1048
|
-
category: "period",
|
|
1049
|
-
publicationDateTime: period.publicationDateTime != null ? new Date(period.publicationDateTime) : null,
|
|
1050
|
-
type: period.type ?? null,
|
|
1051
|
-
number: period.n ?? null,
|
|
1052
|
-
identification: parseIdentification(period.identification),
|
|
1053
|
-
description: period.description ? parseStringContent(period.description) : null
|
|
1054
|
-
};
|
|
1055
|
-
}
|
|
1056
|
-
function parsePeriods(periods) {
|
|
1057
|
-
const returnPeriods = [];
|
|
1058
|
-
for (const period of periods) {
|
|
1059
|
-
returnPeriods.push(parsePeriod(period));
|
|
1060
|
-
}
|
|
1061
|
-
return returnPeriods;
|
|
1062
|
-
}
|
|
1063
|
-
function parseBibliography(bibliography) {
|
|
1064
|
-
let resource = null;
|
|
1065
|
-
if (bibliography.source?.resource) {
|
|
1066
|
-
resource = {
|
|
1067
|
-
uuid: bibliography.source.resource.uuid,
|
|
1068
|
-
publicationDateTime: bibliography.source.resource.publicationDateTime ? new Date(bibliography.source.resource.publicationDateTime) : null,
|
|
1069
|
-
type: bibliography.source.resource.type,
|
|
1070
|
-
identification: parseIdentification(
|
|
1071
|
-
bibliography.source.resource.identification
|
|
1072
|
-
)
|
|
1073
|
-
};
|
|
1074
|
-
}
|
|
1075
|
-
return {
|
|
1076
|
-
uuid: bibliography.uuid,
|
|
1077
|
-
category: "bibliography",
|
|
1078
|
-
publicationDateTime: bibliography.publicationDateTime != null ? new Date(bibliography.publicationDateTime) : null,
|
|
1079
|
-
type: bibliography.type ?? null,
|
|
1080
|
-
number: bibliography.n ?? null,
|
|
1081
|
-
identification: bibliography.identification ? parseIdentification(bibliography.identification) : null,
|
|
1082
|
-
projectIdentification: bibliography.project?.identification ? parseIdentification(bibliography.project.identification) : null,
|
|
1083
|
-
context: bibliography.context ? parseContext(bibliography.context) : null,
|
|
1084
|
-
citation: {
|
|
1085
|
-
format: bibliography.citationFormat ?? null,
|
|
1086
|
-
short: bibliography.citationFormatSpan ? parseFakeString(
|
|
1087
|
-
"default:span" in bibliography.citationFormatSpan ? bibliography.citationFormatSpan["default:span"].content : bibliography.citationFormatSpan.span.content
|
|
1088
|
-
) : null,
|
|
1089
|
-
long: bibliography.referenceFormatDiv ? parseFakeString(
|
|
1090
|
-
"default:div" in bibliography.referenceFormatDiv ? bibliography.referenceFormatDiv["default:div"]["default:div"].content : bibliography.referenceFormatDiv.div.div.content
|
|
1091
|
-
) : null
|
|
1092
|
-
},
|
|
1093
|
-
publicationInfo: {
|
|
1094
|
-
publishers: bibliography.publicationInfo?.publishers ? parsePersons(
|
|
1095
|
-
Array.isArray(
|
|
1096
|
-
bibliography.publicationInfo.publishers.publishers.person
|
|
1097
|
-
) ? bibliography.publicationInfo.publishers.publishers.person : [bibliography.publicationInfo.publishers.publishers.person]
|
|
1098
|
-
) : [],
|
|
1099
|
-
startDate: bibliography.publicationInfo?.startDate ? new Date(
|
|
1100
|
-
bibliography.publicationInfo.startDate.year,
|
|
1101
|
-
bibliography.publicationInfo.startDate.month,
|
|
1102
|
-
bibliography.publicationInfo.startDate.day
|
|
1103
|
-
) : null
|
|
1104
|
-
},
|
|
1105
|
-
entryInfo: bibliography.entryInfo ? {
|
|
1106
|
-
startIssue: parseFakeString(bibliography.entryInfo.startIssue),
|
|
1107
|
-
startVolume: parseFakeString(bibliography.entryInfo.startVolume)
|
|
1108
|
-
} : null,
|
|
1109
|
-
source: {
|
|
1110
|
-
resource,
|
|
1111
|
-
documentUrl: bibliography.sourceDocument ? `https://ochre.lib.uchicago.edu/ochre?uuid=${bibliography.sourceDocument.uuid}&load` : null
|
|
1112
|
-
},
|
|
1113
|
-
periods: bibliography.periods ? parsePeriods(
|
|
1114
|
-
Array.isArray(bibliography.periods.period) ? bibliography.periods.period : [bibliography.periods.period]
|
|
1115
|
-
) : [],
|
|
1116
|
-
authors: bibliography.authors ? parsePersons(
|
|
1117
|
-
Array.isArray(bibliography.authors.person) ? bibliography.authors.person : [bibliography.authors.person]
|
|
1118
|
-
) : [],
|
|
1119
|
-
properties: bibliography.properties ? parseProperties(
|
|
1120
|
-
Array.isArray(bibliography.properties.property) ? bibliography.properties.property : [bibliography.properties.property]
|
|
1121
|
-
) : []
|
|
1122
|
-
};
|
|
1123
|
-
}
|
|
1124
|
-
function parseBibliographies(bibliographies) {
|
|
1125
|
-
const returnBibliographies = [];
|
|
1126
|
-
for (const bibliography of bibliographies) {
|
|
1127
|
-
returnBibliographies.push(parseBibliography(bibliography));
|
|
1128
|
-
}
|
|
1129
|
-
return returnBibliographies;
|
|
1130
|
-
}
|
|
1131
|
-
function parsePropertyValue(propertyValue) {
|
|
1132
|
-
return {
|
|
1133
|
-
uuid: propertyValue.uuid,
|
|
1134
|
-
category: "propertyValue",
|
|
1135
|
-
n: propertyValue.n,
|
|
1136
|
-
publicationDateTime: propertyValue.publicationDateTime ? new Date(propertyValue.publicationDateTime) : null,
|
|
1137
|
-
context: propertyValue.context ? parseContext(propertyValue.context) : null,
|
|
1138
|
-
availability: propertyValue.availability ? parseLicense(propertyValue.availability) : null,
|
|
1139
|
-
identification: parseIdentification(propertyValue.identification),
|
|
1140
|
-
date: propertyValue.date ? new Date(propertyValue.date) : null,
|
|
1141
|
-
creators: propertyValue.creators ? parsePersons(
|
|
1142
|
-
Array.isArray(propertyValue.creators.creator) ? propertyValue.creators.creator : [propertyValue.creators.creator]
|
|
1143
|
-
) : [],
|
|
1144
|
-
description: propertyValue.description ? ["string", "number", "boolean"].includes(
|
|
1145
|
-
typeof propertyValue.description
|
|
1146
|
-
) ? parseFakeString(propertyValue.description) : parseStringContent(propertyValue.description) : "",
|
|
1147
|
-
notes: propertyValue.notes ? parseNotes(
|
|
1148
|
-
Array.isArray(propertyValue.notes.note) ? propertyValue.notes.note : [propertyValue.notes.note]
|
|
1149
|
-
) : [],
|
|
1150
|
-
links: propertyValue.links ? parseLinks(
|
|
1151
|
-
Array.isArray(propertyValue.links) ? propertyValue.links : [propertyValue.links]
|
|
1152
|
-
) : []
|
|
1153
|
-
};
|
|
1154
|
-
}
|
|
1155
|
-
function parsePropertyValues(propertyValues) {
|
|
1156
|
-
const returnPropertyValues = [];
|
|
1157
|
-
for (const propertyValue of propertyValues) {
|
|
1158
|
-
returnPropertyValues.push(parsePropertyValue(propertyValue));
|
|
1159
|
-
}
|
|
1160
|
-
return returnPropertyValues;
|
|
1161
|
-
}
|
|
1162
|
-
function parseTree(tree) {
|
|
1163
|
-
let creators = [];
|
|
1164
|
-
if (tree.creators) {
|
|
1165
|
-
creators = parsePersons(
|
|
1166
|
-
Array.isArray(tree.creators.creator) ? tree.creators.creator : [tree.creators.creator]
|
|
1167
|
-
);
|
|
1168
|
-
}
|
|
1169
|
-
let date = null;
|
|
1170
|
-
if (tree.date != null) {
|
|
1171
|
-
date = new Date(tree.date);
|
|
1172
|
-
}
|
|
1173
|
-
let resources = [];
|
|
1174
|
-
let spatialUnits = [];
|
|
1175
|
-
let concepts = [];
|
|
1176
|
-
let periods = [];
|
|
1177
|
-
let bibliographies = [];
|
|
1178
|
-
let persons = [];
|
|
1179
|
-
let propertyValues = [];
|
|
1180
|
-
if (typeof tree.items !== "string" && "resource" in tree.items) {
|
|
1181
|
-
resources = parseResources(
|
|
1182
|
-
Array.isArray(tree.items.resource) ? tree.items.resource : [tree.items.resource]
|
|
1183
|
-
);
|
|
1184
|
-
}
|
|
1185
|
-
if (typeof tree.items !== "string" && "spatialUnit" in tree.items) {
|
|
1186
|
-
spatialUnits = parseSpatialUnits(
|
|
1187
|
-
Array.isArray(tree.items.spatialUnit) ? tree.items.spatialUnit : [tree.items.spatialUnit]
|
|
1188
|
-
);
|
|
1189
|
-
}
|
|
1190
|
-
if (typeof tree.items !== "string" && "concept" in tree.items) {
|
|
1191
|
-
concepts = parseConcepts(
|
|
1192
|
-
Array.isArray(tree.items.concept) ? tree.items.concept : [tree.items.concept]
|
|
1193
|
-
);
|
|
1194
|
-
}
|
|
1195
|
-
if (typeof tree.items !== "string" && "period" in tree.items) {
|
|
1196
|
-
periods = parsePeriods(
|
|
1197
|
-
Array.isArray(tree.items.period) ? tree.items.period : [tree.items.period]
|
|
1198
|
-
);
|
|
1199
|
-
}
|
|
1200
|
-
if (typeof tree.items !== "string" && "bibliography" in tree.items) {
|
|
1201
|
-
bibliographies = parseBibliographies(
|
|
1202
|
-
Array.isArray(tree.items.bibliography) ? tree.items.bibliography : [tree.items.bibliography]
|
|
1203
|
-
);
|
|
1204
|
-
}
|
|
1205
|
-
if (typeof tree.items !== "string" && "person" in tree.items) {
|
|
1206
|
-
persons = parsePersons(
|
|
1207
|
-
Array.isArray(tree.items.person) ? tree.items.person : [tree.items.person]
|
|
1208
|
-
);
|
|
1209
|
-
}
|
|
1210
|
-
if (typeof tree.items !== "string" && "propertyValue" in tree.items) {
|
|
1211
|
-
propertyValues = parsePropertyValues(
|
|
1212
|
-
Array.isArray(tree.items.propertyValue) ? tree.items.propertyValue : [tree.items.propertyValue]
|
|
1213
|
-
);
|
|
1214
|
-
}
|
|
1215
|
-
const returnTree = {
|
|
1216
|
-
uuid: tree.uuid,
|
|
1217
|
-
category: "tree",
|
|
1218
|
-
publicationDateTime: new Date(tree.publicationDateTime),
|
|
1219
|
-
identification: parseIdentification(tree.identification),
|
|
1220
|
-
creators,
|
|
1221
|
-
license: parseLicense(tree.availability),
|
|
1222
|
-
date,
|
|
1223
|
-
type: tree.type,
|
|
1224
|
-
number: tree.n,
|
|
1225
|
-
items: {
|
|
1226
|
-
resources,
|
|
1227
|
-
spatialUnits,
|
|
1228
|
-
concepts,
|
|
1229
|
-
periods,
|
|
1230
|
-
bibliographies,
|
|
1231
|
-
persons,
|
|
1232
|
-
propertyValues
|
|
1233
|
-
},
|
|
1234
|
-
properties: tree.properties ? parseProperties(
|
|
1235
|
-
Array.isArray(tree.properties.property) ? tree.properties.property : [tree.properties.property]
|
|
1236
|
-
) : []
|
|
1237
|
-
};
|
|
1238
|
-
return returnTree;
|
|
1239
|
-
}
|
|
1240
|
-
function parseSet(set) {
|
|
1241
|
-
if (typeof set.items === "string") {
|
|
1242
|
-
throw new TypeError("Invalid OCHRE data: Set has no items");
|
|
1243
|
-
}
|
|
1244
|
-
const itemCategory = getItemCategory(Object.keys(set.items));
|
|
1245
|
-
let items = [];
|
|
1246
|
-
switch (itemCategory) {
|
|
1247
|
-
case "resource": {
|
|
1248
|
-
if (!("resource" in set.items)) {
|
|
1249
|
-
throw new Error("Invalid OCHRE data: Set has no resources");
|
|
1250
|
-
}
|
|
1251
|
-
items = parseResources(
|
|
1252
|
-
Array.isArray(set.items.resource) ? set.items.resource : [set.items.resource]
|
|
1253
|
-
);
|
|
1254
|
-
break;
|
|
1255
|
-
}
|
|
1256
|
-
case "spatialUnit": {
|
|
1257
|
-
if (!("spatialUnit" in set.items)) {
|
|
1258
|
-
throw new Error("Invalid OCHRE data: Set has no spatial units");
|
|
1259
|
-
}
|
|
1260
|
-
items = parseSpatialUnits(
|
|
1261
|
-
Array.isArray(set.items.spatialUnit) ? set.items.spatialUnit : [set.items.spatialUnit]
|
|
1262
|
-
);
|
|
1263
|
-
break;
|
|
1264
|
-
}
|
|
1265
|
-
case "concept": {
|
|
1266
|
-
if (!("concept" in set.items)) {
|
|
1267
|
-
throw new Error("Invalid OCHRE data: Set has no concepts");
|
|
1268
|
-
}
|
|
1269
|
-
items = parseConcepts(
|
|
1270
|
-
Array.isArray(set.items.concept) ? set.items.concept : [set.items.concept]
|
|
1271
|
-
);
|
|
1272
|
-
break;
|
|
1273
|
-
}
|
|
1274
|
-
case "period": {
|
|
1275
|
-
if (!("period" in set.items)) {
|
|
1276
|
-
throw new Error("Invalid OCHRE data: Set has no periods");
|
|
1277
|
-
}
|
|
1278
|
-
items = parsePeriods(
|
|
1279
|
-
Array.isArray(set.items.period) ? set.items.period : [set.items.period]
|
|
1280
|
-
);
|
|
1281
|
-
break;
|
|
1282
|
-
}
|
|
1283
|
-
case "bibliography": {
|
|
1284
|
-
if (!("bibliography" in set.items)) {
|
|
1285
|
-
throw new Error("Invalid OCHRE data: Set has no bibliographies");
|
|
1286
|
-
}
|
|
1287
|
-
items = parseBibliographies(
|
|
1288
|
-
Array.isArray(set.items.bibliography) ? set.items.bibliography : [set.items.bibliography]
|
|
1289
|
-
);
|
|
1290
|
-
break;
|
|
1291
|
-
}
|
|
1292
|
-
case "person": {
|
|
1293
|
-
if (!("person" in set.items)) {
|
|
1294
|
-
throw new Error("Invalid OCHRE data: Set has no persons");
|
|
1295
|
-
}
|
|
1296
|
-
items = parsePersons(
|
|
1297
|
-
Array.isArray(set.items.person) ? set.items.person : [set.items.person]
|
|
1298
|
-
);
|
|
1299
|
-
break;
|
|
1300
|
-
}
|
|
1301
|
-
case "propertyValue": {
|
|
1302
|
-
if (!("propertyValue" in set.items)) {
|
|
1303
|
-
throw new Error("Invalid OCHRE data: Set has no property values");
|
|
1304
|
-
}
|
|
1305
|
-
items = parsePropertyValues(
|
|
1306
|
-
Array.isArray(set.items.propertyValue) ? set.items.propertyValue : [set.items.propertyValue]
|
|
1307
|
-
);
|
|
1308
|
-
break;
|
|
1309
|
-
}
|
|
1310
|
-
default: {
|
|
1311
|
-
throw new Error("Invalid OCHRE data: Set has no items or is malformed");
|
|
1312
|
-
}
|
|
1313
|
-
}
|
|
1314
|
-
return {
|
|
1315
|
-
uuid: set.uuid,
|
|
1316
|
-
category: "set",
|
|
1317
|
-
itemCategory,
|
|
1318
|
-
publicationDateTime: set.publicationDateTime ? new Date(set.publicationDateTime) : null,
|
|
1319
|
-
date: set.date != null ? new Date(set.date) : null,
|
|
1320
|
-
license: parseLicense(set.availability),
|
|
1321
|
-
identification: parseIdentification(set.identification),
|
|
1322
|
-
isSuppressingBlanks: set.suppressBlanks ?? false,
|
|
1323
|
-
description: set.description ? ["string", "number", "boolean"].includes(typeof set.description) ? parseFakeString(set.description) : parseStringContent(set.description) : "",
|
|
1324
|
-
creators: set.creators ? parsePersons(
|
|
1325
|
-
Array.isArray(set.creators.creator) ? set.creators.creator : [set.creators.creator]
|
|
1326
|
-
) : [],
|
|
1327
|
-
type: set.type,
|
|
1328
|
-
number: set.n,
|
|
1329
|
-
items
|
|
1330
|
-
};
|
|
1331
|
-
}
|
|
1332
|
-
function parseResource(resource) {
|
|
1333
|
-
const returnResource = {
|
|
1334
|
-
uuid: resource.uuid,
|
|
1335
|
-
category: "resource",
|
|
1336
|
-
publicationDateTime: resource.publicationDateTime ? new Date(resource.publicationDateTime) : null,
|
|
1337
|
-
type: resource.type,
|
|
1338
|
-
number: resource.n,
|
|
1339
|
-
format: resource.format ?? null,
|
|
1340
|
-
context: "context" in resource && resource.context ? parseContext(resource.context) : null,
|
|
1341
|
-
license: "availability" in resource && resource.availability ? parseLicense(resource.availability) : null,
|
|
1342
|
-
copyright: "copyright" in resource && resource.copyright != null ? parseFakeString(resource.copyright) : null,
|
|
1343
|
-
identification: parseIdentification(resource.identification),
|
|
1344
|
-
date: resource.date != null ? new Date(resource.date) : null,
|
|
1345
|
-
image: resource.image ? parseImage(resource.image) : null,
|
|
1346
|
-
creators: resource.creators ? parsePersons(
|
|
1347
|
-
Array.isArray(resource.creators.creator) ? resource.creators.creator : [resource.creators.creator]
|
|
1348
|
-
) : [],
|
|
1349
|
-
notes: resource.notes ? parseNotes(
|
|
1350
|
-
Array.isArray(resource.notes.note) ? resource.notes.note : [resource.notes.note]
|
|
1351
|
-
) : [],
|
|
1352
|
-
description: resource.description ? ["string", "number", "boolean"].includes(typeof resource.description) ? parseFakeString(resource.description) : parseStringContent(resource.description) : "",
|
|
1353
|
-
document: resource.document && "content" in resource.document ? parseDocument(resource.document.content) : null,
|
|
1354
|
-
href: resource.href ?? null,
|
|
1355
|
-
imageMap: resource.imagemap ? parseImageMap(resource.imagemap) : null,
|
|
1356
|
-
periods: resource.periods ? parsePeriods(
|
|
1357
|
-
Array.isArray(resource.periods.period) ? resource.periods.period : [resource.periods.period]
|
|
1358
|
-
) : [],
|
|
1359
|
-
links: resource.links ? parseLinks(
|
|
1360
|
-
Array.isArray(resource.links) ? resource.links : [resource.links]
|
|
1361
|
-
) : [],
|
|
1362
|
-
reverseLinks: resource.reverseLinks ? parseLinks(
|
|
1363
|
-
Array.isArray(resource.reverseLinks) ? resource.reverseLinks : [resource.reverseLinks]
|
|
1364
|
-
) : [],
|
|
1365
|
-
properties: resource.properties ? parseProperties(
|
|
1366
|
-
Array.isArray(resource.properties.property) ? resource.properties.property : [resource.properties.property]
|
|
1367
|
-
) : [],
|
|
1368
|
-
citedBibliographies: resource.citedBibliography ? parseBibliographies(
|
|
1369
|
-
Array.isArray(resource.citedBibliography.reference) ? resource.citedBibliography.reference : [resource.citedBibliography.reference]
|
|
1370
|
-
) : [],
|
|
1371
|
-
resources: resource.resource ? parseResources(
|
|
1372
|
-
Array.isArray(resource.resource) ? resource.resource : [resource.resource]
|
|
1373
|
-
) : []
|
|
1374
|
-
};
|
|
1375
|
-
return returnResource;
|
|
1376
|
-
}
|
|
1377
|
-
function parseResources(resources) {
|
|
1378
|
-
const returnResources = [];
|
|
1379
|
-
const resourcesToParse = Array.isArray(resources) ? resources : [resources];
|
|
1380
|
-
for (const resource of resourcesToParse) {
|
|
1381
|
-
returnResources.push(parseResource(resource));
|
|
1382
|
-
}
|
|
1383
|
-
return returnResources;
|
|
1384
|
-
}
|
|
1385
|
-
function parseSpatialUnit(spatialUnit) {
|
|
1386
|
-
const returnSpatialUnit = {
|
|
1387
|
-
uuid: spatialUnit.uuid,
|
|
1388
|
-
category: "spatialUnit",
|
|
1389
|
-
publicationDateTime: spatialUnit.publicationDateTime != null ? new Date(spatialUnit.publicationDateTime) : null,
|
|
1390
|
-
type: spatialUnit.type,
|
|
1391
|
-
number: spatialUnit.n,
|
|
1392
|
-
context: "context" in spatialUnit && spatialUnit.context ? parseContext(spatialUnit.context) : null,
|
|
1393
|
-
license: "availability" in spatialUnit && spatialUnit.availability ? parseLicense(spatialUnit.availability) : null,
|
|
1394
|
-
identification: parseIdentification(spatialUnit.identification),
|
|
1395
|
-
image: spatialUnit.image ? parseImage(spatialUnit.image) : null,
|
|
1396
|
-
description: spatialUnit.description ? ["string", "number", "boolean"].includes(
|
|
1397
|
-
typeof spatialUnit.description
|
|
1398
|
-
) ? parseFakeString(spatialUnit.description) : parseStringContent(spatialUnit.description) : "",
|
|
1399
|
-
coordinates: spatialUnit.coordinates ? parseCoordinates(spatialUnit.coordinates) : null,
|
|
1400
|
-
observations: "observations" in spatialUnit && spatialUnit.observations ? parseObservations(
|
|
1401
|
-
Array.isArray(spatialUnit.observations.observation) ? spatialUnit.observations.observation : [spatialUnit.observations.observation]
|
|
1402
|
-
) : spatialUnit.observation ? [parseObservation(spatialUnit.observation)] : [],
|
|
1403
|
-
events: "events" in spatialUnit && spatialUnit.events ? parseEvents(
|
|
1404
|
-
Array.isArray(spatialUnit.events.event) ? spatialUnit.events.event : [spatialUnit.events.event]
|
|
1405
|
-
) : [],
|
|
1406
|
-
properties: "properties" in spatialUnit && spatialUnit.properties ? parseProperties(
|
|
1407
|
-
Array.isArray(spatialUnit.properties.property) ? spatialUnit.properties.property : [spatialUnit.properties.property]
|
|
1408
|
-
) : []
|
|
1409
|
-
};
|
|
1410
|
-
return returnSpatialUnit;
|
|
1411
|
-
}
|
|
1412
|
-
function parseSpatialUnits(spatialUnits) {
|
|
1413
|
-
const returnSpatialUnits = [];
|
|
1414
|
-
const spatialUnitsToParse = Array.isArray(spatialUnits) ? spatialUnits : [spatialUnits];
|
|
1415
|
-
for (const spatialUnit of spatialUnitsToParse) {
|
|
1416
|
-
returnSpatialUnits.push(parseSpatialUnit(spatialUnit));
|
|
1417
|
-
}
|
|
1418
|
-
return returnSpatialUnits;
|
|
1419
|
-
}
|
|
1420
|
-
function parseConcept(concept) {
|
|
1421
|
-
const returnConcept = {
|
|
1422
|
-
uuid: concept.uuid,
|
|
1423
|
-
category: "concept",
|
|
1424
|
-
publicationDateTime: concept.publicationDateTime ? new Date(concept.publicationDateTime) : null,
|
|
1425
|
-
number: concept.n,
|
|
1426
|
-
license: "availability" in concept && concept.availability ? parseLicense(concept.availability) : null,
|
|
1427
|
-
context: "context" in concept && concept.context ? parseContext(concept.context) : null,
|
|
1428
|
-
identification: parseIdentification(concept.identification),
|
|
1429
|
-
interpretations: parseInterpretations(
|
|
1430
|
-
Array.isArray(concept.interpretations.interpretation) ? concept.interpretations.interpretation : [concept.interpretations.interpretation]
|
|
1431
|
-
)
|
|
1432
|
-
};
|
|
1433
|
-
return returnConcept;
|
|
1434
|
-
}
|
|
1435
|
-
var parseWebpageResources = async (webpageResources, type) => {
|
|
1436
|
-
const returnElements = [];
|
|
1437
|
-
for (const resource of webpageResources) {
|
|
1438
|
-
const resourceProperties = resource.properties ? parseProperties(
|
|
1439
|
-
Array.isArray(resource.properties.property) ? resource.properties.property : [resource.properties.property]
|
|
1440
|
-
) : [];
|
|
1441
|
-
const resourceProperty = resourceProperties.find(
|
|
1442
|
-
(property) => property.label === "presentation" && property.values[0].content === type
|
|
1443
|
-
);
|
|
1444
|
-
if (!resourceProperty) continue;
|
|
1445
|
-
switch (type) {
|
|
1446
|
-
case "element": {
|
|
1447
|
-
const element = await parseWebElement(resource);
|
|
1448
|
-
returnElements.push(
|
|
1449
|
-
element
|
|
1450
|
-
);
|
|
1451
|
-
break;
|
|
1452
|
-
}
|
|
1453
|
-
case "page": {
|
|
1454
|
-
const webpage = await parseWebpage(resource);
|
|
1455
|
-
if (webpage) {
|
|
1456
|
-
returnElements.push(
|
|
1457
|
-
webpage
|
|
1458
|
-
);
|
|
1459
|
-
}
|
|
1460
|
-
break;
|
|
1461
|
-
}
|
|
1462
|
-
case "block": {
|
|
1463
|
-
const block = await parseBlock(resource);
|
|
1464
|
-
if (block) {
|
|
1465
|
-
returnElements.push(
|
|
1466
|
-
block
|
|
1467
|
-
);
|
|
1468
|
-
}
|
|
1469
|
-
break;
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
|
-
return returnElements;
|
|
1474
|
-
};
|
|
1475
|
-
function parseConcepts(concepts) {
|
|
1476
|
-
const returnConcepts = [];
|
|
1477
|
-
const conceptsToParse = Array.isArray(concepts) ? concepts : [concepts];
|
|
1478
|
-
for (const concept of conceptsToParse) {
|
|
1479
|
-
returnConcepts.push(parseConcept(concept));
|
|
1480
|
-
}
|
|
1481
|
-
return returnConcepts;
|
|
1482
|
-
}
|
|
1483
|
-
async function parseWebElementProperties(componentProperty, elementResource) {
|
|
1484
|
-
const componentName = componentSchema.parse(
|
|
1485
|
-
componentProperty.values[0].content
|
|
1486
|
-
);
|
|
1487
|
-
const properties = {
|
|
1488
|
-
component: componentName
|
|
1489
|
-
};
|
|
1490
|
-
const links = elementResource.links ? parseLinks(
|
|
1491
|
-
Array.isArray(elementResource.links) ? elementResource.links : [elementResource.links]
|
|
1492
|
-
) : [];
|
|
1493
|
-
const imageLinks = links.filter(
|
|
1494
|
-
(link) => link.type === "image" || link.type === "IIIF"
|
|
1495
|
-
);
|
|
1496
|
-
let document = elementResource.document && "content" in elementResource.document ? parseDocument(elementResource.document.content) : null;
|
|
1497
|
-
if (document === null) {
|
|
1498
|
-
const documentLink = links.find((link) => link.type === "internalDocument");
|
|
1499
|
-
if (documentLink) {
|
|
1500
|
-
const { item, error } = await fetchItem(documentLink.uuid, "resource");
|
|
1501
|
-
if (error !== null) {
|
|
1502
|
-
throw new Error("Failed to fetch OCHRE data");
|
|
1503
|
-
}
|
|
1504
|
-
document = item.document;
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
switch (componentName) {
|
|
1508
|
-
case "annotated-document": {
|
|
1509
|
-
if (!document) {
|
|
1510
|
-
throw new Error(
|
|
1511
|
-
`Document not found for the following component: \u201C${componentName}\u201D`
|
|
1512
|
-
);
|
|
1513
|
-
}
|
|
1514
|
-
properties.document = document;
|
|
1515
|
-
break;
|
|
1516
|
-
}
|
|
1517
|
-
case "annotated-image": {
|
|
1518
|
-
if (imageLinks.length === 0) {
|
|
1519
|
-
throw new Error(
|
|
1520
|
-
`Image link not found for the following component: \u201C${componentName}\u201D`
|
|
1521
|
-
);
|
|
1522
|
-
}
|
|
1523
|
-
const isSearchable = getPropertyValueByLabel(
|
|
1524
|
-
componentProperty.properties,
|
|
1525
|
-
"is-searchable"
|
|
1526
|
-
) === "Yes";
|
|
1527
|
-
properties.imageUuid = imageLinks[0].uuid;
|
|
1528
|
-
properties.isSearchable = isSearchable;
|
|
1529
|
-
break;
|
|
1530
|
-
}
|
|
1531
|
-
case "bibliography": {
|
|
1532
|
-
const bibliographyLink = links.find(
|
|
1533
|
-
(link) => link.category === "bibliography"
|
|
1534
|
-
);
|
|
1535
|
-
if (!bibliographyLink) {
|
|
1536
|
-
throw new Error(
|
|
1537
|
-
`Bibliography link not found for the following component: \u201C${componentName}\u201D`
|
|
1538
|
-
);
|
|
1539
|
-
}
|
|
1540
|
-
if (!bibliographyLink.bibliographies) {
|
|
1541
|
-
throw new Error(
|
|
1542
|
-
`Bibliography not found for the following component: \u201C${componentName}\u201D`
|
|
1543
|
-
);
|
|
1544
|
-
}
|
|
1545
|
-
let layout = getPropertyValueByLabel(
|
|
1546
|
-
componentProperty.properties,
|
|
1547
|
-
"layout"
|
|
1548
|
-
);
|
|
1549
|
-
layout ??= "long";
|
|
1550
|
-
properties.bibliographies = bibliographyLink.bibliographies;
|
|
1551
|
-
properties.layout = layout;
|
|
1552
|
-
break;
|
|
1553
|
-
}
|
|
1554
|
-
case "blog": {
|
|
1555
|
-
const blogLink = links.find((link) => link.category === "tree");
|
|
1556
|
-
if (!blogLink) {
|
|
1557
|
-
throw new Error(
|
|
1558
|
-
`Blog link not found for the following component: \u201C${componentName}\u201D`
|
|
1559
|
-
);
|
|
1560
|
-
}
|
|
1561
|
-
properties.blogId = blogLink.uuid;
|
|
1562
|
-
break;
|
|
1563
|
-
}
|
|
1564
|
-
case "button": {
|
|
1565
|
-
let variant = getPropertyValueByLabel(
|
|
1566
|
-
componentProperty.properties,
|
|
1567
|
-
"variant"
|
|
1568
|
-
);
|
|
1569
|
-
variant ??= "default";
|
|
1570
|
-
let isExternal = false;
|
|
1571
|
-
let href = getPropertyValueByLabel(
|
|
1572
|
-
componentProperty.properties,
|
|
1573
|
-
"navigate-to"
|
|
1574
|
-
);
|
|
1575
|
-
if (href === null) {
|
|
1576
|
-
href = getPropertyValueByLabel(componentProperty.properties, "link-to");
|
|
1577
|
-
if (href === null) {
|
|
1578
|
-
throw new Error(
|
|
1579
|
-
`Properties \u201Cnavigate-to\u201D or \u201Clink-to\u201D not found for the following component: \u201C${componentName}\u201D`
|
|
1580
|
-
);
|
|
1581
|
-
} else {
|
|
1582
|
-
isExternal = true;
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
let icon = null;
|
|
1586
|
-
const iconProperty = getPropertyValueByLabel(
|
|
1587
|
-
componentProperty.properties,
|
|
1588
|
-
"icon"
|
|
1589
|
-
);
|
|
1590
|
-
if (iconProperty !== null) {
|
|
1591
|
-
icon = iconProperty;
|
|
1592
|
-
}
|
|
1593
|
-
properties.variant = variant;
|
|
1594
|
-
properties.href = href;
|
|
1595
|
-
properties.isExternal = isExternal;
|
|
1596
|
-
properties.label = ["string", "number", "boolean"].includes(
|
|
1597
|
-
typeof elementResource.identification.label
|
|
1598
|
-
) ? parseFakeString(elementResource.identification.label) : parseStringContent(
|
|
1599
|
-
elementResource.identification.label
|
|
1600
|
-
);
|
|
1601
|
-
properties.icon = icon;
|
|
1602
|
-
break;
|
|
1603
|
-
}
|
|
1604
|
-
case "collection": {
|
|
1605
|
-
const collectionLink = links.find((link) => link.category === "set");
|
|
1606
|
-
if (!collectionLink) {
|
|
1607
|
-
throw new Error(
|
|
1608
|
-
`Collection link not found for the following component: \u201C${componentName}\u201D`
|
|
1609
|
-
);
|
|
1610
|
-
}
|
|
1611
|
-
let variant = getPropertyValueByLabel(
|
|
1612
|
-
componentProperty.properties,
|
|
1613
|
-
"variant"
|
|
1614
|
-
);
|
|
1615
|
-
variant ??= "full";
|
|
1616
|
-
let itemVariant = getPropertyValueByLabel(
|
|
1617
|
-
componentProperty.properties,
|
|
1618
|
-
"item-variant"
|
|
1619
|
-
);
|
|
1620
|
-
itemVariant ??= "default";
|
|
1621
|
-
let showCount = false;
|
|
1622
|
-
const showCountProperty = getPropertyValueByLabel(
|
|
1623
|
-
componentProperty.properties,
|
|
1624
|
-
"show-count"
|
|
1625
|
-
);
|
|
1626
|
-
if (showCountProperty !== null) {
|
|
1627
|
-
showCount = showCountProperty === "Yes";
|
|
1628
|
-
}
|
|
1629
|
-
let isSearchable = false;
|
|
1630
|
-
const isSearchableProperty = getPropertyValueByLabel(
|
|
1631
|
-
componentProperty.properties,
|
|
1632
|
-
"is-searchable"
|
|
1633
|
-
);
|
|
1634
|
-
if (isSearchableProperty !== null) {
|
|
1635
|
-
isSearchable = isSearchableProperty === "Yes";
|
|
1636
|
-
}
|
|
1637
|
-
let layout = getPropertyValueByLabel(
|
|
1638
|
-
componentProperty.properties,
|
|
1639
|
-
"layout"
|
|
1640
|
-
);
|
|
1641
|
-
layout ??= "image-start";
|
|
1642
|
-
properties.collectionId = collectionLink.uuid;
|
|
1643
|
-
properties.variant = variant;
|
|
1644
|
-
properties.itemVariant = itemVariant;
|
|
1645
|
-
properties.isSearchable = isSearchable;
|
|
1646
|
-
properties.showCount = showCount;
|
|
1647
|
-
properties.layout = layout;
|
|
1648
|
-
break;
|
|
1649
|
-
}
|
|
1650
|
-
case "empty-space": {
|
|
1651
|
-
const height = getPropertyValueByLabel(
|
|
1652
|
-
componentProperty.properties,
|
|
1653
|
-
"height"
|
|
1654
|
-
);
|
|
1655
|
-
const width = getPropertyValueByLabel(
|
|
1656
|
-
componentProperty.properties,
|
|
1657
|
-
"width"
|
|
1658
|
-
);
|
|
1659
|
-
properties.height = height;
|
|
1660
|
-
properties.width = width;
|
|
1661
|
-
break;
|
|
1662
|
-
}
|
|
1663
|
-
case "filter-categories": {
|
|
1664
|
-
const filterLink = links.find((link) => link.category === "set");
|
|
1665
|
-
if (!filterLink) {
|
|
1666
|
-
throw new Error(
|
|
1667
|
-
`Filter link not found for the following component: \u201C${componentName}\u201D`
|
|
1668
|
-
);
|
|
1669
|
-
}
|
|
1670
|
-
properties.filterId = filterLink.uuid;
|
|
1671
|
-
break;
|
|
1672
|
-
}
|
|
1673
|
-
case "iframe": {
|
|
1674
|
-
const href = links.find((link) => link.type === "webpage")?.href;
|
|
1675
|
-
if (!href) {
|
|
1676
|
-
throw new Error(
|
|
1677
|
-
`URL not found for the following component: \u201C${componentName}\u201D`
|
|
1678
|
-
);
|
|
1679
|
-
}
|
|
1680
|
-
const height = getPropertyValueByLabel(
|
|
1681
|
-
componentProperty.properties,
|
|
1682
|
-
"height"
|
|
1683
|
-
);
|
|
1684
|
-
const width = getPropertyValueByLabel(
|
|
1685
|
-
componentProperty.properties,
|
|
1686
|
-
"width"
|
|
1687
|
-
);
|
|
1688
|
-
properties.href = href;
|
|
1689
|
-
properties.height = height;
|
|
1690
|
-
properties.width = width;
|
|
1691
|
-
break;
|
|
1692
|
-
}
|
|
1693
|
-
case "iiif-viewer": {
|
|
1694
|
-
const manifestLink = links.find((link) => link.type === "IIIF");
|
|
1695
|
-
if (!manifestLink) {
|
|
1696
|
-
throw new Error(
|
|
1697
|
-
`Manifest link not found for the following component: \u201C${componentName}\u201D`
|
|
1698
|
-
);
|
|
1699
|
-
}
|
|
1700
|
-
properties.IIIFId = manifestLink.uuid;
|
|
1701
|
-
break;
|
|
1702
|
-
}
|
|
1703
|
-
case "image": {
|
|
1704
|
-
if (imageLinks.length === 0) {
|
|
1705
|
-
throw new Error(
|
|
1706
|
-
`Image link not found for the following component: \u201C${componentName}\u201D`
|
|
1707
|
-
);
|
|
1708
|
-
}
|
|
1709
|
-
const images = [];
|
|
1710
|
-
for (const imageLink of imageLinks) {
|
|
1711
|
-
images.push({
|
|
1712
|
-
url: `https://ochre.lib.uchicago.edu/ochre?uuid=${imageLink.uuid}&load`,
|
|
1713
|
-
label: imageLink.identification?.label ?? null,
|
|
1714
|
-
width: imageLink.image?.width ?? 0,
|
|
1715
|
-
height: imageLink.image?.height ?? 0
|
|
1716
|
-
});
|
|
1717
|
-
}
|
|
1718
|
-
let variant = getPropertyValueByLabel(
|
|
1719
|
-
componentProperty.properties,
|
|
1720
|
-
"variant"
|
|
1721
|
-
);
|
|
1722
|
-
variant ??= "default";
|
|
1723
|
-
let captionLayout = getPropertyValueByLabel(
|
|
1724
|
-
componentProperty.properties,
|
|
1725
|
-
"layout-caption"
|
|
1726
|
-
);
|
|
1727
|
-
captionLayout ??= "bottom";
|
|
1728
|
-
let width = null;
|
|
1729
|
-
const widthProperty = getPropertyValueByLabel(
|
|
1730
|
-
componentProperty.properties,
|
|
1731
|
-
"width"
|
|
1732
|
-
);
|
|
1733
|
-
if (widthProperty !== null) {
|
|
1734
|
-
if (typeof widthProperty === "number") {
|
|
1735
|
-
width = widthProperty;
|
|
1736
|
-
} else if (typeof widthProperty === "string") {
|
|
1737
|
-
width = Number.parseFloat(widthProperty);
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
|
-
let height = null;
|
|
1741
|
-
const heightProperty = getPropertyValueByLabel(
|
|
1742
|
-
componentProperty.properties,
|
|
1743
|
-
"height"
|
|
1744
|
-
);
|
|
1745
|
-
if (heightProperty !== null) {
|
|
1746
|
-
if (typeof heightProperty === "number") {
|
|
1747
|
-
height = heightProperty;
|
|
1748
|
-
} else if (typeof heightProperty === "string") {
|
|
1749
|
-
height = Number.parseFloat(heightProperty);
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
let isFullWidth = true;
|
|
1753
|
-
const isFullWidthProperty = getPropertyValueByLabel(
|
|
1754
|
-
componentProperty.properties,
|
|
1755
|
-
"is-full-width"
|
|
1756
|
-
);
|
|
1757
|
-
if (isFullWidthProperty !== null) {
|
|
1758
|
-
isFullWidth = isFullWidthProperty === "Yes";
|
|
1759
|
-
}
|
|
1760
|
-
let isFullHeight = true;
|
|
1761
|
-
const isFullHeightProperty = getPropertyValueByLabel(
|
|
1762
|
-
componentProperty.properties,
|
|
1763
|
-
"is-full-height"
|
|
1764
|
-
);
|
|
1765
|
-
if (isFullHeightProperty !== null) {
|
|
1766
|
-
isFullHeight = isFullHeightProperty === "Yes";
|
|
1767
|
-
}
|
|
1768
|
-
let imageQuality = getPropertyValueByLabel(
|
|
1769
|
-
componentProperty.properties,
|
|
1770
|
-
"image-quality"
|
|
1771
|
-
);
|
|
1772
|
-
imageQuality ??= "high";
|
|
1773
|
-
let captionSource = getPropertyValueByLabel(
|
|
1774
|
-
componentProperty.properties,
|
|
1775
|
-
"caption-source"
|
|
1776
|
-
);
|
|
1777
|
-
captionSource ??= "name";
|
|
1778
|
-
let altTextSource = getPropertyValueByLabel(
|
|
1779
|
-
componentProperty.properties,
|
|
1780
|
-
"alt-text-source"
|
|
1781
|
-
);
|
|
1782
|
-
altTextSource ??= "name";
|
|
1783
|
-
let isTransparentBackground = false;
|
|
1784
|
-
const isTransparentBackgroundProperty = getPropertyValueByLabel(
|
|
1785
|
-
componentProperty.properties,
|
|
1786
|
-
"is-transparent"
|
|
1787
|
-
);
|
|
1788
|
-
if (isTransparentBackgroundProperty !== null) {
|
|
1789
|
-
isTransparentBackground = isTransparentBackgroundProperty === "Yes";
|
|
1790
|
-
}
|
|
1791
|
-
let isCover = false;
|
|
1792
|
-
const isCoverProperty = getPropertyValueByLabel(
|
|
1793
|
-
componentProperty.properties,
|
|
1794
|
-
"is-cover"
|
|
1795
|
-
);
|
|
1796
|
-
if (isCoverProperty !== null) {
|
|
1797
|
-
isCover = isCoverProperty === "Yes";
|
|
1798
|
-
}
|
|
1799
|
-
let carouselOptions = null;
|
|
1800
|
-
if (images.length > 1) {
|
|
1801
|
-
const variantProperty = getPropertyByLabel(
|
|
1802
|
-
componentProperty.properties,
|
|
1803
|
-
"variant"
|
|
1804
|
-
);
|
|
1805
|
-
let secondsPerImage = 5;
|
|
1806
|
-
if (variantProperty && variantProperty.values[0].content === "carousel") {
|
|
1807
|
-
const secondsPerImageProperty = getPropertyValueByLabel(
|
|
1808
|
-
variantProperty.properties,
|
|
1809
|
-
"seconds-per-image"
|
|
1810
|
-
);
|
|
1811
|
-
if (secondsPerImageProperty !== null) {
|
|
1812
|
-
if (typeof secondsPerImageProperty === "number") {
|
|
1813
|
-
secondsPerImage = secondsPerImageProperty;
|
|
1814
|
-
} else if (typeof secondsPerImageProperty === "string") {
|
|
1815
|
-
secondsPerImage = Number.parseFloat(secondsPerImageProperty);
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
carouselOptions = {
|
|
1820
|
-
secondsPerImage
|
|
1821
|
-
};
|
|
1822
|
-
}
|
|
1823
|
-
properties.images = images;
|
|
1824
|
-
properties.variant = variant;
|
|
1825
|
-
properties.width = width;
|
|
1826
|
-
properties.height = height;
|
|
1827
|
-
properties.isFullWidth = isFullWidth;
|
|
1828
|
-
properties.isFullHeight = isFullHeight;
|
|
1829
|
-
properties.imageQuality = imageQuality;
|
|
1830
|
-
properties.captionLayout = captionLayout;
|
|
1831
|
-
properties.captionSource = captionSource;
|
|
1832
|
-
properties.altTextSource = altTextSource;
|
|
1833
|
-
properties.isTransparentBackground = isTransparentBackground;
|
|
1834
|
-
properties.isCover = isCover;
|
|
1835
|
-
properties.carouselOptions = carouselOptions;
|
|
1836
|
-
break;
|
|
1837
|
-
}
|
|
1838
|
-
case "image-gallery": {
|
|
1839
|
-
const galleryLink = links.find(
|
|
1840
|
-
(link) => link.category === "tree" || link.category === "set"
|
|
1841
|
-
);
|
|
1842
|
-
if (!galleryLink) {
|
|
1843
|
-
throw new Error(
|
|
1844
|
-
`Image gallery link not found for the following component: \u201C${componentName}\u201D`
|
|
1845
|
-
);
|
|
1846
|
-
}
|
|
1847
|
-
const isSearchable = getPropertyValueByLabel(
|
|
1848
|
-
componentProperty.properties,
|
|
1849
|
-
"is-searchable"
|
|
1850
|
-
) === "Yes";
|
|
1851
|
-
properties.galleryId = galleryLink.uuid;
|
|
1852
|
-
properties.isSearchable = isSearchable;
|
|
1853
|
-
break;
|
|
1854
|
-
}
|
|
1855
|
-
case "n-columns": {
|
|
1856
|
-
const subElements = elementResource.resource ? await parseWebpageResources(
|
|
1857
|
-
Array.isArray(elementResource.resource) ? elementResource.resource : [elementResource.resource],
|
|
1858
|
-
"element"
|
|
1859
|
-
) : [];
|
|
1860
|
-
properties.columns = subElements;
|
|
1861
|
-
break;
|
|
1862
|
-
}
|
|
1863
|
-
case "n-rows": {
|
|
1864
|
-
const subElements = elementResource.resource ? await parseWebpageResources(
|
|
1865
|
-
Array.isArray(elementResource.resource) ? elementResource.resource : [elementResource.resource],
|
|
1866
|
-
"element"
|
|
1867
|
-
) : [];
|
|
1868
|
-
properties.rows = subElements;
|
|
1869
|
-
break;
|
|
1870
|
-
}
|
|
1871
|
-
case "network-graph": {
|
|
1872
|
-
break;
|
|
1873
|
-
}
|
|
1874
|
-
case "table": {
|
|
1875
|
-
const tableLink = links.find((link) => link.category === "set");
|
|
1876
|
-
if (!tableLink) {
|
|
1877
|
-
throw new Error(
|
|
1878
|
-
`Table link not found for the following component: \u201C${componentName}\u201D`
|
|
1879
|
-
);
|
|
1880
|
-
}
|
|
1881
|
-
properties.tableId = tableLink.uuid;
|
|
1882
|
-
break;
|
|
1883
|
-
}
|
|
1884
|
-
case "search-bar": {
|
|
1885
|
-
let variant = getPropertyValueByLabel(
|
|
1886
|
-
componentProperty.properties,
|
|
1887
|
-
"variant"
|
|
1888
|
-
);
|
|
1889
|
-
variant ??= "default";
|
|
1890
|
-
properties.variant = variant;
|
|
1891
|
-
break;
|
|
1892
|
-
}
|
|
1893
|
-
case "text": {
|
|
1894
|
-
if (!document) {
|
|
1895
|
-
throw new Error(
|
|
1896
|
-
`Document not found for the following component: \u201C${componentName}\u201D`
|
|
1897
|
-
);
|
|
1898
|
-
}
|
|
1899
|
-
let variant = getPropertyValueByLabel(
|
|
1900
|
-
componentProperty.properties,
|
|
1901
|
-
"variant"
|
|
1902
|
-
);
|
|
1903
|
-
variant ??= "block";
|
|
1904
|
-
const heading = getPropertyValueByLabel(
|
|
1905
|
-
componentProperty.properties,
|
|
1906
|
-
"heading"
|
|
1907
|
-
);
|
|
1908
|
-
properties.variant = variant;
|
|
1909
|
-
properties.heading = heading;
|
|
1910
|
-
properties.content = document.content;
|
|
1911
|
-
break;
|
|
1912
|
-
}
|
|
1913
|
-
case "timeline": {
|
|
1914
|
-
const timelineLink = links.find((link) => link.category === "tree");
|
|
1915
|
-
if (!timelineLink) {
|
|
1916
|
-
throw new Error(
|
|
1917
|
-
`Timeline link not found for the following component: \u201C${componentName}\u201D`
|
|
1918
|
-
);
|
|
1919
|
-
}
|
|
1920
|
-
properties.timelineId = timelineLink.uuid;
|
|
1921
|
-
break;
|
|
1922
|
-
}
|
|
1923
|
-
case "video": {
|
|
1924
|
-
const videoLink = links.find((link) => link.type === "video");
|
|
1925
|
-
if (!videoLink) {
|
|
1926
|
-
throw new Error(
|
|
1927
|
-
`Video link not found for the following component: \u201C${componentName}\u201D`
|
|
1928
|
-
);
|
|
1929
|
-
}
|
|
1930
|
-
let isChaptersDislayed = getPropertyValueByLabel(
|
|
1931
|
-
componentProperty.properties,
|
|
1932
|
-
"chapters-displayed"
|
|
1933
|
-
);
|
|
1934
|
-
isChaptersDislayed ??= "Yes";
|
|
1935
|
-
properties.videoId = videoLink.uuid;
|
|
1936
|
-
properties.isChaptersDislayed = isChaptersDislayed === "Yes";
|
|
1937
|
-
break;
|
|
1938
|
-
}
|
|
1939
|
-
default: {
|
|
1940
|
-
console.warn(
|
|
1941
|
-
`Invalid or non-implemented component name \u201C${componentName}\u201D for the following element: \u201C${parseStringContent(
|
|
1942
|
-
elementResource.identification.label
|
|
1943
|
-
)}\u201D`
|
|
1944
|
-
);
|
|
1945
|
-
break;
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
1948
|
-
return properties;
|
|
1949
|
-
}
|
|
1950
|
-
async function parseWebElement(elementResource) {
|
|
1951
|
-
const identification = parseIdentification(elementResource.identification);
|
|
1952
|
-
const elementProperties = elementResource.properties?.property ? parseProperties(
|
|
1953
|
-
Array.isArray(elementResource.properties.property) ? elementResource.properties.property : [elementResource.properties.property]
|
|
1954
|
-
) : [];
|
|
1955
|
-
const presentationProperty = elementProperties.find(
|
|
1956
|
-
(property) => property.label === "presentation"
|
|
1957
|
-
);
|
|
1958
|
-
if (!presentationProperty) {
|
|
1959
|
-
throw new Error(
|
|
1960
|
-
`Presentation property not found for element \u201C${identification.label}\u201D`
|
|
1961
|
-
);
|
|
1962
|
-
}
|
|
1963
|
-
const componentProperty = presentationProperty.properties.find(
|
|
1964
|
-
(property) => property.label === "component"
|
|
1965
|
-
);
|
|
1966
|
-
if (!componentProperty) {
|
|
1967
|
-
throw new Error(
|
|
1968
|
-
`Component for element \u201C${identification.label}\u201D not found`
|
|
1969
|
-
);
|
|
1970
|
-
}
|
|
1971
|
-
const properties = await parseWebElementProperties(
|
|
1972
|
-
componentProperty,
|
|
1973
|
-
elementResource
|
|
1974
|
-
);
|
|
1975
|
-
const elementResourceProperties = elementResource.properties?.property ? parseProperties(
|
|
1976
|
-
Array.isArray(elementResource.properties.property) ? elementResource.properties.property : [elementResource.properties.property]
|
|
1977
|
-
) : [];
|
|
1978
|
-
const cssProperties = elementResourceProperties.find(
|
|
1979
|
-
(property) => property.label === "presentation" && property.values[0].content === "css"
|
|
1980
|
-
)?.properties ?? [];
|
|
1981
|
-
const cssStyles = [];
|
|
1982
|
-
for (const property of cssProperties) {
|
|
1983
|
-
const cssStyle = property.values[0].content;
|
|
1984
|
-
cssStyles.push({ label: property.label, value: cssStyle });
|
|
1985
|
-
}
|
|
1986
|
-
const mobileCssProperties = elementResourceProperties.find(
|
|
1987
|
-
(property) => property.label === "presentation" && property.values[0].content === "css-mobile"
|
|
1988
|
-
)?.properties ?? [];
|
|
1989
|
-
const cssStylesMobile = [];
|
|
1990
|
-
for (const property of mobileCssProperties) {
|
|
1991
|
-
const cssStyle = property.values[0].content;
|
|
1992
|
-
cssStylesMobile.push({ label: property.label, value: cssStyle });
|
|
1993
|
-
}
|
|
1994
|
-
const titleProperties = elementResourceProperties.find(
|
|
1995
|
-
(property) => property.label === "presentation" && property.values[0].content === "title"
|
|
1996
|
-
)?.properties;
|
|
1997
|
-
let variant = "default";
|
|
1998
|
-
let isNameDisplayed = false;
|
|
1999
|
-
let isDescriptionDisplayed = false;
|
|
2000
|
-
let isDateDisplayed = false;
|
|
2001
|
-
let isCreatorsDisplayed = false;
|
|
2002
|
-
if (titleProperties) {
|
|
2003
|
-
const titleVariant = getPropertyValueByLabel(titleProperties, "variant");
|
|
2004
|
-
if (titleVariant) {
|
|
2005
|
-
variant = titleVariant;
|
|
2006
|
-
}
|
|
2007
|
-
const titleShow = titleProperties.filter(
|
|
2008
|
-
(property) => property.label === "display"
|
|
2009
|
-
);
|
|
2010
|
-
if (titleShow.length > 0) {
|
|
2011
|
-
isNameDisplayed = titleShow.some(
|
|
2012
|
-
(property) => property.values[0].content === "name"
|
|
2013
|
-
);
|
|
2014
|
-
isDescriptionDisplayed = titleShow.some(
|
|
2015
|
-
(property) => property.values[0].content === "description"
|
|
2016
|
-
);
|
|
2017
|
-
isDateDisplayed = titleShow.some(
|
|
2018
|
-
(property) => property.values[0].content === "date"
|
|
2019
|
-
);
|
|
2020
|
-
isCreatorsDisplayed = titleShow.some(
|
|
2021
|
-
(property) => property.values[0].content === "creators"
|
|
2022
|
-
);
|
|
2023
|
-
}
|
|
2024
|
-
}
|
|
2025
|
-
return {
|
|
2026
|
-
uuid: elementResource.uuid,
|
|
2027
|
-
type: "element",
|
|
2028
|
-
title: {
|
|
2029
|
-
label: identification.label,
|
|
2030
|
-
variant,
|
|
2031
|
-
properties: {
|
|
2032
|
-
isNameDisplayed,
|
|
2033
|
-
isDescriptionDisplayed,
|
|
2034
|
-
isDateDisplayed,
|
|
2035
|
-
isCreatorsDisplayed
|
|
2036
|
-
}
|
|
2037
|
-
},
|
|
2038
|
-
cssStyles,
|
|
2039
|
-
cssStylesMobile,
|
|
2040
|
-
...properties
|
|
2041
|
-
};
|
|
2042
|
-
}
|
|
2043
|
-
async function parseWebpage(webpageResource) {
|
|
2044
|
-
const webpageProperties = webpageResource.properties ? parseProperties(
|
|
2045
|
-
Array.isArray(webpageResource.properties.property) ? webpageResource.properties.property : [webpageResource.properties.property]
|
|
2046
|
-
) : [];
|
|
2047
|
-
if (webpageProperties.length === 0 || webpageProperties.find((property) => property.label === "presentation")?.values[0]?.content !== "page") {
|
|
2048
|
-
return null;
|
|
2049
|
-
}
|
|
2050
|
-
const identification = parseIdentification(webpageResource.identification);
|
|
2051
|
-
const slug = webpageResource.slug;
|
|
2052
|
-
if (slug === void 0) {
|
|
2053
|
-
throw new Error(`Slug not found for page \u201C${identification.label}\u201D`);
|
|
2054
|
-
}
|
|
2055
|
-
const links = webpageResource.links ? parseLinks(
|
|
2056
|
-
Array.isArray(webpageResource.links) ? webpageResource.links : [webpageResource.links]
|
|
2057
|
-
) : [];
|
|
2058
|
-
const imageLink = links.find(
|
|
2059
|
-
(link) => link.type === "image" || link.type === "IIIF"
|
|
2060
|
-
);
|
|
2061
|
-
const webpageResources = webpageResource.resource ? Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource] : [];
|
|
2062
|
-
const items = [];
|
|
2063
|
-
for (const resource of webpageResources) {
|
|
2064
|
-
const resourceProperties = resource.properties ? parseProperties(
|
|
2065
|
-
Array.isArray(resource.properties.property) ? resource.properties.property : [resource.properties.property]
|
|
2066
|
-
) : [];
|
|
2067
|
-
const resourceType = getPropertyValueByLabel(
|
|
2068
|
-
resourceProperties,
|
|
2069
|
-
"presentation"
|
|
2070
|
-
);
|
|
2071
|
-
if (resourceType == null) {
|
|
2072
|
-
continue;
|
|
2073
|
-
}
|
|
2074
|
-
switch (resourceType) {
|
|
2075
|
-
case "element": {
|
|
2076
|
-
const element = await parseWebElement(resource);
|
|
2077
|
-
items.push(element);
|
|
2078
|
-
break;
|
|
2079
|
-
}
|
|
2080
|
-
case "block": {
|
|
2081
|
-
const block = await parseBlock(resource);
|
|
2082
|
-
if (block) {
|
|
2083
|
-
items.push(block);
|
|
2084
|
-
}
|
|
2085
|
-
break;
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
}
|
|
2089
|
-
const webpages = webpageResource.resource ? await parseWebpageResources(
|
|
2090
|
-
Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource],
|
|
2091
|
-
"page"
|
|
2092
|
-
) : [];
|
|
2093
|
-
let displayedInHeader = true;
|
|
2094
|
-
let width = "default";
|
|
2095
|
-
let variant = "default";
|
|
2096
|
-
let isSidebarDisplayed = true;
|
|
2097
|
-
const webpageSubProperties = webpageProperties.find(
|
|
2098
|
-
(property) => property.label === "presentation" && property.values[0]?.content === "page"
|
|
2099
|
-
)?.properties;
|
|
2100
|
-
if (webpageSubProperties) {
|
|
2101
|
-
const headerProperty = webpageSubProperties.find(
|
|
2102
|
-
(property) => property.label === "header"
|
|
2103
|
-
)?.values[0];
|
|
2104
|
-
if (headerProperty) {
|
|
2105
|
-
displayedInHeader = headerProperty.content === "Yes";
|
|
2106
|
-
}
|
|
2107
|
-
const widthProperty = webpageSubProperties.find(
|
|
2108
|
-
(property) => property.label === "width"
|
|
2109
|
-
)?.values[0];
|
|
2110
|
-
if (widthProperty) {
|
|
2111
|
-
width = widthProperty.content;
|
|
2112
|
-
}
|
|
2113
|
-
const variantProperty = webpageSubProperties.find(
|
|
2114
|
-
(property) => property.label === "variant"
|
|
2115
|
-
)?.values[0];
|
|
2116
|
-
if (variantProperty) {
|
|
2117
|
-
variant = variantProperty.content;
|
|
2118
|
-
}
|
|
2119
|
-
const isSidebarDisplayedProperty = webpageSubProperties.find(
|
|
2120
|
-
(property) => property.label === "sidebar-visible"
|
|
2121
|
-
)?.values[0];
|
|
2122
|
-
if (isSidebarDisplayedProperty) {
|
|
2123
|
-
isSidebarDisplayed = isSidebarDisplayedProperty.content === "Yes";
|
|
2124
|
-
}
|
|
2125
|
-
}
|
|
2126
|
-
const cssStyleSubProperties = webpageProperties.find(
|
|
2127
|
-
(property) => property.label === "presentation" && property.values[0]?.content === "css"
|
|
2128
|
-
)?.properties;
|
|
2129
|
-
const cssStyles = [];
|
|
2130
|
-
if (cssStyleSubProperties) {
|
|
2131
|
-
for (const property of cssStyleSubProperties) {
|
|
2132
|
-
cssStyles.push({
|
|
2133
|
-
label: property.label,
|
|
2134
|
-
value: property.values[0].content
|
|
2135
|
-
});
|
|
2136
|
-
}
|
|
2137
|
-
}
|
|
2138
|
-
const mobileCssStyleSubProperties = webpageProperties.find(
|
|
2139
|
-
(property) => property.label === "presentation" && property.values[0]?.content === "css-mobile"
|
|
2140
|
-
)?.properties;
|
|
2141
|
-
const cssStylesMobile = [];
|
|
2142
|
-
if (mobileCssStyleSubProperties) {
|
|
2143
|
-
for (const property of mobileCssStyleSubProperties) {
|
|
2144
|
-
cssStylesMobile.push({
|
|
2145
|
-
label: property.label,
|
|
2146
|
-
value: property.values[0].content
|
|
2147
|
-
});
|
|
2148
|
-
}
|
|
2149
|
-
}
|
|
2150
|
-
return {
|
|
2151
|
-
title: identification.label,
|
|
2152
|
-
slug,
|
|
2153
|
-
items,
|
|
2154
|
-
properties: {
|
|
2155
|
-
displayedInHeader,
|
|
2156
|
-
width,
|
|
2157
|
-
variant,
|
|
2158
|
-
backgroundImageUrl: imageLink ? `https://ochre.lib.uchicago.edu/ochre?uuid=${imageLink.uuid}&load` : null,
|
|
2159
|
-
isSidebarDisplayed,
|
|
2160
|
-
cssStyles,
|
|
2161
|
-
cssStylesMobile
|
|
2162
|
-
},
|
|
2163
|
-
webpages
|
|
2164
|
-
};
|
|
2165
|
-
}
|
|
2166
|
-
async function parseWebpages(webpageResources) {
|
|
2167
|
-
const returnPages = [];
|
|
2168
|
-
const pagesToParse = Array.isArray(webpageResources) ? webpageResources : [webpageResources];
|
|
2169
|
-
for (const page of pagesToParse) {
|
|
2170
|
-
const webpage = await parseWebpage(page);
|
|
2171
|
-
if (webpage) {
|
|
2172
|
-
returnPages.push(webpage);
|
|
2173
|
-
}
|
|
2174
|
-
}
|
|
2175
|
-
return returnPages;
|
|
2176
|
-
}
|
|
2177
|
-
async function parseBlock(blockResource) {
|
|
2178
|
-
const returnBlock = {
|
|
2179
|
-
uuid: blockResource.uuid,
|
|
2180
|
-
type: "block",
|
|
2181
|
-
layout: "vertical",
|
|
2182
|
-
items: [],
|
|
2183
|
-
properties: {
|
|
2184
|
-
spacing: void 0,
|
|
2185
|
-
gap: void 0,
|
|
2186
|
-
alignItems: "start",
|
|
2187
|
-
justifyContent: "stretch"
|
|
2188
|
-
},
|
|
2189
|
-
propertiesMobile: null,
|
|
2190
|
-
cssStyles: [],
|
|
2191
|
-
cssStylesMobile: []
|
|
2192
|
-
};
|
|
2193
|
-
const blockProperties = blockResource.properties ? parseProperties(
|
|
2194
|
-
Array.isArray(blockResource.properties.property) ? blockResource.properties.property : [blockResource.properties.property]
|
|
2195
|
-
) : [];
|
|
2196
|
-
const blockMainProperties = blockProperties.find(
|
|
2197
|
-
(property) => property.label === "presentation" && property.values[0]?.content === "block"
|
|
2198
|
-
)?.properties;
|
|
2199
|
-
if (blockMainProperties) {
|
|
2200
|
-
const layoutProperty = blockMainProperties.find(
|
|
2201
|
-
(property) => property.label === "layout"
|
|
2202
|
-
)?.values[0];
|
|
2203
|
-
if (layoutProperty) {
|
|
2204
|
-
returnBlock.layout = layoutProperty.content;
|
|
2205
|
-
}
|
|
2206
|
-
const spacingProperty = blockMainProperties.find(
|
|
2207
|
-
(property) => property.label === "spacing"
|
|
2208
|
-
)?.values[0];
|
|
2209
|
-
if (spacingProperty) {
|
|
2210
|
-
returnBlock.properties.spacing = spacingProperty.content;
|
|
2211
|
-
}
|
|
2212
|
-
const gapProperty = blockMainProperties.find(
|
|
2213
|
-
(property) => property.label === "gap"
|
|
2214
|
-
)?.values[0];
|
|
2215
|
-
if (gapProperty) {
|
|
2216
|
-
returnBlock.properties.gap = gapProperty.content;
|
|
2217
|
-
}
|
|
2218
|
-
const alignItemsProperty = blockMainProperties.find(
|
|
2219
|
-
(property) => property.label === "align-items"
|
|
2220
|
-
)?.values[0];
|
|
2221
|
-
if (alignItemsProperty) {
|
|
2222
|
-
returnBlock.properties.alignItems = alignItemsProperty.content;
|
|
2223
|
-
}
|
|
2224
|
-
const justifyContentProperty = blockMainProperties.find(
|
|
2225
|
-
(property) => property.label === "justify-content"
|
|
2226
|
-
)?.values[0];
|
|
2227
|
-
if (justifyContentProperty) {
|
|
2228
|
-
returnBlock.properties.justifyContent = justifyContentProperty.content;
|
|
2229
|
-
}
|
|
2230
|
-
const mobileOverwriteProperty = blockMainProperties.find(
|
|
2231
|
-
(property) => property.label === "overwrite-mobile"
|
|
2232
|
-
);
|
|
2233
|
-
if (mobileOverwriteProperty) {
|
|
2234
|
-
const mobileOverwriteProperties = mobileOverwriteProperty.properties;
|
|
2235
|
-
const propertiesMobile = {};
|
|
2236
|
-
for (const property of mobileOverwriteProperties) {
|
|
2237
|
-
propertiesMobile[property.label] = property.values[0].content;
|
|
2238
|
-
}
|
|
2239
|
-
returnBlock.propertiesMobile = propertiesMobile;
|
|
2240
|
-
}
|
|
2241
|
-
}
|
|
2242
|
-
const blockResources = blockResource.resource ? Array.isArray(blockResource.resource) ? blockResource.resource : [blockResource.resource] : [];
|
|
2243
|
-
const blockItems = [];
|
|
2244
|
-
for (const resource of blockResources) {
|
|
2245
|
-
const resourceProperties = resource.properties ? parseProperties(
|
|
2246
|
-
Array.isArray(resource.properties.property) ? resource.properties.property : [resource.properties.property]
|
|
2247
|
-
) : [];
|
|
2248
|
-
const resourceType = getPropertyValueByLabel(
|
|
2249
|
-
resourceProperties,
|
|
2250
|
-
"presentation"
|
|
2251
|
-
);
|
|
2252
|
-
if (resourceType == null) {
|
|
2253
|
-
continue;
|
|
2254
|
-
}
|
|
2255
|
-
switch (resourceType) {
|
|
2256
|
-
case "element": {
|
|
2257
|
-
const element = await parseWebElement(resource);
|
|
2258
|
-
blockItems.push(element);
|
|
2259
|
-
break;
|
|
2260
|
-
}
|
|
2261
|
-
case "block": {
|
|
2262
|
-
const block = await parseBlock(resource);
|
|
2263
|
-
if (block) {
|
|
2264
|
-
blockItems.push(block);
|
|
2265
|
-
}
|
|
2266
|
-
break;
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
}
|
|
2270
|
-
returnBlock.items = blockItems;
|
|
2271
|
-
const blockCssStyles = blockProperties.find(
|
|
2272
|
-
(property) => property.label === "presentation" && property.values[0]?.content === "css"
|
|
2273
|
-
)?.properties;
|
|
2274
|
-
if (blockCssStyles) {
|
|
2275
|
-
for (const property of blockCssStyles) {
|
|
2276
|
-
returnBlock.cssStyles.push({
|
|
2277
|
-
label: property.label,
|
|
2278
|
-
value: property.values[0].content
|
|
2279
|
-
});
|
|
2280
|
-
}
|
|
2281
|
-
}
|
|
2282
|
-
const blockMobileCssStyles = blockProperties.find(
|
|
2283
|
-
(property) => property.label === "presentation" && property.values[0]?.content === "css-mobile"
|
|
2284
|
-
)?.properties;
|
|
2285
|
-
if (blockMobileCssStyles) {
|
|
2286
|
-
for (const property of blockMobileCssStyles) {
|
|
2287
|
-
returnBlock.cssStylesMobile.push({
|
|
2288
|
-
label: property.label,
|
|
2289
|
-
value: property.values[0].content
|
|
2290
|
-
});
|
|
2291
|
-
}
|
|
2292
|
-
}
|
|
2293
|
-
return returnBlock;
|
|
2294
|
-
}
|
|
2295
|
-
function parseWebsiteProperties(properties) {
|
|
2296
|
-
const mainProperties = parseProperties(properties);
|
|
2297
|
-
const websiteProperties = mainProperties.find(
|
|
2298
|
-
(property) => property.label === "presentation"
|
|
2299
|
-
)?.properties;
|
|
2300
|
-
if (!websiteProperties) {
|
|
2301
|
-
throw new Error("Presentation property not found");
|
|
2302
|
-
}
|
|
2303
|
-
const type = websiteProperties.find((property) => property.label === "webUI")?.values[0]?.content;
|
|
2304
|
-
if (type == null) {
|
|
2305
|
-
throw new Error("Website type not found");
|
|
2306
|
-
}
|
|
2307
|
-
const status = websiteProperties.find(
|
|
2308
|
-
(property) => property.label === "status"
|
|
2309
|
-
)?.values[0]?.content;
|
|
2310
|
-
if (status == null) {
|
|
2311
|
-
throw new Error("Website status not found");
|
|
2312
|
-
}
|
|
2313
|
-
let privacy = websiteProperties.find(
|
|
2314
|
-
(property) => property.label === "privacy"
|
|
2315
|
-
)?.values[0]?.content;
|
|
2316
|
-
privacy ??= "public";
|
|
2317
|
-
const result = websiteSchema.safeParse({
|
|
2318
|
-
type,
|
|
2319
|
-
status,
|
|
2320
|
-
privacy
|
|
2321
|
-
});
|
|
2322
|
-
if (!result.success) {
|
|
2323
|
-
throw new Error(`Invalid website properties: ${result.error.message}`);
|
|
2324
|
-
}
|
|
2325
|
-
let contact = null;
|
|
2326
|
-
const contactProperty = websiteProperties.find(
|
|
2327
|
-
(property) => property.label === "contact"
|
|
2328
|
-
);
|
|
2329
|
-
if (contactProperty) {
|
|
2330
|
-
const [name, email] = (contactProperty.values[0]?.content).split(
|
|
2331
|
-
";"
|
|
2332
|
-
);
|
|
2333
|
-
contact = { name, email: email ?? null };
|
|
2334
|
-
}
|
|
2335
|
-
const logoUuid = websiteProperties.find((property) => property.label === "logo")?.values[0]?.uuid ?? null;
|
|
2336
|
-
let isHeaderDisplayed = true;
|
|
2337
|
-
let headerVariant = "default";
|
|
2338
|
-
let headerAlignment = "start";
|
|
2339
|
-
let isHeaderProjectDisplayed = true;
|
|
2340
|
-
let isFooterDisplayed = true;
|
|
2341
|
-
let isSidebarDisplayed = false;
|
|
2342
|
-
let searchCollectionUuid = null;
|
|
2343
|
-
let supportsThemeToggle = true;
|
|
2344
|
-
const headerProperty = websiteProperties.find(
|
|
2345
|
-
(property) => property.label === "navbar-visible"
|
|
2346
|
-
)?.values[0];
|
|
2347
|
-
if (headerProperty) {
|
|
2348
|
-
isHeaderDisplayed = headerProperty.content === "Yes";
|
|
2349
|
-
}
|
|
2350
|
-
const headerVariantProperty = websiteProperties.find(
|
|
2351
|
-
(property) => property.label === "navbar-variant"
|
|
2352
|
-
)?.values[0];
|
|
2353
|
-
if (headerVariantProperty) {
|
|
2354
|
-
headerVariant = headerVariantProperty.content;
|
|
2355
|
-
}
|
|
2356
|
-
const headerAlignmentProperty = websiteProperties.find(
|
|
2357
|
-
(property) => property.label === "navbar-alignment"
|
|
2358
|
-
)?.values[0];
|
|
2359
|
-
if (headerAlignmentProperty) {
|
|
2360
|
-
headerAlignment = headerAlignmentProperty.content;
|
|
2361
|
-
}
|
|
2362
|
-
const isHeaderProjectDisplayedProperty = websiteProperties.find(
|
|
2363
|
-
(property) => property.label === "navbar-project-visible"
|
|
2364
|
-
)?.values[0];
|
|
2365
|
-
if (isHeaderProjectDisplayedProperty) {
|
|
2366
|
-
isHeaderProjectDisplayed = isHeaderProjectDisplayedProperty.content === "Yes";
|
|
2367
|
-
}
|
|
2368
|
-
const footerProperty = websiteProperties.find(
|
|
2369
|
-
(property) => property.label === "footer-visible"
|
|
2370
|
-
)?.values[0];
|
|
2371
|
-
if (footerProperty) {
|
|
2372
|
-
isFooterDisplayed = footerProperty.content === "Yes";
|
|
2373
|
-
}
|
|
2374
|
-
const sidebarProperty = websiteProperties.find(
|
|
2375
|
-
(property) => property.label === "sidebar-visible"
|
|
2376
|
-
)?.values[0];
|
|
2377
|
-
if (sidebarProperty) {
|
|
2378
|
-
isSidebarDisplayed = sidebarProperty.content === "Yes";
|
|
2379
|
-
}
|
|
2380
|
-
const collectionSearchProperty = websiteProperties.find(
|
|
2381
|
-
(property) => property.label === "search-collection"
|
|
2382
|
-
)?.values[0];
|
|
2383
|
-
if (collectionSearchProperty) {
|
|
2384
|
-
searchCollectionUuid = collectionSearchProperty.uuid;
|
|
2385
|
-
}
|
|
2386
|
-
const supportsThemeToggleProperty = websiteProperties.find(
|
|
2387
|
-
(property) => property.label === "supports-theme-toggle"
|
|
2388
|
-
)?.values[0];
|
|
2389
|
-
if (supportsThemeToggleProperty) {
|
|
2390
|
-
supportsThemeToggle = supportsThemeToggleProperty.content === "Yes";
|
|
2391
|
-
}
|
|
2392
|
-
const {
|
|
2393
|
-
type: validatedType,
|
|
2394
|
-
status: validatedStatus,
|
|
2395
|
-
privacy: validatedPrivacy
|
|
2396
|
-
} = result.data;
|
|
2397
|
-
return {
|
|
2398
|
-
type: validatedType,
|
|
2399
|
-
privacy: validatedPrivacy,
|
|
2400
|
-
status: validatedStatus,
|
|
2401
|
-
contact,
|
|
2402
|
-
isHeaderDisplayed,
|
|
2403
|
-
headerVariant,
|
|
2404
|
-
headerAlignment,
|
|
2405
|
-
isHeaderProjectDisplayed,
|
|
2406
|
-
isFooterDisplayed,
|
|
2407
|
-
isSidebarDisplayed,
|
|
2408
|
-
supportsThemeToggle,
|
|
2409
|
-
searchCollectionUuid,
|
|
2410
|
-
logoUrl: logoUuid !== null ? `https://ochre.lib.uchicago.edu/ochre?uuid=${logoUuid}&load` : null
|
|
2411
|
-
};
|
|
2412
|
-
}
|
|
2413
|
-
async function parseWebsite(websiteTree, projectName, website) {
|
|
2414
|
-
if (!websiteTree.properties) {
|
|
2415
|
-
throw new Error("Website properties not found");
|
|
2416
|
-
}
|
|
2417
|
-
const properties = parseWebsiteProperties(
|
|
2418
|
-
Array.isArray(websiteTree.properties.property) ? websiteTree.properties.property : [websiteTree.properties.property]
|
|
2419
|
-
);
|
|
2420
|
-
if (typeof websiteTree.items === "string" || !("resource" in websiteTree.items)) {
|
|
2421
|
-
throw new Error("Website pages not found");
|
|
2422
|
-
}
|
|
2423
|
-
const resources = Array.isArray(websiteTree.items.resource) ? websiteTree.items.resource : [websiteTree.items.resource];
|
|
2424
|
-
const pages = await parseWebpages(resources);
|
|
2425
|
-
let sidebar = null;
|
|
2426
|
-
const sidebarElements = [];
|
|
2427
|
-
const sidebarTitle = {
|
|
2428
|
-
label: "",
|
|
2429
|
-
variant: "default",
|
|
2430
|
-
properties: {
|
|
2431
|
-
isNameDisplayed: false,
|
|
2432
|
-
isDescriptionDisplayed: false,
|
|
2433
|
-
isDateDisplayed: false,
|
|
2434
|
-
isCreatorsDisplayed: false
|
|
2435
|
-
}
|
|
2436
|
-
};
|
|
2437
|
-
let sidebarLayout = "start";
|
|
2438
|
-
let sidebarMobileLayout = "default";
|
|
2439
|
-
const sidebarCssStyles = [];
|
|
2440
|
-
const sidebarCssStylesMobile = [];
|
|
2441
|
-
const sidebarResource = resources.find((resource) => {
|
|
2442
|
-
const resourceProperties = resource.properties ? parseProperties(
|
|
2443
|
-
Array.isArray(resource.properties.property) ? resource.properties.property : [resource.properties.property]
|
|
2444
|
-
) : [];
|
|
2445
|
-
return resourceProperties.some(
|
|
2446
|
-
(property) => property.label === "presentation" && property.values[0]?.content === "element" && property.properties[0]?.label === "component" && property.properties[0].values[0]?.content === "sidebar"
|
|
2447
|
-
);
|
|
2448
|
-
});
|
|
2449
|
-
if (sidebarResource) {
|
|
2450
|
-
sidebarTitle.label = typeof sidebarResource.identification.label === "string" || typeof sidebarResource.identification.label === "number" || typeof sidebarResource.identification.label === "boolean" ? parseFakeString(sidebarResource.identification.label) : parseStringContent(sidebarResource.identification.label);
|
|
2451
|
-
const sidebarBaseProperties = sidebarResource.properties ? parseProperties(
|
|
2452
|
-
Array.isArray(sidebarResource.properties.property) ? sidebarResource.properties.property : [sidebarResource.properties.property]
|
|
2453
|
-
) : [];
|
|
2454
|
-
const sidebarProperties = sidebarBaseProperties.find(
|
|
2455
|
-
(property) => property.label === "presentation" && property.values[0]?.content === "element"
|
|
2456
|
-
)?.properties.find(
|
|
2457
|
-
(property) => property.label === "component" && property.values[0]?.content === "sidebar"
|
|
2458
|
-
)?.properties ?? [];
|
|
2459
|
-
const sidebarLayoutProperty = sidebarProperties.find(
|
|
2460
|
-
(property) => property.label === "layout"
|
|
2461
|
-
);
|
|
2462
|
-
if (sidebarLayoutProperty) {
|
|
2463
|
-
sidebarLayout = sidebarLayoutProperty.values[0].content;
|
|
2464
|
-
}
|
|
2465
|
-
const sidebarMobileLayoutProperty = sidebarProperties.find(
|
|
2466
|
-
(property) => property.label === "layout-mobile"
|
|
2467
|
-
);
|
|
2468
|
-
if (sidebarMobileLayoutProperty) {
|
|
2469
|
-
sidebarMobileLayout = sidebarMobileLayoutProperty.values[0].content;
|
|
2470
|
-
}
|
|
2471
|
-
const cssProperties = sidebarBaseProperties.find(
|
|
2472
|
-
(property) => property.label === "presentation" && property.values[0].content === "css"
|
|
2473
|
-
)?.properties ?? [];
|
|
2474
|
-
for (const property of cssProperties) {
|
|
2475
|
-
const cssStyle = property.values[0].content;
|
|
2476
|
-
sidebarCssStyles.push({ label: property.label, value: cssStyle });
|
|
2477
|
-
}
|
|
2478
|
-
const mobileCssProperties = sidebarBaseProperties.find(
|
|
2479
|
-
(property) => property.label === "presentation" && property.values[0].content === "css-mobile"
|
|
2480
|
-
)?.properties ?? [];
|
|
2481
|
-
for (const property of mobileCssProperties) {
|
|
2482
|
-
const cssStyle = property.values[0].content;
|
|
2483
|
-
sidebarCssStylesMobile.push({ label: property.label, value: cssStyle });
|
|
2484
|
-
}
|
|
2485
|
-
const titleProperties = sidebarBaseProperties.find(
|
|
2486
|
-
(property) => property.label === "presentation" && property.values[0].content === "title"
|
|
2487
|
-
)?.properties;
|
|
2488
|
-
if (titleProperties) {
|
|
2489
|
-
const titleVariant = getPropertyValueByLabel(titleProperties, "variant");
|
|
2490
|
-
if (titleVariant) {
|
|
2491
|
-
sidebarTitle.variant = titleVariant;
|
|
2492
|
-
}
|
|
2493
|
-
const titleShow = titleProperties.filter(
|
|
2494
|
-
(property) => property.label === "display"
|
|
2495
|
-
);
|
|
2496
|
-
if (titleShow.length > 0) {
|
|
2497
|
-
sidebarTitle.properties.isNameDisplayed = titleShow.some(
|
|
2498
|
-
(property) => property.values[0].content === "name"
|
|
2499
|
-
);
|
|
2500
|
-
sidebarTitle.properties.isDescriptionDisplayed = titleShow.some(
|
|
2501
|
-
(property) => property.values[0].content === "description"
|
|
2502
|
-
);
|
|
2503
|
-
sidebarTitle.properties.isDateDisplayed = titleShow.some(
|
|
2504
|
-
(property) => property.values[0].content === "date"
|
|
2505
|
-
);
|
|
2506
|
-
sidebarTitle.properties.isCreatorsDisplayed = titleShow.some(
|
|
2507
|
-
(property) => property.values[0].content === "creators"
|
|
2508
|
-
);
|
|
2509
|
-
}
|
|
2510
|
-
}
|
|
2511
|
-
const sidebarResources = sidebarResource.resource ? Array.isArray(sidebarResource.resource) ? sidebarResource.resource : [sidebarResource.resource] : [];
|
|
2512
|
-
for (const resource of sidebarResources) {
|
|
2513
|
-
const element = await parseWebElement(resource);
|
|
2514
|
-
sidebarElements.push(element);
|
|
2515
|
-
}
|
|
2516
|
-
}
|
|
2517
|
-
if (sidebarElements.length > 0) {
|
|
2518
|
-
sidebar = {
|
|
2519
|
-
elements: sidebarElements,
|
|
2520
|
-
title: sidebarTitle,
|
|
2521
|
-
layout: sidebarLayout,
|
|
2522
|
-
mobileLayout: sidebarMobileLayout,
|
|
2523
|
-
cssStyles: sidebarCssStyles,
|
|
2524
|
-
cssStylesMobile: sidebarCssStylesMobile
|
|
2525
|
-
};
|
|
2526
|
-
}
|
|
2527
|
-
return {
|
|
2528
|
-
uuid: websiteTree.uuid,
|
|
2529
|
-
publicationDateTime: websiteTree.publicationDateTime ? new Date(websiteTree.publicationDateTime) : null,
|
|
2530
|
-
identification: parseIdentification(websiteTree.identification),
|
|
2531
|
-
project: {
|
|
2532
|
-
name: parseFakeString(projectName),
|
|
2533
|
-
website: website !== null ? parseFakeString(website) : null
|
|
2534
|
-
},
|
|
2535
|
-
creators: websiteTree.creators ? parsePersons(
|
|
2536
|
-
Array.isArray(websiteTree.creators.creator) ? websiteTree.creators.creator : [websiteTree.creators.creator]
|
|
2537
|
-
) : [],
|
|
2538
|
-
license: parseLicense(websiteTree.availability),
|
|
2539
|
-
pages,
|
|
2540
|
-
sidebar,
|
|
2541
|
-
properties
|
|
2542
|
-
};
|
|
2543
|
-
}
|
|
2544
|
-
|
|
2545
|
-
// src/utils/fetchers/gallery.ts
|
|
2546
|
-
async function fetchGallery(uuid, filter, page, perPage) {
|
|
2547
|
-
try {
|
|
2548
|
-
const {
|
|
2549
|
-
uuid: parsedUuid,
|
|
2550
|
-
filter: parsedFilter,
|
|
2551
|
-
page: parsedPage,
|
|
2552
|
-
perPage: parsedPerPage
|
|
2553
|
-
} = gallerySchema.parse({ uuid, filter, page, perPage });
|
|
2554
|
-
const response = await fetch(
|
|
2555
|
-
`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
|
|
2556
|
-
for $q in input()/ochre[@uuid='${parsedUuid}']
|
|
2557
|
-
let $filtered := $q//items/resource[contains(lower-case(identification/label), lower-case('${parsedFilter}'))]
|
|
1
|
+
import{z as I}from"zod";var pe=I.string().uuid({message:"Invalid UUID provided"}),ue=I.object({type:I.enum(["traditional","digital-collection","plum","cedar","elm","maple","oak","palm"],{message:"Invalid website type"}),status:I.enum(["development","preview","production"],{message:"Invalid website status"}),privacy:I.enum(["public","password","private"],{message:"Invalid website privacy"})}),fe=I.enum(["annotated-document","annotated-image","bibliography","blog","button","collection","empty-space","filter-categories","iframe","iiif-viewer","image","image-gallery","n-columns","n-rows","network-graph","search-bar","table","text","timeline","video"],{message:"Invalid component"}),J=I.enum(["resource","spatialUnit","concept","period","bibliography","person","propertyValue","set","tree"]),de=I.enum(["string","integer","decimal","boolean","date","dateTime","time","coordinate","IDREF"]),ye=I.object({uuid:I.string().uuid({message:"Invalid UUID"}),filter:I.string().optional(),page:I.number().positive({message:"Page must be positive"}),perPage:I.number().positive({message:"Per page must be positive"})}).strict(),he=I.string().transform(e=>e.split(" ")).pipe(I.array(I.enum(["bold","italic","underline"]))),ge=I.string().transform(e=>e.split(" ")).pipe(I.array(I.enum(["newline","trailing","leading"]))),me=I.string().email({message:"Invalid email"});var N={searchNestedProperties:!1};function _(e,r,n=N){let{searchNestedProperties:t}=n,i=e.find(s=>s.label===r);if(i)return i;if(t){for(let s of e)if(s.properties.length>0){let o=_(s.properties,r,{searchNestedProperties:t});if(o)return o}}return null}function be(e,r,n=N){let{searchNestedProperties:t}=n,i=e.find(s=>s.label===r);if(i)return i.values.map(s=>s.content);if(t){for(let s of e)if(s.properties.length>0){let o=be(s.properties,r,{searchNestedProperties:t});if(o)return o}}return null}function h(e,r,n=N){let{searchNestedProperties:t}=n,i=be(e,r,{searchNestedProperties:t});if(i!==null&&i.length>0)return i[0];if(t){for(let s of e)if(s.properties.length>0){let o=h(s.properties,r,{searchNestedProperties:t});if(o!==null)return o}}return null}function We(e,r=N){let{searchNestedProperties:n}=r,t=new Set;for(let i of e)if(t.add(i.label),i.properties.length>0&&n){let s=We(i.properties,{searchNestedProperties:!0});for(let o of s)t.add(o)}return[...t]}function Fe(e,r,n=N){let{searchNestedProperties:t}=n;if(r.label.toLocaleLowerCase("en-US")==="all fields"||e.label.toLocaleLowerCase("en-US")===r.label.toLocaleLowerCase("en-US")){let s=e.values.some(o=>o.content===null?!1:typeof o.content=="string"?typeof r.value!="string"?!1:o.content.toLocaleLowerCase("en-US").includes(r.value.toLocaleLowerCase("en-US")):typeof o.content=="number"?typeof r.value!="number"?!1:o.content===r.value:typeof o.content=="boolean"?typeof r.value!="boolean"?!1:o.booleanValue===r.value:o.content instanceof Date&&r.value instanceof Date?o.content.getTime()===r.value.getTime():!1);return!s&&t&&(s=e.properties.some(o=>Fe(o,r,{searchNestedProperties:!0}))),s}return!1}function Be(e,r){return e.find(t=>t.lang===r)??null}function W(e){let r=e.split(" "),n=[];for(let t of r){let i=t.replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g,"").replace(/[!),.:;?\]]$/,""),s=t.indexOf(i),o=t.slice(0,s),a=t.slice(s+i.length);if(me.safeParse(i).success){n.push(o,`${o}<ExternalLink href="mailto:${i}">${i}</ExternalLink>${a}`);continue}n.push(t)}return n.join(" ")}function Ae(e,r){let n=e,t=he.safeParse(r);if(!t.success)return console.warn(`Invalid render options string provided: \u201C${r}\u201D`),e;for(let i of t.data)switch(i){case"bold":{n=`**${n}**`;break}case"italic":{n=`*${n}*`;break}case"underline":{n=`_${n}_`;break}}return n.replaceAll("'","'")}function Q(e,r){let n=e,t=ge.safeParse(r);if(!t.success)return console.warn(`Invalid whitespace string provided: \u201C${r}\u201D`),e;for(let i of t.data)switch(i){case"newline":{n=`<br />
|
|
2
|
+
${n}`;break}case"trailing":{n=`${n} `;break}case"leading":{n=` ${n}`;break}}return n.replaceAll("'","'")}function f(e){let r="";return typeof e=="string"?r=e:typeof e=="number"?r=e.toString():typeof e=="boolean"&&(r=e?"Yes":"No"),r.replaceAll("'","'").replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}function z(e){let r="";switch(typeof e.string){case"string":{r=e.string;break}case"number":case"boolean":{r=f(e.string);break}case"object":{let n=Array.isArray(e.string)?e.string:[e.string];for(let t of n)if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")r+=f(t);else{let i=t.rend!=null?Ae(f(t.content),t.rend):f(t.content),s=t.whitespace!=null?Q(i,t.whitespace):i;r+=s}break}default:{r="";break}}return r.replaceAll("'","'").replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}function R(e,r){if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return W(f(e));if("whitespace"in e&&!("content"in e)&&!("string"in e))return e.whitespace==="newline"?`
|
|
3
|
+
`:"";if("links"in e){let t="";typeof e.string=="object"?t=w(e.string):t=f(e.string).replaceAll("<",String.raw`\<`).replaceAll("{",String.raw`\{`);let i=Array.isArray(e.links)?e.links:[e.links];for(let s of i)if("resource"in s){let o=Array.isArray(s.resource)?s.resource[0]:s.resource,a=null;switch(o.content!=null&&(a=f(o.content).replaceAll("<",String.raw`\<`).replaceAll("{",String.raw`\{`)),o.type){case"image":return o.rend==="inline"?`<InlineImage uuid="${o.uuid}" ${a!==null?`content="${a}"`:""} height={${o.height?.toString()??"null"}} width={${o.width?.toString()??"null"}} />`:o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="image"${a!==null?` content="${a}"`:""}>${t}</ExternalLink>`:`<TooltipSpan type="image" ${a!==null?`content="${a}"`:""}>${t}</TooltipSpan>`;case"internalDocument":return a?.toLocaleLowerCase("en-US").includes("footnote")?(r&&r.push({uuid:o.uuid,label:t,content:""}),` <Footnote uuid="${o.uuid}"${t?` label="${t}"`:""}${a!==null?` content="${a}"`:""} />`):`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="internalDocument" ${a!==null?`content="${a}"`:""}>${t}</ExternalLink>`;case"externalDocument":return o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="externalDocument" ${a!==null?`content="${a}"`:""}>${t}</ExternalLink>`:`<TooltipSpan type="externalDocument" ${a!==null?`content="${a}"`:""}>${t}</TooltipSpan>`;case"webpage":return`<ExternalLink href="${o.href}" type="webpage" ${a!==null?`content="${a}"`:""}>${t}</ExternalLink>`;default:return""}}else if("concept"in s){let o=Array.isArray(s.concept)?s.concept[0]:s.concept;return o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="concept">${t}</ExternalLink>`:`<TooltipSpan type="concept">${t}</TooltipSpan>`}else if("set"in s){let o=Array.isArray(s.set)?s.set[0]:s.set;return o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="set">${t}</ExternalLink>`:`<TooltipSpan type="set">${t}</TooltipSpan>`}else if("person"in s){let o=Array.isArray(s.person)?s.person[0]:s.person,a=o.identification?["string","number","boolean"].includes(typeof o.identification.label)?f(o.identification.label):w(o.identification.label):null;return o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="${o.type??"person"}" ${a!==null?`content="${a}"`:""}>${t}</ExternalLink>`:`<TooltipSpan type="${o.type??"person"}" ${a!==null?`content="${a}"`:""}>${t}</TooltipSpan>`}else if("bibliography"in s){let o=Array.isArray(s.bibliography)?s.bibliography[0]:s.bibliography;return o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="${o.type??"bibliography"}">${t}</ExternalLink>`:`<TooltipSpan type="bibliography">${t}</TooltipSpan>`}}let n="";if("string"in e){let t=Array.isArray(e.string)?e.string:[e.string];for(let i of t)n+=R(i,r);return"whitespace"in e&&e.whitespace!=null&&(n=Q(W(n),e.whitespace)),n.replaceAll("'","'").replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}else n=f(e.content),e.rend!=null&&(n=Ae(W(n),e.rend)),e.whitespace!=null&&(n=Q(W(n),e.whitespace));return n.replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}function w(e,r="eng"){switch(typeof e.content){case"string":case"number":case"boolean":return f(e.content);case"object":if(Array.isArray(e.content)){let n=Be(e.content,r);if(n)return z(n);{let t=e.content[0];if(!t)throw new Error(`No string item found for language \u201C${r}\u201D in the following content:
|
|
4
|
+
${JSON.stringify(e.content)}.`);return z(t)}}else return z(e.content);default:return String(e.content).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}}function Y(e){let r=e.find(t=>J.safeParse(t).success);if(!r){let t=e.find(i=>!["uuid","uuidBelongsTo","belongsTo","publicationDateTime","metadata","languages"].includes(i));throw new Error(`Invalid OCHRE data; found unexpected "${t}" key`)}return J.parse(r)}async function we(e){try{let r=pe.parse(e),n=await fetch(`https://ochre.lib.uchicago.edu/ochre?uuid=${r}&format=json&lang="*"`);if(!n.ok)throw new Error("Failed to fetch OCHRE data");let t=await n.json();if(!("ochre"in t))throw new Error("Invalid OCHRE data: API response missing 'ochre' key");return[null,t]}catch(r){return[r instanceof Error?r.message:"Unknown error",null]}}async function ve(e,r){try{let[n,t]=await we(e);if(n!==null)throw new Error(n);let i=Y(Object.keys(t.ochre)),s;switch(i){case"resource":{if(!("resource"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'resource' key");s=re(t.ochre.resource);break}case"spatialUnit":{if(!("spatialUnit"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'spatialUnit' key");s=ne(t.ochre.spatialUnit);break}case"concept":{if(!("concept"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'concept' key");s=ie(t.ochre.concept);break}case"period":{if(!("period"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'period' key");s=Z(t.ochre.period);break}case"bibliography":{if(!("bibliography"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'bibliography' key");s=ee(t.ochre.bibliography);break}case"person":{if(!("person"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'person' key");s=X(t.ochre.person);break}case"propertyValue":{if(!("propertyValue"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");s=te(t.ochre.propertyValue);break}case"set":{if(!("set"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'set' key");s=ke(t.ochre.set);break}case"tree":{if(!("tree"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'tree' key");s=Se(t.ochre.tree);break}default:throw new Error("Invalid category")}let o=Pe(t.ochre.metadata),a={uuid:t.ochre.uuidBelongsTo,abbreviation:f(t.ochre.belongsTo)};return{error:null,metadata:o,belongsTo:a,item:s,category:r}}catch(n){return{error:n instanceof Error?n.message:"Unknown error",metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}function v(e){try{let r={label:["string","number","boolean"].includes(typeof e.label)?f(e.label):w(e.label),abbreviation:""};for(let n of Object.keys(e).filter(t=>t!=="label"))r[n]=w(e[n]);return r}catch(r){return console.error(r),{label:"",abbreviation:""}}}function je(e){return e==null?["eng"]:Array.isArray(e)?e.map(r=>w(r)):[w(e)]}function Pe(e){let r={label:"",abbreviation:""};if(e.item)if(e.item.label||e.item.abbreviation){let i="",s="";e.item.label&&(i=w(e.item.label)),e.item.abbreviation&&(s=w(e.item.abbreviation)),r={label:i,abbreviation:s}}else r=v(e.item.identification);let n=null,t=e.project?.identification?v(e.project.identification):null;return t&&(n={...t,website:e.project?.identification.website??null}),{project:n?{identification:n}:null,item:e.item?{identification:r,category:e.item.category,type:e.item.type,maxLength:e.item.maxLength??null}:null,dataset:w(e.dataset),publisher:w(e.publisher),languages:je(e.language),identifier:w(e.identifier),description:w(e.description)}}function oe(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,number:e.n,content:f(e.content)}}function H(e){return{nodes:(Array.isArray(e.context)?e.context:[e.context]).map(t=>{let i=[];if("spatialUnit"in t&&t.spatialUnit){let s=Array.isArray(t.spatialUnit)?t.spatialUnit:[t.spatialUnit];for(let o of s)i.push(oe(o))}return{tree:oe(t.tree),project:oe(t.project),spatialUnit:i}}),displayPath:e.displayPath}}function B(e){return typeof e.license=="string"?null:{content:e.license.content,url:e.license.target}}function X(e){return{uuid:e.uuid,category:"person",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,date:e.date!=null?new Date(e.date):null,identification:e.identification?v(e.identification):null,content:e.content!=null?f(e.content):null}}function L(e){let r=[];for(let n of e)r.push(X(n));return r}function Ue(e){let r="resource"in e?e.resource:"spatialUnit"in e?e.spatialUnit:"concept"in e?e.concept:"set"in e?e.set:"tree"in e?e.tree:"person"in e?e.person:"bibliography"in e?e.bibliography:"epigraphicUnit"in e?e.epigraphicUnit:"propertyValue"in e?e.propertyValue:null;if(!r)throw new Error(`Invalid link provided: ${JSON.stringify(e,null,2)}`);let n=Array.isArray(r)?r:[r],t=[];for(let i of n){let s={category:"resource"in e?"resource":"spatialUnit"in e?"spatialUnit":"concept"in e?"concept":"set"in e?"set":"person"in e?"person":"tree"in e?"tree":"bibliography"in e?"bibliography":"epigraphicUnit"in e?"epigraphicUnit":"propertyValue"in e?"propertyValue":null,content:"content"in i&&i.content!=null?f(i.content):null,href:"href"in i&&i.href!=null?i.href:null,uuid:i.uuid,type:i.type??null,identification:i.identification?v(i.identification):null,image:null,bibliographies:"bibliography"in e?G(Array.isArray(e.bibliography)?e.bibliography:[e.bibliography]):null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null};"height"in i&&i.height!=null&&i.width!=null&&i.heightPreview!=null&&i.widthPreview!=null&&(s.image={isInline:i.rend==="inline",isPrimary:i.isPrimary??!1,heightPreview:i.heightPreview,widthPreview:i.widthPreview,height:i.height,width:i.width}),t.push(s)}return t}function j(e){let r=[];for(let n of e)r.push(...Ue(n));return r}function se(e,r="eng"){let n="",t=[],i=Array.isArray(e)?e.find(s=>s.lang===r):e;if(typeof i.string=="string"||typeof i.string=="number"||typeof i.string=="boolean")n+=W(f(i.string));else{let s=Array.isArray(i.string)?i.string:[i.string];for(let o of s)n+=R(o,t)}return{content:n,footnotes:t}}function Ie(e){return{publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,identification:e.identification?v(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?f(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?f(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function le(e,r="eng"){let n=[];for(let t of e){if(typeof t=="string"){if(t==="")continue;n.push({number:-1,title:null,content:t});continue}let i="",s=Array.isArray(t.content)?t.content:[t.content],o=s.find(a=>a.lang===r);if(!o&&(o=s[0],!o))throw new Error(`Note does not have a valid content item: ${JSON.stringify(t,null,2)}`);typeof o.string=="string"||typeof o.string=="number"||typeof o.string=="boolean"?i=W(f(o.string)):i=W(se(o).content),n.push({number:t.noteNo,title:o.title!=null?f(o.title):null,content:i})}return n}function xe(e){if(typeof e=="string"){let[r,n]=e.split(", ");return{latitude:Number(r),longitude:Number(n),type:null,label:null}}return{latitude:e.latitude,longitude:e.longitude,type:e.coord?.coordType??null,label:e.coord?.coordLabel!=null?f(e.coord.coordLabel):null}}function Te(e){return{number:e.observationNo,date:e.date!=null?new Date(e.date):null,observers:e.observers!=null?f(e.observers).split(";").map(r=>r.trim()):[],notes:e.notes?le(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?j(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Ve(e){let r=[];for(let n of e)r.push(Te(n));return r}function Ne(e){let r=[];for(let n of e)r.push({date:n.dateTime!=null?new Date(n.dateTime):null,label:w(n.label),agent:n.agent?{uuid:n.agent.uuid,content:f(n.agent.content)}:null});return r}function He(e,r="eng"){let t=("value"in e&&e.value?Array.isArray(e.value)?e.value:[e.value]:[]).map(i=>{let s=null,o=null;if(typeof i=="string"||typeof i=="number"||typeof i=="boolean")return s=f(i),{content:s,booleanValue:o,type:"string",category:"value",uuid:null,publicationDateTime:null,unit:null};{switch(i.type){case"integer":case"decimal":{s=Number(i.content);break}case"dateTime":{s=i.content?typeof i.content=="string"?new Date(i.content):new Date(w({content:i.content})):null;break}default:{"slug"in i&&i.slug!=null?s=f(i.slug):i.content!=null&&(s=w({content:i.content})),i.type==="boolean"&&(o=i.booleanValue??null);break}}let a="string";if(i.type!=null){let{data:c,error:g}=de.safeParse(i.type);if(g)throw new Error(`Invalid property value content type: "${i.type}"`);a=c}return{content:s,booleanValue:o,type:a,category:i.category??"value",uuid:i.uuid??null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null,unit:i.unit??null}}});return{label:w(e.label,r).replace(/\s*\.{3}$/,"").trim(),values:t,comment:e.comment!=null?f(e.comment):null,properties:e.property?D(Array.isArray(e.property)?e.property:[e.property]):[]}}function D(e,r="eng"){let n=[];for(let t of e)n.push(He(t,r));return n}function Me(e){let r=[];for(let n of e)r.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?D(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return r}function Ye(e){let r={area:[],width:e.width,height:e.height},n=Array.isArray(e.area)?e.area:[e.area];for(let t of n)r.area.push({uuid:t.uuid,publicationDateTime:t.publicationDateTime!=null?new Date(t.publicationDateTime):null,type:t.type,title:f(t.title),shape:t.shape==="rect"?"rectangle":"polygon",coords:t.coords.split(",").map(i=>Number.parseInt(i))});return r}function Z(e){return{uuid:e.uuid,category:"period",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,number:e.n??null,identification:v(e.identification),description:e.description?w(e.description):null}}function q(e){let r=[];for(let n of e)r.push(Z(n));return r}function ee(e){let r=null;return e.source?.resource&&(r={uuid:e.source.resource.uuid,publicationDateTime:e.source.resource.publicationDateTime?new Date(e.source.resource.publicationDateTime):null,type:e.source.resource.type,identification:v(e.source.resource.identification)}),{uuid:e.uuid,category:"bibliography",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,number:e.n??null,identification:e.identification?v(e.identification):null,projectIdentification:e.project?.identification?v(e.project.identification):null,context:e.context?H(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?f("default:span"in e.citationFormatSpan?e.citationFormatSpan["default:span"].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?f("default:div"in e.referenceFormatDiv?e.referenceFormatDiv["default:div"]["default:div"].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?L(Array.isArray(e.publicationInfo.publishers.publishers.person)?e.publicationInfo.publishers.publishers.person:[e.publicationInfo.publishers.publishers.person]):[],startDate:e.publicationInfo?.startDate?new Date(e.publicationInfo.startDate.year,e.publicationInfo.startDate.month,e.publicationInfo.startDate.day):null},entryInfo:e.entryInfo?{startIssue:f(e.entryInfo.startIssue),startVolume:f(e.entryInfo.startVolume)}:null,source:{resource:r,documentUrl:e.sourceDocument?`https://ochre.lib.uchicago.edu/ochre?uuid=${e.sourceDocument.uuid}&load`:null},periods:e.periods?q(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?L(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function G(e){let r=[];for(let n of e)r.push(ee(n));return r}function te(e){return{uuid:e.uuid,category:"propertyValue",n:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?H(e.context):null,availability:e.availability?B(e.availability):null,identification:v(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?f(e.description):w(e.description):"",notes:e.notes?le(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?j(Array.isArray(e.links)?e.links:[e.links]):[]}}function De(e){let r=[];for(let n of e)r.push(te(n));return r}function Se(e){let r=[];e.creators&&(r=L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let n=null;e.date!=null&&(n=new Date(e.date));let t=[],i=[],s=[],o=[],a=[],l=[],c=[];return typeof e.items!="string"&&"resource"in e.items&&(t=M(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!="string"&&"spatialUnit"in e.items&&(i=Oe(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!="string"&&"concept"in e.items&&(s=Ce(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!="string"&&"period"in e.items&&(o=q(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!="string"&&"bibliography"in e.items&&(a=G(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!="string"&&"person"in e.items&&(l=L(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!="string"&&"propertyValue"in e.items&&(c=De(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue])),{uuid:e.uuid,category:"tree",publicationDateTime:new Date(e.publicationDateTime),identification:v(e.identification),creators:r,license:B(e.availability),date:n,type:e.type,number:e.n,items:{resources:t,spatialUnits:i,concepts:s,periods:o,bibliographies:a,persons:l,propertyValues:c},properties:e.properties?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function ke(e){if(typeof e.items=="string")throw new TypeError("Invalid OCHRE data: Set has no items");let r=Y(Object.keys(e.items)),n=[];switch(r){case"resource":{if(!("resource"in e.items))throw new Error("Invalid OCHRE data: Set has no resources");n=M(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource]);break}case"spatialUnit":{if(!("spatialUnit"in e.items))throw new Error("Invalid OCHRE data: Set has no spatial units");n=Oe(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit]);break}case"concept":{if(!("concept"in e.items))throw new Error("Invalid OCHRE data: Set has no concepts");n=Ce(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break}case"period":{if(!("period"in e.items))throw new Error("Invalid OCHRE data: Set has no periods");n=q(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break}case"bibliography":{if(!("bibliography"in e.items))throw new Error("Invalid OCHRE data: Set has no bibliographies");n=G(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography]);break}case"person":{if(!("person"in e.items))throw new Error("Invalid OCHRE data: Set has no persons");n=L(Array.isArray(e.items.person)?e.items.person:[e.items.person]);break}case"propertyValue":{if(!("propertyValue"in e.items))throw new Error("Invalid OCHRE data: Set has no property values");n=De(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break}default:throw new Error("Invalid OCHRE data: Set has no items or is malformed")}return{uuid:e.uuid,category:"set",itemCategory:r,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,date:e.date!=null?new Date(e.date):null,license:B(e.availability),identification:v(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?["string","number","boolean"].includes(typeof e.description)?f(e.description):w(e.description):"",creators:e.creators?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:n}}function re(e){return{uuid:e.uuid,category:"resource",publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,format:e.format??null,context:"context"in e&&e.context?H(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,copyright:"copyright"in e&&e.copyright!=null?f(e.copyright):null,identification:v(e.identification),date:e.date!=null?new Date(e.date):null,image:e.image?Ie(e.image):null,creators:e.creators?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?le(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?f(e.description):w(e.description):"",document:e.document&&"content"in e.document?se(e.document.content):null,href:e.href??null,imageMap:e.imagemap?Ye(e.imagemap):null,periods:e.periods?q(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?j(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?j(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?G(Array.isArray(e.citedBibliography.reference)?e.citedBibliography.reference:[e.citedBibliography.reference]):[],resources:e.resource?M(Array.isArray(e.resource)?e.resource:[e.resource]):[]}}function M(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(re(t));return r}function ne(e){return{uuid:e.uuid,category:"spatialUnit",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type,number:e.n,context:"context"in e&&e.context?H(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,identification:v(e.identification),image:e.image?Ie(e.image):null,description:e.description?["string","number","boolean"].includes(typeof e.description)?f(e.description):w(e.description):"",coordinates:e.coordinates?xe(e.coordinates):e.coordinate?xe(e.coordinate):null,observations:"observations"in e&&e.observations?Ve(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[Te(e.observation)]:[],events:"events"in e&&e.events?Ne(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:"properties"in e&&e.properties?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Oe(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(ne(t));return r}function ie(e){return{uuid:e.uuid,category:"concept",publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,number:e.n,license:"availability"in e&&e.availability?B(e.availability):null,context:"context"in e&&e.context?H(e.context):null,identification:v(e.identification),interpretations:Me(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])}}var ae=async(e,r)=>{let n=[];for(let t of e)if((t.properties?D(Array.isArray(t.properties.property)?t.properties.property:[t.properties.property]):[]).find(o=>o.label==="presentation"&&o.values[0].content===r))switch(r){case"element":{let o=await K(t);n.push(o);break}case"page":{let o=await Ee(t);o&&n.push(o);break}case"block":{let o=await ce(t);o&&n.push(o);break}}return n};function Ce(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(ie(t));return r}async function qe(e,r){let n=fe.parse(e.values[0].content),t={component:n},i=r.links?j(Array.isArray(r.links)?r.links:[r.links]):[],s=i.filter(a=>a.type==="image"||a.type==="IIIF"),o=r.document&&"content"in r.document?se(r.document.content):null;if(o===null){let a=i.find(l=>l.type==="internalDocument");if(a){let{item:l,error:c}=await ve(a.uuid,"resource");if(c!==null)throw new Error("Failed to fetch OCHRE data");o=l.document}}switch(n){case"annotated-document":{if(!o)throw new Error(`Document not found for the following component: \u201C${n}\u201D`);t.document=o;break}case"annotated-image":{if(s.length===0)throw new Error(`Image link not found for the following component: \u201C${n}\u201D`);let a=h(e.properties,"is-searchable")==="Yes";t.imageUuid=s[0].uuid,t.isSearchable=a;break}case"bibliography":{let a=i.find(c=>c.category==="bibliography");if(!a)throw new Error(`Bibliography link not found for the following component: \u201C${n}\u201D`);if(!a.bibliographies)throw new Error(`Bibliography not found for the following component: \u201C${n}\u201D`);let l=h(e.properties,"layout");l??="long",t.bibliographies=a.bibliographies,t.layout=l;break}case"blog":{let a=i.find(l=>l.category==="tree");if(!a)throw new Error(`Blog link not found for the following component: \u201C${n}\u201D`);t.blogId=a.uuid;break}case"button":{let a=h(e.properties,"variant");a??="default";let l=!1,c=h(e.properties,"navigate-to");if(c===null){if(c=h(e.properties,"link-to"),c===null)throw new Error(`Properties \u201Cnavigate-to\u201D or \u201Clink-to\u201D not found for the following component: \u201C${n}\u201D`);l=!0}let g=null,m=h(e.properties,"icon");m!==null&&(g=m),t.variant=a,t.href=c,t.isExternal=l,t.label=["string","number","boolean"].includes(typeof r.identification.label)?f(r.identification.label):w(r.identification.label),t.icon=g;break}case"collection":{let a=i.find(x=>x.category==="set");if(!a)throw new Error(`Collection link not found for the following component: \u201C${n}\u201D`);let l=h(e.properties,"variant");l??="full";let c=h(e.properties,"item-variant");c??="default";let g=!1,m=h(e.properties,"show-count");m!==null&&(g=m==="Yes");let P=!1,d=h(e.properties,"is-searchable");d!==null&&(P=d==="Yes");let y=h(e.properties,"layout");y??="image-start",t.collectionId=a.uuid,t.variant=l,t.itemVariant=c,t.isSearchable=P,t.showCount=g,t.layout=y;break}case"empty-space":{let a=h(e.properties,"height"),l=h(e.properties,"width");t.height=a,t.width=l;break}case"filter-categories":{let a=i.find(l=>l.category==="set");if(!a)throw new Error(`Filter link not found for the following component: \u201C${n}\u201D`);t.filterId=a.uuid;break}case"iframe":{let a=i.find(g=>g.type==="webpage")?.href;if(!a)throw new Error(`URL not found for the following component: \u201C${n}\u201D`);let l=h(e.properties,"height"),c=h(e.properties,"width");t.href=a,t.height=l,t.width=c;break}case"iiif-viewer":{let a=i.find(l=>l.type==="IIIF");if(!a)throw new Error(`Manifest link not found for the following component: \u201C${n}\u201D`);t.IIIFId=a.uuid;break}case"image":{if(s.length===0)throw new Error(`Image link not found for the following component: \u201C${n}\u201D`);let a=[];for(let $ of s)a.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${$.uuid}&load`,label:$.identification?.label??null,width:$.image?.width??0,height:$.image?.height??0});let l=h(e.properties,"variant");l??="default";let c=h(e.properties,"layout-caption");c??="bottom";let g=null,m=h(e.properties,"width");m!==null&&(typeof m=="number"?g=m:typeof m=="string"&&(g=Number.parseFloat(m)));let P=null,d=h(e.properties,"height");d!==null&&(typeof d=="number"?P=d:typeof d=="string"&&(P=Number.parseFloat(d)));let y=!0,x=h(e.properties,"is-full-width");x!==null&&(y=x==="Yes");let S=!0,b=h(e.properties,"is-full-height");b!==null&&(S=b==="Yes");let p=h(e.properties,"image-quality");p??="high";let k=h(e.properties,"caption-source");k??="name";let O=h(e.properties,"alt-text-source");O??="name";let C=!1,u=h(e.properties,"is-transparent");u!==null&&(C=u==="Yes");let T=!1,E=h(e.properties,"is-cover");E!==null&&(T=E==="Yes");let U=null;if(a.length>1){let $=_(e.properties,"variant"),V=5;if($&&$.values[0].content==="carousel"){let F=h($.properties,"seconds-per-image");F!==null&&(typeof F=="number"?V=F:typeof F=="string"&&(V=Number.parseFloat(F)))}U={secondsPerImage:V}}t.images=a,t.variant=l,t.width=g,t.height=P,t.isFullWidth=y,t.isFullHeight=S,t.imageQuality=p,t.captionLayout=c,t.captionSource=k,t.altTextSource=O,t.isTransparentBackground=C,t.isCover=T,t.carouselOptions=U;break}case"image-gallery":{let a=i.find(c=>c.category==="tree"||c.category==="set");if(!a)throw new Error(`Image gallery link not found for the following component: \u201C${n}\u201D`);let l=h(e.properties,"is-searchable")==="Yes";t.galleryId=a.uuid,t.isSearchable=l;break}case"n-columns":{let a=r.resource?await ae(Array.isArray(r.resource)?r.resource:[r.resource],"element"):[];t.columns=a;break}case"n-rows":{let a=r.resource?await ae(Array.isArray(r.resource)?r.resource:[r.resource],"element"):[];t.rows=a;break}case"network-graph":break;case"table":{let a=i.find(l=>l.category==="set");if(!a)throw new Error(`Table link not found for the following component: \u201C${n}\u201D`);t.tableId=a.uuid;break}case"search-bar":{let a=h(e.properties,"variant");a??="default",t.variant=a;break}case"text":{if(!o)throw new Error(`Document not found for the following component: \u201C${n}\u201D`);let a=h(e.properties,"variant");a??="block";let l=h(e.properties,"heading");t.variant=a,t.heading=l,t.content=o.content;break}case"timeline":{let a=i.find(l=>l.category==="tree");if(!a)throw new Error(`Timeline link not found for the following component: \u201C${n}\u201D`);t.timelineId=a.uuid;break}case"video":{let a=i.find(c=>c.type==="video");if(!a)throw new Error(`Video link not found for the following component: \u201C${n}\u201D`);let l=h(e.properties,"chapters-displayed");l??="Yes",t.videoId=a.uuid,t.isChaptersDislayed=l==="Yes";break}default:{console.warn(`Invalid or non-implemented component name \u201C${n}\u201D for the following element: \u201C${w(r.identification.label)}\u201D`);break}}return t}async function K(e){let r=v(e.identification),t=(e.properties?.property?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]).find(b=>b.label==="presentation");if(!t)throw new Error(`Presentation property not found for element \u201C${r.label}\u201D`);let i=t.properties.find(b=>b.label==="component");if(!i)throw new Error(`Component for element \u201C${r.label}\u201D not found`);let s=await qe(i,e),o=e.properties?.property?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],a=o.find(b=>b.label==="presentation"&&b.values[0].content==="css")?.properties??[],l=[];for(let b of a){let p=b.values[0].content;l.push({label:b.label,value:p})}let c=o.find(b=>b.label==="presentation"&&b.values[0].content==="css-mobile")?.properties??[],g=[];for(let b of c){let p=b.values[0].content;g.push({label:b.label,value:p})}let m=o.find(b=>b.label==="presentation"&&b.values[0].content==="title")?.properties,P="default",d=!1,y=!1,x=!1,S=!1;if(m){let b=h(m,"variant");b&&(P=b);let p=m.filter(k=>k.label==="display");p.length>0&&(d=p.some(k=>k.values[0].content==="name"),y=p.some(k=>k.values[0].content==="description"),x=p.some(k=>k.values[0].content==="date"),S=p.some(k=>k.values[0].content==="creators"))}return{uuid:e.uuid,type:"element",title:{label:r.label,variant:P,properties:{isNameDisplayed:d,isDescriptionDisplayed:y,isDateDisplayed:x,isCreatorsDisplayed:S}},cssStyles:l,cssStylesMobile:g,...s}}async function Ee(e){let r=e.properties?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(r.length===0||r.find(p=>p.label==="presentation")?.values[0]?.content!=="page")return null;let n=v(e.identification),t=e.slug;if(t===void 0)throw new Error(`Slug not found for page \u201C${n.label}\u201D`);let s=(e.links?j(Array.isArray(e.links)?e.links:[e.links]):[]).find(p=>p.type==="image"||p.type==="IIIF"),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let p of o){let k=p.properties?D(Array.isArray(p.properties.property)?p.properties.property:[p.properties.property]):[],O=h(k,"presentation");if(O!=null)switch(O){case"element":{let C=await K(p);a.push(C);break}case"block":{let C=await ce(p);C&&a.push(C);break}}}let l=e.resource?await ae(Array.isArray(e.resource)?e.resource:[e.resource],"page"):[],c=!0,g="default",m="default",P=!0,d=r.find(p=>p.label==="presentation"&&p.values[0]?.content==="page")?.properties;if(d){let p=d.find(u=>u.label==="header")?.values[0];p&&(c=p.content==="Yes");let k=d.find(u=>u.label==="width")?.values[0];k&&(g=k.content);let O=d.find(u=>u.label==="variant")?.values[0];O&&(m=O.content);let C=d.find(u=>u.label==="sidebar-visible")?.values[0];C&&(P=C.content==="Yes")}let y=r.find(p=>p.label==="presentation"&&p.values[0]?.content==="css")?.properties,x=[];if(y)for(let p of y)x.push({label:p.label,value:p.values[0].content});let S=r.find(p=>p.label==="presentation"&&p.values[0]?.content==="css-mobile")?.properties,b=[];if(S)for(let p of S)b.push({label:p.label,value:p.values[0].content});return{title:n.label,slug:t,items:a,properties:{displayedInHeader:c,width:g,variant:m,backgroundImageUrl:s?`https://ochre.lib.uchicago.edu/ochre?uuid=${s.uuid}&load`:null,isSidebarDisplayed:P,cssStyles:x,cssStylesMobile:b},webpages:l}}async function Ge(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n){let i=await Ee(t);i&&r.push(i)}return r}async function ce(e){let r={uuid:e.uuid,type:"block",layout:"vertical",items:[],properties:{spacing:void 0,gap:void 0,alignItems:"start",justifyContent:"stretch"},propertiesMobile:null,cssStyles:[],cssStylesMobile:[]},n=e.properties?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],t=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="block")?.properties;if(t){let l=t.find(y=>y.label==="layout")?.values[0];l&&(r.layout=l.content);let c=t.find(y=>y.label==="spacing")?.values[0];c&&(r.properties.spacing=c.content);let g=t.find(y=>y.label==="gap")?.values[0];g&&(r.properties.gap=g.content);let m=t.find(y=>y.label==="align-items")?.values[0];m&&(r.properties.alignItems=m.content);let P=t.find(y=>y.label==="justify-content")?.values[0];P&&(r.properties.justifyContent=P.content);let d=t.find(y=>y.label==="overwrite-mobile");if(d){let y=d.properties,x={};for(let S of y)x[S.label]=S.values[0].content;r.propertiesMobile=x}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let l of i){let c=l.properties?D(Array.isArray(l.properties.property)?l.properties.property:[l.properties.property]):[],g=h(c,"presentation");if(g!=null)switch(g){case"element":{let m=await K(l);s.push(m);break}case"block":{let m=await ce(l);m&&s.push(m);break}}}r.items=s;let o=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="css")?.properties;if(o)for(let l of o)r.cssStyles.push({label:l.label,value:l.values[0].content});let a=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="css-mobile")?.properties;if(a)for(let l of a)r.cssStylesMobile.push({label:l.label,value:l.values[0].content});return r}function Ke(e){let n=D(e).find(A=>A.label==="presentation")?.properties;if(!n)throw new Error("Presentation property not found");let t=n.find(A=>A.label==="webUI")?.values[0]?.content;if(t==null)throw new Error("Website type not found");let i=n.find(A=>A.label==="status")?.values[0]?.content;if(i==null)throw new Error("Website status not found");let s=n.find(A=>A.label==="privacy")?.values[0]?.content;s??="public";let o=ue.safeParse({type:t,status:i,privacy:s});if(!o.success)throw new Error(`Invalid website properties: ${o.error.message}`);let a=null,l=n.find(A=>A.label==="contact");if(l){let[A,Le]=(l.values[0]?.content).split(";");a={name:A,email:Le??null}}let c=n.find(A=>A.label==="logo")?.values[0]?.uuid??null,g=!0,m="default",P="start",d=!0,y=!0,x=!1,S=null,b=!0,p=n.find(A=>A.label==="navbar-visible")?.values[0];p&&(g=p.content==="Yes");let k=n.find(A=>A.label==="navbar-variant")?.values[0];k&&(m=k.content);let O=n.find(A=>A.label==="navbar-alignment")?.values[0];O&&(P=O.content);let C=n.find(A=>A.label==="navbar-project-visible")?.values[0];C&&(d=C.content==="Yes");let u=n.find(A=>A.label==="footer-visible")?.values[0];u&&(y=u.content==="Yes");let T=n.find(A=>A.label==="sidebar-visible")?.values[0];T&&(x=T.content==="Yes");let E=n.find(A=>A.label==="search-collection")?.values[0];E&&(S=E.uuid);let U=n.find(A=>A.label==="supports-theme-toggle")?.values[0];U&&(b=U.content==="Yes");let{type:$,status:V,privacy:F}=o.data;return{type:$,privacy:F,status:V,contact:a,isHeaderDisplayed:g,headerVariant:m,headerAlignment:P,isHeaderProjectDisplayed:d,isFooterDisplayed:y,isSidebarDisplayed:x,supportsThemeToggle:b,searchCollectionUuid:S,logoUrl:c!==null?`https://ochre.lib.uchicago.edu/ochre?uuid=${c}&load`:null}}async function $e(e,r,n){if(!e.properties)throw new Error("Website properties not found");let t=Ke(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]);if(typeof e.items=="string"||!("resource"in e.items))throw new Error("Website pages not found");let i=Array.isArray(e.items.resource)?e.items.resource:[e.items.resource],s=await Ge(i),o=null,a=[],l={label:"",variant:"default",properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},c="start",g="default",m=[],P=[],d=i.find(y=>(y.properties?D(Array.isArray(y.properties.property)?y.properties.property:[y.properties.property]):[]).some(S=>S.label==="presentation"&&S.values[0]?.content==="element"&&S.properties[0]?.label==="component"&&S.properties[0].values[0]?.content==="sidebar"));if(d){l.label=typeof d.identification.label=="string"||typeof d.identification.label=="number"||typeof d.identification.label=="boolean"?f(d.identification.label):w(d.identification.label);let y=d.properties?D(Array.isArray(d.properties.property)?d.properties.property:[d.properties.property]):[],x=y.find(u=>u.label==="presentation"&&u.values[0]?.content==="element")?.properties.find(u=>u.label==="component"&&u.values[0]?.content==="sidebar")?.properties??[],S=x.find(u=>u.label==="layout");S&&(c=S.values[0].content);let b=x.find(u=>u.label==="layout-mobile");b&&(g=b.values[0].content);let p=y.find(u=>u.label==="presentation"&&u.values[0].content==="css")?.properties??[];for(let u of p){let T=u.values[0].content;m.push({label:u.label,value:T})}let k=y.find(u=>u.label==="presentation"&&u.values[0].content==="css-mobile")?.properties??[];for(let u of k){let T=u.values[0].content;P.push({label:u.label,value:T})}let O=y.find(u=>u.label==="presentation"&&u.values[0].content==="title")?.properties;if(O){let u=h(O,"variant");u&&(l.variant=u);let T=O.filter(E=>E.label==="display");T.length>0&&(l.properties.isNameDisplayed=T.some(E=>E.values[0].content==="name"),l.properties.isDescriptionDisplayed=T.some(E=>E.values[0].content==="description"),l.properties.isDateDisplayed=T.some(E=>E.values[0].content==="date"),l.properties.isCreatorsDisplayed=T.some(E=>E.values[0].content==="creators"))}let C=d.resource?Array.isArray(d.resource)?d.resource:[d.resource]:[];for(let u of C){let T=await K(u);a.push(T)}}return a.length>0&&(o={elements:a,title:l,layout:c,mobileLayout:g,cssStyles:m,cssStylesMobile:P}),{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:v(e.identification),project:{name:f(r),website:n!==null?f(n):null},creators:e.creators?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:B(e.availability),pages:s,sidebar:o,properties:t}}async function ht(e,r,n,t){try{let{uuid:i,filter:s,page:o,perPage:a}=ye.parse({uuid:e,filter:r,page:n,perPage:t}),l=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
|
|
5
|
+
for $q in input()/ochre[@uuid='${i}']
|
|
6
|
+
let $filtered := $q//items/resource[contains(lower-case(identification/label), lower-case('${s}'))]
|
|
2558
7
|
let $maxLength := count($filtered)
|
|
2559
8
|
return <gallery maxLength='{$maxLength}'>
|
|
2560
9
|
{$q/metadata/project}
|
|
2561
10
|
{$q/metadata/item}
|
|
2562
|
-
{$filtered[position() >= ${((
|
|
11
|
+
{$filtered[position() >= ${((o-1)*a+1).toString()} and position() < ${(o*a+1).toString()}]}
|
|
2563
12
|
</gallery>
|
|
2564
|
-
`)}&format=json`
|
|
2565
|
-
);
|
|
2566
|
-
if (!response.ok) {
|
|
2567
|
-
throw new Error("Error fetching gallery items, please try again later.");
|
|
2568
|
-
}
|
|
2569
|
-
const data = await response.json();
|
|
2570
|
-
if (!("gallery" in data.result)) {
|
|
2571
|
-
throw new Error("Failed to fetch gallery");
|
|
2572
|
-
}
|
|
2573
|
-
const galleryIdentification = parseIdentification(
|
|
2574
|
-
data.result.gallery.item.identification
|
|
2575
|
-
);
|
|
2576
|
-
const galleryProjectIdentification = parseIdentification(
|
|
2577
|
-
data.result.gallery.project.identification
|
|
2578
|
-
);
|
|
2579
|
-
const gallery = {
|
|
2580
|
-
identification: galleryIdentification,
|
|
2581
|
-
projectIdentification: galleryProjectIdentification,
|
|
2582
|
-
resources: parseResources(
|
|
2583
|
-
data.result.gallery.resource ? Array.isArray(data.result.gallery.resource) ? data.result.gallery.resource : [data.result.gallery.resource] : []
|
|
2584
|
-
),
|
|
2585
|
-
maxLength: data.result.gallery.maxLength
|
|
2586
|
-
};
|
|
2587
|
-
return { item: gallery, error: null };
|
|
2588
|
-
} catch (error) {
|
|
2589
|
-
console.error(error);
|
|
2590
|
-
return {
|
|
2591
|
-
item: null,
|
|
2592
|
-
error: error instanceof Error ? error.message : "Failed to fetch gallery"
|
|
2593
|
-
};
|
|
2594
|
-
}
|
|
2595
|
-
}
|
|
2596
|
-
|
|
2597
|
-
// src/utils/fetchers/website.ts
|
|
2598
|
-
async function fetchWebsite(abbreviation) {
|
|
2599
|
-
try {
|
|
2600
|
-
const response = await fetch(
|
|
2601
|
-
`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${abbreviation.toLocaleLowerCase("en-US")}']] return $q&format=json`
|
|
2602
|
-
);
|
|
2603
|
-
if (!response.ok) {
|
|
2604
|
-
throw new Error("Failed to fetch website");
|
|
2605
|
-
}
|
|
2606
|
-
const data = await response.json();
|
|
2607
|
-
if (!("ochre" in data.result) || !("tree" in data.result.ochre)) {
|
|
2608
|
-
throw new Error("Failed to fetch website");
|
|
2609
|
-
}
|
|
2610
|
-
const projectIdentification = data.result.ochre.metadata.project?.identification ? parseIdentification(data.result.ochre.metadata.project.identification) : null;
|
|
2611
|
-
const website = await parseWebsite(
|
|
2612
|
-
data.result.ochre.tree,
|
|
2613
|
-
projectIdentification?.label ?? "",
|
|
2614
|
-
data.result.ochre.metadata.project?.identification.website ?? null
|
|
2615
|
-
);
|
|
2616
|
-
return website;
|
|
2617
|
-
} catch (error) {
|
|
2618
|
-
console.error(error);
|
|
2619
|
-
return null;
|
|
2620
|
-
}
|
|
2621
|
-
}
|
|
2622
|
-
export {
|
|
2623
|
-
fetchByUuid,
|
|
2624
|
-
fetchGallery,
|
|
2625
|
-
fetchItem,
|
|
2626
|
-
fetchWebsite,
|
|
2627
|
-
filterProperties,
|
|
2628
|
-
getAllPropertyLabels,
|
|
2629
|
-
getPropertyByLabel,
|
|
2630
|
-
getPropertyValueByLabel,
|
|
2631
|
-
getPropertyValuesByLabel,
|
|
2632
|
-
parseBibliographies,
|
|
2633
|
-
parseBibliography,
|
|
2634
|
-
parseConcept,
|
|
2635
|
-
parseConcepts,
|
|
2636
|
-
parseContext,
|
|
2637
|
-
parseCoordinates,
|
|
2638
|
-
parseDocument,
|
|
2639
|
-
parseEmail,
|
|
2640
|
-
parseEvents,
|
|
2641
|
-
parseFakeString,
|
|
2642
|
-
parseIdentification,
|
|
2643
|
-
parseImage,
|
|
2644
|
-
parseImageMap,
|
|
2645
|
-
parseInterpretations,
|
|
2646
|
-
parseLanguages,
|
|
2647
|
-
parseLicense,
|
|
2648
|
-
parseLink,
|
|
2649
|
-
parseLinks,
|
|
2650
|
-
parseMetadata,
|
|
2651
|
-
parseNotes,
|
|
2652
|
-
parseObservation,
|
|
2653
|
-
parseObservations,
|
|
2654
|
-
parsePeriod,
|
|
2655
|
-
parsePeriods,
|
|
2656
|
-
parsePerson,
|
|
2657
|
-
parsePersons,
|
|
2658
|
-
parseProperties,
|
|
2659
|
-
parseProperty,
|
|
2660
|
-
parsePropertyValue,
|
|
2661
|
-
parsePropertyValues,
|
|
2662
|
-
parseResource,
|
|
2663
|
-
parseResources,
|
|
2664
|
-
parseSet,
|
|
2665
|
-
parseSpatialUnit,
|
|
2666
|
-
parseSpatialUnits,
|
|
2667
|
-
parseStringContent,
|
|
2668
|
-
parseStringDocumentItem,
|
|
2669
|
-
parseStringItem,
|
|
2670
|
-
parseTree,
|
|
2671
|
-
parseWebsite
|
|
2672
|
-
};
|
|
13
|
+
`)}&format=json`);if(!l.ok)throw new Error("Error fetching gallery items, please try again later.");let c=await l.json();if(!("gallery"in c.result))throw new Error("Failed to fetch gallery");let g=v(c.result.gallery.item.identification),m=v(c.result.gallery.project.identification);return{item:{identification:g,projectIdentification:m,resources:M(c.result.gallery.resource?Array.isArray(c.result.gallery.resource)?c.result.gallery.resource:[c.result.gallery.resource]:[]),maxLength:c.result.gallery.maxLength},error:null}}catch(i){return console.error(i),{item:null,error:i instanceof Error?i.message:"Failed to fetch gallery"}}}async function bt(e){try{let r=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${e.toLocaleLowerCase("en-US")}']] return $q&format=json`);if(!r.ok)throw new Error("Failed to fetch website");let n=await r.json();if(!("ochre"in n.result)||!("tree"in n.result.ochre))throw new Error("Failed to fetch website");let t=n.result.ochre.metadata.project?.identification?v(n.result.ochre.metadata.project.identification):null;return await $e(n.result.ochre.tree,t?.label??"",n.result.ochre.metadata.project?.identification.website??null)}catch(r){return console.error(r),null}}export{we as fetchByUuid,ht as fetchGallery,ve as fetchItem,bt as fetchWebsite,Fe as filterProperties,We as getAllPropertyLabels,_ as getPropertyByLabel,h as getPropertyValueByLabel,be as getPropertyValuesByLabel,G as parseBibliographies,ee as parseBibliography,ie as parseConcept,Ce as parseConcepts,H as parseContext,xe as parseCoordinates,se as parseDocument,W as parseEmail,Ne as parseEvents,f as parseFakeString,v as parseIdentification,Ie as parseImage,Ye as parseImageMap,Me as parseInterpretations,je as parseLanguages,B as parseLicense,Ue as parseLink,j as parseLinks,Pe as parseMetadata,le as parseNotes,Te as parseObservation,Ve as parseObservations,Z as parsePeriod,q as parsePeriods,X as parsePerson,L as parsePersons,D as parseProperties,He as parseProperty,te as parsePropertyValue,De as parsePropertyValues,re as parseResource,M as parseResources,ke as parseSet,ne as parseSpatialUnit,Oe as parseSpatialUnits,w as parseStringContent,R as parseStringDocumentItem,z as parseStringItem,Se as parseTree,$e as parseWebsite};
|