@canopy-iiif/app 1.5.8 → 1.5.10

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/lib/build/iiif.js CHANGED
@@ -21,6 +21,7 @@ const { getPageContext } = require("../page-context");
21
21
  const PageContext = getPageContext();
22
22
  const referenced = require("../components/referenced");
23
23
  const navPlace = require("../components/nav-place");
24
+ const navigation = require("../components/navigation.js");
24
25
  const {
25
26
  getThumbnail,
26
27
  getRepresentativeImage,
@@ -1850,7 +1851,11 @@ async function buildIiifCollectionPages(CONFIG) {
1850
1851
  pageDetails.meta.image = ogImageForPage;
1851
1852
  pageDetails.meta.ogImage = ogImageForPage;
1852
1853
  }
1853
- const pageContextValue = { navigation: null, page: pageDetails };
1854
+ const navigationRoots = navigation.buildNavigationRoots(slug || "");
1855
+ const navigationContext = navigationRoots && Object.keys(navigationRoots).length
1856
+ ? { allRoots: navigationRoots }
1857
+ : null;
1858
+ const pageContextValue = { navigation: navigationContext, page: pageDetails };
1854
1859
  if (metadataFacetLabels.length && manifest && typeof manifest === "object") {
1855
1860
  try {
1856
1861
  Object.defineProperty(manifest, "__canopyMetadataFacets", {
@@ -1893,7 +1898,7 @@ async function buildIiifCollectionPages(CONFIG) {
1893
1898
  if (app && app.Head) {
1894
1899
  const headElement = React.createElement(app.Head, {
1895
1900
  page: pageContextValue.page,
1896
- navigation: null,
1901
+ navigation: pageContextValue.navigation,
1897
1902
  });
1898
1903
  const wrappedHead = PageContext
1899
1904
  ? React.createElement(
@@ -87,6 +87,9 @@ async function renderContentMdxToHtml(filePath, outPath, extraProps = {}, source
87
87
  const normalizedRel = navigation.normalizeRelativePath(relContentPath);
88
88
  const pageInfo = navigation.getPageInfo(normalizedRel);
89
89
  const navData = navigation.buildNavigationForFile(normalizedRel);
90
+ const allNavigationRoots = navigation.buildNavigationRoots(
91
+ pageInfo && pageInfo.slug ? pageInfo.slug : ""
92
+ );
90
93
  const mergedProps = { ...(extraProps || {}) };
91
94
  const frontmatter =
92
95
  typeof mdx.parseFrontmatter === 'function'
@@ -174,8 +177,23 @@ async function renderContentMdxToHtml(filePath, outPath, extraProps = {}, source
174
177
  if (referencedItems.length) {
175
178
  mergedProps.referencedItems = referencedItems;
176
179
  }
177
- if (navData && !mergedProps.navigation) {
178
- mergedProps.navigation = navData;
180
+ if (!mergedProps.navigation) {
181
+ if (navData || (allNavigationRoots && Object.keys(allNavigationRoots).length)) {
182
+ const navigationPayload = navData ? {...navData} : {};
183
+ if (allNavigationRoots && Object.keys(allNavigationRoots).length) {
184
+ navigationPayload.allRoots = allNavigationRoots;
185
+ }
186
+ mergedProps.navigation = Object.keys(navigationPayload).length
187
+ ? navigationPayload
188
+ : null;
189
+ }
190
+ } else if (
191
+ mergedProps.navigation &&
192
+ allNavigationRoots &&
193
+ Object.keys(allNavigationRoots).length &&
194
+ !mergedProps.navigation.allRoots
195
+ ) {
196
+ mergedProps.navigation.allRoots = allNavigationRoots;
179
197
  }
180
198
  if (headings && headings.length) {
181
199
  mergedProps.page = mergedProps.page
@@ -313,6 +313,26 @@ function buildNavigationForFile(relativePath) {
313
313
  };
314
314
  }
315
315
 
316
+ function buildNavigationRoots(currentSlug) {
317
+ const cache = getNavigationCache();
318
+ const result = {};
319
+ const normalizedSlug = typeof currentSlug === "string" ? currentSlug : "";
320
+ for (const [segment, rootNode] of cache.roots.entries()) {
321
+ if (!segment || EXCLUDED_ROOTS.has(segment)) continue;
322
+ const shouldExpand =
323
+ normalizedSlug &&
324
+ (normalizedSlug === segment || normalizedSlug.startsWith(segment + "/"));
325
+ const clone = cloneNode(rootNode, shouldExpand ? normalizedSlug : null);
326
+ if (!clone) continue;
327
+ result[segment] = {
328
+ rootSegment: segment,
329
+ root: clone,
330
+ title: clone.title,
331
+ };
332
+ }
333
+ return result;
334
+ }
335
+
316
336
  function resetNavigationCache() {
317
337
  NAV_CACHE = null;
318
338
  }
@@ -321,6 +341,7 @@ module.exports = {
321
341
  normalizeRelativePath,
322
342
  getPageInfo,
323
343
  buildNavigationForFile,
344
+ buildNavigationRoots,
324
345
  resetNavigationCache,
325
346
  getPageContext,
326
347
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopy-iiif/app",
3
- "version": "1.5.8",
3
+ "version": "1.5.10",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "Mat Jordan <mat@northwestern.edu>",