@museumwnf/viewer-core 2.24.1 → 2.25.0
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
package/src/dxa/countryCodes.js
CHANGED
|
@@ -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)
|
|
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
|
-
|
|
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,7 +54,7 @@ export function useGalleryCollection(data, config = {}) {
|
|
|
53
54
|
*/
|
|
54
55
|
const FACETS = {
|
|
55
56
|
country: {
|
|
56
|
-
values: (item) => countryById.value.get(item.country_id)
|
|
57
|
+
values: (item) => countryUrlCode(countryById.value.get(item.country_id)),
|
|
57
58
|
label: (code) => labelOf('countries', countryIdForCode(code)),
|
|
58
59
|
},
|
|
59
60
|
...Object.fromEntries(
|
|
@@ -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
|
|
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
|
|