@uniweb/core 1.4.8 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/core",
3
- "version": "1.4.8",
3
+ "version": "1.4.10",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
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 — because a host caches it
15
- * under a key of publish-time facts, one entry serving a site's every hostname. Besides its inputs,
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
@@ -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. By the rule a
1053
- * link to another locale is made with (`localeUrl`), so a translated route is the route that
1054
- * locale shows. Null when the site's address is unknown (`config.url`): a URL guessed from where
1055
- * the page happens to be loaded could be another copy of the site.
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 = localeUrl(this._routeIndex, localeCode, route, this._routeContext())
1068
+ const path = localeUrlOnAddress(this._routeIndex, localeCode, route, this._routeContext())
1066
1069
  return pageUrl(this.url, path, { trailingSlash: this.trailingSlash })
1067
1070
  }
1068
1071
 
@@ -1086,19 +1089,6 @@ export default class Website {
1086
1089
  return alternates
1087
1090
  }
1088
1091
 
1089
- /**
1090
- * The pages of the content this Website was built from, as the content states them, in its
1091
- * order — for a rule written over site content to read the pages the build read. The runtime
1092
- * links each page's markdown this way (`pageMarkdownUrls` in `@uniweb/projections`), whose rules
1093
- * read fields a Page does not keep, such as a container's `hasContent: false`. The not-found
1094
- * page is not among them.
1095
- *
1096
- * @returns {Object[]}
1097
- */
1098
- getContentPages() {
1099
- return [...this._pageOfData.keys()]
1100
- }
1101
-
1102
1092
  /**
1103
1093
  * Show the page in another locale.
1104
1094
  *