@museumwnf/viewer-core 2.22.0 → 2.23.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/README.md CHANGED
@@ -157,6 +157,8 @@ What a website's `main.js` still writes, and why it cannot move here:
157
157
  | `media` | `{ legacyHost }` | no | the host of the legacy media server, for [`mediaUrl()`](#the-declaration-outside-a-component) |
158
158
  | `links` | object | no | the addresses a website links out to: `portal`, `galleries`, `myCollection`, `about`, `contact`, `legalNotice`, `credits`, `cookies` |
159
159
  | `site.origin` | string | no | the absolute origin this build is deployed at, base path included when there is one (`https://metanull.github.io/islamicart`, no trailing slash) — declared once here rather than baked into the package, since the package cannot know where it will be served; read by [`sourceUrl()`](#the-declaration-outside-a-component) |
160
+ | `site.slug` | string | no | the site's slug, as in the exporters' instance files; defaults to the last segment of `site.origin`. The global search's link sends it as `from` |
161
+ | `globalSearch` | `true` or `{ url }` | no | **off by default.** Turns on the link to the global search (inventory-app M15, ADR 005): `true` for its default address (`GLOBAL_SEARCH_URL`), `{ url }` for another https address. viewer-layout's header then shows its search box. The parity check turns it on for the sites whose legacy had a similar feature |
160
162
 
161
163
  `dataset.config.js` is the whole declaration of a website. Before it mounts,
162
164
  a website reads nothing from its data package but `manifest.json`; it reads
@@ -579,6 +581,9 @@ below for whichever future site needs its own).
579
581
  | `mediaUrl(path, size = 'hi_res')` | `${config.media.legacyHost}/${size}/${path}` for a legacy media path the package carries; an address is returned as it is |
580
582
  | `useSiteRights()` | `{ holder, termsUrl, attribution }` from the data package's `manifest.rights`; a package with no such block offers no holder or attribution, and `termsUrl` falls back to `mwnfLinks.legalNotice` |
581
583
  | `sourceUrl(route)` | `${config.site.origin}/#${path}` for `route` — a route already resolved (its `fullPath` read as it is) or a raw location the installed router resolves; null when the website declares no `site.origin` |
584
+ | `globalSearchUrl({ q, lang })` | the global search's address for `q` in `lang`, with this site's slug as `from`; null unless the site sets `globalSearch`. It never takes an address from content: the search site accepts only slugs from its own list of sites |
585
+ | `useGlobalSearch()` | `{ enabled, url(q, lang) }` for a component, such as viewer-layout's search box |
586
+ | `siteSlug()` | this site's slug: `site.slug`, else the last segment of `site.origin`; null when neither is a valid slug |
582
587
 
583
588
  ### `useDataPackage()` → data access (the only allowed way to read the data package)
584
589
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@museumwnf/viewer-core",
3
- "version": "2.22.0",
3
+ "version": "2.23.1",
4
4
  "description": "Application engine for MWNF websites: turns a dataset.config.js into a mounted Vue application.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -0,0 +1,74 @@
1
+ import { useSiteConfig } from './siteConfig.js'
2
+
3
+ // The global search (inventory-app M15, ADR 005): one search over every site's
4
+ // items, on a site of its own. A site opts in with `globalSearch` in its
5
+ // dataset.config.js, off by default:
6
+ //
7
+ // globalSearch: true // the default address
8
+ // globalSearch: { url: 'https://example.org/search/' } // another address
9
+ //
10
+ // The link carries the text, the language and this site's own slug as `from`,
11
+ // and nothing else: the search site accepts a slug only if it is in its list
12
+ // of sites, never an address, so no parameter can send a visitor elsewhere.
13
+
14
+ /** Where the search site is served, unless a site's config names another. */
15
+ export const GLOBAL_SEARCH_URL = 'https://museumwithnofrontiers.github.io/search/'
16
+
17
+ /** A site's slug: lowercase words joined by single hyphens, as the exporters' instance files. */
18
+ const SLUG = /^[a-z0-9]+(-[a-z0-9]+)*$/
19
+ const LANGUAGE = /^[a-z]{2}$/
20
+
21
+ function searchBase(setting) {
22
+ if (setting === true) return GLOBAL_SEARCH_URL
23
+ if (setting && typeof setting === 'object' && typeof setting.url === 'string') {
24
+ let url
25
+ try {
26
+ url = new URL(setting.url)
27
+ } catch {
28
+ return null
29
+ }
30
+ if (url.protocol !== 'https:' || url.search || url.hash || url.username || url.password) return null
31
+ return url.href.endsWith('/') ? url.href : `${url.href}/`
32
+ }
33
+ return null
34
+ }
35
+
36
+ /**
37
+ * This site's slug: `site.slug` when declared, else the last segment of
38
+ * `site.origin` (every site is served one path segment under a common
39
+ * parent). Null when neither gives a valid slug.
40
+ */
41
+ export function siteSlug(config = useSiteConfig()) {
42
+ const declared = config?.site?.slug
43
+ if (typeof declared === 'string') return SLUG.test(declared) ? declared : null
44
+ const origin = String(config?.site?.origin ?? '').replace(/\/+$/, '')
45
+ const last = origin.slice(origin.lastIndexOf('/') + 1)
46
+ return SLUG.test(last) ? last : null
47
+ }
48
+
49
+ /**
50
+ * The address of the global search for `q` in `lang`, or null when the site
51
+ * has not opted in. Built only from the configured address and the escaped
52
+ * parameters.
53
+ */
54
+ export function globalSearchUrl({ q = '', lang = '' } = {}, config = useSiteConfig()) {
55
+ const base = searchBase(config?.globalSearch)
56
+ if (!base) return null
57
+ const params = new URLSearchParams()
58
+ const text = String(q ?? '').trim()
59
+ if (text) params.set('q', text)
60
+ if (LANGUAGE.test(String(lang))) params.set('lang', String(lang))
61
+ const from = siteSlug(config)
62
+ if (from) params.set('from', from)
63
+ const query = params.toString()
64
+ return `${base}#/${query ? `?${query}` : ''}`
65
+ }
66
+
67
+ /** For a component: whether the site has opted in, and the link builder. */
68
+ export function useGlobalSearch() {
69
+ const config = useSiteConfig()
70
+ return {
71
+ enabled: searchBase(config?.globalSearch) !== null,
72
+ url: (q, lang) => globalSearchUrl({ q, lang }, config),
73
+ }
74
+ }
package/src/index.js CHANGED
@@ -21,6 +21,7 @@ export { mediaUrl, useSiteConfig } from './siteConfig.js'
21
21
  export { bindDisplayLanguage, displayLanguage } from './displayLanguage.js'
22
22
  export { siblingSiteUrl, sourceUrl, useSiteRights } from './rights.js'
23
23
  export { LEGACY_SITES, toNewSite, watchNewSiteLinks, withScheme } from './legacySites.js'
24
+ export { GLOBAL_SEARCH_URL, globalSearchUrl, siteSlug, useGlobalSearch } from './globalSearch.js'
24
25
  export { legacyRecordId } from './legacyIds.js'
25
26
 
26
27
  // The list pages: query state, pagination, facets, dates, keyword search.
@@ -122,6 +122,8 @@ const PAGES = {
122
122
  '/hcr_home.php': '/timeline', '/dynasties/': '/dynasties',
123
123
  '/isl_missionstatement.php': '/mission-statement', '/recommendedlinks.php': '/recommended-links',
124
124
  '/atrium_sponsor_detail.php': '/sponsors', '/glossarysearch.php': '/glossary-spelling',
125
+ // The list of the virtual exhibitions; each one is a mini-site row above.
126
+ '/exhibitions/isl': '/exhibitions', '/exhibitions/isl/': '/exhibitions', '/exhibitions/isl/index.php': '/exhibitions',
125
127
  },
126
128
  baroqueart: {
127
129
  '/': '/', '/index.php': '/',
@@ -206,6 +208,18 @@ function travelsRoute(path, url) {
206
208
  return null
207
209
  }
208
210
 
211
+ // Discover Islamic Art's partner page (`pm_partner.php?id=<partner>;<country>&type=museum|institution`),
212
+ // keyed as the importer keys a partner (`mwnf3:museums:…`, `mwnf3:institutions:…`). Travels' trails and the
213
+ // books link to it for their museums. Its other pages are PAGES above.
214
+ const PARTNER_KINDS = { museum: 'museums', institution: 'institutions' }
215
+ function islamicartRecordRoute(path, url) {
216
+ if (path.toLowerCase() !== '/pm_partner.php') return undefined
217
+ const [partner, country] = (url.searchParams.get('id') ?? '').split(';').map((part) => part.trim())
218
+ const kind = PARTNER_KINDS[(url.searchParams.get('type') ?? 'museum').toLowerCase()]
219
+ if (!partner || !country || !kind) return null
220
+ return `/partner/${legacyRecordId('partner', `mwnf3:${kind}:${partner}:${country}`)}`
221
+ }
222
+
209
223
  // The families whose pages name a record or a page in their address.
210
224
  const RECORD_PAGES = { publications: publicationsRoute, travels: travelsRoute }
211
225
 
@@ -241,6 +255,10 @@ function routeFor(row, url) {
241
255
  const lang = /^[a-z]{2}$/.test(rest[0] ?? '') ? rest.shift() : null
242
256
  return `/${rest.join('/')}${lang ? `?lang=${lang}` : ''}`
243
257
  }
258
+ if (row.family === 'islamicart') {
259
+ const record = islamicartRecordRoute(path, url)
260
+ if (record !== undefined) return record
261
+ }
244
262
  const route = PAGES[row.family]?.[pathname.toLowerCase()]
245
263
  if (!route) return null
246
264
  const keep = (KEPT_QUERY[route] ?? []).filter((key) => url.searchParams.has(key))