@museumwnf/viewer-core 2.27.0 → 2.29.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/README.md +10 -1
- package/package.json +2 -1
- package/src/composables/useDataPackage.js +16 -0
- package/src/dxa/gallery/useGalleryCollection.js +6 -2
- package/src/dxa/gallery/useGalleryData.js +21 -2
- package/src/dxa/gallery/useGalleryItemDetail.js +5 -1
- package/src/i18n/language.js +2 -6
- package/src/i18n/legacyLanguageCodes.js +8 -0
- package/src/index.js +1 -1
- package/src/legacy/index.js +23 -0
- package/src/legacyAddresses.js +312 -0
- package/src/legacySites.js +8 -303
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ all the packages:
|
|
|
22
22
|
| `@museumwnf/viewer-core` | engine and data layer | the application factory, the router and the texts runtime; the **data layer** — how a site reads its data package ([records](#records-useentities-the-standard-way-a-website-reads-them), [a website's data composable](#a-websites-data-composable), [`useDataPackage`](#usedatapackage--data-access-the-only-allowed-way-to-read-the-data-package)); the engines of list pages, timelines and record pages; the view-model builders the blocks of `@museumwnf/viewer-layout` are fed with ([record pages](#record-pages), [collection trees](#collection-trees), [partners](#partners)) |
|
|
23
23
|
| `@museumwnf/viewer-core/dxa` | DXA family layer | the data composables of the gallery and the exhibition families ([below](#museumwnfviewer-coredxa)) |
|
|
24
24
|
| `@museumwnf/viewer-core/legacy` | legacy address mapping | pure functions decoding `backward_compatibility` for legacy URL shapes |
|
|
25
|
+
| `@museumwnf/viewer-core/legacy-addresses` | legacy MWNF addresses | `LEGACY_SITES`, `legacyAddressTarget(href)` → `{ slug, route } | null` and `legacyAddressRoute(href)` → its route: where a legacy MWNF address lands on the new sites. No Vue, router or DOM, so an exporter imports it in plain Node and ships its links already on the new sites; `toNewSite` draws every link of a website through it |
|
|
25
26
|
| `@museumwnf/viewer-core/testing` | a website's tests | the shared smoke-test kit ([Testing a website](#testing-a-website)) |
|
|
26
27
|
| `@museumwnf/viewer-core/vite` | a website's build | `defineViewerConfig` |
|
|
27
28
|
|
|
@@ -523,6 +524,8 @@ needs it; the standalone sites never import it.
|
|
|
523
524
|
| `partnerKey(partner, countries = [])` | `{ legacyId, countryCode }` from a partner's `backward_compatibility` — `mwnf3:museums:Mus21:ua` on the DXA sites, `mwnf3_sharing_history:sh_partners:at_01_d` on Sharing History, whose key carries the country as its own prefix rather than a fourth segment. `countries` is the fallback for a partner with no `backward_compatibility` at all: its `country_id` resolved to the country's own `code`. |
|
|
524
525
|
| `partnerFromKey(partners, countries, countryCode, legacyId)` | the partner a legacy `/partner/:country/:id` route names, or null — `partnerKey` in reverse |
|
|
525
526
|
| `itemFromUidPath(items, path)` | the item a legacy dbUid *path* names, or null — `backward_compatibility` with `:` swapped for `/`, matched case-insensitively (Sharing History stores its keys lowercase) |
|
|
527
|
+
| `itemIdFromLegacyPaths(legacyPaths, path)` | the item id a dbUid path names in a package's `legacy_paths.json` (`items`, keyed by the path lower case); null for none, `undefined` when the package has no map |
|
|
528
|
+
| `partnerIdFromLegacyPaths(legacyPaths, countryCode, legacyId)` | the partner id `legacy_paths.json`'s `partners` map gives `<country>/<legacy id>`; null for none, `undefined` without a map |
|
|
526
529
|
|
|
527
530
|
### `@museumwnf/viewer-core/dxa`
|
|
528
531
|
|
|
@@ -568,7 +571,7 @@ below for whichever future site needs its own).
|
|
|
568
571
|
|
|
569
572
|
| Export (gallery / exhibition) | Reads | Returns |
|
|
570
573
|
| --- | --- | --- |
|
|
571
|
-
| `useGalleryData(config)` / `useExhibitionData(config)` | `config.eager` (entity names `loadEnglish` loads eagerly; default the family's own list, the exhibition's also carrying `themes`) | the family's whole data layer: `tr`/`md`/`mdInline`/`mdStrip`/`labelOf`/`loadEnglish`/`translations`, every entity and lookup map (`items`, `partners`, `countries`, `tags`, `dynasties`, `timelines`, `timelineEvents`, …), the routes (`itemRoute`, `partnerRoute`, `partnerObjectsRoute`), the legacy URL wrappers (`itemFromUidPath`, `partnerFromKey` — gallery only), the DXA legacy country code both ways (`countryIdForCode(code)`, idempotent on an id, and `countryLabel(countryId)`, one table the collection and the timeline both read), `chromeImage`, `manifest`, `defaultLang`, plus family-specific fields (gallery: `siblingGalleries`/`pickSiblings`; exhibition: `isHiddenPartner` (the site's `exhibition.hiddenPartners` when its config sets them, else the package's `hidden_partner_ids`), `isInstitution`, `projectName`, `exhibitionTitle`/`exhibitionSubtitle`/`exhibitionHeadline`/`bannerCaption`, `siblingSites`) |
|
|
574
|
+
| `useGalleryData(config)` / `useExhibitionData(config)` | `config.eager` (entity names `loadEnglish` loads eagerly; default the family's own list, the exhibition's also carrying `themes`) | the family's whole data layer: `tr`/`md`/`mdInline`/`mdStrip`/`labelOf`/`loadEnglish`/`translations`, every entity and lookup map (`items`, `partners`, `countries`, `tags`, `dynasties`, `timelines`, `timelineEvents`, …), the routes (`itemRoute`, `partnerRoute`, `partnerObjectsRoute`), the legacy URL wrappers (`itemFromUidPath`, `partnerFromKey` — gallery only; they look the address up in `legacy_paths.json` once `loadLegacyPaths()` has loaded it, else decode the legacy keys), the DXA legacy country code both ways (`countryIdForCode(code)`, idempotent on an id, and `countryLabel(countryId)`, one table the collection and the timeline both read), `chromeImage`, `manifest`, `defaultLang`, plus family-specific fields (gallery: `siblingGalleries`/`pickSiblings`; exhibition: `isHiddenPartner` (the site's `exhibition.hiddenPartners` when its config sets them, else the package's `hidden_partner_ids`), `isInstitution`, `projectName`, `exhibitionTitle`/`exhibitionSubtitle`/`exhibitionHeadline`/`bannerCaption`, `siblingSites`) |
|
|
572
575
|
| `useGalleryCollection(data, config)` / `useExhibitionCollection(data, config)` | the `data` object above; `config` unused today | `FACETS`, `tile(item, t)`, `collectionResults` (the `CatalogueResultsView` spec), plus the facet-value helpers (`countryIdForCode` — the data layer's —, `tagLabelForLegacy`, a tag facet keyed on the tag's `legacy_tag_id`, or on its own `id` when it has none, gallery's own `tagIdForLegacy`, `hasEveryTag`) |
|
|
573
576
|
| `useGalleryTimeline(data, collection, config)` / `useExhibitionTimeline(data, collection, config)` | `data`, the `collection` object above (for its `tile`); `config` unused today | the timeline specs (`timelineResults`/`timelineSpec`, `timelineGallery`/`timelineGallerySpec`), `timelineEvents` (viewer-core's `useTimelineEvents` engine — for an exhibition, the one its flags put in force, country or local), and the data layer's `countryLabel`/`countryIdForCode`; the gallery adds `timelineGalleryItems`, the exhibition `usesLocalTimeline` and `hasTimeline` for its local-vs-country chronology switch, decided by the site's `exhibition.timeline` (`'site'`, `'country'` or `false`) when its config sets one, else by the package's `has_timeline`/`has_country_timeline` |
|
|
574
577
|
| `useGalleryPartner(data, collection, config)` / `useExhibitionPartner(data, config)` | `data`, and (gallery only) `collection` for its `tile` | `partnerList`/`partnerListSpec`, `partnerSheet`/`partnerSheetSpec`, and (gallery only) `partnerObjects` — the exhibition shape's `partnerSpecs.js` never carried an objects-page spec |
|
|
@@ -602,6 +605,7 @@ below for whichever future site needs its own).
|
|
|
602
605
|
| `loadTranslations(entity, lang)` | `Promise<object>` | lazy-loads `translations/<entity>.<lang>.json` (id → translated fields); `{}` if the file is absent. Cached. |
|
|
603
606
|
| `translations(entity, lang)` | object | the already-loaded map for that pair; `{}` if not loaded yet |
|
|
604
607
|
| `tr(entity, id, lang, fallbackLang = 'en')` | object | one record's translated fields, falling back to `fallbackLang` then `{}` — reads only what's already loaded |
|
|
608
|
+
| `trFields(entity, id, lang, fallbackLang = 'en')` | object | one record's translated fields in `lang`, each field it lacks (empty or null) taken from `fallbackLang`: a row with its name and no introduction reads its own name and the fallback's introduction. `tr` keeps its whole-row fallback |
|
|
605
609
|
|
|
606
610
|
Always resolve a per-language file by name through `loadTranslations`/`translations`/`tr` —
|
|
607
611
|
never `import(\`...${lang}...\`)`. A dynamic import with an interpolated
|
|
@@ -758,6 +762,11 @@ static host has no file for it. Once the legacy host points at the new site:
|
|
|
758
762
|
`legacyAddressRoute(href)` answers the new site's route of any legacy MWNF
|
|
759
763
|
address, or null. A site without `site.legacyHost` is unchanged.
|
|
760
764
|
|
|
765
|
+
`legacyAddressTarget(href)` answers `{ slug, route }`: the new site and
|
|
766
|
+
its route. Both, and `LEGACY_SITES`, are also at
|
|
767
|
+
`@museumwnf/viewer-core/legacy-addresses`, a module with no Vue, so an
|
|
768
|
+
exporter can rewrite a data package's links with the same table.
|
|
769
|
+
|
|
761
770
|
### Views
|
|
762
771
|
|
|
763
772
|
Every website has three slots — the home page, a list page, a record page —
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@museumwnf/viewer-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.29.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",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"./dxa": "./src/dxa/index.js",
|
|
23
23
|
"./i18n": "./src/i18n/index.js",
|
|
24
24
|
"./legacy": "./src/legacy/index.js",
|
|
25
|
+
"./legacy-addresses": "./src/legacyAddresses.js",
|
|
25
26
|
"./testing": "./src/testing/index.js",
|
|
26
27
|
"./vite": "./src/vite.js",
|
|
27
28
|
"./styles/base.css": "./src/styles/base.css"
|
|
@@ -94,5 +94,21 @@ export function useDataPackage() {
|
|
|
94
94
|
{}
|
|
95
95
|
)
|
|
96
96
|
},
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* One record's translated fields in `lang`, field by field: each field the
|
|
100
|
+
* record has (not empty) in `lang`, else the same field in `fallbackLang`
|
|
101
|
+
* (default `'en'`). A theme whose Spanish row has a name and no
|
|
102
|
+
* introduction reads its Spanish name and its English introduction. `tr`
|
|
103
|
+
* keeps its whole-row fallback. Reads only what is already loaded, as `tr`
|
|
104
|
+
* does.
|
|
105
|
+
*/
|
|
106
|
+
trFields(entity, id, lang, fallbackLang = 'en') {
|
|
107
|
+
const fallback = translationCache.value[`${entity}.${fallbackLang}`]?.[id] ?? {}
|
|
108
|
+
if (lang === fallbackLang) return fallback
|
|
109
|
+
const own = translationCache.value[`${entity}.${lang}`]?.[id] ?? {}
|
|
110
|
+
const kept = Object.entries(own).filter(([, value]) => value !== '' && value != null)
|
|
111
|
+
return { ...fallback, ...Object.fromEntries(kept) }
|
|
112
|
+
},
|
|
97
113
|
}
|
|
98
114
|
}
|
|
@@ -130,11 +130,15 @@ export function useGalleryCollection(data, config = {}) {
|
|
|
130
130
|
// `sort.tiebreak`, viewer-layout's dxa/gallery pages):
|
|
131
131
|
// dxa-api's `ORDER BY startDate, countryName, partnerName`, then MySQL's
|
|
132
132
|
// own order, which is the table's key: the record's legacy key, its
|
|
133
|
-
// numbers compared as numbers (inventory-app#2423).
|
|
133
|
+
// numbers compared as numbers (inventory-app#2423). A package from
|
|
134
|
+
// inventory-app's pass 3 ships that order as each record's `sort_key`
|
|
135
|
+
// (a rank), which then breaks the tie in place of the legacy key.
|
|
134
136
|
function legacyOrder(a, b) {
|
|
135
137
|
return compareText(labelOf('countries', a.country_id), labelOf('countries', b.country_id))
|
|
136
138
|
|| compareText(labelOf('partners', a.partner_id), labelOf('partners', b.partner_id))
|
|
137
|
-
||
|
|
139
|
+
|| (Number.isInteger(a.sort_key) && Number.isInteger(b.sort_key)
|
|
140
|
+
? a.sort_key - b.sort_key
|
|
141
|
+
: compareKeys(a.backward_compatibility, b.backward_compatibility))
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
// ── The results page, as a spec ──────────────────────────────────────
|
|
@@ -2,7 +2,10 @@ import { computed } from 'vue'
|
|
|
2
2
|
import { mediaUrl } from '../../siteConfig.js'
|
|
3
3
|
import { useCatalogueData } from '../../composables/useCatalogueData.js'
|
|
4
4
|
import { useDataPackage } from '../../composables/useDataPackage.js'
|
|
5
|
-
import {
|
|
5
|
+
import { entityRef, loadEntities } from '../../composables/useEntities.js'
|
|
6
|
+
import {
|
|
7
|
+
itemFromUidPath as legacyItemFromUidPath, itemIdFromLegacyPaths, partnerFromKey as legacyPartnerFromKey, partnerIdFromLegacyPaths,
|
|
8
|
+
} from '../../legacy/index.js'
|
|
6
9
|
import { useLegacyCountryCodes } from '../countryCodes.js'
|
|
7
10
|
import { toNewSite, withScheme } from '../../legacySites.js'
|
|
8
11
|
|
|
@@ -95,11 +98,27 @@ export function useGalleryData(config = {}) {
|
|
|
95
98
|
// site does, pure, over plain lists; these two wrappers bind it to this
|
|
96
99
|
// gallery's own `items`/`partners`/`countries` refs, so the site's legacy
|
|
97
100
|
// routes keep calling them with the arguments they already carry.
|
|
101
|
+
//
|
|
102
|
+
// A package from inventory-app's pass 3 ships the addresses resolved, as
|
|
103
|
+
// `legacy_paths.json`: once it is loaded (`loadLegacyPaths()`), the two
|
|
104
|
+
// look the address up there and never read a record's legacy key. An older
|
|
105
|
+
// package has no such file, and they decode the keys as before.
|
|
106
|
+
const legacyPaths = entityRef('legacy_paths')
|
|
107
|
+
|
|
108
|
+
/** Loads `legacy_paths.json` when the package has it; resolves either way. */
|
|
109
|
+
function loadLegacyPaths() {
|
|
110
|
+
return loadEntities(['legacy_paths']).catch(() => null)
|
|
111
|
+
}
|
|
112
|
+
|
|
98
113
|
function itemFromUidPath(path) {
|
|
114
|
+
const id = itemIdFromLegacyPaths(legacyPaths.value, path)
|
|
115
|
+
if (id !== undefined) return id === null ? null : itemById.value.get(id) ?? null
|
|
99
116
|
return legacyItemFromUidPath(items.value ?? [], path)
|
|
100
117
|
}
|
|
101
118
|
|
|
102
119
|
function partnerFromKey(countryCode, legacyId) {
|
|
120
|
+
const id = partnerIdFromLegacyPaths(legacyPaths.value, countryCode, legacyId)
|
|
121
|
+
if (id !== undefined) return id === null ? null : partnerById.value.get(id) ?? null
|
|
103
122
|
return legacyPartnerFromKey(partners.value ?? [], countries.value ?? [], countryCode, legacyId)
|
|
104
123
|
}
|
|
105
124
|
|
|
@@ -151,7 +170,7 @@ export function useGalleryData(config = {}) {
|
|
|
151
170
|
gallery, items, tags, partners, countries, languages, dynasties, glossary, timelines, timelineEvents,
|
|
152
171
|
itemById, partnerById, countryById, tagById, dynastyById, timelineById, languageByCode,
|
|
153
172
|
countryIdForCode, countryLabel,
|
|
154
|
-
itemRoute, partnerRoute, partnerObjectsRoute, itemFromUidPath, partnerFromKey,
|
|
173
|
+
itemRoute, partnerRoute, partnerObjectsRoute, itemFromUidPath, partnerFromKey, loadLegacyPaths,
|
|
155
174
|
chromeImage, siblingGalleries, siblingUrl, pickSiblings,
|
|
156
175
|
}
|
|
157
176
|
}
|
|
@@ -84,7 +84,11 @@ export function useGalleryItemDetail(data, timeline) {
|
|
|
84
84
|
chipClass,
|
|
85
85
|
},
|
|
86
86
|
notice: {
|
|
87
|
-
|
|
87
|
+
// A package from inventory-app's pass 3 says it on the record (`notice`);
|
|
88
|
+
// an older one is read through the site's `noticeProjects`.
|
|
89
|
+
show: (record) => (typeof record.notice === 'boolean'
|
|
90
|
+
? record.notice
|
|
91
|
+
: (useSiteConfig().noticeProjects ?? []).includes(record.project_id)),
|
|
88
92
|
label: 'partner.item.explorePartnerNote',
|
|
89
93
|
},
|
|
90
94
|
museum: {
|
package/src/i18n/language.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { watch } from 'vue'
|
|
2
2
|
import { START_LOCATION } from 'vue-router'
|
|
3
|
+
import { LEGACY_LANGUAGE_CODES } from './legacyLanguageCodes.js'
|
|
3
4
|
|
|
4
5
|
// Which language a visitor gets, decided once, in one place.
|
|
5
6
|
//
|
|
@@ -17,12 +18,7 @@ export function isRtl(code) {
|
|
|
17
18
|
return RTL_LANGUAGES.has(String(code ?? '').toLowerCase().split('-')[0])
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
* Legacy MWNF's own codes where they differ from ISO 639-1: Swedish, Chinese
|
|
22
|
-
* and Slovenian. The sites offer the ISO code; an old address (`?lang=se`) or
|
|
23
|
-
* a choice remembered before the switch still selects the language.
|
|
24
|
-
*/
|
|
25
|
-
export const LEGACY_LANGUAGE_CODES = Object.freeze({ se: 'sv', ch: 'zh', si: 'sl' })
|
|
21
|
+
export { LEGACY_LANGUAGE_CODES }
|
|
26
22
|
|
|
27
23
|
/**
|
|
28
24
|
* The URL first, then the visitor's own earlier choice, then what their
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Legacy MWNF's own codes where they differ from ISO 639-1: Swedish, Chinese
|
|
3
|
+
* and Slovenian. The sites offer the ISO code; an old address (`?lang=se`) or
|
|
4
|
+
* a choice remembered before the switch still selects the language. Its own
|
|
5
|
+
* module, with no Vue behind it, so `legacyAddresses.js` (which an exporter
|
|
6
|
+
* imports in plain Node) shares the one table with `negotiateLanguage`.
|
|
7
|
+
*/
|
|
8
|
+
export const LEGACY_LANGUAGE_CODES = Object.freeze({ se: 'sv', ch: 'zh', si: 'sl' })
|
package/src/index.js
CHANGED
|
@@ -20,7 +20,7 @@ export { defaultScrollBehavior, resolveViews } from './router/index.js'
|
|
|
20
20
|
export { mediaUrl, useSiteConfig } from './siteConfig.js'
|
|
21
21
|
export { bindDisplayLanguage, displayLanguage } from './displayLanguage.js'
|
|
22
22
|
export { siblingSiteUrl, sourceUrl, useSiteRights } from './rights.js'
|
|
23
|
-
export { LEGACY_SITES, legacyAddressRoute, openLegacyAddress, toNewSite, watchNewSiteLinks, withScheme } from './legacySites.js'
|
|
23
|
+
export { LEGACY_SITES, legacyAddressRoute, legacyAddressTarget, openLegacyAddress, toNewSite, watchNewSiteLinks, withScheme } from './legacySites.js'
|
|
24
24
|
export { GLOBAL_SEARCH_URL, globalSearchUrl, siteSlug, useGlobalSearch } from './globalSearch.js'
|
|
25
25
|
export { legacyRecordId } from './legacyIds.js'
|
|
26
26
|
|
package/src/legacy/index.js
CHANGED
|
@@ -56,3 +56,26 @@ export function itemFromUidPath(items, path) {
|
|
|
56
56
|
const needle = String(path ?? '').split('/').join(':').toLowerCase()
|
|
57
57
|
return (items ?? []).find((item) => item?.backward_compatibility?.toLowerCase() === needle) ?? null
|
|
58
58
|
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The item id a legacy dbUid *path* names, from the package's
|
|
62
|
+
* `legacy_paths.json` (inventory-app pass 3): its `items` map, keyed by the
|
|
63
|
+
* path lower case. `undefined` when the package has no such map (an older
|
|
64
|
+
* package: the caller decodes `backward_compatibility` as before), `null`
|
|
65
|
+
* when the map has no entry.
|
|
66
|
+
*/
|
|
67
|
+
export function itemIdFromLegacyPaths(legacyPaths, path) {
|
|
68
|
+
if (!legacyPaths?.items) return undefined
|
|
69
|
+
return legacyPaths.items[String(path ?? '').split(/[/:]/).join('/').toLowerCase()] ?? null
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The partner id a legacy `/partner/:country/:id` route names, from the
|
|
74
|
+
* package's `legacy_paths.json` `partners` map (`<country>/<legacy id>`).
|
|
75
|
+
* `undefined` when the package has no such map, `null` for no entry.
|
|
76
|
+
*/
|
|
77
|
+
export function partnerIdFromLegacyPaths(legacyPaths, countryCode, legacyId) {
|
|
78
|
+
if (!legacyPaths?.partners) return undefined
|
|
79
|
+
return legacyPaths.partners[`${countryCode}/${legacyId}`] ?? null
|
|
80
|
+
}
|
|
81
|
+
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { LEGACY_LANGUAGE_CODES } from './i18n/legacyLanguageCodes.js'
|
|
2
|
+
import { legacyRecordId } from './legacyIds.js'
|
|
3
|
+
|
|
4
|
+
// The legacy MWNF addresses and the new route each one lands on, with no
|
|
5
|
+
// Vue, router or DOM behind them: `legacySites.js` draws links through
|
|
6
|
+
// it, and an exporter can import it (`@museumwnf/viewer-core/legacy-addresses`)
|
|
7
|
+
// to ship a package's links already on the new sites.
|
|
8
|
+
|
|
9
|
+
// Links to legacy MWNF sites that have a new one (inventory-app#2482). The
|
|
10
|
+
// legacy sites linked to each other by address, and those addresses are in
|
|
11
|
+
// the texts a site shows (its package's, its locales', extracted from legacy
|
|
12
|
+
// as they were written) and in its configuration. A link to a legacy site
|
|
13
|
+
// that has a new site goes to the new one; the texts themselves stay as
|
|
14
|
+
// imported, and a link with no new site behind it stays as it is.
|
|
15
|
+
//
|
|
16
|
+
// The estate's legacy addresses, one row a site: a gallery, Explore, the
|
|
17
|
+
// galleries hub and the three products by host; an exhibition by host and
|
|
18
|
+
// its first path segment (they share a host); Publications (legacy books)
|
|
19
|
+
// and Travels (legacy's Exhibition Trails) by host; a mini-site by its own page
|
|
20
|
+
// (a Sharing History one by its `eId`). Built from the parity tool's sitemap
|
|
21
|
+
// (the legacy dumps) and the exporters' instance files; the parity `links`
|
|
22
|
+
// pass fails on a link this table misses.
|
|
23
|
+
export const LEGACY_SITES = [
|
|
24
|
+
{ host: 'amulets.museumwnf.org', slug: 'amulets', family: 'gallery' },
|
|
25
|
+
{ host: 'archaeology.museumwnf.org', slug: 'archaeology', family: 'gallery' },
|
|
26
|
+
{ host: 'architectural-elements.museumwnf.org', slug: 'architectural-elements', family: 'gallery' },
|
|
27
|
+
{ host: 'arms-armoury.museumwnf.org', slug: 'arms-armoury', family: 'gallery' },
|
|
28
|
+
{ host: 'books.museumwnf.org', slug: 'publications', family: 'publications' },
|
|
29
|
+
{ host: 'exhibitions.museumwnf.org', path: '/arts_in_dialogue/', slug: 'arts-in-dialogue', family: 'exhibition' },
|
|
30
|
+
{ host: 'baroqueart.museumwnf.org', slug: 'baroqueart', family: 'baroqueart' },
|
|
31
|
+
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/absolutism/', slug: 'baroqueart-absolutism', family: 'minisite' },
|
|
32
|
+
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/bourgeoisie/', slug: 'baroqueart-bourgeoisie', family: 'minisite' },
|
|
33
|
+
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/devotion/', slug: 'baroqueart-devotion', family: 'minisite' },
|
|
34
|
+
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/enlightenment/', slug: 'baroqueart-enlightenment', family: 'minisite' },
|
|
35
|
+
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/ephemera/', slug: 'baroqueart-ephemera', family: 'minisite' },
|
|
36
|
+
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/languages_baroque/', slug: 'baroqueart-languages-baroque', family: 'minisite' },
|
|
37
|
+
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/reformation/', slug: 'baroqueart-reformation', family: 'minisite' },
|
|
38
|
+
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/travelling_and_exotism/', slug: 'baroqueart-travelling-and-exotism', family: 'minisite' },
|
|
39
|
+
{ host: 'calligraphy.museumwnf.org', slug: 'calligraphy', family: 'gallery' },
|
|
40
|
+
{ host: 'carpets.museumwnf.org', slug: 'carpets', family: 'gallery' },
|
|
41
|
+
{ host: 'ceramics.museumwnf.org', slug: 'ceramics', family: 'gallery' },
|
|
42
|
+
{ host: 'clothing.museumwnf.org', slug: 'clothing', family: 'gallery' },
|
|
43
|
+
{ host: 'coins-medals.museumwnf.org', slug: 'coins-medals', family: 'gallery' },
|
|
44
|
+
{ host: 'communication.museumwnf.org', slug: 'communication', family: 'gallery' },
|
|
45
|
+
{ host: 'explore.museumwnf.org', slug: 'explore', family: 'explore' },
|
|
46
|
+
{ host: 'funerary-objects.museumwnf.org', slug: 'funerary-objects', family: 'gallery' },
|
|
47
|
+
{ host: 'galleries.museumwnf.org', slug: 'galleries', family: 'galleries' },
|
|
48
|
+
{ host: 'glass.museumwnf.org', slug: 'glass', family: 'gallery' },
|
|
49
|
+
{ host: 'gold-silver.museumwnf.org', slug: 'gold-silver', family: 'gallery' },
|
|
50
|
+
{ host: 'cars.museumwnf.org', slug: 'historical-cars', family: 'gallery' },
|
|
51
|
+
{ host: 'islamicart.museumwnf.org', slug: 'islamicart', family: 'islamicart' },
|
|
52
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/arabic_calligraphy/', slug: 'islamicart-arabic-calligraphy', family: 'minisite' },
|
|
53
|
+
{ host: 'islamicart.museumwnf.org', path: '/gai/isl/', slug: 'islamicart-artistic-introduction', family: 'minisite' },
|
|
54
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/crusader/', slug: 'islamicart-crusader', family: 'minisite' },
|
|
55
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/fatimids/', slug: 'islamicart-fatimids', family: 'minisite' },
|
|
56
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/figural/', slug: 'islamicart-figural', family: 'minisite' },
|
|
57
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/floral/', slug: 'islamicart-floral', family: 'minisite' },
|
|
58
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/geometric/', slug: 'islamicart-geometric', family: 'minisite' },
|
|
59
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/mudejar_art/', slug: 'islamicart-mudejar-art', family: 'minisite' },
|
|
60
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/muslim_west/', slug: 'islamicart-muslim-west', family: 'minisite' },
|
|
61
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/pilgrimage/', slug: 'islamicart-pilgrimage', family: 'minisite' },
|
|
62
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/siculo_norman/', slug: 'islamicart-siculo-norman', family: 'minisite' },
|
|
63
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/the_abbasids/', slug: 'islamicart-the-abbasids', family: 'minisite' },
|
|
64
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/the_ayyubids/', slug: 'islamicart-the-ayyubids', family: 'minisite' },
|
|
65
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/the_mamluks/', slug: 'islamicart-the-mamluks', family: 'minisite' },
|
|
66
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/the_ottomans/', slug: 'islamicart-the-ottomans', family: 'minisite' },
|
|
67
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/the_umayyads/', slug: 'islamicart-the-umayyads', family: 'minisite' },
|
|
68
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/water/', slug: 'islamicart-water', family: 'minisite' },
|
|
69
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/western_influence/', slug: 'islamicart-western-influence', family: 'minisite' },
|
|
70
|
+
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/women/', slug: 'islamicart-women', family: 'minisite' },
|
|
71
|
+
{ host: 'ivory.museumwnf.org', slug: 'ivory', family: 'gallery' },
|
|
72
|
+
{ host: 'jewellery.museumwnf.org', slug: 'jewellery', family: 'gallery' },
|
|
73
|
+
{ host: 'landscapes.museumwnf.org', slug: 'landscapes', family: 'gallery' },
|
|
74
|
+
{ host: 'leatherworks.museumwnf.org', slug: 'leatherworks', family: 'gallery' },
|
|
75
|
+
{ host: 'manuscripts.museumwnf.org', slug: 'manuscripts', family: 'gallery' },
|
|
76
|
+
{ host: 'metalwork.museumwnf.org', slug: 'metalwork', family: 'gallery' },
|
|
77
|
+
{ host: 'mosaics.museumwnf.org', slug: 'mosaics', family: 'gallery' },
|
|
78
|
+
{ host: 'musical-instruments.museumwnf.org', slug: 'musical-instruments', family: 'gallery' },
|
|
79
|
+
{ host: 'paintings.museumwnf.org', slug: 'paintings', family: 'gallery' },
|
|
80
|
+
{ host: 'photographs.museumwnf.org', slug: 'photographs', family: 'gallery' },
|
|
81
|
+
{ host: 'porcelain.museumwnf.org', slug: 'porcelain', family: 'gallery' },
|
|
82
|
+
{ host: 'portraits.museumwnf.org', slug: 'portraits', family: 'gallery' },
|
|
83
|
+
{ host: 'precious-stones.museumwnf.org', slug: 'precious-stones', family: 'gallery' },
|
|
84
|
+
{ host: 'prints-drawings.museumwnf.org', slug: 'prints-drawings', family: 'gallery' },
|
|
85
|
+
{ host: 'religious-life.museumwnf.org', slug: 'religious-life', family: 'gallery' },
|
|
86
|
+
{ host: 'scientific-objects.museumwnf.org', slug: 'scientific-objects', family: 'gallery' },
|
|
87
|
+
{ host: 'sculptures.museumwnf.org', slug: 'sculptures', family: 'gallery' },
|
|
88
|
+
{ host: 'sharinghistory.museumwnf.org', slug: 'sharinghistory', family: 'sharinghistory' },
|
|
89
|
+
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '3' }, slug: 'sharinghistory-cities-and-urban-spaces', family: 'minisite' },
|
|
90
|
+
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '6' }, slug: 'sharinghistory-economy-and-trade', family: 'minisite' },
|
|
91
|
+
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '5' }, slug: 'sharinghistory-fine-and-applied-arts', family: 'minisite' },
|
|
92
|
+
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '4' }, slug: 'sharinghistory-great-inventions-of-the-19th-century', family: 'minisite' },
|
|
93
|
+
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '7' }, slug: 'sharinghistory-international-exhibitions', family: 'minisite' },
|
|
94
|
+
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '8' }, slug: 'sharinghistory-migrations', family: 'minisite' },
|
|
95
|
+
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '9' }, slug: 'sharinghistory-music-literature-dance-and-fashion', family: 'minisite' },
|
|
96
|
+
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '1' }, slug: 'sharinghistory-rediscovering-the-past', family: 'minisite' },
|
|
97
|
+
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '10' }, slug: 'sharinghistory-reforms-and-social-changes', family: 'minisite' },
|
|
98
|
+
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '11' }, slug: 'sharinghistory-travelling', family: 'minisite' },
|
|
99
|
+
{ host: 'textiles.museumwnf.org', slug: 'textiles', family: 'gallery' },
|
|
100
|
+
{ host: 'upgrade-exhibitions.museumwnf.org', path: '/the_hijaz_railway/', slug: 'the-hijaz-railway', family: 'exhibition' },
|
|
101
|
+
{ host: 'exhibitions.museumwnf.org', path: '/the_table_is_set/', slug: 'the-table-is-set', family: 'exhibition' },
|
|
102
|
+
{ host: 'exhibitions.museumwnf.org', path: '/the_use_of_colours_in_art/', slug: 'the-use-of-colours-in-art', family: 'exhibition' },
|
|
103
|
+
{ host: 'theatre.museumwnf.org', slug: 'theatre', family: 'gallery' },
|
|
104
|
+
{ host: 'toys-games.museumwnf.org', slug: 'toys-games', family: 'gallery' },
|
|
105
|
+
{ host: 'travels.museumwnf.org', slug: 'travels', family: 'travels' },
|
|
106
|
+
{ host: 'wallpaintings.museumwnf.org', slug: 'wallpaintings', family: 'gallery' },
|
|
107
|
+
{ host: 'exhibitions.museumwnf.org', path: '/water_in_islam/', slug: 'water-in-islam', family: 'exhibition' },
|
|
108
|
+
{ host: 'weights-measures.museumwnf.org', slug: 'weights-measures', family: 'gallery' },
|
|
109
|
+
{ host: 'exhibitions.museumwnf.org', path: '/with_brush_and_qalam/', slug: 'with-brush-and-qalam', family: 'exhibition' },
|
|
110
|
+
{ host: 'woodwork.museumwnf.org', slug: 'woodwork', family: 'gallery' },
|
|
111
|
+
{ host: 'exhibitions.museumwnf.org', path: '/the_hijaz_railway/', slug: 'the-hijaz-railway', family: 'exhibition' },
|
|
112
|
+
// Legacy's three products also answered on their own domains.
|
|
113
|
+
{ host: 'discoverislamicart.org', slug: 'islamicart', family: 'islamicart' },
|
|
114
|
+
{ host: 'discoverbaroqueart.org', slug: 'baroqueart', family: 'baroqueart' },
|
|
115
|
+
{ host: 'sharinghistory.org', slug: 'sharinghistory', family: 'sharinghistory' },
|
|
116
|
+
]
|
|
117
|
+
|
|
118
|
+
// The new route of each legacy page the products and their siblings link
|
|
119
|
+
// to: legacy's script name → the route. A page that is not here stays on
|
|
120
|
+
// legacy (a page with no counterpart, or one that needs a record id).
|
|
121
|
+
const PAGES = {
|
|
122
|
+
islamicart: {
|
|
123
|
+
'/': '/', '/index.php': '/',
|
|
124
|
+
'/database.php': '/database', '/database_results.php': '/database/results',
|
|
125
|
+
'/partners.php': '/partners', '/pm_partner_list.php': '/partners/results', '/pm_partner_list_eiac.php': '/partners/explore',
|
|
126
|
+
'/pc_entrance.php': '/permanent-collection', '/pclist_all.php': '/permanent-collection/results',
|
|
127
|
+
'/hcr_home.php': '/timeline', '/dynasties/': '/dynasties',
|
|
128
|
+
'/isl_missionstatement.php': '/mission-statement', '/recommendedlinks.php': '/recommended-links',
|
|
129
|
+
'/atrium_sponsor_detail.php': '/sponsors', '/glossarysearch.php': '/glossary-spelling',
|
|
130
|
+
// The list of the virtual exhibitions; each one is a mini-site row above.
|
|
131
|
+
'/exhibitions/isl': '/exhibitions', '/exhibitions/isl/': '/exhibitions', '/exhibitions/isl/index.php': '/exhibitions',
|
|
132
|
+
},
|
|
133
|
+
baroqueart: {
|
|
134
|
+
'/': '/', '/index.php': '/',
|
|
135
|
+
'/database.php': '/database', '/database_results.php': '/database/results',
|
|
136
|
+
'/partners.php': '/partners', '/pm_partner_list.php': '/partners/results',
|
|
137
|
+
'/pc_entrance.php': '/permanent-collection', '/pclist_all.php': '/permanent-collection/results',
|
|
138
|
+
'/hcr_home.php': '/timeline', '/atrium_sponsor_detail.php': '/sponsors', '/mwnf_credit.php': '/credits',
|
|
139
|
+
},
|
|
140
|
+
sharinghistory: {
|
|
141
|
+
'/': '/', '/index.php': '/',
|
|
142
|
+
'/about.php': '/about', '/about_team.php': '/about/team', '/about_chronology_list.php': '/about/chronology',
|
|
143
|
+
'/pc_home.php': '/permanent-collection', '/database_searchform.php': '/database',
|
|
144
|
+
'/historical_background.php': '/historical-background', '/hcr_home.php': '/timeline',
|
|
145
|
+
'/exhibitions/awe/index.php': '/exhibitions', '/partners.php': '/partners', '/pm_partner_list.php': '/partners/results',
|
|
146
|
+
'/sponsor_detail.php': '/sponsors', '/sponsor_detail_local.php': '/sponsors/local',
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
// The query keys a page's new route reads as legacy's did.
|
|
150
|
+
const KEPT_QUERY = { '/partners/results': ['type'] }
|
|
151
|
+
|
|
152
|
+
// Legacy books.museumwnf.org (book-client's routes): a book by its legacy id
|
|
153
|
+
// (`mwnf3:bookbase:<id>`) in the version's language, a category's page, the
|
|
154
|
+
// search (its free-text fields and the language, whose values the new search
|
|
155
|
+
// reads as legacy's did). Its sign-up page has no counterpart.
|
|
156
|
+
const BOOK_SEARCH_KEYS = ['title', 'author', 'isbn', 'language']
|
|
157
|
+
function publicationsRoute(path, url) {
|
|
158
|
+
if (path === '/') return '/'
|
|
159
|
+
let match = /^\/book\/(\d+)(?:\/([a-z]{2}))?$/i.exec(path)
|
|
160
|
+
if (match) {
|
|
161
|
+
const id = legacyRecordId('publication', `mwnf3:bookbase:${match[1]}`)
|
|
162
|
+
return `/publication/${id}${match[2] ? `/${match[2].toLowerCase()}` : ''}`
|
|
163
|
+
}
|
|
164
|
+
match = /^\/category\/([a-z0-9-]+)(?:\/(\d+))?$/i.exec(path)
|
|
165
|
+
if (match) {
|
|
166
|
+
const page = match[2] && match[2] !== '1' ? `?page=${match[2]}` : ''
|
|
167
|
+
return `/category/${match[1].toLowerCase()}${page}`
|
|
168
|
+
}
|
|
169
|
+
if (path === '/results') {
|
|
170
|
+
const kept = BOOK_SEARCH_KEYS.filter((key) => url.searchParams.get(key))
|
|
171
|
+
return kept.length ? `/results?${kept.map((key) => `${key}=${encodeURIComponent(url.searchParams.get(key))}`).join('&')}` : '/results'
|
|
172
|
+
}
|
|
173
|
+
return null
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// A legacy address writes its language as legacy MWNF wrote it; the sites
|
|
177
|
+
// offer it as ISO 639-1. The two differ only for Swedish, Chinese and
|
|
178
|
+
// Slovenian; the other legacy codes are ISO already.
|
|
179
|
+
function isoLanguage(code) {
|
|
180
|
+
if (!/^[a-z]{2}$/i.test(code ?? '')) return null
|
|
181
|
+
const lang = code.toLowerCase()
|
|
182
|
+
return LEGACY_LANGUAGE_CODES[lang] ?? lang
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Legacy travels.museumwnf.org's Exhibition Trails: a country's or a theme's
|
|
186
|
+
// trails, a trail (`?id=<project>;<country>;<number>;<language>`) and an
|
|
187
|
+
// itinerary (`?id=<project>;<country>;<roman number>;<language>;<trail>`),
|
|
188
|
+
// keyed as the importer keys them (`mwnf3_travels:trail:…`,
|
|
189
|
+
// `mwnf3_travels:itinerary:…`), each tab (`fl`) the new page has. The rest of
|
|
190
|
+
// the host (the tours, the booking form) has no new site and stays there.
|
|
191
|
+
// The trails' countries: legacy's code → the inventory id travels-data's
|
|
192
|
+
// countries.json gives it.
|
|
193
|
+
const TRAVELS_COUNTRIES = {
|
|
194
|
+
dz: 'dza', eg: 'egy', es: 'esp', it: 'ita', jo: 'jor', ma: 'mar', pa: 'pse', pt: 'prt', sy: 'syr', tn: 'tun', tr: 'tur',
|
|
195
|
+
}
|
|
196
|
+
const TRAIL_TABS = ['desc', 'its', 'cur']
|
|
197
|
+
const ITINERARY_TABS = ['des', 'vl']
|
|
198
|
+
function travelsQuery(url, tabs, language) {
|
|
199
|
+
const tab = (url.searchParams.get('fl') ?? '').toLowerCase()
|
|
200
|
+
const lang = isoLanguage(language)
|
|
201
|
+
const query = [tabs.includes(tab) ? `tab=${tab}` : null, lang ? `lang=${lang}` : null]
|
|
202
|
+
const kept = query.filter(Boolean)
|
|
203
|
+
return kept.length ? `?${kept.join('&')}` : ''
|
|
204
|
+
}
|
|
205
|
+
function travelsRoute(path, url) {
|
|
206
|
+
const script = path.toLowerCase()
|
|
207
|
+
if (script === '/travel_et_home.php') return '/'
|
|
208
|
+
if (script === '/travel_et_trail.php') {
|
|
209
|
+
const country = TRAVELS_COUNTRIES[(url.searchParams.get('cid') ?? '').toLowerCase()]
|
|
210
|
+
if (country) return `/trails?country=${country}`
|
|
211
|
+
const project = url.searchParams.get('tid')
|
|
212
|
+
return /^[a-z0-9]+$/i.test(project ?? '') ? `/trails?project=${project.toUpperCase()}` : null
|
|
213
|
+
}
|
|
214
|
+
const id = (url.searchParams.get('id') ?? '').split(';').map((part) => part.trim())
|
|
215
|
+
if (script === '/travel_et_traildetail.php' && id.length >= 3 && id.slice(0, 3).every(Boolean)) {
|
|
216
|
+
const [project, country, number, language] = id
|
|
217
|
+
return `/trail/${legacyRecordId('collection', `mwnf3_travels:trail:${project}:${country}:${number}`)}${travelsQuery(url, TRAIL_TABS, language)}`
|
|
218
|
+
}
|
|
219
|
+
if (script === '/travel_et_itenary.php' && id.length >= 5 && [0, 1, 2, 4].every((i) => id[i])) {
|
|
220
|
+
const [project, country, number, language, trail] = id
|
|
221
|
+
return `/itinerary/${legacyRecordId('collection', `mwnf3_travels:itinerary:${project}:${country}:${trail}:${number}`)}${travelsQuery(url, ITINERARY_TABS, language)}`
|
|
222
|
+
}
|
|
223
|
+
return null
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Discover Islamic Art's partner page (`pm_partner.php?id=<partner>;<country>&type=museum|institution`),
|
|
227
|
+
// keyed as the importer keys a partner (`mwnf3:museums:…`, `mwnf3:institutions:…`). Travels' trails and the
|
|
228
|
+
// books link to it for their museums. Its other pages are PAGES above.
|
|
229
|
+
const PARTNER_KINDS = { museum: 'museums', institution: 'institutions' }
|
|
230
|
+
function islamicartRecordRoute(path, url) {
|
|
231
|
+
if (path.toLowerCase() !== '/pm_partner.php') return undefined
|
|
232
|
+
const [partner, country] = (url.searchParams.get('id') ?? '').split(';').map((part) => part.trim())
|
|
233
|
+
const kind = PARTNER_KINDS[(url.searchParams.get('type') ?? 'museum').toLowerCase()]
|
|
234
|
+
if (!partner || !country || !kind) return null
|
|
235
|
+
return `/partner/${legacyRecordId('partner', `mwnf3:${kind}:${partner}:${country}`)}`
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// The families whose pages name a record or a page in their address.
|
|
239
|
+
const RECORD_PAGES = { publications: publicationsRoute, travels: travelsRoute }
|
|
240
|
+
|
|
241
|
+
export const bareHost = (host) => host.toLowerCase().replace(/^www\./, '')
|
|
242
|
+
|
|
243
|
+
function rowFor(url) {
|
|
244
|
+
const host = bareHost(url.host)
|
|
245
|
+
const path = url.pathname.toLowerCase().replace(/\/?$/, '/')
|
|
246
|
+
return LEGACY_SITES.filter(
|
|
247
|
+
(row) =>
|
|
248
|
+
row.host === host &&
|
|
249
|
+
path.startsWith((row.path ?? '/').replace(/\.php$/, '.php/')) &&
|
|
250
|
+
Object.entries(row.query ?? {}).every(([key, value]) => url.searchParams.get(key) === value),
|
|
251
|
+
).sort((a, b) => (b.path ?? '/').length - (a.path ?? '/').length)[0]
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The route on the new site that a legacy address of `row` lands on, or null
|
|
256
|
+
* when it has none. Galleries, Explore and the hub kept legacy's paths as
|
|
257
|
+
* routes (their legacy redirects); an exhibition drops its own segment and
|
|
258
|
+
* moves the language to the query; a mini-site opens on its home; a
|
|
259
|
+
* product's page goes through PAGES.
|
|
260
|
+
*/
|
|
261
|
+
function routeFor(row, url) {
|
|
262
|
+
// A legacy text may write the address with a space before its closing `>`.
|
|
263
|
+
const pathname = decodeURIComponent(url.pathname).trim() || '/'
|
|
264
|
+
const path = pathname.replace(/\/+$/, '') || '/'
|
|
265
|
+
if (row.family === 'gallery' || row.family === 'explore' || row.family === 'galleries') return `${path}${url.search}`
|
|
266
|
+
if (row.family === 'minisite') return '/'
|
|
267
|
+
if (RECORD_PAGES[row.family]) return RECORD_PAGES[row.family](path, url)
|
|
268
|
+
if (row.family === 'exhibition') {
|
|
269
|
+
const rest = path.split('/').filter(Boolean).slice(1)
|
|
270
|
+
const lang = /^[a-z]{2}$/.test(rest[0] ?? '') ? isoLanguage(rest.shift()) : null
|
|
271
|
+
return `/${rest.join('/')}${lang ? `?lang=${lang}` : ''}`
|
|
272
|
+
}
|
|
273
|
+
if (row.family === 'islamicart') {
|
|
274
|
+
const record = islamicartRecordRoute(path, url)
|
|
275
|
+
if (record !== undefined) return record
|
|
276
|
+
}
|
|
277
|
+
const route = PAGES[row.family]?.[pathname.toLowerCase()]
|
|
278
|
+
if (!route) return null
|
|
279
|
+
const keep = (KEPT_QUERY[route] ?? []).filter((key) => url.searchParams.has(key))
|
|
280
|
+
return keep.length ? `${route}?${keep.map((key) => `${key}=${encodeURIComponent(url.searchParams.get(key))}`).join('&')}` : route
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* `{ slug, route }` for a legacy MWNF address of a site that has a new one:
|
|
286
|
+
* the new site's slug and the route on it the address lands on. `null` for
|
|
287
|
+
* anything else: not an address, not a legacy site, or a page with no
|
|
288
|
+
* counterpart. Pure: the caller turns it into an address (the viewer's
|
|
289
|
+
* `toNewSite` through `siblingSiteUrl`, an exporter through its sites'
|
|
290
|
+
* origins).
|
|
291
|
+
*/
|
|
292
|
+
export function legacyAddressTarget(href) {
|
|
293
|
+
let url
|
|
294
|
+
try {
|
|
295
|
+
url = new URL(String(href ?? '').trim())
|
|
296
|
+
} catch {
|
|
297
|
+
return null
|
|
298
|
+
}
|
|
299
|
+
const row = rowFor(url)
|
|
300
|
+
if (!row) return null
|
|
301
|
+
const route = routeFor(row, url)
|
|
302
|
+
return route === null ? null : { slug: row.slug, route }
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* The route on the new site that a legacy MWNF address lands on (a book's
|
|
307
|
+
* `/publication/<id>/<language>` for `books.museumwnf.org/book/5/en`), or
|
|
308
|
+
* null when the address is no legacy site's, or names nothing there.
|
|
309
|
+
*/
|
|
310
|
+
export function legacyAddressRoute(href) {
|
|
311
|
+
return legacyAddressTarget(href)?.route ?? null
|
|
312
|
+
}
|
package/src/legacySites.js
CHANGED
|
@@ -1,280 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LEGACY_SITES, bareHost, legacyAddressRoute, legacyAddressTarget } from './legacyAddresses.js'
|
|
2
2
|
import { siblingSiteUrl } from './rights.js'
|
|
3
|
-
import { LEGACY_LANGUAGE_CODES } from './i18n/language.js'
|
|
4
3
|
|
|
5
|
-
// Links to legacy MWNF sites that have a new one (inventory-app#2482)
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
// that has a new site goes to the new one; the texts themselves stay as
|
|
10
|
-
// imported, and a link with no new site behind it stays as it is.
|
|
11
|
-
//
|
|
12
|
-
// The estate's legacy addresses, one row a site: a gallery, Explore, the
|
|
13
|
-
// galleries hub and the three products by host; an exhibition by host and
|
|
14
|
-
// its first path segment (they share a host); Publications (legacy books)
|
|
15
|
-
// and Travels (legacy's Exhibition Trails) by host; a mini-site by its own page
|
|
16
|
-
// (a Sharing History one by its `eId`). Built from the parity tool's sitemap
|
|
17
|
-
// (the legacy dumps) and the exporters' instance files; the parity `links`
|
|
18
|
-
// pass fails on a link this table misses.
|
|
19
|
-
export const LEGACY_SITES = [
|
|
20
|
-
{ host: 'amulets.museumwnf.org', slug: 'amulets', family: 'gallery' },
|
|
21
|
-
{ host: 'archaeology.museumwnf.org', slug: 'archaeology', family: 'gallery' },
|
|
22
|
-
{ host: 'architectural-elements.museumwnf.org', slug: 'architectural-elements', family: 'gallery' },
|
|
23
|
-
{ host: 'arms-armoury.museumwnf.org', slug: 'arms-armoury', family: 'gallery' },
|
|
24
|
-
{ host: 'books.museumwnf.org', slug: 'publications', family: 'publications' },
|
|
25
|
-
{ host: 'exhibitions.museumwnf.org', path: '/arts_in_dialogue/', slug: 'arts-in-dialogue', family: 'exhibition' },
|
|
26
|
-
{ host: 'baroqueart.museumwnf.org', slug: 'baroqueart', family: 'baroqueart' },
|
|
27
|
-
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/absolutism/', slug: 'baroqueart-absolutism', family: 'minisite' },
|
|
28
|
-
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/bourgeoisie/', slug: 'baroqueart-bourgeoisie', family: 'minisite' },
|
|
29
|
-
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/devotion/', slug: 'baroqueart-devotion', family: 'minisite' },
|
|
30
|
-
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/enlightenment/', slug: 'baroqueart-enlightenment', family: 'minisite' },
|
|
31
|
-
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/ephemera/', slug: 'baroqueart-ephemera', family: 'minisite' },
|
|
32
|
-
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/languages_baroque/', slug: 'baroqueart-languages-baroque', family: 'minisite' },
|
|
33
|
-
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/reformation/', slug: 'baroqueart-reformation', family: 'minisite' },
|
|
34
|
-
{ host: 'baroqueart.museumwnf.org', path: '/exhibitions/bar/travelling_and_exotism/', slug: 'baroqueart-travelling-and-exotism', family: 'minisite' },
|
|
35
|
-
{ host: 'calligraphy.museumwnf.org', slug: 'calligraphy', family: 'gallery' },
|
|
36
|
-
{ host: 'carpets.museumwnf.org', slug: 'carpets', family: 'gallery' },
|
|
37
|
-
{ host: 'ceramics.museumwnf.org', slug: 'ceramics', family: 'gallery' },
|
|
38
|
-
{ host: 'clothing.museumwnf.org', slug: 'clothing', family: 'gallery' },
|
|
39
|
-
{ host: 'coins-medals.museumwnf.org', slug: 'coins-medals', family: 'gallery' },
|
|
40
|
-
{ host: 'communication.museumwnf.org', slug: 'communication', family: 'gallery' },
|
|
41
|
-
{ host: 'explore.museumwnf.org', slug: 'explore', family: 'explore' },
|
|
42
|
-
{ host: 'funerary-objects.museumwnf.org', slug: 'funerary-objects', family: 'gallery' },
|
|
43
|
-
{ host: 'galleries.museumwnf.org', slug: 'galleries', family: 'galleries' },
|
|
44
|
-
{ host: 'glass.museumwnf.org', slug: 'glass', family: 'gallery' },
|
|
45
|
-
{ host: 'gold-silver.museumwnf.org', slug: 'gold-silver', family: 'gallery' },
|
|
46
|
-
{ host: 'cars.museumwnf.org', slug: 'historical-cars', family: 'gallery' },
|
|
47
|
-
{ host: 'islamicart.museumwnf.org', slug: 'islamicart', family: 'islamicart' },
|
|
48
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/arabic_calligraphy/', slug: 'islamicart-arabic-calligraphy', family: 'minisite' },
|
|
49
|
-
{ host: 'islamicart.museumwnf.org', path: '/gai/isl/', slug: 'islamicart-artistic-introduction', family: 'minisite' },
|
|
50
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/crusader/', slug: 'islamicart-crusader', family: 'minisite' },
|
|
51
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/fatimids/', slug: 'islamicart-fatimids', family: 'minisite' },
|
|
52
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/figural/', slug: 'islamicart-figural', family: 'minisite' },
|
|
53
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/floral/', slug: 'islamicart-floral', family: 'minisite' },
|
|
54
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/geometric/', slug: 'islamicart-geometric', family: 'minisite' },
|
|
55
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/mudejar_art/', slug: 'islamicart-mudejar-art', family: 'minisite' },
|
|
56
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/muslim_west/', slug: 'islamicart-muslim-west', family: 'minisite' },
|
|
57
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/pilgrimage/', slug: 'islamicart-pilgrimage', family: 'minisite' },
|
|
58
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/siculo_norman/', slug: 'islamicart-siculo-norman', family: 'minisite' },
|
|
59
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/the_abbasids/', slug: 'islamicart-the-abbasids', family: 'minisite' },
|
|
60
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/the_ayyubids/', slug: 'islamicart-the-ayyubids', family: 'minisite' },
|
|
61
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/the_mamluks/', slug: 'islamicart-the-mamluks', family: 'minisite' },
|
|
62
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/the_ottomans/', slug: 'islamicart-the-ottomans', family: 'minisite' },
|
|
63
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/the_umayyads/', slug: 'islamicart-the-umayyads', family: 'minisite' },
|
|
64
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/water/', slug: 'islamicart-water', family: 'minisite' },
|
|
65
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/western_influence/', slug: 'islamicart-western-influence', family: 'minisite' },
|
|
66
|
-
{ host: 'islamicart.museumwnf.org', path: '/exhibitions/isl/women/', slug: 'islamicart-women', family: 'minisite' },
|
|
67
|
-
{ host: 'ivory.museumwnf.org', slug: 'ivory', family: 'gallery' },
|
|
68
|
-
{ host: 'jewellery.museumwnf.org', slug: 'jewellery', family: 'gallery' },
|
|
69
|
-
{ host: 'landscapes.museumwnf.org', slug: 'landscapes', family: 'gallery' },
|
|
70
|
-
{ host: 'leatherworks.museumwnf.org', slug: 'leatherworks', family: 'gallery' },
|
|
71
|
-
{ host: 'manuscripts.museumwnf.org', slug: 'manuscripts', family: 'gallery' },
|
|
72
|
-
{ host: 'metalwork.museumwnf.org', slug: 'metalwork', family: 'gallery' },
|
|
73
|
-
{ host: 'mosaics.museumwnf.org', slug: 'mosaics', family: 'gallery' },
|
|
74
|
-
{ host: 'musical-instruments.museumwnf.org', slug: 'musical-instruments', family: 'gallery' },
|
|
75
|
-
{ host: 'paintings.museumwnf.org', slug: 'paintings', family: 'gallery' },
|
|
76
|
-
{ host: 'photographs.museumwnf.org', slug: 'photographs', family: 'gallery' },
|
|
77
|
-
{ host: 'porcelain.museumwnf.org', slug: 'porcelain', family: 'gallery' },
|
|
78
|
-
{ host: 'portraits.museumwnf.org', slug: 'portraits', family: 'gallery' },
|
|
79
|
-
{ host: 'precious-stones.museumwnf.org', slug: 'precious-stones', family: 'gallery' },
|
|
80
|
-
{ host: 'prints-drawings.museumwnf.org', slug: 'prints-drawings', family: 'gallery' },
|
|
81
|
-
{ host: 'religious-life.museumwnf.org', slug: 'religious-life', family: 'gallery' },
|
|
82
|
-
{ host: 'scientific-objects.museumwnf.org', slug: 'scientific-objects', family: 'gallery' },
|
|
83
|
-
{ host: 'sculptures.museumwnf.org', slug: 'sculptures', family: 'gallery' },
|
|
84
|
-
{ host: 'sharinghistory.museumwnf.org', slug: 'sharinghistory', family: 'sharinghistory' },
|
|
85
|
-
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '3' }, slug: 'sharinghistory-cities-and-urban-spaces', family: 'minisite' },
|
|
86
|
-
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '6' }, slug: 'sharinghistory-economy-and-trade', family: 'minisite' },
|
|
87
|
-
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '5' }, slug: 'sharinghistory-fine-and-applied-arts', family: 'minisite' },
|
|
88
|
-
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '4' }, slug: 'sharinghistory-great-inventions-of-the-19th-century', family: 'minisite' },
|
|
89
|
-
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '7' }, slug: 'sharinghistory-international-exhibitions', family: 'minisite' },
|
|
90
|
-
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '8' }, slug: 'sharinghistory-migrations', family: 'minisite' },
|
|
91
|
-
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '9' }, slug: 'sharinghistory-music-literature-dance-and-fashion', family: 'minisite' },
|
|
92
|
-
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '1' }, slug: 'sharinghistory-rediscovering-the-past', family: 'minisite' },
|
|
93
|
-
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '10' }, slug: 'sharinghistory-reforms-and-social-changes', family: 'minisite' },
|
|
94
|
-
{ host: 'sharinghistory.museumwnf.org', path: '/exhibitions/awe/exh_items.php', query: { eId: '11' }, slug: 'sharinghistory-travelling', family: 'minisite' },
|
|
95
|
-
{ host: 'textiles.museumwnf.org', slug: 'textiles', family: 'gallery' },
|
|
96
|
-
{ host: 'upgrade-exhibitions.museumwnf.org', path: '/the_hijaz_railway/', slug: 'the-hijaz-railway', family: 'exhibition' },
|
|
97
|
-
{ host: 'exhibitions.museumwnf.org', path: '/the_table_is_set/', slug: 'the-table-is-set', family: 'exhibition' },
|
|
98
|
-
{ host: 'exhibitions.museumwnf.org', path: '/the_use_of_colours_in_art/', slug: 'the-use-of-colours-in-art', family: 'exhibition' },
|
|
99
|
-
{ host: 'theatre.museumwnf.org', slug: 'theatre', family: 'gallery' },
|
|
100
|
-
{ host: 'toys-games.museumwnf.org', slug: 'toys-games', family: 'gallery' },
|
|
101
|
-
{ host: 'travels.museumwnf.org', slug: 'travels', family: 'travels' },
|
|
102
|
-
{ host: 'wallpaintings.museumwnf.org', slug: 'wallpaintings', family: 'gallery' },
|
|
103
|
-
{ host: 'exhibitions.museumwnf.org', path: '/water_in_islam/', slug: 'water-in-islam', family: 'exhibition' },
|
|
104
|
-
{ host: 'weights-measures.museumwnf.org', slug: 'weights-measures', family: 'gallery' },
|
|
105
|
-
{ host: 'exhibitions.museumwnf.org', path: '/with_brush_and_qalam/', slug: 'with-brush-and-qalam', family: 'exhibition' },
|
|
106
|
-
{ host: 'woodwork.museumwnf.org', slug: 'woodwork', family: 'gallery' },
|
|
107
|
-
{ host: 'exhibitions.museumwnf.org', path: '/the_hijaz_railway/', slug: 'the-hijaz-railway', family: 'exhibition' },
|
|
108
|
-
// Legacy's three products also answered on their own domains.
|
|
109
|
-
{ host: 'discoverislamicart.org', slug: 'islamicart', family: 'islamicart' },
|
|
110
|
-
{ host: 'discoverbaroqueart.org', slug: 'baroqueart', family: 'baroqueart' },
|
|
111
|
-
{ host: 'sharinghistory.org', slug: 'sharinghistory', family: 'sharinghistory' },
|
|
112
|
-
]
|
|
113
|
-
|
|
114
|
-
// The new route of each legacy page the products and their siblings link
|
|
115
|
-
// to: legacy's script name → the route. A page that is not here stays on
|
|
116
|
-
// legacy (a page with no counterpart, or one that needs a record id).
|
|
117
|
-
const PAGES = {
|
|
118
|
-
islamicart: {
|
|
119
|
-
'/': '/', '/index.php': '/',
|
|
120
|
-
'/database.php': '/database', '/database_results.php': '/database/results',
|
|
121
|
-
'/partners.php': '/partners', '/pm_partner_list.php': '/partners/results', '/pm_partner_list_eiac.php': '/partners/explore',
|
|
122
|
-
'/pc_entrance.php': '/permanent-collection', '/pclist_all.php': '/permanent-collection/results',
|
|
123
|
-
'/hcr_home.php': '/timeline', '/dynasties/': '/dynasties',
|
|
124
|
-
'/isl_missionstatement.php': '/mission-statement', '/recommendedlinks.php': '/recommended-links',
|
|
125
|
-
'/atrium_sponsor_detail.php': '/sponsors', '/glossarysearch.php': '/glossary-spelling',
|
|
126
|
-
// The list of the virtual exhibitions; each one is a mini-site row above.
|
|
127
|
-
'/exhibitions/isl': '/exhibitions', '/exhibitions/isl/': '/exhibitions', '/exhibitions/isl/index.php': '/exhibitions',
|
|
128
|
-
},
|
|
129
|
-
baroqueart: {
|
|
130
|
-
'/': '/', '/index.php': '/',
|
|
131
|
-
'/database.php': '/database', '/database_results.php': '/database/results',
|
|
132
|
-
'/partners.php': '/partners', '/pm_partner_list.php': '/partners/results',
|
|
133
|
-
'/pc_entrance.php': '/permanent-collection', '/pclist_all.php': '/permanent-collection/results',
|
|
134
|
-
'/hcr_home.php': '/timeline', '/atrium_sponsor_detail.php': '/sponsors', '/mwnf_credit.php': '/credits',
|
|
135
|
-
},
|
|
136
|
-
sharinghistory: {
|
|
137
|
-
'/': '/', '/index.php': '/',
|
|
138
|
-
'/about.php': '/about', '/about_team.php': '/about/team', '/about_chronology_list.php': '/about/chronology',
|
|
139
|
-
'/pc_home.php': '/permanent-collection', '/database_searchform.php': '/database',
|
|
140
|
-
'/historical_background.php': '/historical-background', '/hcr_home.php': '/timeline',
|
|
141
|
-
'/exhibitions/awe/index.php': '/exhibitions', '/partners.php': '/partners', '/pm_partner_list.php': '/partners/results',
|
|
142
|
-
'/sponsor_detail.php': '/sponsors', '/sponsor_detail_local.php': '/sponsors/local',
|
|
143
|
-
},
|
|
144
|
-
}
|
|
145
|
-
// The query keys a page's new route reads as legacy's did.
|
|
146
|
-
const KEPT_QUERY = { '/partners/results': ['type'] }
|
|
147
|
-
|
|
148
|
-
// Legacy books.museumwnf.org (book-client's routes): a book by its legacy id
|
|
149
|
-
// (`mwnf3:bookbase:<id>`) in the version's language, a category's page, the
|
|
150
|
-
// search (its free-text fields and the language, whose values the new search
|
|
151
|
-
// reads as legacy's did). Its sign-up page has no counterpart.
|
|
152
|
-
const BOOK_SEARCH_KEYS = ['title', 'author', 'isbn', 'language']
|
|
153
|
-
function publicationsRoute(path, url) {
|
|
154
|
-
if (path === '/') return '/'
|
|
155
|
-
let match = /^\/book\/(\d+)(?:\/([a-z]{2}))?$/i.exec(path)
|
|
156
|
-
if (match) {
|
|
157
|
-
const id = legacyRecordId('publication', `mwnf3:bookbase:${match[1]}`)
|
|
158
|
-
return `/publication/${id}${match[2] ? `/${match[2].toLowerCase()}` : ''}`
|
|
159
|
-
}
|
|
160
|
-
match = /^\/category\/([a-z0-9-]+)(?:\/(\d+))?$/i.exec(path)
|
|
161
|
-
if (match) {
|
|
162
|
-
const page = match[2] && match[2] !== '1' ? `?page=${match[2]}` : ''
|
|
163
|
-
return `/category/${match[1].toLowerCase()}${page}`
|
|
164
|
-
}
|
|
165
|
-
if (path === '/results') {
|
|
166
|
-
const kept = BOOK_SEARCH_KEYS.filter((key) => url.searchParams.get(key))
|
|
167
|
-
return kept.length ? `/results?${kept.map((key) => `${key}=${encodeURIComponent(url.searchParams.get(key))}`).join('&')}` : '/results'
|
|
168
|
-
}
|
|
169
|
-
return null
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// A legacy address writes its language as legacy MWNF wrote it; the sites
|
|
173
|
-
// offer it as ISO 639-1. The two differ only for Swedish, Chinese and
|
|
174
|
-
// Slovenian; the other legacy codes are ISO already.
|
|
175
|
-
function isoLanguage(code) {
|
|
176
|
-
if (!/^[a-z]{2}$/i.test(code ?? '')) return null
|
|
177
|
-
const lang = code.toLowerCase()
|
|
178
|
-
return LEGACY_LANGUAGE_CODES[lang] ?? lang
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Legacy travels.museumwnf.org's Exhibition Trails: a country's or a theme's
|
|
182
|
-
// trails, a trail (`?id=<project>;<country>;<number>;<language>`) and an
|
|
183
|
-
// itinerary (`?id=<project>;<country>;<roman number>;<language>;<trail>`),
|
|
184
|
-
// keyed as the importer keys them (`mwnf3_travels:trail:…`,
|
|
185
|
-
// `mwnf3_travels:itinerary:…`), each tab (`fl`) the new page has. The rest of
|
|
186
|
-
// the host (the tours, the booking form) has no new site and stays there.
|
|
187
|
-
// The trails' countries: legacy's code → the inventory id travels-data's
|
|
188
|
-
// countries.json gives it.
|
|
189
|
-
const TRAVELS_COUNTRIES = {
|
|
190
|
-
dz: 'dza', eg: 'egy', es: 'esp', it: 'ita', jo: 'jor', ma: 'mar', pa: 'pse', pt: 'prt', sy: 'syr', tn: 'tun', tr: 'tur',
|
|
191
|
-
}
|
|
192
|
-
const TRAIL_TABS = ['desc', 'its', 'cur']
|
|
193
|
-
const ITINERARY_TABS = ['des', 'vl']
|
|
194
|
-
function travelsQuery(url, tabs, language) {
|
|
195
|
-
const tab = (url.searchParams.get('fl') ?? '').toLowerCase()
|
|
196
|
-
const lang = isoLanguage(language)
|
|
197
|
-
const query = [tabs.includes(tab) ? `tab=${tab}` : null, lang ? `lang=${lang}` : null]
|
|
198
|
-
const kept = query.filter(Boolean)
|
|
199
|
-
return kept.length ? `?${kept.join('&')}` : ''
|
|
200
|
-
}
|
|
201
|
-
function travelsRoute(path, url) {
|
|
202
|
-
const script = path.toLowerCase()
|
|
203
|
-
if (script === '/travel_et_home.php') return '/'
|
|
204
|
-
if (script === '/travel_et_trail.php') {
|
|
205
|
-
const country = TRAVELS_COUNTRIES[(url.searchParams.get('cid') ?? '').toLowerCase()]
|
|
206
|
-
if (country) return `/trails?country=${country}`
|
|
207
|
-
const project = url.searchParams.get('tid')
|
|
208
|
-
return /^[a-z0-9]+$/i.test(project ?? '') ? `/trails?project=${project.toUpperCase()}` : null
|
|
209
|
-
}
|
|
210
|
-
const id = (url.searchParams.get('id') ?? '').split(';').map((part) => part.trim())
|
|
211
|
-
if (script === '/travel_et_traildetail.php' && id.length >= 3 && id.slice(0, 3).every(Boolean)) {
|
|
212
|
-
const [project, country, number, language] = id
|
|
213
|
-
return `/trail/${legacyRecordId('collection', `mwnf3_travels:trail:${project}:${country}:${number}`)}${travelsQuery(url, TRAIL_TABS, language)}`
|
|
214
|
-
}
|
|
215
|
-
if (script === '/travel_et_itenary.php' && id.length >= 5 && [0, 1, 2, 4].every((i) => id[i])) {
|
|
216
|
-
const [project, country, number, language, trail] = id
|
|
217
|
-
return `/itinerary/${legacyRecordId('collection', `mwnf3_travels:itinerary:${project}:${country}:${trail}:${number}`)}${travelsQuery(url, ITINERARY_TABS, language)}`
|
|
218
|
-
}
|
|
219
|
-
return null
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// Discover Islamic Art's partner page (`pm_partner.php?id=<partner>;<country>&type=museum|institution`),
|
|
223
|
-
// keyed as the importer keys a partner (`mwnf3:museums:…`, `mwnf3:institutions:…`). Travels' trails and the
|
|
224
|
-
// books link to it for their museums. Its other pages are PAGES above.
|
|
225
|
-
const PARTNER_KINDS = { museum: 'museums', institution: 'institutions' }
|
|
226
|
-
function islamicartRecordRoute(path, url) {
|
|
227
|
-
if (path.toLowerCase() !== '/pm_partner.php') return undefined
|
|
228
|
-
const [partner, country] = (url.searchParams.get('id') ?? '').split(';').map((part) => part.trim())
|
|
229
|
-
const kind = PARTNER_KINDS[(url.searchParams.get('type') ?? 'museum').toLowerCase()]
|
|
230
|
-
if (!partner || !country || !kind) return null
|
|
231
|
-
return `/partner/${legacyRecordId('partner', `mwnf3:${kind}:${partner}:${country}`)}`
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// The families whose pages name a record or a page in their address.
|
|
235
|
-
const RECORD_PAGES = { publications: publicationsRoute, travels: travelsRoute }
|
|
236
|
-
|
|
237
|
-
const bareHost = (host) => host.toLowerCase().replace(/^www\./, '')
|
|
238
|
-
|
|
239
|
-
function rowFor(url) {
|
|
240
|
-
const host = bareHost(url.host)
|
|
241
|
-
const path = url.pathname.toLowerCase().replace(/\/?$/, '/')
|
|
242
|
-
return LEGACY_SITES.filter(
|
|
243
|
-
(row) =>
|
|
244
|
-
row.host === host &&
|
|
245
|
-
path.startsWith((row.path ?? '/').replace(/\.php$/, '.php/')) &&
|
|
246
|
-
Object.entries(row.query ?? {}).every(([key, value]) => url.searchParams.get(key) === value),
|
|
247
|
-
).sort((a, b) => (b.path ?? '/').length - (a.path ?? '/').length)[0]
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* The route on the new site that a legacy address of `row` lands on, or null
|
|
252
|
-
* when it has none. Galleries, Explore and the hub kept legacy's paths as
|
|
253
|
-
* routes (their legacy redirects); an exhibition drops its own segment and
|
|
254
|
-
* moves the language to the query; a mini-site opens on its home; a
|
|
255
|
-
* product's page goes through PAGES.
|
|
256
|
-
*/
|
|
257
|
-
function routeFor(row, url) {
|
|
258
|
-
// A legacy text may write the address with a space before its closing `>`.
|
|
259
|
-
const pathname = decodeURIComponent(url.pathname).trim() || '/'
|
|
260
|
-
const path = pathname.replace(/\/+$/, '') || '/'
|
|
261
|
-
if (row.family === 'gallery' || row.family === 'explore' || row.family === 'galleries') return `${path}${url.search}`
|
|
262
|
-
if (row.family === 'minisite') return '/'
|
|
263
|
-
if (RECORD_PAGES[row.family]) return RECORD_PAGES[row.family](path, url)
|
|
264
|
-
if (row.family === 'exhibition') {
|
|
265
|
-
const rest = path.split('/').filter(Boolean).slice(1)
|
|
266
|
-
const lang = /^[a-z]{2}$/.test(rest[0] ?? '') ? isoLanguage(rest.shift()) : null
|
|
267
|
-
return `/${rest.join('/')}${lang ? `?lang=${lang}` : ''}`
|
|
268
|
-
}
|
|
269
|
-
if (row.family === 'islamicart') {
|
|
270
|
-
const record = islamicartRecordRoute(path, url)
|
|
271
|
-
if (record !== undefined) return record
|
|
272
|
-
}
|
|
273
|
-
const route = PAGES[row.family]?.[pathname.toLowerCase()]
|
|
274
|
-
if (!route) return null
|
|
275
|
-
const keep = (KEPT_QUERY[route] ?? []).filter((key) => url.searchParams.has(key))
|
|
276
|
-
return keep.length ? `${route}?${keep.map((key) => `${key}=${encodeURIComponent(url.searchParams.get(key))}`).join('&')}` : route
|
|
277
|
-
}
|
|
4
|
+
// Links to legacy MWNF sites that have a new one (inventory-app#2482): the
|
|
5
|
+
// table and the routes are `legacyAddresses.js`'s (no Vue, so an exporter can
|
|
6
|
+
// use them too); this module draws every link of a site through them.
|
|
7
|
+
export { LEGACY_SITES, legacyAddressRoute, legacyAddressTarget }
|
|
278
8
|
|
|
279
9
|
function fixAnchor(anchor) {
|
|
280
10
|
const href = anchor.getAttribute('href')
|
|
@@ -321,34 +51,9 @@ export function withScheme(address) {
|
|
|
321
51
|
*/
|
|
322
52
|
export function toNewSite(href) {
|
|
323
53
|
if (typeof href !== 'string') return href
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
} catch {
|
|
328
|
-
return href
|
|
329
|
-
}
|
|
330
|
-
if (!/^https?:$/.test(url.protocol)) return href
|
|
331
|
-
const row = rowFor(url)
|
|
332
|
-
if (!row) return href
|
|
333
|
-
const route = routeFor(row, url)
|
|
334
|
-
if (route === null) return href
|
|
335
|
-
return siblingSiteUrl(row.slug, route) ?? href
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* The route on the new site that a legacy MWNF address lands on (a book's
|
|
340
|
-
* `/publication/<id>/<language>` for `books.museumwnf.org/book/5/en`), or
|
|
341
|
-
* null when the address is no legacy site's, or names nothing there.
|
|
342
|
-
*/
|
|
343
|
-
export function legacyAddressRoute(href) {
|
|
344
|
-
let url
|
|
345
|
-
try {
|
|
346
|
-
url = new URL(String(href ?? '').trim())
|
|
347
|
-
} catch {
|
|
348
|
-
return null
|
|
349
|
-
}
|
|
350
|
-
const row = rowFor(url)
|
|
351
|
-
return row ? routeFor(row, url) : null
|
|
54
|
+
const target = legacyAddressTarget(href)
|
|
55
|
+
if (!target) return href
|
|
56
|
+
return siblingSiteUrl(target.slug, target.route) ?? href
|
|
352
57
|
}
|
|
353
58
|
|
|
354
59
|
/**
|