@uniweb/core 1.4.9 → 1.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/page-shell.js +5 -3
- package/src/resolve-route.js +34 -0
- package/src/website.js +8 -5
package/package.json
CHANGED
package/src/page-shell.js
CHANGED
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
* host wrote its own shell, and one escaped `__DATA__` its own way, as invalid JSON, so no page
|
|
12
12
|
* of the site it served could start.
|
|
13
13
|
*
|
|
14
|
-
* Its output is a function of its inputs only — no request, no clock —
|
|
15
|
-
*
|
|
16
|
-
* only this code changes it, and `pageShellFingerprint` says when.
|
|
14
|
+
* Its output is a function of its inputs only — no request, no clock — so a host can cache it under
|
|
15
|
+
* a key of what it hands in, one entry serving every hostname that hands in the same. Besides its
|
|
16
|
+
* inputs, only this code changes it, and `pageShellFingerprint` says when. ⛔ Not every input is a
|
|
17
|
+
* publish-time fact: the site's address (`content.config.url`), which `__DATA__` carries, is stated
|
|
18
|
+
* by whoever serves the site and can change between publishes.
|
|
17
19
|
*
|
|
18
20
|
* ⛔ A change to what this writes that an older runtime's browser build cannot read — a new
|
|
19
21
|
* `__DATA__` encoding, a new split shape — is a breaking change: mark the commit `!` and name the
|
package/src/resolve-route.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
import { decodeRouteValue, matchDynamicRoute, parentRouteOf } from './route-match.js'
|
|
25
25
|
import { resolveDefaultLocale } from './locale-config.js'
|
|
26
|
+
import { siteAddress } from './site-address.js'
|
|
26
27
|
|
|
27
28
|
/** The not-found page's route. It is never a routable page of its own. */
|
|
28
29
|
export const NOT_FOUND_ROUTE = '/404'
|
|
@@ -99,9 +100,18 @@ export function routeIndex(content = {}) {
|
|
|
99
100
|
activeLocale: config.activeLocale || defaultLocale,
|
|
100
101
|
locales: servedLocales(config, siteDefaultLocale),
|
|
101
102
|
domainLocales: config.domainLocales || null,
|
|
103
|
+
// The locale the site's address (`config.url`) serves unprefixed, whichever host serves this
|
|
104
|
+
// copy: the address's domain's own, else the site's default.
|
|
105
|
+
addressLocale: addressLocaleOf(config, siteDefaultLocale),
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
108
|
|
|
109
|
+
function addressLocaleOf(config, siteDefaultLocale) {
|
|
110
|
+
const address = siteAddress(config.url)
|
|
111
|
+
const host = address ? new URL(address).host : null
|
|
112
|
+
return (host && config.domainLocales?.[host]) || siteDefaultLocale
|
|
113
|
+
}
|
|
114
|
+
|
|
105
115
|
function servedLocales(config, siteDefaultLocale) {
|
|
106
116
|
const codes = [siteDefaultLocale]
|
|
107
117
|
for (const entry of Array.isArray(config.languages) ? config.languages : []) {
|
|
@@ -202,6 +212,30 @@ export function localeUrl(site, localeCode, route, context = {}) {
|
|
|
202
212
|
return translated === '/' ? `/${localeCode}/` : `/${localeCode}${translated}`
|
|
203
213
|
}
|
|
204
214
|
|
|
215
|
+
/**
|
|
216
|
+
* ⭐ **A PAGE'S URL IN A LOCALE, AS THE SITE'S ADDRESS SERVES IT** — what its canonical, `og:url`,
|
|
217
|
+
* hreflang and sitemap entry join to `config.url` (`./site-address.js`). `localeUrl` made on the
|
|
218
|
+
* address's host rather than on the host serving this copy: the route is read as this copy shows
|
|
219
|
+
* it (`context`), and the URL is made with the locale the address serves unprefixed — its domain's
|
|
220
|
+
* own (`config.domainLocales`), else the site's default. A locale with a domain of its own is that
|
|
221
|
+
* domain, as `localeUrl` has it.
|
|
222
|
+
*
|
|
223
|
+
* ⛔ Until 2026-10-27 these URLs were made as the serving host shows the site. On a domain pinned
|
|
224
|
+
* to French, an English page's canonical, and every page's `en` and `x-default` alternates, named
|
|
225
|
+
* `/en/…` on an address that answers it with a 301 to the unprefixed URL.
|
|
226
|
+
*
|
|
227
|
+
* @param {Object} site - a locale's site content, or its `routeIndex`
|
|
228
|
+
* @param {string} localeCode - the locale the URL is for
|
|
229
|
+
* @param {string} route - the page's route, canonical or as the active locale shows it
|
|
230
|
+
* @param {{ activeLocale?: string, defaultLocale?: string }} [context] - this copy's
|
|
231
|
+
* @returns {string} a path from the address's root, or an absolute URL on a locale's own domain
|
|
232
|
+
*/
|
|
233
|
+
export function localeUrlOnAddress(site, localeCode, route, context = {}) {
|
|
234
|
+
const index = indexOf(site)
|
|
235
|
+
const target = canonicalRoute(index, route, context)
|
|
236
|
+
return localeUrl(index, localeCode, target, { activeLocale: index.siteDefaultLocale, defaultLocale: index.addressLocale })
|
|
237
|
+
}
|
|
238
|
+
|
|
205
239
|
/**
|
|
206
240
|
* The locale a path names by its prefix, and the path without it — for a host choosing which
|
|
207
241
|
* locale's content to resolve a request against. A path with no served locale's prefix is the
|
package/src/website.js
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
routeIndex,
|
|
24
24
|
resolveRoute as resolveRouteIn,
|
|
25
25
|
localeUrl,
|
|
26
|
+
localeUrlOnAddress,
|
|
26
27
|
canonicalRoute,
|
|
27
28
|
translateRoute as translateRouteIn,
|
|
28
29
|
reverseTranslateRoute as reverseTranslateRouteIn,
|
|
@@ -1049,10 +1050,12 @@ export default class Website {
|
|
|
1049
1050
|
|
|
1050
1051
|
/**
|
|
1051
1052
|
* A page's URL as the public reaches it — absolute, on the site's address — in a locale (default:
|
|
1052
|
-
* the active one): the URL its canonical, `og:url`, hreflang and sitemap entry name.
|
|
1053
|
-
*
|
|
1054
|
-
* locale
|
|
1055
|
-
*
|
|
1053
|
+
* the active one): the URL its canonical, `og:url`, hreflang and sitemap entry name. As the address
|
|
1054
|
+
* serves the site (`localeUrlOnAddress`): a translated route is the route that locale shows, a
|
|
1055
|
+
* locale with a domain of its own is that domain, and the rest are prefixed as on the address —
|
|
1056
|
+
* which is not how a domain pinned to another locale links to them. Null when the site's address is
|
|
1057
|
+
* unknown (`config.url`): a URL guessed from where the page happens to be loaded could be another
|
|
1058
|
+
* copy of the site.
|
|
1056
1059
|
*
|
|
1057
1060
|
* @param {Object|string} page - A Page, or a route
|
|
1058
1061
|
* @param {string} [localeCode]
|
|
@@ -1062,7 +1065,7 @@ export default class Website {
|
|
|
1062
1065
|
if (!this.url) return null
|
|
1063
1066
|
const route = typeof page === 'string' ? page : page?.getNavRoute?.() ?? page?.route
|
|
1064
1067
|
if (typeof route !== 'string') return null
|
|
1065
|
-
const path =
|
|
1068
|
+
const path = localeUrlOnAddress(this._routeIndex, localeCode, route, this._routeContext())
|
|
1066
1069
|
return pageUrl(this.url, path, { trailingSlash: this.trailingSlash })
|
|
1067
1070
|
}
|
|
1068
1071
|
|