@canopy-iiif/app 1.6.3 → 1.6.4

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/mdx.js CHANGED
@@ -12,6 +12,7 @@ const {
12
12
  ensureDirSync,
13
13
  withBase,
14
14
  readSiteMetadata,
15
+ readPrimaryNavigation,
15
16
  } = require("../common");
16
17
  let remarkGfm = null;
17
18
  try {
@@ -1045,11 +1046,13 @@ async function compileMdxFile(filePath, outPath, Layout, extraProps = {}) {
1045
1046
  const withApp = React.createElement(app.App, null, withLayout);
1046
1047
  const PageContext = getPageContext();
1047
1048
  const siteMeta = readSiteMetadata();
1049
+ const primaryNav = readPrimaryNavigation();
1048
1050
  const contextValue = {
1049
1051
  navigation:
1050
1052
  extraProps && extraProps.navigation ? extraProps.navigation : null,
1051
1053
  page: extraProps && extraProps.page ? extraProps.page : null,
1052
1054
  site: siteMeta ? {...siteMeta} : null,
1055
+ primaryNavigation: Array.isArray(primaryNav) ? primaryNav : [],
1053
1056
  };
1054
1057
  const withContext = PageContext
1055
1058
  ? React.createElement(PageContext.Provider, {value: contextValue}, withApp)
package/lib/common.js CHANGED
@@ -116,6 +116,25 @@ function readSearchPageMetadata() {
116
116
  return cachedSearchPageMetadata;
117
117
  }
118
118
 
119
+ let cachedPrimaryNavigation = null;
120
+
121
+ function readPrimaryNavigation() {
122
+ if (cachedPrimaryNavigation) return cachedPrimaryNavigation;
123
+ cachedPrimaryNavigation = [];
124
+ try {
125
+ const navPath = path.resolve(CONTENT_DIR, 'navigation.yml');
126
+ if (!fs.existsSync(navPath)) return cachedPrimaryNavigation;
127
+ const raw = fs.readFileSync(navPath, 'utf8');
128
+ const data = yaml.load(raw) || {};
129
+ if (Array.isArray(data.navigation)) {
130
+ cachedPrimaryNavigation = data.navigation.filter(
131
+ (item) => item && typeof item === 'object' && typeof item.href === 'string'
132
+ );
133
+ }
134
+ } catch (_) {}
135
+ return cachedPrimaryNavigation;
136
+ }
137
+
119
138
  // Determine the absolute site origin (scheme + host[:port])
120
139
  // Priority:
121
140
  // 1) CANOPY_BASE_URL env
@@ -288,4 +307,5 @@ module.exports = {
288
307
  readSearchPageMetadata,
289
308
  DEFAULT_SEARCH_PAGE_TITLE,
290
309
  DEFAULT_SEARCH_PAGE_DESCRIPTION,
310
+ readPrimaryNavigation,
291
311
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopy-iiif/app",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "Mat Jordan <mat@northwestern.edu>",
package/ui/dist/index.mjs CHANGED
@@ -1281,9 +1281,10 @@ function CanopyHeader(props = {}) {
1281
1281
  title: titleProp,
1282
1282
  logo: SiteLogo
1283
1283
  } = props;
1284
- const navLinks = ensureArray(navLinksProp);
1285
1284
  const PageContext = getSafePageContext();
1286
1285
  const context = React15.useContext(PageContext);
1286
+ const contextPrimaryNav = context && Array.isArray(context.primaryNavigation) ? context.primaryNavigation : [];
1287
+ const navLinks = navLinksProp && navLinksProp.length ? ensureArray(navLinksProp) : ensureArray(contextPrimaryNav);
1287
1288
  const contextNavigation = context && context.navigation ? context.navigation : null;
1288
1289
  const contextSite = context && context.site ? context.site : null;
1289
1290
  const contextSiteTitle = contextSite && typeof contextSite.title === "string" ? contextSite.title.trim() : "";