@uniweb/core 1.5.2 → 1.6.1

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.5.2",
3
+ "version": "1.6.1",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
@@ -53,7 +53,7 @@
53
53
  "vitest": "^4.1.7"
54
54
  },
55
55
  "dependencies": {
56
- "@uniweb/semantic-parser": "~1.13.1",
56
+ "@uniweb/semantic-parser": "~1.13.2",
57
57
  "@uniweb/theming": "~1.2.1"
58
58
  },
59
59
  "scripts": {
package/src/page.js CHANGED
@@ -31,6 +31,16 @@ function normalizeHideIn(pageData) {
31
31
  return out
32
32
  }
33
33
 
34
+ // A folder's `noindex` covers the pages in it, as the sitemap and `llms.txt` read it
35
+ // (`@uniweb/projections`, `closedFolders`). On a page with content of its own, it stays that page's.
36
+ // ⛔ Until 2026-11-01 only `llms.txt` read it, and a page it left out still asked to be indexed.
37
+ function underNoindexFolder(page) {
38
+ for (let up = page.parent; up; up = up.parent) {
39
+ if (up.seo.noindex && !up.hasContent()) return true
40
+ }
41
+ return false
42
+ }
43
+
34
44
  export default class Page {
35
45
  constructor(pageData, id, website) {
36
46
  this.id = id
@@ -119,11 +129,6 @@ export default class Page {
119
129
  // the flag was set on the page DATA and this sealed class dropped it.
120
130
  this.notFound = pageData.notFound === true
121
131
 
122
- // Version context (for pages within versioned sections like /docs/v1/*)
123
- this.version = pageData.version || null // { id, label, latest, deprecated }
124
- this.versionMeta = pageData.versionMeta || null // { versions, latestId }
125
- this.versionScope = pageData.versionScope || null // The route where versioning starts
126
-
127
132
  // Build-time flag: does this page have renderable content?
128
133
  // Distinct from "are sections loaded?" — content-less containers
129
134
  // (folders with page.yml but no markdown) are always false.
@@ -214,7 +219,7 @@ export default class Page {
214
219
  description: own || home,
215
220
  keywords: this.keywords || siteKeywords,
216
221
  canonical,
217
- robots: this.seo.noindex || site.noindex ? 'noindex, nofollow' : null,
222
+ robots: this.seo.noindex || site.noindex || underNoindexFolder(this) ? 'noindex, nofollow' : null,
218
223
  alternates: website?.getPageAlternates?.(this) ?? [],
219
224
  og: {
220
225
  // Page content wins; site-level seo only fills gaps. Image is the
@@ -726,60 +731,6 @@ export default class Page {
726
731
  const pathForAncestorCheck = this.sourcePath || this.route
727
732
  return this.website.isRouteActiveOrAncestor(pathForAncestorCheck, currentRoute)
728
733
  }
729
-
730
- // ─────────────────────────────────────────────────────────────────
731
- // Version API (for documentation pages)
732
- // ─────────────────────────────────────────────────────────────────
733
-
734
- /**
735
- * Check if this page is within a versioned section
736
- * @returns {boolean}
737
- */
738
- isVersioned() {
739
- return this.version !== null
740
- }
741
-
742
- /**
743
- * Get the current version for this page
744
- * @returns {Object|null} Version info { id, label, latest, deprecated } or null
745
- */
746
- getVersion() {
747
- return this.version
748
- }
749
-
750
- /**
751
- * Get all available versions for this page's scope
752
- * @returns {Array} Array of version objects, or empty array
753
- */
754
- getVersions() {
755
- return this.versionMeta?.versions || []
756
- }
757
-
758
- /**
759
- * Check if this page is on the latest version
760
- * @returns {boolean}
761
- */
762
- isLatestVersion() {
763
- return this.version?.latest === true
764
- }
765
-
766
- /**
767
- * Check if this page is on a deprecated version
768
- * @returns {boolean}
769
- */
770
- isDeprecatedVersion() {
771
- return this.version?.deprecated === true
772
- }
773
-
774
- /**
775
- * Get URL for switching to a different version of this page
776
- * @param {string} targetVersion - Target version ID (e.g., 'v1')
777
- * @returns {string|null} Target URL or null if not versioned
778
- */
779
- getVersionUrl(targetVersion) {
780
- if (!this.isVersioned()) return null
781
- return this.website.getVersionUrl(targetVersion, this.route)
782
- }
783
734
  }
784
735
 
785
736
  /**
@@ -527,13 +527,6 @@ export function routeParamName(pattern, declared = null) {
527
527
  * included — when a page holds that route. A top-level page has none: the homepage
528
528
  * is not everyone's parent.
529
529
  *
530
- * ⭐ Past a version folder, the versioned section. In `docs/v1/` + `docs/v2/` the latest
531
- * version's pages sit at `/docs/…` and hang from `/docs`; an older one's sit at
532
- * `/docs/v1/…`, and `/docs/v1` is a folder, never a page — so they hang from `/docs` too.
533
- * The segment is a version by the build's own convention (`v1`, `v2.1`). ⛔ Until
534
- * 2026-10-19 they had no parent: every menu listed them as top-level pages, and no
535
- * branch of the tree held them.
536
- *
537
530
  * ⛔ Measured 2026-09-11, before this existed: the prefetch read the declared field
538
531
  * only, so on a payload without it `/members/alice` resolved no configs at all,
539
532
  * while the SPA inferred `/members` and fetched the list and the record itself.
@@ -551,16 +544,9 @@ export function parentRouteOf(route, { declared = null, has } = {}) {
551
544
  const cut = r.lastIndexOf('/')
552
545
  if (cut <= 0) return null
553
546
  const up = r.slice(0, cut)
554
- if (has(up)) return up
555
- const versionCut = up.lastIndexOf('/')
556
- if (versionCut <= 0 || !VERSION_SEGMENT.test(up.slice(versionCut + 1))) return null
557
- const section = up.slice(0, versionCut)
558
- return has(section) ? section : null
547
+ return has(up) ? up : null
559
548
  }
560
549
 
561
- /** A version folder's name — `v1`, `v2.1` — the build's convention for a versioned section. */
562
- const VERSION_SEGMENT = /^v\d+(\.\d+)?$/
563
-
564
550
  /**
565
551
  * The base route a record's URL composes onto, for a page that ADDRESSES ONE RECORD —
566
552
  * or null when the page is not one.
package/src/tracker.js CHANGED
@@ -287,6 +287,12 @@ export default class Tracker {
287
287
  // after construction. Same reason `Uniweb.defaultInsets` is pre-declared.
288
288
  this.onGranted = null
289
289
 
290
+ // Told each new path, after its `page_view`. The runtime's on-demand listener
291
+ // chunk uses it to notice a page the site counts as a conversion, without
292
+ // every site paying for a route subscription. Declared here for the same
293
+ // reason as `onGranted`.
294
+ this.onPage = null
295
+
290
296
  if (isBrowser && this.isEnabled()) {
291
297
  this.acquisition = captureAcquisition()
292
298
  // Minted even when consent is pending: events buffered before the visitor
@@ -499,21 +505,27 @@ export default class Tracker {
499
505
  this.currentPath = path
500
506
  this.startTimeOnPage()
501
507
 
502
- if (!this.arms('page_view')) return
503
508
  // Promptly, rather than waiting out the batch window: a page view is the
504
509
  // event most likely to be the only one of a short visit.
505
510
  //
506
511
  // Emitted only when true, like `continues` — absent is the negative, and it
507
512
  // keeps every later view the size it already was.
508
- this.enqueue(
509
- {
510
- event: 'page_view',
511
- path,
512
- ...(this.acquisition || {}),
513
- ...(firstOfLoad ? { first_of_load: true } : {})
514
- },
515
- true
516
- )
513
+ if (this.arms('page_view')) {
514
+ this.enqueue(
515
+ {
516
+ event: 'page_view',
517
+ path,
518
+ ...(this.acquisition || {}),
519
+ ...(firstOfLoad ? { first_of_load: true } : {})
520
+ },
521
+ true
522
+ )
523
+ }
524
+
525
+ // After the view, so what it reports follows the arrival it belongs to. Not
526
+ // behind `page_view`'s selection, for the reason this method's first comment
527
+ // gives: a site can select one without the other.
528
+ this.onPage?.(path)
517
529
  }
518
530
 
519
531
  /**
package/src/uniweb.js CHANGED
@@ -94,7 +94,7 @@ export default class Uniweb {
94
94
  // which is not what this class is for; and the guard it bought was never
95
95
  // taken up — every reader in the workspace already optional-chains
96
96
  // (`block.js`'s `track()`, and the runtime's `usePageView`,
97
- // `useSectionViews`, `useOutboundClicks`, `useSectionClicks`), so the
97
+ // `useSectionViews`, `useDocumentEvents`), so the
98
98
  // invariant lived only in the comment. Cost of carrying it: 1,576 gzip in
99
99
  // core's chunk, which press, unipress, `@uniweb/api` and every SSR isolate
100
100
  // paid for a class they never wire.
package/src/website.js CHANGED
@@ -126,7 +126,6 @@ export default class Website {
126
126
  // A payload page → its Page, for the pages `resolveRoute` names.
127
127
  this._pageOfData = new Map()
128
128
  this.basePath = ''
129
- this.versionedScopes = {}
130
129
  this.assets = {}
131
130
  this._pageIdMap = new Map()
132
131
 
@@ -149,7 +148,6 @@ export default class Website {
149
148
  config = {},
150
149
  layouts,
151
150
  notFound,
152
- versionedScopes = {},
153
151
  assets = {},
154
152
  } = content || {}
155
153
 
@@ -220,7 +218,6 @@ export default class Website {
220
218
  this.activeLang = this.activeLocale
221
219
  this.langs = this.locales.map((l) => ({ label: l.label || l.code, value: l.code }))
222
220
 
223
- this.versionedScopes = versionedScopes
224
221
  this.assets = assets
225
222
  }
226
223
 
@@ -1371,6 +1368,7 @@ export default class Website {
1371
1368
  * @param {boolean} [options.nested=true] - Return nested hierarchy (with children) or flat list
1372
1369
  * @param {string} [options.for] - Filter for specific navigation: 'header', 'footer', or undefined (all)
1373
1370
  * @param {boolean} [options.includeHidden=false] - Include hidden pages
1371
+ * @param {string} [options.under] - The pages below this route, whether or not it is listed itself
1374
1372
  * @param {function} [options.filter] - Custom filter function (page) => boolean
1375
1373
  * @param {function} [options.sort] - Custom sort function (a, b) => number
1376
1374
  * @returns {Array<Object>} Array of page info objects for navigation
@@ -1392,6 +1390,7 @@ export default class Website {
1392
1390
  nested = true,
1393
1391
  for: navType,
1394
1392
  includeHidden = false,
1393
+ under,
1395
1394
  filter: customFilter,
1396
1395
  sort: customSort
1397
1396
  } = options
@@ -1438,11 +1437,11 @@ export default class Website {
1438
1437
  return true
1439
1438
  }
1440
1439
 
1441
- let filteredPages = this.pages.filter(isPageVisible)
1440
+ let filteredPages = (under ? this.getPage(under)?.children ?? [] : this.pages).filter(isPageVisible)
1442
1441
 
1443
1442
  // When nested, only include root-level pages at top level
1444
1443
  // (children will be nested inside their parents)
1445
- if (nested) {
1444
+ if (nested && !under) {
1446
1445
  // Exclude child pages from root list. Also exclude orphans whose parent
1447
1446
  // was removed (e.g., hidden) — they have parentRoute but no resolved parent.
1448
1447
  filteredPages = filteredPages.filter(page => !page.parent && !page.parentRoute)
@@ -1466,7 +1465,6 @@ export default class Website {
1466
1465
  label: page.getLabel(),
1467
1466
  description: page.description,
1468
1467
  hasContent: page.hasContent(),
1469
- version: page.version || null, // Version metadata for filtering by version
1470
1468
  children: nested && page.hasChildren()
1471
1469
  ? page.children.filter(isPageVisible).map(buildPageInfo)
1472
1470
  : []
@@ -1654,187 +1652,4 @@ export default class Website {
1654
1652
  // Check if current starts with target followed by /
1655
1653
  return current.startsWith(target + '/')
1656
1654
  }
1657
-
1658
- // ─────────────────────────────────────────────────────────────────
1659
- // Version API (for documentation sites)
1660
- // ─────────────────────────────────────────────────────────────────
1661
-
1662
- /**
1663
- * Get all versioned scopes
1664
- * Returns a map of scope routes to their version metadata
1665
- *
1666
- * @returns {Object} Map of scope → { versions, latestId }
1667
- *
1668
- * @example
1669
- * website.getVersionedScopes()
1670
- * // { '/docs': { versions: [...], latestId: 'v2' } }
1671
- */
1672
- getVersionedScopes() {
1673
- return this.versionedScopes
1674
- }
1675
-
1676
- /**
1677
- * Check if site has any versioned content
1678
- * @returns {boolean}
1679
- */
1680
- hasVersionedContent() {
1681
- return Object.keys(this.versionedScopes).length > 0
1682
- }
1683
-
1684
- /**
1685
- * Get the versioned scope that contains a given route
1686
- * Returns the scope route if the route is within a versioned section
1687
- *
1688
- * @param {string} route - Route to check (e.g., '/docs/getting-started')
1689
- * @returns {string|null} The scope route (e.g., '/docs') or null
1690
- *
1691
- * @example
1692
- * website.getVersionScope('/docs/getting-started') // '/docs'
1693
- * website.getVersionScope('/about') // null
1694
- */
1695
- getVersionScope(route) {
1696
- const normalizedRoute = route || ''
1697
-
1698
- // Check each versioned scope to see if route falls within it
1699
- for (const scope of Object.keys(this.versionedScopes)) {
1700
- // Route matches scope exactly
1701
- if (normalizedRoute === scope) {
1702
- return scope
1703
- }
1704
-
1705
- // Root scope matches all routes starting with /
1706
- if (scope === '/') {
1707
- if (normalizedRoute.startsWith('/') || normalizedRoute === '') {
1708
- return scope
1709
- }
1710
- } else if (normalizedRoute.startsWith(scope + '/')) {
1711
- // Route is a child of this scope
1712
- return scope
1713
- }
1714
- }
1715
-
1716
- return null
1717
- }
1718
-
1719
- /**
1720
- * Check if a route is within a versioned section
1721
- *
1722
- * @param {string} route - Route to check
1723
- * @returns {boolean}
1724
- */
1725
- isVersionedRoute(route) {
1726
- return this.getVersionScope(route) !== null
1727
- }
1728
-
1729
- /**
1730
- * Get version metadata for a scope
1731
- *
1732
- * @param {string} scope - The scope route (e.g., '/docs')
1733
- * @returns {Object|null} Version metadata { versions, latestId } or null
1734
- *
1735
- * @example
1736
- * website.getVersionMeta('/docs')
1737
- * // { versions: [{ id: 'v2', label: 'v2', latest: true }, ...], latestId: 'v2' }
1738
- */
1739
- getVersionMeta(scope) {
1740
- return this.versionedScopes[scope] || null
1741
- }
1742
-
1743
- /**
1744
- * Get the current version for a page
1745
- * Returns the version object from the page's version metadata
1746
- *
1747
- * @param {Page} page - The page to check
1748
- * @returns {Object|null} Version object { id, label, latest, deprecated } or null
1749
- */
1750
- getPageVersion(page) {
1751
- return page?.version || null
1752
- }
1753
-
1754
- /**
1755
- * Get available versions for a route's scope
1756
- *
1757
- * @param {string} route - Route within a versioned scope
1758
- * @returns {Array} Array of version objects, or empty array
1759
- *
1760
- * @example
1761
- * website.getVersionsForRoute('/docs/getting-started')
1762
- * // [{ id: 'v2', label: 'v2', latest: true }, { id: 'v1', label: 'v1' }]
1763
- */
1764
- getVersionsForRoute(route) {
1765
- const scope = this.getVersionScope(route)
1766
- if (!scope) return []
1767
-
1768
- const meta = this.versionedScopes[scope]
1769
- return meta?.versions || []
1770
- }
1771
-
1772
- /**
1773
- * Compute URL for switching to a different version
1774
- * Takes the current route and computes what the URL would be for another version
1775
- *
1776
- * @param {string} targetVersion - Target version ID (e.g., 'v1')
1777
- * @param {string} currentRoute - Current route (e.g., '/docs/getting-started')
1778
- * @returns {string|null} Target URL or null if not versioned
1779
- *
1780
- * @example
1781
- * // Current: /docs/getting-started (latest v2)
1782
- * website.getVersionUrl('v1', '/docs/getting-started')
1783
- * // → '/docs/v1/getting-started'
1784
- *
1785
- * // Current: /docs/v1/getting-started (older v1)
1786
- * website.getVersionUrl('v2', '/docs/v1/getting-started')
1787
- * // → '/docs/getting-started' (latest has no prefix)
1788
- */
1789
- getVersionUrl(targetVersion, currentRoute) {
1790
- const scope = this.getVersionScope(currentRoute)
1791
- if (!scope) return null
1792
-
1793
- const meta = this.versionedScopes[scope]
1794
- if (!meta) return null
1795
-
1796
- // Find target version info
1797
- const targetVersionInfo = meta.versions.find(v => v.id === targetVersion)
1798
- if (!targetVersionInfo) return null
1799
-
1800
- // Extract the path within the scope (after scope and any version prefix)
1801
- // For root scope ('/'), keep the full path; otherwise slice off the scope
1802
- const afterScope = scope === '/'
1803
- ? currentRoute
1804
- : currentRoute.slice(scope.length) // e.g., '/getting-started' or '/v1/getting-started'
1805
-
1806
- // Check if current route has a version prefix
1807
- let pathWithinVersion = afterScope
1808
- for (const version of meta.versions) {
1809
- const versionPrefix = `/${version.id}`
1810
- if (afterScope.startsWith(versionPrefix + '/') || afterScope === versionPrefix) {
1811
- // Remove version prefix
1812
- pathWithinVersion = afterScope.slice(versionPrefix.length)
1813
- break
1814
- }
1815
- }
1816
-
1817
- // Build target URL
1818
- // Latest version has no prefix, others have /vN prefix
1819
- if (targetVersionInfo.latest) {
1820
- // For root scope, return path directly; otherwise prepend scope
1821
- return scope === '/' ? pathWithinVersion : scope + pathWithinVersion
1822
- } else {
1823
- // For root scope: /v1/path; otherwise: scope/v1/path
1824
- return scope === '/'
1825
- ? '/' + targetVersion + pathWithinVersion
1826
- : scope + '/' + targetVersion + pathWithinVersion
1827
- }
1828
- }
1829
-
1830
- /**
1831
- * Get the latest version ID for a scope
1832
- *
1833
- * @param {string} scope - The scope route
1834
- * @returns {string|null} Latest version ID or null
1835
- */
1836
- getLatestVersion(scope) {
1837
- const meta = this.versionedScopes[scope]
1838
- return meta?.latestId || null
1839
- }
1840
1655
  }