@museumwnf/viewer-core 2.21.0 → 2.22.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@museumwnf/viewer-core",
3
- "version": "2.21.0",
3
+ "version": "2.22.0",
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",
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 { legacyRecordId } from './legacyIds.js'
24
25
 
25
26
  // The list pages: query state, pagination, facets, dates, keyword search.
26
27
  export { useListQuery } from './catalogue/listQuery.js'
@@ -0,0 +1,75 @@
1
+ // The inventory id of a legacy record, from its legacy key (inventory-app#2544).
2
+ // The importer gives every legacy record the same id on every import: a
3
+ // UUIDv5 of `<entity>:<backward_compatibility, lowercased>` in one frozen
4
+ // namespace (inventory-app scripts/importer/src/utils/deterministic-uuid.ts,
5
+ // whose header makes the namespace and the name's shape a contract). A link
6
+ // to a legacy record's page can therefore name the new page's record without
7
+ // reading the other site's package. Synchronous on purpose: a link is
8
+ // rewritten as it is drawn.
9
+
10
+ /** The importer's namespace (`IMPORTER_UUID_NAMESPACE`), frozen there. */
11
+ export const IMPORTER_UUID_NAMESPACE = 'bc112041-0784-4475-80b2-0c96425ac5ea'
12
+
13
+ function utf8(text) {
14
+ return new TextEncoder().encode(text)
15
+ }
16
+
17
+ // SHA-1 (FIPS 180-4) of `bytes`, as 20 bytes. Only UUIDv5 needs it here.
18
+ function sha1(bytes) {
19
+ const length = bytes.length
20
+ const blocks = ((length + 8) >> 6) + 1
21
+ const words = new Uint32Array(blocks * 16)
22
+ for (let i = 0; i < length; i++) words[i >> 2] |= bytes[i] << (24 - (i % 4) * 8)
23
+ words[length >> 2] |= 0x80 << (24 - (length % 4) * 8)
24
+ words[blocks * 16 - 1] = length * 8
25
+ words[blocks * 16 - 2] = Math.floor((length * 8) / 0x100000000)
26
+ let [a, b, c, d, e] = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]
27
+ const w = new Uint32Array(80)
28
+ const rotl = (x, n) => (x << n) | (x >>> (32 - n))
29
+ for (let block = 0; block < blocks; block++) {
30
+ for (let t = 0; t < 16; t++) w[t] = words[block * 16 + t]
31
+ for (let t = 16; t < 80; t++) w[t] = rotl(w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16], 1)
32
+ let [h0, h1, h2, h3, h4] = [a, b, c, d, e]
33
+ for (let t = 0; t < 80; t++) {
34
+ let f, k
35
+ if (t < 20) [f, k] = [(h1 & h2) | (~h1 & h3), 0x5a827999]
36
+ else if (t < 40) [f, k] = [h1 ^ h2 ^ h3, 0x6ed9eba1]
37
+ else if (t < 60) [f, k] = [(h1 & h2) | (h1 & h3) | (h2 & h3), 0x8f1bbcdc]
38
+ else [f, k] = [h1 ^ h2 ^ h3, 0xca62c1d6]
39
+ const next = (rotl(h0, 5) + f + h4 + k + w[t]) >>> 0
40
+ ;[h4, h3, h2, h1, h0] = [h3, h2, rotl(h1, 30) >>> 0, h0, next]
41
+ }
42
+ a = (a + h0) >>> 0
43
+ b = (b + h1) >>> 0
44
+ c = (c + h2) >>> 0
45
+ d = (d + h3) >>> 0
46
+ e = (e + h4) >>> 0
47
+ }
48
+ const out = new Uint8Array(20)
49
+ ;[a, b, c, d, e].forEach((word, i) => {
50
+ for (let j = 0; j < 4; j++) out[i * 4 + j] = (word >>> (24 - j * 8)) & 0xff
51
+ })
52
+ return out
53
+ }
54
+
55
+ /** RFC 4122 UUIDv5 of `name` in `namespace`. */
56
+ export function uuidV5(name, namespace = IMPORTER_UUID_NAMESPACE) {
57
+ const ns = namespace.replace(/-/g, '').match(/../g).map((hex) => parseInt(hex, 16))
58
+ const nameBytes = utf8(name)
59
+ const input = new Uint8Array(16 + nameBytes.length)
60
+ input.set(ns, 0)
61
+ input.set(nameBytes, 16)
62
+ const hash = sha1(input).slice(0, 16)
63
+ hash[6] = (hash[6] & 0x0f) | 0x50
64
+ hash[8] = (hash[8] & 0x3f) | 0x80
65
+ const hex = Array.from(hash, (byte) => byte.toString(16).padStart(2, '0')).join('')
66
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`
67
+ }
68
+
69
+ /**
70
+ * The inventory id the importer gives the legacy record `key` (its
71
+ * `backward_compatibility`) of `entity` (`publication`, `collection`…).
72
+ */
73
+ export function legacyRecordId(entity, key) {
74
+ return uuidV5(`${entity}:${String(key).toLowerCase()}`)
75
+ }
@@ -1,3 +1,4 @@
1
+ import { legacyRecordId } from './legacyIds.js'
1
2
  import { siblingSiteUrl } from './rights.js'
2
3
 
3
4
  // Links to legacy MWNF sites that have a new one (inventory-app#2482). The
@@ -9,7 +10,8 @@ import { siblingSiteUrl } from './rights.js'
9
10
  //
10
11
  // The estate's legacy addresses, one row a site: a gallery, Explore, the
11
12
  // galleries hub and the three products by host; an exhibition by host and
12
- // its first path segment (they share a host); a mini-site by its own page
13
+ // its first path segment (they share a host); Publications (legacy books)
14
+ // and Travels (legacy's Exhibition Trails) by host; a mini-site by its own page
13
15
  // (a Sharing History one by its `eId`). Built from the parity tool's sitemap
14
16
  // (the legacy dumps) and the exporters' instance files; the parity `links`
15
17
  // pass fails on a link this table misses.
@@ -18,6 +20,7 @@ export const LEGACY_SITES = [
18
20
  { host: 'archaeology.museumwnf.org', slug: 'archaeology', family: 'gallery' },
19
21
  { host: 'architectural-elements.museumwnf.org', slug: 'architectural-elements', family: 'gallery' },
20
22
  { host: 'arms-armoury.museumwnf.org', slug: 'arms-armoury', family: 'gallery' },
23
+ { host: 'books.museumwnf.org', slug: 'publications', family: 'publications' },
21
24
  { host: 'exhibitions.museumwnf.org', path: '/arts_in_dialogue/', slug: 'arts-in-dialogue', family: 'exhibition' },
22
25
  { host: 'baroqueart.museumwnf.org', slug: 'baroqueart', family: 'baroqueart' },
23
26
  { host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/absolutism/', slug: 'baroqueart-absolutism', family: 'minisite' },
@@ -94,6 +97,7 @@ export const LEGACY_SITES = [
94
97
  { host: 'exhibitions.museumwnf.org', path: '/the_use_of_colours_in_art/', slug: 'the-use-of-colours-in-art', family: 'exhibition' },
95
98
  { host: 'theatre.museumwnf.org', slug: 'theatre', family: 'gallery' },
96
99
  { host: 'toys-games.museumwnf.org', slug: 'toys-games', family: 'gallery' },
100
+ { host: 'travels.museumwnf.org', slug: 'travels', family: 'travels' },
97
101
  { host: 'wallpaintings.museumwnf.org', slug: 'wallpaintings', family: 'gallery' },
98
102
  { host: 'exhibitions.museumwnf.org', path: '/water_in_islam/', slug: 'water-in-islam', family: 'exhibition' },
99
103
  { host: 'weights-measures.museumwnf.org', slug: 'weights-measures', family: 'gallery' },
@@ -138,6 +142,73 @@ const PAGES = {
138
142
  // The query keys a page's new route reads as legacy's did.
139
143
  const KEPT_QUERY = { '/partners/results': ['type'] }
140
144
 
145
+ // Legacy books.museumwnf.org (book-client's routes): a book by its legacy id
146
+ // (`mwnf3:bookbase:<id>`) in the version's language, a category's page, the
147
+ // search (its free-text fields and the language, whose values the new search
148
+ // reads as legacy's did). Its sign-up page has no counterpart.
149
+ const BOOK_SEARCH_KEYS = ['title', 'author', 'isbn', 'language']
150
+ function publicationsRoute(path, url) {
151
+ if (path === '/') return '/'
152
+ let match = /^\/book\/(\d+)(?:\/([a-z]{2}))?$/i.exec(path)
153
+ if (match) {
154
+ const id = legacyRecordId('publication', `mwnf3:bookbase:${match[1]}`)
155
+ return `/publication/${id}${match[2] ? `/${match[2].toLowerCase()}` : ''}`
156
+ }
157
+ match = /^\/category\/([a-z0-9-]+)(?:\/(\d+))?$/i.exec(path)
158
+ if (match) {
159
+ const page = match[2] && match[2] !== '1' ? `?page=${match[2]}` : ''
160
+ return `/category/${match[1].toLowerCase()}${page}`
161
+ }
162
+ if (path === '/results') {
163
+ const kept = BOOK_SEARCH_KEYS.filter((key) => url.searchParams.get(key))
164
+ return kept.length ? `/results?${kept.map((key) => `${key}=${encodeURIComponent(url.searchParams.get(key))}`).join('&')}` : '/results'
165
+ }
166
+ return null
167
+ }
168
+
169
+ // Legacy travels.museumwnf.org's Exhibition Trails: a country's or a theme's
170
+ // trails, a trail (`?id=<project>;<country>;<number>;<language>`) and an
171
+ // itinerary (`?id=<project>;<country>;<roman number>;<language>;<trail>`),
172
+ // keyed as the importer keys them (`mwnf3_travels:trail:…`,
173
+ // `mwnf3_travels:itinerary:…`), each tab (`fl`) the new page has. The rest of
174
+ // the host (the tours, the booking form) has no new site and stays there.
175
+ // The trails' countries: legacy's code → the inventory id travels-data's
176
+ // countries.json gives it.
177
+ const TRAVELS_COUNTRIES = {
178
+ dz: 'dza', eg: 'egy', es: 'esp', it: 'ita', jo: 'jor', ma: 'mar', pa: 'pse', pt: 'prt', sy: 'syr', tn: 'tun', tr: 'tur',
179
+ }
180
+ const TRAIL_TABS = ['desc', 'its', 'cur']
181
+ const ITINERARY_TABS = ['des', 'vl']
182
+ function travelsQuery(url, tabs, language) {
183
+ const tab = (url.searchParams.get('fl') ?? '').toLowerCase()
184
+ const query = [tabs.includes(tab) ? `tab=${tab}` : null, /^[a-z]{2}$/i.test(language ?? '') ? `lang=${language.toLowerCase()}` : null]
185
+ const kept = query.filter(Boolean)
186
+ return kept.length ? `?${kept.join('&')}` : ''
187
+ }
188
+ function travelsRoute(path, url) {
189
+ const script = path.toLowerCase()
190
+ if (script === '/travel_et_home.php') return '/'
191
+ if (script === '/travel_et_trail.php') {
192
+ const country = TRAVELS_COUNTRIES[(url.searchParams.get('cid') ?? '').toLowerCase()]
193
+ if (country) return `/trails?country=${country}`
194
+ const project = url.searchParams.get('tid')
195
+ return /^[a-z0-9]+$/i.test(project ?? '') ? `/trails?project=${project.toUpperCase()}` : null
196
+ }
197
+ const id = (url.searchParams.get('id') ?? '').split(';').map((part) => part.trim())
198
+ if (script === '/travel_et_traildetail.php' && id.length >= 3 && id.slice(0, 3).every(Boolean)) {
199
+ const [project, country, number, language] = id
200
+ return `/trail/${legacyRecordId('collection', `mwnf3_travels:trail:${project}:${country}:${number}`)}${travelsQuery(url, TRAIL_TABS, language)}`
201
+ }
202
+ if (script === '/travel_et_itenary.php' && id.length >= 5 && [0, 1, 2, 4].every((i) => id[i])) {
203
+ const [project, country, number, language, trail] = id
204
+ return `/itinerary/${legacyRecordId('collection', `mwnf3_travels:itinerary:${project}:${country}:${trail}:${number}`)}${travelsQuery(url, ITINERARY_TABS, language)}`
205
+ }
206
+ return null
207
+ }
208
+
209
+ // The families whose pages name a record or a page in their address.
210
+ const RECORD_PAGES = { publications: publicationsRoute, travels: travelsRoute }
211
+
141
212
  const bareHost = (host) => host.toLowerCase().replace(/^www\./, '')
142
213
 
143
214
  function rowFor(url) {
@@ -164,6 +235,7 @@ function routeFor(row, url) {
164
235
  const path = pathname.replace(/\/+$/, '') || '/'
165
236
  if (row.family === 'gallery' || row.family === 'explore' || row.family === 'galleries') return `${path}${url.search}`
166
237
  if (row.family === 'minisite') return '/'
238
+ if (RECORD_PAGES[row.family]) return RECORD_PAGES[row.family](path, url)
167
239
  if (row.family === 'exhibition') {
168
240
  const rest = path.split('/').filter(Boolean).slice(1)
169
241
  const lang = /^[a-z]{2}$/.test(rest[0] ?? '') ? rest.shift() : null