@museumwnf/viewer-core 2.26.0 → 2.28.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 +30 -1
- package/package.json +2 -1
- package/src/composables/useDataPackage.js +16 -0
- package/src/conventions.js +19 -0
- package/src/createViewer.js +4 -1
- package/src/i18n/language.js +2 -6
- package/src/i18n/legacyLanguageCodes.js +8 -0
- package/src/index.js +2 -2
- package/src/legacyAddresses.js +312 -0
- package/src/legacySites.js +37 -284
- package/src/testing/viteConfig.js +18 -1
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
|
|
|
@@ -157,6 +158,7 @@ What a website's `main.js` still writes, and why it cannot move here:
|
|
|
157
158
|
| `media` | `{ legacyHost }` | no | the host of the legacy media server, for [`mediaUrl()`](#the-declaration-outside-a-component) |
|
|
158
159
|
| `links` | object | no | the addresses a website links out to: `portal`, `galleries`, `myCollection`, `about`, `contact`, `legalNotice`, `credits`, `cookies` |
|
|
159
160
|
| `site.origin` | string | no | the absolute origin this build is deployed at, base path included when there is one (`https://metanull.github.io/islamicart`, no trailing slash) — declared once here rather than baked into the package, since the package cannot know where it will be served; read by [`sourceUrl()`](#the-declaration-outside-a-component) |
|
|
161
|
+
| `site.legacyHost` | string | no | the legacy host this site replaces (`books.museumwnf.org`): once that host points at the site, an old address on it (`/book/5/en`) opens the page it names (see [Old addresses](#old-addresses-at-the-domain-switch)); nothing without it |
|
|
160
162
|
| `site.slug` | string | no | the site's slug, as in the exporters' instance files; defaults to the last segment of `site.origin`. The global search's link sends it as `from` |
|
|
161
163
|
| `globalSearch` | `true` or `{ url }` | no | **off by default.** Turns on the link to the global search (inventory-app M15, ADR 005): `true` for its default address (`GLOBAL_SEARCH_URL`), `{ url }` for another https address. viewer-layout's header then shows its search box. The parity check turns it on for the sites whose legacy had a similar feature |
|
|
162
164
|
|
|
@@ -485,6 +487,7 @@ under the main partner it belongs to.
|
|
|
485
487
|
| `useSection()` | the `meta.section` of the current route — see Routing |
|
|
486
488
|
| `useFeaturedRecord(entity, { withImage = true, seed, filter })` | one record at random for a landing page's spotlight, among those with an image; null until the entity is loaded; `seed` pins the pick; `filter(record)` applies a site's own visible rule first |
|
|
487
489
|
| `sectionMeta(chrome = [])` | returns `meta(section, ...entities) => ({ section, entities: [...chrome, ...entities] })` — a route's `meta` in one call, `chrome` being the entities every page of the site loads regardless of which one it is |
|
|
490
|
+
| `mwnfPortalPages` | the portal's own pages a site's footer links to (`chronology`, `support`, `volunteers`, `honoraryCommittee`, `commemoration`, `pressLounge`, `languagePolicy`, `leagueOfArabStates`, `cafeteria`, `partnerList`) — frozen, kept apart from `mwnfLinks` so the DXA configs' `links` do not change |
|
|
488
491
|
| `mwnfLinks` | the portal and sibling-site addresses the four DXA configs each repeat under `links` — frozen, spread into a site's own `links` rather than retyped |
|
|
489
492
|
|
|
490
493
|
#### Projects, from the data package (epic metanull/inventory-app#1727)
|
|
@@ -600,6 +603,7 @@ below for whichever future site needs its own).
|
|
|
600
603
|
| `loadTranslations(entity, lang)` | `Promise<object>` | lazy-loads `translations/<entity>.<lang>.json` (id → translated fields); `{}` if the file is absent. Cached. |
|
|
601
604
|
| `translations(entity, lang)` | object | the already-loaded map for that pair; `{}` if not loaded yet |
|
|
602
605
|
| `tr(entity, id, lang, fallbackLang = 'en')` | object | one record's translated fields, falling back to `fallbackLang` then `{}` — reads only what's already loaded |
|
|
606
|
+
| `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 |
|
|
603
607
|
|
|
604
608
|
Always resolve a per-language file by name through `loadTranslations`/`translations`/`tr` —
|
|
605
609
|
never `import(\`...${lang}...\`)`. A dynamic import with an interpolated
|
|
@@ -708,6 +712,9 @@ The convention, applied by the router every website shares:
|
|
|
708
712
|
location (`{ name, params }` or a path) or nothing, which is the not-found
|
|
709
713
|
page. It may be async, so a website can load the entity it maps a legacy
|
|
710
714
|
key through `backward_compatibility` with;
|
|
715
|
+
- an old address of the legacy site this one replaces, once its host points
|
|
716
|
+
here, is a path the hash router never sees: see
|
|
717
|
+
[Old addresses](#old-addresses-at-the-domain-switch);
|
|
711
718
|
- a route says what section it belongs to — `meta: { section: 'collection' }`
|
|
712
719
|
— and a shell reads it with `useSection()` for the banner title or the
|
|
713
720
|
active menu entry, instead of deriving it from the path;
|
|
@@ -736,6 +743,28 @@ export default {
|
|
|
736
743
|
}
|
|
737
744
|
```
|
|
738
745
|
|
|
746
|
+
### Old addresses at the domain switch
|
|
747
|
+
|
|
748
|
+
The router uses hash history, so an old address of the legacy site
|
|
749
|
+
(`https://books.museumwnf.org/book/5/en`) is a path it never sees, and a
|
|
750
|
+
static host has no file for it. Once the legacy host points at the new site:
|
|
751
|
+
|
|
752
|
+
1. the build adds a `404.html` that is the site itself:
|
|
753
|
+
`defineViewerConfig({ ..., notFoundPage: true })`;
|
|
754
|
+
2. the site declares the host it replaces: `site.legacyHost`;
|
|
755
|
+
3. before the router starts, `createViewer` calls
|
|
756
|
+
`openLegacyAddress(config.site)`: the address becomes
|
|
757
|
+
`<base>#<route>`, the route `legacyAddressRoute()` gives (the same
|
|
758
|
+
table `toNewSite()` rewrites links with), or the not-found page.
|
|
759
|
+
|
|
760
|
+
`legacyAddressRoute(href)` answers the new site's route of any legacy MWNF
|
|
761
|
+
address, or null. A site without `site.legacyHost` is unchanged.
|
|
762
|
+
|
|
763
|
+
`legacyAddressTarget(href)` answers `{ slug, route }`: the new site and
|
|
764
|
+
its route. Both, and `LEGACY_SITES`, are also at
|
|
765
|
+
`@museumwnf/viewer-core/legacy-addresses`, a module with no Vue, so an
|
|
766
|
+
exporter can rewrite a data package's links with the same table.
|
|
767
|
+
|
|
739
768
|
### Views
|
|
740
769
|
|
|
741
770
|
Every website has three slots — the home page, a list page, a record page —
|
|
@@ -808,7 +837,7 @@ The package exports shared smoke-test helpers at @museumwnf/viewer-core/testing:
|
|
|
808
837
|
| checkRoutes(config, { names, legacyPaths }) | Verify every route has a name, no route is a catch-all, and expected names and legacy paths are present. Returns the list of problems found. |
|
|
809
838
|
| checkSectionMeta(config) | Verify every route has a meta.section string (used by the menu to highlight the current page). Returns the list of problems found. |
|
|
810
839
|
| checkTextsRendered(host, { namespaces }) | Match text keys in the rendered host against a regex like /\b(ns1\|ns2)\.[a-z]/i. Returns the list of namespaces found (empty if none). |
|
|
811
|
-
| defineViewerConfig({ dataPackage, inline, plugins, root }) | Return the Vite config object every website shares: the @inventory-data alias, optimizeDeps to inline viewer packages, testTimeout of 60s, and the test environment. Exported from `@museumwnf/viewer-core/vite` for use in `vite.config.js` (separate entry because Vite's config loader runs under Node.js, which cannot parse `.vue` files; the `/testing` barrel reaches a `.vue` file). dataPackage is the npm package name; inline is an optional array of extra packages; plugins is the Vite plugins array (e.g. @vitejs/plugin-vue); root is the project root path (default `process.cwd()`), used to resolve the data package from the project root. |
|
|
840
|
+
| defineViewerConfig({ dataPackage, inline, plugins, notFoundPage, root }) | Return the Vite config object every website shares: the @inventory-data alias, optimizeDeps to inline viewer packages, testTimeout of 60s, and the test environment. Exported from `@museumwnf/viewer-core/vite` for use in `vite.config.js` (separate entry because Vite's config loader runs under Node.js, which cannot parse `.vue` files; the `/testing` barrel reaches a `.vue` file). dataPackage is the npm package name; inline is an optional array of extra packages; plugins is the Vite plugins array (e.g. @vitejs/plugin-vue); root is the project root path (default `process.cwd()`), used to resolve the data package from the project root. notFoundPage (default false) adds the build's `404.html`, a copy of its `index.html`, for [old addresses](#old-addresses-at-the-domain-switch). |
|
|
812
841
|
| checkOfferedLanguages(config) | Check that the website offers only languages with content, in the declared order, with labels on the switcher. Returns the list of problems found. |
|
|
813
842
|
|
|
814
843
|
@museumwnf/viewer-core/testing is not imported by websites, only by their tests. A website test might be:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@museumwnf/viewer-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.28.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
|
}
|
package/src/conventions.js
CHANGED
|
@@ -166,3 +166,22 @@ export const mwnfLinks = Object.freeze({
|
|
|
166
166
|
baroqueArt: 'https://baroqueart.museumwnf.org',
|
|
167
167
|
sharingHistory: 'https://sharinghistory.museumwnf.org',
|
|
168
168
|
})
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The portal's own pages a site's footer links to (the Publications footer,
|
|
172
|
+
* as legacy's books pages drew it, read from the portal's footer). Kept here
|
|
173
|
+
* so they change in one place when the portal does; apart from `mwnfLinks`,
|
|
174
|
+
* which the DXA configs copy whole into their `links`.
|
|
175
|
+
*/
|
|
176
|
+
export const mwnfPortalPages = Object.freeze({
|
|
177
|
+
chronology: 'https://www.museumwnf.org/about/chronology',
|
|
178
|
+
support: 'https://www.museumwnf.org/about/support',
|
|
179
|
+
volunteers: 'https://www.museumwnf.org/about/volunteers',
|
|
180
|
+
honoraryCommittee: 'https://www.museumwnf.org/about/honorary-committee',
|
|
181
|
+
commemoration: 'https://www.museumwnf.org/about/commemoration',
|
|
182
|
+
pressLounge: 'https://www.museumwnf.org/about/press-lounge',
|
|
183
|
+
languagePolicy: 'https://www.museumwnf.org/about/language-policy',
|
|
184
|
+
leagueOfArabStates: 'https://www.museumwnf.org/league-of-arab-states/',
|
|
185
|
+
cafeteria: 'https://www.museumwnf.org/cafeteria/',
|
|
186
|
+
partnerList: 'https://www.museumwnf.org/partner_list.php',
|
|
187
|
+
})
|
package/src/createViewer.js
CHANGED
|
@@ -7,7 +7,7 @@ import { connectLanguageToRouter, resolveInitialLanguage } from './i18n/language
|
|
|
7
7
|
import { VIEWER_CONFIG } from './injectionKeys.js'
|
|
8
8
|
import { createViewerRouter } from './router/index.js'
|
|
9
9
|
import { setSiteConfig } from './siteConfig.js'
|
|
10
|
-
import { watchNewSiteLinks } from './legacySites.js'
|
|
10
|
+
import { openLegacyAddress, watchNewSiteLinks } from './legacySites.js'
|
|
11
11
|
import './styles/base.css'
|
|
12
12
|
|
|
13
13
|
export function createViewer(config = {}) {
|
|
@@ -16,6 +16,9 @@ export function createViewer(config = {}) {
|
|
|
16
16
|
const messages = config.messages ?? {}
|
|
17
17
|
const resolved = { ...config, languages }
|
|
18
18
|
|
|
19
|
+
// An old link to the legacy site this one replaces opens the page it
|
|
20
|
+
// names (`site.legacyHost`; nothing without it).
|
|
21
|
+
openLegacyAddress(config.site)
|
|
19
22
|
const router = createViewerRouter(config)
|
|
20
23
|
const i18n = createI18n({ messages, locale: resolveInitialLanguage(languages) })
|
|
21
24
|
|
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, 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
|
|
|
@@ -53,7 +53,7 @@ export { groupByCountry, partnerHierarchy, partnerView } from './record/partners
|
|
|
53
53
|
|
|
54
54
|
// Conventions every website had written for itself.
|
|
55
55
|
export {
|
|
56
|
-
mwnfLinks, projectLabel, projectLinks, sectionMeta, useFeaturedRecord,
|
|
56
|
+
mwnfLinks, mwnfPortalPages, projectLabel, projectLinks, sectionMeta, useFeaturedRecord,
|
|
57
57
|
useProjects, useSection,
|
|
58
58
|
} from './conventions.js'
|
|
59
59
|
|
|
@@ -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,16 +51,39 @@ export function withScheme(address) {
|
|
|
321
51
|
*/
|
|
322
52
|
export function toNewSite(href) {
|
|
323
53
|
if (typeof href !== 'string') return href
|
|
324
|
-
|
|
54
|
+
const target = legacyAddressTarget(href)
|
|
55
|
+
if (!target) return href
|
|
56
|
+
return siblingSiteUrl(target.slug, target.route) ?? href
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Turns the page's own address into the route it names when it is one of
|
|
61
|
+
* the site's legacy addresses: a site declares the legacy host it replaces
|
|
62
|
+
* (`site.legacyHost`, e.g. `books.museumwnf.org`) and its address
|
|
63
|
+
* (`site.origin`). Once that host points at the site, an old link such as
|
|
64
|
+
* `/book/5/en` reaches the build's 404 page (`defineViewerConfig({
|
|
65
|
+
* notFoundPage: true })`), which is the site itself: before the router
|
|
66
|
+
* starts, the address becomes `<base>#/publication/<id>/en`. An address
|
|
67
|
+
* that names nothing goes to the not-found page. Does nothing without
|
|
68
|
+
* `legacyHost`, on the site's home, or when the address already has a
|
|
69
|
+
* route. Returns the address it moved to, or null.
|
|
70
|
+
*/
|
|
71
|
+
export function openLegacyAddress(site, win = typeof window === 'undefined' ? undefined : window) {
|
|
72
|
+
const host = site?.legacyHost
|
|
73
|
+
if (!host || !win?.location || !win.history?.replaceState) return null
|
|
74
|
+
const { pathname, search, hash } = win.location
|
|
75
|
+
if (hash && hash !== '#' && hash !== '#/') return null
|
|
76
|
+
let base = '/'
|
|
325
77
|
try {
|
|
326
|
-
|
|
78
|
+
base = new URL(site.origin).pathname.replace(/\/?$/, '/')
|
|
327
79
|
} catch {
|
|
328
|
-
|
|
80
|
+
// No origin: the site is served at the root.
|
|
329
81
|
}
|
|
330
|
-
if (
|
|
331
|
-
const
|
|
332
|
-
if (
|
|
333
|
-
const route =
|
|
334
|
-
|
|
335
|
-
|
|
82
|
+
if (!pathname.startsWith(base)) return null
|
|
83
|
+
const rest = `/${pathname.slice(base.length)}`
|
|
84
|
+
if (rest === '/' || rest === '/index.html' || rest === '/404.html') return null
|
|
85
|
+
const route = legacyAddressRoute(`https://${bareHost(host)}${rest}${search}`) ?? rest
|
|
86
|
+
const target = `${base}#${route}`
|
|
87
|
+
win.history.replaceState(win.history.state, '', target)
|
|
88
|
+
return target
|
|
336
89
|
}
|
|
@@ -11,6 +11,9 @@ import path from 'node:path'
|
|
|
11
11
|
* the required `'@museumwnf/viewer-core'` and `'@museumwnf/viewer-layout'`.
|
|
12
12
|
* `plugins` is an optional array of Vite plugins (e.g. `@vitejs/plugin-vue`),
|
|
13
13
|
* which the site must supply because this package does not depend on them.
|
|
14
|
+
* `notFoundPage`, when true, adds the build's `404.html`: a copy of its
|
|
15
|
+
* `index.html`, so GitHub Pages serves the site itself for an address it
|
|
16
|
+
* has no file for, and an old link reaches `openLegacyAddress`.
|
|
14
17
|
* `root` is an optional project root path (default `process.cwd()`); use it when
|
|
15
18
|
* loading the config from a context other than the project directory.
|
|
16
19
|
*/
|
|
@@ -18,10 +21,11 @@ export function defineViewerConfig({
|
|
|
18
21
|
dataPackage,
|
|
19
22
|
inline = [],
|
|
20
23
|
plugins = [],
|
|
24
|
+
notFoundPage = false,
|
|
21
25
|
root = process.cwd(),
|
|
22
26
|
} = {}) {
|
|
23
27
|
return {
|
|
24
|
-
plugins,
|
|
28
|
+
plugins: notFoundPage ? [...plugins, notFoundPagePlugin()] : plugins,
|
|
25
29
|
resolve: {
|
|
26
30
|
alias: {
|
|
27
31
|
// viewer-core reads every JSON of the data package through this alias.
|
|
@@ -73,3 +77,16 @@ export function defineViewerConfig({
|
|
|
73
77
|
},
|
|
74
78
|
}
|
|
75
79
|
}
|
|
80
|
+
|
|
81
|
+
/** The build's `404.html`, a copy of its `index.html` (`notFoundPage`). */
|
|
82
|
+
export function notFoundPagePlugin() {
|
|
83
|
+
return {
|
|
84
|
+
name: 'viewer-not-found-page',
|
|
85
|
+
apply: 'build',
|
|
86
|
+
enforce: 'post',
|
|
87
|
+
generateBundle(_options, bundle) {
|
|
88
|
+
const index = bundle['index.html']
|
|
89
|
+
if (index?.type === 'asset') this.emitFile({ type: 'asset', fileName: '404.html', source: index.source })
|
|
90
|
+
},
|
|
91
|
+
}
|
|
92
|
+
}
|