@museumwnf/viewer-core 2.16.0 → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@museumwnf/viewer-core",
3
- "version": "2.16.0",
3
+ "version": "2.17.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",
@@ -18,6 +18,7 @@ import { resolveRecordLanguage } from './composables/useRecordLanguage.js'
18
18
  // site_url: 'https://…' | null,
19
19
  // related_database_url: 'https://…' | null,
20
20
  // artistic_introduction_url: 'https://…' | null,
21
+ // home_site: '<site slug>' | null, // the site home to its records
21
22
  // }
22
23
  //
23
24
  // A data package built before this phase simply has no `projects` key at
@@ -49,10 +50,12 @@ export function projectLabel(manifest, projectId, lang) {
49
50
  }
50
51
 
51
52
  /**
52
- * The three URLs `manifest.projects[projectId]` carries. `null` for the
53
- * whole result (not per field) when the package predates the section or
54
- * does not carry `projectId`; each field is `null` on its own when the
55
- * project simply has no value for it (import time never invents one).
53
+ * The three URLs `manifest.projects[projectId]` carries, and `homeSite`, the
54
+ * slug of the site home to the project's records (`siblingSiteUrl` turns it
55
+ * into an address). `null` for the whole result (not per field) when the
56
+ * package predates the section or does not carry `projectId`; each field is
57
+ * `null` on its own when the project simply has no value for it (import
58
+ * time never invents one).
56
59
  */
57
60
  export function projectLinks(manifest, projectId) {
58
61
  const entry = projectEntry(manifest, projectId)
@@ -61,6 +64,7 @@ export function projectLinks(manifest, projectId) {
61
64
  siteUrl: entry.site_url ?? null,
62
65
  relatedDatabaseUrl: entry.related_database_url ?? null,
63
66
  artisticIntroductionUrl: entry.artistic_introduction_url ?? null,
67
+ homeSite: entry.home_site ?? null,
64
68
  }
65
69
  }
66
70
 
package/src/index.js CHANGED
@@ -19,7 +19,7 @@ export { languageLabels, offeredLanguages } from './languages.js'
19
19
  export { defaultScrollBehavior, resolveViews } from './router/index.js'
20
20
  export { mediaUrl, useSiteConfig } from './siteConfig.js'
21
21
  export { bindDisplayLanguage, displayLanguage } from './displayLanguage.js'
22
- export { sourceUrl, useSiteRights } from './rights.js'
22
+ export { siblingSiteUrl, sourceUrl, useSiteRights } from './rights.js'
23
23
 
24
24
  // The list pages: query state, pagination, facets, dates, keyword search.
25
25
  export { useListQuery } from './catalogue/listQuery.js'
package/src/rights.js CHANGED
@@ -30,7 +30,13 @@ export function useSiteRights() {
30
30
  }
31
31
  }
32
32
 
33
- const TRAILING_SLASHES = /\/+$/
33
+ // The declared origin without the trailing slashes a site may have put on it
34
+ // (a loop, not a regular expression: an origin is the site's own input).
35
+ function siteOrigin() {
36
+ let origin = String(useSiteConfig().site?.origin ?? '')
37
+ while (origin.endsWith('/')) origin = origin.slice(0, -1)
38
+ return origin
39
+ }
34
40
 
35
41
  /**
36
42
  * The address of `route` on this deployment: the declared `site.origin`
@@ -43,7 +49,7 @@ const TRAILING_SLASHES = /\/+$/
43
49
  * same way a `<router-link>` would.
44
50
  */
45
51
  export function sourceUrl(route) {
46
- const origin = String(useSiteConfig().site?.origin ?? '').replace(TRAILING_SLASHES, '')
52
+ const origin = siteOrigin()
47
53
  if (!origin) return null
48
54
  const fullPath =
49
55
  typeof route === 'object' && route !== null && typeof route.fullPath === 'string'
@@ -51,3 +57,16 @@ export function sourceUrl(route) {
51
57
  : useRouter().resolve(route).fullPath
52
58
  return `${origin}/#${fullPath}`
53
59
  }
60
+
61
+ /**
62
+ * The address of `path` (a router path, e.g. `/item/<id>`) on the sibling
63
+ * site `slug`: every site is deployed beside the others, one path segment
64
+ * under a common parent, so a sibling's origin is this site's with its last
65
+ * segment swapped. Null when the site declares no origin, or no slug is given.
66
+ */
67
+ export function siblingSiteUrl(slug, path) {
68
+ const origin = siteOrigin()
69
+ if (!origin || !slug) return null
70
+ const parent = origin.slice(0, origin.lastIndexOf('/'))
71
+ return `${parent}/${slug}/#${path}`
72
+ }