ochre-sdk 1.0.1 → 1.0.3

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.d.mts CHANGED
@@ -1319,6 +1319,7 @@ type WebsiteType = "traditional" | "digital-collection" | "plum" | "cedar" | "el
1319
1319
  */
1320
1320
  type Website<T extends LanguageCodes = LanguageCodes> = {
1321
1321
  uuid: string;
1322
+ type: "website" | "segment";
1322
1323
  belongsTo: {
1323
1324
  uuid: string;
1324
1325
  abbreviation: string;
@@ -1328,7 +1329,7 @@ type Website<T extends LanguageCodes = LanguageCodes> = {
1328
1329
  identification: Identification<T>;
1329
1330
  creators: Array<Person<T, "embedded">>;
1330
1331
  license: License | null;
1331
- items: Array<Webpage<T> | WebSegment<T>>;
1332
+ items: Array<Webpage<T>>;
1332
1333
  properties: {
1333
1334
  type: WebsiteType;
1334
1335
  status: "development" | "preview" | "production";
@@ -1399,6 +1400,9 @@ type Website<T extends LanguageCodes = LanguageCodes> = {
1399
1400
  };
1400
1401
  };
1401
1402
  };
1403
+ type WebsiteSegment<T extends LanguageCodes = LanguageCodes> = Website<T> & {
1404
+ type: "segment";
1405
+ };
1402
1406
  /**
1403
1407
  * Represents a webpage with its title, slug, properties, items and subpages
1404
1408
  */
@@ -1408,7 +1412,8 @@ type Webpage<T extends LanguageCodes = LanguageCodes> = {
1408
1412
  title: MultilingualString<T>;
1409
1413
  slug: string;
1410
1414
  publicationDateTime: Date | null;
1411
- items: Array<WebSegment<T> | WebElement<T> | WebBlock<T>>;
1415
+ items: Array<WebElement<T> | WebBlock<T>>;
1416
+ segments: Array<WebsiteSegment<T>>;
1412
1417
  properties: {
1413
1418
  width: "full" | "large" | "narrow" | "default";
1414
1419
  variant: "default" | "no-background";
@@ -1425,28 +1430,6 @@ type Webpage<T extends LanguageCodes = LanguageCodes> = {
1425
1430
  };
1426
1431
  webpages: Array<Webpage<T>>;
1427
1432
  };
1428
- /**
1429
- * Represents a web segment
1430
- */
1431
- type WebSegment<T extends LanguageCodes = LanguageCodes> = {
1432
- uuid: string;
1433
- type: "segment";
1434
- title: MultilingualString<T>;
1435
- slug: string;
1436
- publicationDateTime: Date | null;
1437
- items: Array<WebSegmentItem<T>>;
1438
- };
1439
- /**
1440
- * Represents a web segment item
1441
- */
1442
- type WebSegmentItem<T extends LanguageCodes = LanguageCodes> = {
1443
- uuid: string;
1444
- type: "segment-item";
1445
- title: MultilingualString<T>;
1446
- slug: string;
1447
- publicationDateTime: Date | null;
1448
- items: Array<Webpage<T> | WebSegment<T>>;
1449
- };
1450
1433
  /**
1451
1434
  * Represents a title with its label and variant
1452
1435
  */
@@ -1960,4 +1943,4 @@ declare const DEFAULT_PAGE_SIZE = 48;
1960
1943
  */
1961
1944
  declare function flattenItemProperties<U extends ItemCategory = ItemCategory, V extends ContainedItemCategory<U> = ContainedItemCategory<U>, T extends LanguageCodes = LanguageCodes, W extends ItemPayloadKind = "topLevel">(item: Item<U, V, T, W>): FlattenedItem<Item<U, V, T, W>, T>;
1962
1945
  //#endregion
1963
- export { AccordionWebBlock, AnyBibliography, AnyConcept, AnyItem, AnyPeriod, AnyPerson, AnyPropertyValue, AnyPropertyVariable, AnyResource, AnySet, AnySpatialUnit, AnyText, AnyTree, BaseItem, BaseItemLink, BelongsTo, Bibliography, BibliographyEntryInfo, BibliographyItemLink, BibliographySourceDocument, Concept, ConceptItemLink, ContainedItemCategory, ContainedItemCategoryFromOption, ContainedItemCategoryOption, Context, ContextItem, ContextItemCategory, ContextNode, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, Coordinates, CoordinatesSource, DEFAULT_PAGE_SIZE, DictionaryUnitItemLink, EmbeddedBibliography, EmbeddedConcept, EmbeddedItem, EmbeddedPeriod, EmbeddedPerson, EmbeddedPropertyValue, EmbeddedPropertyVariable, EmbeddedResource, EmbeddedSet, EmbeddedSpatialUnit, EmbeddedText, EmbeddedTree, Event, Gallery, Heading, HeadingItemCategory, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, ItemCategory, ItemContainerCategory, ItemLink, ItemLinkCategory, ItemLinks, ItemPayloadKind, ItemProperty, LanguageCodes, License, Metadata, type MultilingualOptions, MultilingualString, type MultilingualStringEntries, type MultilingualStringEntry, type MultilingualStringInput, type MultilingualStringJSON, type MultilingualStringObject, type MultilingualStringText, Note, Observation, Period, PeriodItemLink, Person, PersonItemLink, Property, PropertyLike, PropertyOptions, PropertyValue, PropertyValueContent, PropertyValueDataType, PropertyValueItemLink, PropertyValueQueryItem, PropertyVariable, PropertyVariableItemLink, Query, QueryGroup, QueryLeaf, QueryablePropertyValueDataType, RecursiveItemCategory, Resource, ResourceItemLink, Scope, Section, Set, SetAttributeValueQueryItem, SetBibliography, SetConcept, SetItem, SetItemCategory, SetItemLink, SetItemProperty, SetItemSimplifiedProperty, SetItemsSort, SetItemsSortDirection, SetPeriod, SetResource, SetSpatialUnit, SetTree, SimplifiedProperty, SpatialUnit, SpatialUnitItemLink, Style, StylesheetCategory, StylesheetItem, Text, TextItemLink, TopLevelItem, Tree, TreeItemCategory, TreeItemLink, WebBlock, WebBlockByLayout, WebBlockLayout, WebElement, WebElementComponent, WebElementComponentName, WebElementComponentOf, WebElementOf, WebImage, WebSegment, WebSegmentItem, WebTitle, Webpage, Website, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteType, defineLanguages, fetchGallery, fetchItem, fetchItemLinks, fetchSetItems, fetchSetPropertyValues, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels, withLanguages };
1946
+ export { AccordionWebBlock, AnyBibliography, AnyConcept, AnyItem, AnyPeriod, AnyPerson, AnyPropertyValue, AnyPropertyVariable, AnyResource, AnySet, AnySpatialUnit, AnyText, AnyTree, BaseItem, BaseItemLink, BelongsTo, Bibliography, BibliographyEntryInfo, BibliographyItemLink, BibliographySourceDocument, Concept, ConceptItemLink, ContainedItemCategory, ContainedItemCategoryFromOption, ContainedItemCategoryOption, Context, ContextItem, ContextItemCategory, ContextNode, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, Coordinates, CoordinatesSource, DEFAULT_PAGE_SIZE, DictionaryUnitItemLink, EmbeddedBibliography, EmbeddedConcept, EmbeddedItem, EmbeddedPeriod, EmbeddedPerson, EmbeddedPropertyValue, EmbeddedPropertyVariable, EmbeddedResource, EmbeddedSet, EmbeddedSpatialUnit, EmbeddedText, EmbeddedTree, Event, Gallery, Heading, HeadingItemCategory, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, ItemCategory, ItemContainerCategory, ItemLink, ItemLinkCategory, ItemLinks, ItemPayloadKind, ItemProperty, LanguageCodes, License, Metadata, type MultilingualOptions, MultilingualString, type MultilingualStringEntries, type MultilingualStringEntry, type MultilingualStringInput, type MultilingualStringJSON, type MultilingualStringObject, type MultilingualStringText, Note, Observation, Period, PeriodItemLink, Person, PersonItemLink, Property, PropertyLike, PropertyOptions, PropertyValue, PropertyValueContent, PropertyValueDataType, PropertyValueItemLink, PropertyValueQueryItem, PropertyVariable, PropertyVariableItemLink, Query, QueryGroup, QueryLeaf, QueryablePropertyValueDataType, RecursiveItemCategory, Resource, ResourceItemLink, Scope, Section, Set, SetAttributeValueQueryItem, SetBibliography, SetConcept, SetItem, SetItemCategory, SetItemLink, SetItemProperty, SetItemSimplifiedProperty, SetItemsSort, SetItemsSortDirection, SetPeriod, SetResource, SetSpatialUnit, SetTree, SimplifiedProperty, SpatialUnit, SpatialUnitItemLink, Style, StylesheetCategory, StylesheetItem, Text, TextItemLink, TopLevelItem, Tree, TreeItemCategory, TreeItemLink, WebBlock, WebBlockByLayout, WebBlockLayout, WebElement, WebElementComponent, WebElementComponentName, WebElementComponentOf, WebElementOf, WebImage, WebTitle, Webpage, Website, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteSegment, WebsiteType, defineLanguages, fetchGallery, fetchItem, fetchItemLinks, fetchSetItems, fetchSetPropertyValues, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels, withLanguages };
package/dist/index.mjs CHANGED
@@ -1008,19 +1008,20 @@ function parseXMLString(string, options) {
1008
1008
  */
1009
1009
  function createMDXComponent(variant, properties) {
1010
1010
  const { uuid, href, height, width, content, text } = properties;
1011
+ const tooltipContent = getDistinctTooltipContent(content, text);
1011
1012
  let returnString = "";
1012
1013
  switch (variant) {
1013
1014
  case "inlineImage":
1014
1015
  returnString = `<InlineImage uuid="${uuid}"${createMDXStringAttribute("content", content)} height={${height ?? "null"}} width={${width ?? "null"}} />`;
1015
1016
  break;
1016
1017
  case "internalLink":
1017
- returnString = `<InternalLink uuid="${uuid}"${createMDXStringAttribute("content", content)}>${text}</InternalLink>`;
1018
+ returnString = `<InternalLink uuid="${uuid}"${createMDXStringAttribute("content", tooltipContent)}>${text}</InternalLink>`;
1018
1019
  break;
1019
1020
  case "externalLink":
1020
- returnString = `<ExternalLink href="${href == null ? "#" : transformPermanentIdentificationUrl(href)}"${createMDXStringAttribute("content", content)}>${text}</ExternalLink>`;
1021
+ returnString = `<ExternalLink href="${href == null ? "#" : transformPermanentIdentificationUrl(href)}"${createMDXStringAttribute("content", tooltipContent)}>${text}</ExternalLink>`;
1021
1022
  break;
1022
1023
  case "documentLink":
1023
- returnString = String.raw`<ExternalLink href="https:\/\/ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=${uuid}&load"${createMDXStringAttribute("content", content)}>${text}</ExternalLink>`;
1024
+ returnString = String.raw`<ExternalLink href="https:\/\/ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=${uuid}&load"${createMDXStringAttribute("content", tooltipContent)}>${text}</ExternalLink>`;
1024
1025
  break;
1025
1026
  case "tooltipSpan":
1026
1027
  returnString = `<TooltipSpan${createMDXStringAttribute("content", content)}>${text}</TooltipSpan>`;
@@ -1028,6 +1029,9 @@ function createMDXComponent(variant, properties) {
1028
1029
  }
1029
1030
  return returnString;
1030
1031
  }
1032
+ function getDistinctTooltipContent(content, textContent) {
1033
+ return content === textContent ? void 0 : content;
1034
+ }
1031
1035
  function createMDXStringAttribute(name, value) {
1032
1036
  if (value == null || value === "") return "";
1033
1037
  return ` ${name}=${MDX_QUOTED_ATTRIBUTE_ESCAPE_REGEX.test(value) ? `{${JSON.stringify(value)}}` : `"${value}"`}`;
@@ -1173,7 +1177,7 @@ function createInternalLinkComponent(properties) {
1173
1177
  case "hover-card": return `<Annotation type="hover-card" uuid="${properties.uuid}">${innerContent}</Annotation>`;
1174
1178
  case "item-page": return `<InternalLink type="item" uuid="${properties.uuid}">${innerContent}</InternalLink>`;
1175
1179
  case "entry-page": return `<InternalLink type="entry" uuid="${properties.uuid}">${innerContent}</InternalLink>`;
1176
- default: return `<InternalLink uuid="${properties.uuid}"${properties.propertyMetadata != null ? ` properties="${properties.propertyMetadata.labelUuid}"${properties.propertyMetadata.valueUuid != null ? ` value="${properties.propertyMetadata.valueUuid}"` : ""}` : ""}${createMDXStringAttribute("content", properties.content)}>${innerContent}</InternalLink>`;
1180
+ default: return `<InternalLink uuid="${properties.uuid}"${properties.propertyMetadata != null ? ` properties="${properties.propertyMetadata.labelUuid}"${properties.propertyMetadata.valueUuid != null ? ` value="${properties.propertyMetadata.valueUuid}"` : ""}` : ""}${createMDXStringAttribute("content", getDistinctTooltipContent(properties.content, properties.text))}>${innerContent}</InternalLink>`;
1177
1181
  }
1178
1182
  }
1179
1183
  function getXMLRichTextLinks(item) {
@@ -5881,7 +5885,11 @@ function normalizeWebsiteResources(resources) {
5881
5885
  return normalized;
5882
5886
  }
5883
5887
  const SEGMENT_UNIQUE_SLUG_PREFIX_REGEX = /^\$[^-]*-/;
5884
- const TRAILING_SLASH_REGEX = /\/$/;
5888
+ function prefixSlug(slug, slugPrefix) {
5889
+ if (slugPrefix == null || slugPrefix === "") return slug;
5890
+ if (slug === "") return slugPrefix;
5891
+ return `${slugPrefix}/${slug}`;
5892
+ }
5885
5893
  function formatXMLWebsiteResourceMetadata(resource) {
5886
5894
  const metadata = [`label “${parseStringContent(resource.identification.label)}”`, `uuid “${resource.uuid}”`];
5887
5895
  if (resource.slug != null) metadata.push(`slug “${resource.slug}”`);
@@ -6552,43 +6560,12 @@ function parseWebElement(elementResource, options) {
6552
6560
  };
6553
6561
  }
6554
6562
  /**
6555
- * Parses raw webpage resources into standardized WebElement or Webpage objects
6556
- *
6557
- * @param webpageResources - Array of raw webpage resources in OCHRE format
6558
- * @param type - Type of resource to parse ("element" or "page")
6559
- * @returns Array of parsed WebElement or Webpage objects
6560
- */
6561
- const parseWebpageResources = (webpageResources, type, options) => {
6562
- const returnElements = [];
6563
- for (const resource of webpageResources) {
6564
- if (websitePresentationReader(resource.properties ? parseSimplifiedProperties(resource.properties, options) : []).propertyByValue("presentation", type) === null) continue;
6565
- switch (type) {
6566
- case "element": {
6567
- const element = parseWebElement(resource, options);
6568
- returnElements.push(element);
6569
- break;
6570
- }
6571
- case "page": {
6572
- const webpage = parseWebpage(resource, options);
6573
- if (webpage) returnElements.push(webpage);
6574
- break;
6575
- }
6576
- case "block": {
6577
- const block = parseWebBlock(resource, options);
6578
- if (block) returnElements.push(block);
6579
- break;
6580
- }
6581
- }
6582
- }
6583
- return returnElements;
6584
- };
6585
- /**
6586
6563
  * Parses raw webpage data into a standardized Webpage structure
6587
6564
  *
6588
6565
  * @param webpageResource - Raw webpage resource data in OCHRE format
6589
6566
  * @returns Parsed Webpage object
6590
6567
  */
6591
- function parseWebpage(webpageResource, options, slugPrefix) {
6568
+ function parseWebpage(webpageResource, options, context, slugPrefix) {
6592
6569
  const webpageProperties = webpageResource.properties ? parseSimplifiedProperties(webpageResource.properties, options) : [];
6593
6570
  const webpageReader = websitePresentationReader(webpageProperties);
6594
6571
  if (webpageReader.value("presentation") !== "page") return null;
@@ -6599,9 +6576,10 @@ function parseWebpage(webpageResource, options, slugPrefix) {
6599
6576
  uuid: webpageResource.uuid,
6600
6577
  type: "page",
6601
6578
  title: identification.label,
6602
- slug: slugPrefix != null ? `${slugPrefix}/${slug}`.replace(TRAILING_SLASH_REGEX, "") : slug,
6579
+ slug: prefixSlug(slug, slugPrefix),
6603
6580
  publicationDateTime: webpageResource.publicationDateTime ?? null,
6604
6581
  items: [],
6582
+ segments: [],
6605
6583
  properties: {
6606
6584
  width: "default",
6607
6585
  variant: "default",
@@ -6625,11 +6603,6 @@ function parseWebpage(webpageResource, options, slugPrefix) {
6625
6603
  const resourceType = websitePresentationReader(resource.properties != null ? parseSimplifiedProperties(resource.properties, options) : []).value("presentation");
6626
6604
  if (resourceType === null) continue;
6627
6605
  switch (resourceType) {
6628
- case "segment": {
6629
- const segment = parseWebSegment(resource, options);
6630
- if (segment) items.push(segment);
6631
- break;
6632
- }
6633
6606
  case "element": {
6634
6607
  const element = parseWebElement(resource, options);
6635
6608
  items.push(element);
@@ -6643,7 +6616,8 @@ function parseWebpage(webpageResource, options, slugPrefix) {
6643
6616
  }
6644
6617
  }
6645
6618
  returnWebpage.items = items;
6646
- returnWebpage.webpages = webpageResource.resource != null ? parseWebpageResources(normalizeWebsiteResources(webpageResource.resource), "page", options) : [];
6619
+ returnWebpage.webpages = parseWebpages(webpageResources, options, context, slugPrefix == null ? void 0 : returnWebpage.slug);
6620
+ returnWebpage.segments = parseWebsiteSegments(webpageResource.resource, context, options, returnWebpage.slug);
6647
6621
  const pageReader = webpageReader.nestedByValue("presentation", "page");
6648
6622
  if (pageReader.size > 0) {
6649
6623
  returnWebpage.properties.isDisplayedInNavbar = pageReader.valueOr("displayed-in-navbar", true);
@@ -6670,86 +6644,21 @@ function parseWebpage(webpageResource, options, slugPrefix) {
6670
6644
  * @param webpageResources - Array of raw webpage resources in OCHRE format
6671
6645
  * @returns Array of parsed Webpage objects
6672
6646
  */
6673
- function parseWebpages(webpageResources, options, slugPrefix) {
6647
+ function parseWebpages(webpageResources, options, context, slugPrefix) {
6674
6648
  const returnPages = [];
6675
6649
  for (const webpageResource of webpageResources) {
6676
- const webpage = parseWebpage(webpageResource, options, slugPrefix);
6650
+ const webpage = parseWebpage(webpageResource, options, context, slugPrefix);
6677
6651
  if (webpage !== null) returnPages.push(webpage);
6678
6652
  }
6679
6653
  return returnPages;
6680
6654
  }
6681
- /**
6682
- * Parses raw segment resource into a standardized WebSegment object
6683
- *
6684
- * @param segmentResource - Raw segment resource in OCHRE format
6685
- * @returns Parsed WebSegment object
6686
- */
6687
- function parseWebSegment(segmentResource, options, slugPrefix) {
6688
- if (websitePresentationReader(segmentResource.properties ? parseSimplifiedProperties(segmentResource.properties, options) : []).value("presentation") !== "segment") return null;
6689
- const identification = parseIdentification(segmentResource.identification, options);
6690
- const slug = segmentResource.identification.abbreviation != null ? parseStringContent(segmentResource.identification.abbreviation, options) : null;
6691
- if (slug == null) throw new Error(`Slug not found for segment (${formatXMLWebsiteResourceMetadata(segmentResource)})`);
6692
- const returnSegment = {
6693
- uuid: segmentResource.uuid,
6694
- type: "segment",
6695
- title: identification.label,
6696
- slug,
6697
- publicationDateTime: segmentResource.publicationDateTime ?? null,
6698
- items: []
6699
- };
6700
- returnSegment.items = parseWebSegmentItems(segmentResource.resource ? normalizeWebsiteResources(segmentResource.resource) : [], options, slugPrefix != null ? `${slugPrefix}/${slug}`.replace(TRAILING_SLASH_REGEX, "") : slug);
6701
- return returnSegment;
6702
- }
6703
- /**
6704
- * Parses raw segment resources into an array of WebSegment objects
6705
- *
6706
- * @param segmentResources - Array of raw segment resources in OCHRE format
6707
- * @returns Array of parsed WebSegment objects
6708
- */
6709
- function parseSegments(segmentResources, options, slugPrefix) {
6710
- const returnSegments = [];
6711
- for (const segmentResource of segmentResources) {
6712
- const segment = parseWebSegment(segmentResource, options, slugPrefix);
6713
- if (segment !== null) returnSegments.push(segment);
6714
- }
6715
- return returnSegments;
6716
- }
6717
- /**
6718
- * Parses raw segment item into a standardized WebSegmentItem object
6719
- *
6720
- * @param segmentItemResource - Raw segment item resource in OCHRE format
6721
- * @returns Parsed WebSegmentItem object
6722
- */
6723
- function parseWebSegmentItem(segmentItemResource, options, slugPrefix) {
6724
- if (websitePresentationReader(segmentItemResource.properties ? parseSimplifiedProperties(segmentItemResource.properties, options) : []).value("presentation") !== "segment-item") return null;
6725
- const identification = parseIdentification(segmentItemResource.identification, options);
6726
- const slug = segmentItemResource.identification.abbreviation != null ? parseStringContent(segmentItemResource.identification.abbreviation, options) : null;
6727
- if (slug == null) throw new Error(`Slug not found for segment item (${formatXMLWebsiteResourceMetadata(segmentItemResource)})`);
6728
- const returnSegmentItem = {
6729
- uuid: segmentItemResource.uuid,
6730
- type: "segment-item",
6731
- title: identification.label,
6732
- slug,
6733
- publicationDateTime: segmentItemResource.publicationDateTime ?? null,
6734
- items: []
6735
- };
6736
- const resources = segmentItemResource.resource ? normalizeWebsiteResources(segmentItemResource.resource) : [];
6737
- returnSegmentItem.items.push(...parseWebpages(resources, options, slugPrefix != null ? `${slugPrefix}/${slug}`.replace(TRAILING_SLASH_REGEX, "") : slug), ...parseSegments(resources, options, slugPrefix != null ? `${slugPrefix}/${slug}`.replace(TRAILING_SLASH_REGEX, "") : slug));
6738
- return returnSegmentItem;
6739
- }
6740
- /**
6741
- * Parses raw segment items into an array of WebSegmentItem objects
6742
- *
6743
- * @param segmentItems - Array of raw segment items in OCHRE format
6744
- * @returns Array of parsed WebSegmentItem objects
6745
- */
6746
- function parseWebSegmentItems(segmentItems, options, slugPrefix) {
6747
- const returnItems = [];
6748
- for (const segmentItem of segmentItems) {
6749
- const segmentItemParsed = parseWebSegmentItem(segmentItem, options, slugPrefix);
6750
- if (segmentItemParsed !== null) returnItems.push(segmentItemParsed);
6655
+ function parseWebsiteSegments(resources, context, options, slugPrefix) {
6656
+ const segments = [];
6657
+ for (const resource of resources ?? []) {
6658
+ if (!("segments" in resource)) continue;
6659
+ for (const tree of resource.segments.tree) segments.push(parseWebsiteTree(tree, context, "segment", options, slugPrefix));
6751
6660
  }
6752
- return returnItems;
6661
+ return segments;
6753
6662
  }
6754
6663
  /**
6755
6664
  * Parses raw sidebar data into a standardized Sidebar structure
@@ -7127,6 +7036,25 @@ function parseFilterContexts(filterContextLevels, options) {
7127
7036
  });
7128
7037
  return filterContextTreeLevels;
7129
7038
  }
7039
+ function parseWebsiteTree(websiteTree, context, type, options, slugPrefix) {
7040
+ if (!websiteTree.properties) throw new Error(`Website properties not found (website uuid “${websiteTree.uuid}”)`);
7041
+ if (type === "website" && websiteTree.items?.resource == null) throw new Error(`Website pages not found (website uuid “${websiteTree.uuid}”)`);
7042
+ const resources = normalizeWebsiteResources(websiteTree.items?.resource);
7043
+ const sidebar = parseSidebar(resources, options);
7044
+ const properties = parseWebsiteProperties(websiteTree.properties.property, websiteTree, sidebar, options);
7045
+ return {
7046
+ uuid: websiteTree.uuid,
7047
+ type,
7048
+ belongsTo: context.belongsTo,
7049
+ metadata: context.metadata,
7050
+ publicationDateTime: websiteTree.publicationDateTime ?? null,
7051
+ identification: parseIdentification(websiteTree.identification, options),
7052
+ creators: websiteTree.creators ? parsePersonList(websiteTree.creators.creator, options) : [],
7053
+ license: parseLicense(websiteTree.availability),
7054
+ items: parseWebpages(resources, options, context, slugPrefix),
7055
+ properties
7056
+ };
7057
+ }
7130
7058
  function parseWebsite(data, options) {
7131
7059
  const rawOchre = data.result.ochre;
7132
7060
  const metadataLanguages = parseMetadataLanguages(rawOchre);
@@ -7135,26 +7063,13 @@ function parseWebsite(data, options) {
7135
7063
  const defaultLanguage = resolveDefaultLanguage(rawOchre, languages);
7136
7064
  const websiteTree = rawOchre.tree[0];
7137
7065
  if (websiteTree == null) throw new Error("Website tree not found");
7138
- if (!websiteTree.properties) throw new Error(`Website properties not found (website uuid “${websiteTree.uuid}”)`);
7139
- if (websiteTree.items?.resource == null) throw new Error(`Website pages not found (website uuid “${websiteTree.uuid}”)`);
7140
- const resources = normalizeWebsiteResources(websiteTree.items.resource);
7141
- const items = [...parseWebpages(resources, parserOptions), ...parseSegments(resources, parserOptions)];
7142
- const sidebar = parseSidebar(resources, parserOptions);
7143
- const properties = parseWebsiteProperties(websiteTree.properties.property, websiteTree, sidebar, parserOptions);
7144
- return {
7145
- uuid: websiteTree.uuid,
7066
+ return parseWebsiteTree(websiteTree, {
7146
7067
  belongsTo: {
7147
7068
  uuid: rawOchre.uuidBelongsTo,
7148
7069
  abbreviation: rawOchre.belongsTo
7149
7070
  },
7150
- metadata: parseMetadata(rawOchre, parserOptions, defaultLanguage),
7151
- publicationDateTime: websiteTree.publicationDateTime ?? null,
7152
- identification: parseIdentification(websiteTree.identification, parserOptions),
7153
- creators: websiteTree.creators ? parsePersonList(websiteTree.creators.creator, parserOptions) : [],
7154
- license: parseLicense(websiteTree.availability),
7155
- items,
7156
- properties
7157
- };
7071
+ metadata: parseMetadata(rawOchre, parserOptions, defaultLanguage)
7072
+ }, "website", parserOptions);
7158
7073
  }
7159
7074
  //#endregion
7160
7075
  //#region src/fetchers/website.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Node.js library for working with OCHRE (Online Cultural and Historical Research Environment) data",