@canopy-iiif/app 1.5.16 → 1.5.17

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/common.js CHANGED
@@ -15,7 +15,10 @@ const BASE_PATH = readBasePath();
15
15
  let cachedAppearance = null;
16
16
  let cachedAccent = null;
17
17
  let cachedSiteMetadata = null;
18
+ let cachedSearchPageMetadata = null;
18
19
  const DEFAULT_SITE_TITLE = 'Site title';
20
+ const DEFAULT_SEARCH_PAGE_TITLE = 'Search';
21
+ const DEFAULT_SEARCH_PAGE_DESCRIPTION = '';
19
22
 
20
23
  function resolveThemeAppearance() {
21
24
  if (cachedAppearance) return cachedAppearance;
@@ -87,6 +90,32 @@ function getSiteTitle() {
87
90
  return DEFAULT_SITE_TITLE;
88
91
  }
89
92
 
93
+ function readSearchPageMetadata() {
94
+ if (cachedSearchPageMetadata) return cachedSearchPageMetadata;
95
+ cachedSearchPageMetadata = {
96
+ title: DEFAULT_SEARCH_PAGE_TITLE,
97
+ description: DEFAULT_SEARCH_PAGE_DESCRIPTION,
98
+ };
99
+ try {
100
+ const cfgPath = resolveCanopyConfigPath();
101
+ if (!fs.existsSync(cfgPath)) return cachedSearchPageMetadata;
102
+ const raw = fs.readFileSync(cfgPath, 'utf8');
103
+ const data = yaml.load(raw) || {};
104
+ const searchCfg = data && data.search ? data.search : null;
105
+ const pageCfg = searchCfg && searchCfg.page ? searchCfg.page : null;
106
+ const title = pageCfg && typeof pageCfg.title === 'string' ? pageCfg.title.trim() : '';
107
+ const description =
108
+ pageCfg && typeof pageCfg.description === 'string'
109
+ ? pageCfg.description.trim()
110
+ : '';
111
+ cachedSearchPageMetadata = {
112
+ title: title || DEFAULT_SEARCH_PAGE_TITLE,
113
+ description: description || DEFAULT_SEARCH_PAGE_DESCRIPTION,
114
+ };
115
+ } catch (_) {}
116
+ return cachedSearchPageMetadata;
117
+ }
118
+
90
119
  // Determine the absolute site origin (scheme + host[:port])
91
120
  // Priority:
92
121
  // 1) CANOPY_BASE_URL env
@@ -256,4 +285,7 @@ module.exports = {
256
285
  readSiteMetadata,
257
286
  getSiteTitle,
258
287
  DEFAULT_SITE_TITLE,
288
+ readSearchPageMetadata,
289
+ DEFAULT_SEARCH_PAGE_TITLE,
290
+ DEFAULT_SEARCH_PAGE_DESCRIPTION,
259
291
  };
@@ -11,6 +11,7 @@ const {
11
11
  OUT_DIR,
12
12
  htmlShell,
13
13
  canopyBodyClassForType,
14
+ readSearchPageMetadata,
14
15
  } = require('../common');
15
16
  const { resolveCanopyConfigPath } = require('../config-path');
16
17
 
@@ -259,14 +260,25 @@ async function buildSearchPage() {
259
260
  }
260
261
  const mdx = require('../build/mdx');
261
262
  const searchHref = rootRelativeHref('search.html');
263
+ const searchPageMeta = readSearchPageMetadata() || {};
264
+ const pageTitle =
265
+ typeof searchPageMeta.title === 'string' && searchPageMeta.title.trim()
266
+ ? searchPageMeta.title.trim()
267
+ : 'Search';
268
+ const pageDescription =
269
+ typeof searchPageMeta.description === 'string'
270
+ ? searchPageMeta.description
271
+ : '';
262
272
  const pageDetails = {
263
- title: 'Search',
273
+ title: pageTitle,
274
+ description: pageDescription,
264
275
  href: searchHref,
265
276
  url: searchHref,
266
277
  type: 'search',
267
278
  canonical: searchHref,
268
279
  meta: {
269
- title: 'Search',
280
+ title: pageTitle,
281
+ description: pageDescription,
270
282
  type: 'search',
271
283
  url: searchHref,
272
284
  canonical: searchHref,
@@ -312,7 +324,7 @@ async function buildSearchPage() {
312
324
  }
313
325
  } catch (_) {}
314
326
  const bodyClass = canopyBodyClassForType('search');
315
- let html = htmlShell({ title: 'Search', body, cssHref: null, scriptHref: jsRel, headExtra, bodyClass });
327
+ let html = htmlShell({ title: pageTitle, body, cssHref: null, scriptHref: jsRel, headExtra, bodyClass });
316
328
  try { html = require('../common').applyBaseToHtml(html); } catch (_) {}
317
329
  await fsp.writeFile(outPath, html, 'utf8');
318
330
  console.log('Search: Built', path.relative(process.cwd(), outPath));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopy-iiif/app",
3
- "version": "1.5.16",
3
+ "version": "1.5.17",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "Mat Jordan <mat@northwestern.edu>",