@uniweb/core 1.4.12 → 1.5.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/website.js +25 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/core",
3
- "version": "1.4.12",
3
+ "version": "1.5.0",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
package/src/website.js CHANGED
@@ -439,30 +439,39 @@ export default class Website {
439
439
  }
440
440
  }
441
441
 
442
- // Build page ID map for makeHref() resolution
443
- // Supports both explicit IDs and route-based lookup
442
+ // ⭐ What a `page:` link names a page BY — its stable id, else its route, and nothing else
443
+ // [Diego, 2026-10-29]: every site's data carries both, a static build's and a hosted site's
444
+ // alike. The homepage's route is the empty name, registered like any other, so `page:/`
445
+ // names it (`_pageByRef`). ⛔ Until 2026-10-29 a page's folder under `pages/` was a third
446
+ // name, added because the homepage had no route name — and a hosted site's data carries no
447
+ // folder, so `page:home` resolved in a static build and nowhere a backend served the site.
444
448
  this._pageIdMap = new Map()
445
449
  for (const page of this.pages) {
446
450
  // Explicit stableId takes priority (survives page reorganization)
447
451
  if (page.stableId) {
448
452
  this._pageIdMap.set(page.stableId, page)
449
453
  }
450
- // Route-based lookup (normalized, without leading/trailing slashes)
454
+ // Route-based lookup (normalized, without leading/trailing slashes; the homepage's is '')
455
+ if (typeof page.route !== 'string') continue
451
456
  const routeId = this.normalizeRoute(page.route)
452
- if (routeId && !this._pageIdMap.has(routeId)) {
457
+ if (!this._pageIdMap.has(routeId)) {
453
458
  this._pageIdMap.set(routeId, page)
454
459
  }
455
- // Folder-name fallback — allows page:home for homepage, page:docs/intro for index pages
456
- // Homepage route normalizes to '' (falsy, skipped above), but sourcePath '/home' → 'home' works
457
- if (page.sourcePath) {
458
- const folderId = page.sourcePath.replace(/^\//, '').replace(/\/$/, '')
459
- if (folderId && !this._pageIdMap.has(folderId)) {
460
- this._pageIdMap.set(folderId, page)
461
- }
462
- }
463
460
  }
464
461
  }
465
462
 
463
+ /**
464
+ * The page a `page:` reference names (`_pageIdMap`): by stable id, else by route, a target read
465
+ * the way a route is — `page:/` the homepage, `page:/docs/` the page `page:docs` names.
466
+ *
467
+ * @param {string} ref - what follows `page:`, before any `#`
468
+ * @returns {Page|undefined}
469
+ */
470
+ _pageByRef(ref) {
471
+ if (typeof ref !== 'string') return undefined
472
+ return this._pageIdMap.get(ref) ?? this._pageIdMap.get(ref.replace(/^\/+/, '').replace(/\/+$/, ''))
473
+ }
474
+
466
475
  /**
467
476
  * Get page by route — the page a URL names, or undefined.
468
477
  *
@@ -839,6 +848,7 @@ export default class Website {
839
848
  * makeHref('page:getting-started') // → '/docs/getting-started'
840
849
  * makeHref('page:getting-started#install') // → '/docs/getting-started#section-install'
841
850
  * makeHref('page:docs/api') // → '/docs/api' (route-based)
851
+ * makeHref('page:/#features') // → '/#section-features' (the homepage)
842
852
  * makeHref('/about') // → '/about' (passthrough)
843
853
  */
844
854
  makeHref(href) {
@@ -848,8 +858,8 @@ export default class Website {
848
858
  // Parse page reference: page:pageId#sectionId
849
859
  const [pageId, sectionId] = withoutPrefix.split('#')
850
860
 
851
- // Look up page by ID (explicit or route-based)
852
- const page = this._pageIdMap?.get(pageId)
861
+ // Look up the page by its stable id, else its route (`_pageByRef`)
862
+ const page = this._pageByRef(pageId)
853
863
 
854
864
  if (!page) {
855
865
  // Page not found - return original href (or could warn in dev)
@@ -946,7 +956,7 @@ export default class Website {
946
956
  resolveDetailPageTemplate(pageRef) {
947
957
  if (!pageRef || typeof pageRef !== 'string') return null
948
958
  const id = pageRef.startsWith('page:') ? pageRef.slice(5) : pageRef
949
- const page = this._pageIdMap?.get(id)
959
+ const page = this._pageByRef(id)
950
960
  if (!page || !page.route) {
951
961
  if (
952
962
  typeof console !== 'undefined' &&