@museumwnf/viewer-core 2.20.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 +1 -1
- package/src/catalogue/catalogueResults.js +123 -0
- package/src/createStandardViewer.js +32 -4
- package/src/index.js +3 -1
- package/src/legacyIds.js +75 -0
- package/src/legacySites.js +73 -1
- package/src/testing/chromeSources.js +35 -0
- package/src/testing/index.js +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { computed, toValue } from 'vue'
|
|
2
|
+
import { useDataPackage } from '../composables/useDataPackage.js'
|
|
3
|
+
import { entityRef } from '../composables/useEntities.js'
|
|
4
|
+
import { useI18n } from '../i18n/index.js'
|
|
5
|
+
import { renderInline, renderPlain } from '../i18n/markdown.js'
|
|
6
|
+
import { dateRange } from './dates.js'
|
|
7
|
+
import { useFacets } from './facets.js'
|
|
8
|
+
import { useListQuery } from './listQuery.js'
|
|
9
|
+
import { sortChronological, usePagination } from './pagination.js'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A results page's engine: the records of one entity, narrowed by the filters
|
|
13
|
+
* and the page the URL carries, in order, a page at a time, each drawn as a
|
|
14
|
+
* row. viewer-layout's `CatalogueResultsView` draws it; a page of another
|
|
15
|
+
* shape can call it directly and draw the result its own way.
|
|
16
|
+
*
|
|
17
|
+
* `spec` (an object, a ref or a getter) is the view's spec — its `entity`,
|
|
18
|
+
* `keys`, `facets`, `facetScope`, `scope`, `match`, `narrow`, `dates`,
|
|
19
|
+
* `sort`, `pageSize`, `record`, `recordRoute`, `summary` and `summaryLabel`;
|
|
20
|
+
* see CatalogueResultsView's header for each. `entity` is the route's own,
|
|
21
|
+
* for a `features.entities` page, used when the spec names none.
|
|
22
|
+
*
|
|
23
|
+
* Returns the query state (`filters`, `page`, `active`, `apply`, `reset`,
|
|
24
|
+
* `goToPage`), the records (`records`, `matching`), the facets' `options`,
|
|
25
|
+
* `pageInfo`, the page's `rows`, the `summary` parts, and `state`: all of it
|
|
26
|
+
* in one object, which is what the view hands each of its slots.
|
|
27
|
+
*/
|
|
28
|
+
export function useCatalogueResults(spec, { entity: routeEntity = '' } = {}) {
|
|
29
|
+
const { t, locale } = useI18n()
|
|
30
|
+
const pkg = useDataPackage()
|
|
31
|
+
const current = computed(() => toValue(spec))
|
|
32
|
+
|
|
33
|
+
// Read once, as the URL keys are: a page does not change entity.
|
|
34
|
+
const entity = current.value.entity ?? routeEntity
|
|
35
|
+
const records = entityRef(entity)
|
|
36
|
+
if (entity) pkg.loadTranslations(entity, 'en')
|
|
37
|
+
|
|
38
|
+
const dates = current.value.dates
|
|
39
|
+
const keys = current.value.keys ?? [
|
|
40
|
+
...Object.keys(current.value.facets ?? {}),
|
|
41
|
+
...(dates ? [dates.begin ?? 'begin', dates.end ?? 'end'] : []),
|
|
42
|
+
]
|
|
43
|
+
const { filters, page, active, apply, reset, goToPage } = useListQuery({ keys })
|
|
44
|
+
|
|
45
|
+
const helpers = {
|
|
46
|
+
t,
|
|
47
|
+
locale,
|
|
48
|
+
tr: (name, id) => pkg.tr(name, id, locale.value, 'en'),
|
|
49
|
+
renderInline,
|
|
50
|
+
renderPlain,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const matching = computed(() => {
|
|
54
|
+
const s = current.value
|
|
55
|
+
let list = records.value ?? []
|
|
56
|
+
if (s.scope) list = list.filter((record) => s.scope(record, filters, helpers))
|
|
57
|
+
for (const [key, facet] of Object.entries(s.facets ?? {})) {
|
|
58
|
+
const wanted = filters[key]
|
|
59
|
+
if (!wanted) continue
|
|
60
|
+
list = list.filter((record) => facetValues(record, facet).map(String).includes(String(wanted)))
|
|
61
|
+
}
|
|
62
|
+
if (s.match) list = list.filter((record) => s.match(record, filters, helpers))
|
|
63
|
+
if (s.narrow) list = s.narrow(list, filters, helpers)
|
|
64
|
+
if (s.dates) {
|
|
65
|
+
list = dateRange(list, {
|
|
66
|
+
begin: filters[s.dates.begin ?? 'begin'],
|
|
67
|
+
end: filters[s.dates.end ?? 'end'],
|
|
68
|
+
mode: s.dates.mode ?? 'overlap',
|
|
69
|
+
fields: s.dates.fields,
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
const sort = s.sort ?? 'chronological'
|
|
73
|
+
if (typeof sort === 'function') return sort(list)
|
|
74
|
+
if (sort === 'chronological') return sortChronological(list)
|
|
75
|
+
if (sort && typeof sort === 'object') return sortChronological(list, sort)
|
|
76
|
+
return list
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const facetSource = computed(() => (current.value.facetScope === 'matching' ? matching.value : records.value ?? []))
|
|
80
|
+
const options = useFacets(facetSource, () => current.value.facets ?? {})
|
|
81
|
+
const pageInfo = usePagination(matching, { page, size: () => current.value.pageSize ?? 20 })
|
|
82
|
+
|
|
83
|
+
const recordRoute = computed(() => current.value.recordRoute ?? (routeEntity ? `${routeEntity}-detail` : 'item'))
|
|
84
|
+
function defaultRecord(record) {
|
|
85
|
+
const text = helpers.tr(entity, record.id)
|
|
86
|
+
const name = text.name ?? record.internal_name ?? record.id
|
|
87
|
+
return {
|
|
88
|
+
id: record.id,
|
|
89
|
+
image: record.images?.[0]?.url ?? '',
|
|
90
|
+
imageAlt: renderPlain(String(name)),
|
|
91
|
+
name: renderInline(String(name)),
|
|
92
|
+
meta: [],
|
|
93
|
+
badge: record.type ?? '',
|
|
94
|
+
to: { name: recordRoute.value, params: { id: record.id } },
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const rows = computed(() => pageInfo.value.rows.map((record) => (current.value.record ?? defaultRecord)(record, helpers)))
|
|
98
|
+
|
|
99
|
+
const state = computed(() => ({
|
|
100
|
+
filters,
|
|
101
|
+
active: active.value,
|
|
102
|
+
apply,
|
|
103
|
+
reset,
|
|
104
|
+
goToPage,
|
|
105
|
+
matching: matching.value,
|
|
106
|
+
pageInfo: pageInfo.value,
|
|
107
|
+
options: options.value,
|
|
108
|
+
}))
|
|
109
|
+
|
|
110
|
+
const summary = computed(() => {
|
|
111
|
+
const s = current.value
|
|
112
|
+
if (s.summary) return s.summary({ ...state.value, t, total: (records.value ?? []).length })
|
|
113
|
+
return [{ label: t(s.summaryLabel ?? 'catalogue.results.itemsFound'), count: pageInfo.value.total }]
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
return { entity, records, filters, page, active, apply, reset, goToPage, matching, options, pageInfo, rows, summary, state, helpers }
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function facetValues(record, facet) {
|
|
120
|
+
if (typeof facet.values === 'function') return [facet.values(record)].flat()
|
|
121
|
+
const raw = record?.[facet.field]
|
|
122
|
+
return Array.isArray(raw) ? raw : [raw]
|
|
123
|
+
}
|
|
@@ -29,12 +29,15 @@ import { mergeMessages } from './i18n/index.js'
|
|
|
29
29
|
* website still imports its own family's `catalogues` and passes it as
|
|
30
30
|
* `dictionary`.
|
|
31
31
|
*
|
|
32
|
+
* Every website calls it as `createStandardViewer(config, { dictionary,
|
|
33
|
+
* ownMessages })`. The older three-argument form, `(config, siteClass,
|
|
34
|
+
* options)`, still works: a second argument that carries none of the option
|
|
35
|
+
* keys below is taken for the shell component.
|
|
36
|
+
*
|
|
32
37
|
* @param {object} config - the site's `dataset.config.js` object, exactly
|
|
33
38
|
* as passed to {@link createViewer} today
|
|
34
|
-
* @param {object} [siteClass] - the site's
|
|
35
|
-
* `config.shell` when `config` does not
|
|
36
|
-
* still declares its own `shell` keeps taking precedence, so existing
|
|
37
|
-
* `dataset.config.js` files need no change)
|
|
39
|
+
* @param {object} [siteClass] - (older form) the site's shell component, used
|
|
40
|
+
* as `config.shell` when `config` does not set one
|
|
38
41
|
* @param {object} [options]
|
|
39
42
|
* @param {object} [options.dictionary] - the family's shared catalogue,
|
|
40
43
|
* i.e. `catalogues` imported from
|
|
@@ -49,6 +52,10 @@ import { mergeMessages } from './i18n/index.js'
|
|
|
49
52
|
* `.unmount()` on it, e.g. in a test)
|
|
50
53
|
*/
|
|
51
54
|
export function createStandardViewer(config, siteClass, options = {}) {
|
|
55
|
+
if (isOptions(siteClass) && arguments.length < 3) {
|
|
56
|
+
options = siteClass
|
|
57
|
+
siteClass = undefined
|
|
58
|
+
}
|
|
52
59
|
const { dictionary, ownMessages, el = '#app' } = options
|
|
53
60
|
|
|
54
61
|
const messages = dictionary
|
|
@@ -59,3 +66,24 @@ export function createStandardViewer(config, siteClass, options = {}) {
|
|
|
59
66
|
app.mount(el)
|
|
60
67
|
return app
|
|
61
68
|
}
|
|
69
|
+
|
|
70
|
+
const OPTION_KEYS = ['dictionary', 'ownMessages', 'el']
|
|
71
|
+
|
|
72
|
+
function isOptions(value) {
|
|
73
|
+
return Boolean(value) && typeof value === 'object' && OPTION_KEYS.some((key) => key in value)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* A website's own texts, by language, from its `locales/<lang>.json` files as
|
|
78
|
+
* `import.meta.glob('../locales/*.json', { eager: true })` returns them — the
|
|
79
|
+
* glob itself stays in the site's `main.js`, where Vite resolves it:
|
|
80
|
+
*
|
|
81
|
+
* ownMessages: textsByLanguage(import.meta.glob('../locales/*.json', { eager: true }))
|
|
82
|
+
*/
|
|
83
|
+
export function textsByLanguage(modules) {
|
|
84
|
+
const texts = {}
|
|
85
|
+
for (const [path, module] of Object.entries(modules ?? {})) {
|
|
86
|
+
texts[path.split('/').pop().replace(/\.json$/, '')] = module.default ?? module
|
|
87
|
+
}
|
|
88
|
+
return texts
|
|
89
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createViewer } from './createViewer.js'
|
|
2
|
-
export { createStandardViewer } from './createStandardViewer.js'
|
|
2
|
+
export { createStandardViewer, textsByLanguage } from './createStandardViewer.js'
|
|
3
3
|
export { useCatalogueData } from './composables/useCatalogueData.js'
|
|
4
4
|
export {
|
|
5
5
|
CATALOGUE_DATE_MODE, CATALOGUE_PAGE_SIZE, objectsAndMonumentsSummary, useCatalogue,
|
|
@@ -21,9 +21,11 @@ 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'
|
|
28
|
+
export { useCatalogueResults } from './catalogue/catalogueResults.js'
|
|
27
29
|
export { paginate, sortChronological, usePagination } from './catalogue/pagination.js'
|
|
28
30
|
export { facetOptions, useFacets } from './catalogue/facets.js'
|
|
29
31
|
export {
|
package/src/legacyIds.js
ADDED
|
@@ -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
|
+
}
|
package/src/legacySites.js
CHANGED
|
@@ -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);
|
|
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
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
3
|
+
import { relative, resolve, sep } from 'node:path'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What is wrong with a site's chrome taken from legacy (decision D7,
|
|
7
|
+
* inventory-app#2233): `sources` is the folder's SOURCES.json, whose `files`
|
|
8
|
+
* name each file by its path from the site's root with the sha256 of the
|
|
9
|
+
* bytes legacy serves. Every listed file must be there, byte for byte, and the
|
|
10
|
+
* folder must hold nothing the list does not name.
|
|
11
|
+
*
|
|
12
|
+
* Returns one line per problem, so a site's test reads
|
|
13
|
+
* `expect(checkChromeSources(sources)).toEqual([])` and a failure names every
|
|
14
|
+
* file at once. Paths resolve from `root`, the site's own directory (where
|
|
15
|
+
* Vitest runs).
|
|
16
|
+
*/
|
|
17
|
+
export function checkChromeSources(sources, { folder = 'theme/assets/legacy', root = process.cwd() } = {}) {
|
|
18
|
+
const problems = []
|
|
19
|
+
const listed = new Set(Object.keys(sources.files ?? {}))
|
|
20
|
+
for (const [path, { sha256 }] of Object.entries(sources.files ?? {})) {
|
|
21
|
+
const file = resolve(root, path)
|
|
22
|
+
if (!existsSync(file)) {
|
|
23
|
+
problems.push(`${path}: missing`)
|
|
24
|
+
continue
|
|
25
|
+
}
|
|
26
|
+
if (createHash('sha256').update(readFileSync(file)).digest('hex') !== sha256) {
|
|
27
|
+
problems.push(`${path}: not the file legacy serves`)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const present = readdirSync(resolve(root, folder), { recursive: true, withFileTypes: true })
|
|
31
|
+
.filter((entry) => entry.isFile() && entry.name !== 'SOURCES.json')
|
|
32
|
+
.map((entry) => `${relative(root, entry.parentPath).split(sep).join('/')}/${entry.name}`)
|
|
33
|
+
for (const path of present.filter((p) => !listed.has(p))) problems.push(`${path}: not listed in SOURCES.json`)
|
|
34
|
+
return problems
|
|
35
|
+
}
|
package/src/testing/index.js
CHANGED