@museumwnf/viewer-core 2.24.1 → 2.25.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@museumwnf/viewer-core",
3
- "version": "2.24.1",
3
+ "version": "2.25.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",
@@ -55,7 +55,9 @@ export function useCatalogueResults(spec, { entity: routeEntity = '' } = {}) {
55
55
  let list = records.value ?? []
56
56
  if (s.scope) list = list.filter((record) => s.scope(record, filters, helpers))
57
57
  for (const [key, facet] of Object.entries(s.facets ?? {})) {
58
- const wanted = filters[key]
58
+ // A facet's `canonical(value)` turns a value the URL may carry in an
59
+ // older spelling (a legacy country code) into the one its records carry.
60
+ const wanted = facet.canonical && filters[key] ? facet.canonical(filters[key]) ?? filters[key] : filters[key]
59
61
  if (!wanted) continue
60
62
  list = list.filter((record) => facetValues(record, facet).map(String).includes(String(wanted)))
61
63
  }
@@ -19,6 +19,18 @@ import { computed } from 'vue'
19
19
  // is the Solomon Islands, where legacy means the UAE and Serbia. Only
20
20
  // countries.json can name them correctly.
21
21
 
22
+ // A gallery package from inventory-app's pass 1 also ships `iso_code` on each
23
+ // country: its ISO 3166-1 alpha-2 code, derived by the exporter from the
24
+ // inventory's ISO-3 id. A site reads it first (`countryUrlCode`), lowercased,
25
+ // so the URL carries an inventory value; the legacy `code` is still matched,
26
+ // so a link shared with a legacy code keeps resolving while packages carry it.
27
+
28
+ /** The code a country stands for in a URL: its ISO code when the package has one, else the legacy code. */
29
+ export function countryUrlCode(country) {
30
+ if (!country) return null
31
+ return country.iso_code ? String(country.iso_code).toLowerCase() : (country.code ?? null)
32
+ }
33
+
22
34
  // Two legacy codes are not ISO 3166-1 alpha-2.
23
35
  const LEGACY_TO_ISO = { uk: 'GB', pa: 'PS' }
24
36
 
@@ -51,7 +63,7 @@ export function useLegacyCountryCodes({ countries, countryById, timelines, label
51
63
  // last segment in only the first — taking the last one yields `2` on the
52
64
  // second.
53
65
  function legacyCodeOf(timeline) {
54
- const fromPackage = countryById.value.get(timeline.country_id)?.code
66
+ const fromPackage = countryUrlCode(countryById.value.get(timeline.country_id))
55
67
  if (fromPackage) return fromPackage
56
68
  const parts = (timeline.backward_compatibility ?? '').split(':')
57
69
  const at = parts.indexOf('country')
@@ -85,7 +97,8 @@ export function useLegacyCountryCodes({ countries, countryById, timelines, label
85
97
  const timeline = (timelines.value ?? []).find((t) => legacyCodeOf(t) === code)
86
98
  if (timeline) return timeline.country_id
87
99
  // A country with no chronology: countries.json's own code.
88
- return (countries.value ?? []).find((c) => c.code === code)?.id ?? null
100
+ const list = countries.value ?? []
101
+ return (list.find((c) => countryUrlCode(c) === code) ?? list.find((c) => c.code === code))?.id ?? null
89
102
  }
90
103
 
91
104
  return { countryIdForCode, countryLabel }
@@ -1,4 +1,5 @@
1
1
  import { projectLabel } from '../../conventions.js'
2
+ import { countryUrlCode } from '../countryCodes.js'
2
3
  import { DATE_MODE, FACET_CATEGORIES, PAGE_SIZE } from '../shared.js'
3
4
 
4
5
  export { DATE_MODE, FACET_CATEGORIES, FACET_LABEL_KEYS, GALLERY_PAGE_SIZE, PAGE_SIZE, useFacetLabels } from '../shared.js'
@@ -53,8 +54,12 @@ export function useGalleryCollection(data, config = {}) {
53
54
  */
54
55
  const FACETS = {
55
56
  country: {
56
- values: (item) => countryById.value.get(item.country_id)?.code ?? null,
57
+ values: (item) => countryUrlCode(countryById.value.get(item.country_id)),
57
58
  label: (code) => labelOf('countries', countryIdForCode(code)),
59
+ // A link shared with a legacy code (`uk`) still filters: the code is
60
+ // read as the country's URL code (`gb`). Where a legacy code is another
61
+ // country's ISO code (`ua`), the ISO reading wins.
62
+ canonical: (code) => countryUrlCode(countryById.value.get(countryIdForCode(code))),
58
63
  },
59
64
  ...Object.fromEntries(
60
65
  FACET_CATEGORIES.map((category) => [
@@ -125,8 +125,11 @@ export function useGalleryData(config = {}) {
125
125
  (gallery.value?.sibling_galleries ?? []).filter((g) => !g.hidden),
126
126
  )
127
127
 
128
- // A sibling with a new site links to it (inventory-app#2482).
128
+ // A sibling links to its site: the address the package ships (`url`, from
129
+ // the exporter's instance files), else, for an older package, its legacy
130
+ // host turned into the new site's address (inventory-app#2482).
129
131
  function siblingUrl(sibling) {
132
+ if (sibling?.url) return sibling.url
130
133
  return sibling?.legacy_host ? toNewSite(withScheme(sibling.legacy_host)) : null
131
134
  }
132
135