@uniweb/core 0.2.1 → 0.2.2
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 +2 -2
- package/src/block.js +2 -1
- package/src/page.js +18 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"jest": "^29.7.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@uniweb/semantic-parser": "1.0.
|
|
33
|
+
"@uniweb/semantic-parser": "1.0.14"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
|
package/src/block.js
CHANGED
package/src/page.js
CHANGED
|
@@ -20,6 +20,7 @@ export default class Page {
|
|
|
20
20
|
this.id = id
|
|
21
21
|
this.stableId = pageData.id || null // Stable page ID for page: links (from page.yml)
|
|
22
22
|
this.route = pageData.route
|
|
23
|
+
this.sourcePath = pageData.sourcePath || null // Original folder-based path (for ancestor checking)
|
|
23
24
|
this.isIndex = pageData.isIndex || false // True if this page is the index for its parent route
|
|
24
25
|
this.title = pageData.title || ''
|
|
25
26
|
this.description = pageData.description || ''
|
|
@@ -345,22 +346,12 @@ export default class Page {
|
|
|
345
346
|
|
|
346
347
|
/**
|
|
347
348
|
* Get the navigation route (canonical route for links)
|
|
348
|
-
*
|
|
349
|
-
*
|
|
349
|
+
* With the new routing model, route is already the canonical nav route.
|
|
350
|
+
* Index pages have route set to parent route (e.g., '/' for homepage).
|
|
350
351
|
* @returns {string}
|
|
351
352
|
*/
|
|
352
353
|
getNavRoute() {
|
|
353
|
-
|
|
354
|
-
return this.route
|
|
355
|
-
}
|
|
356
|
-
// Index page - compute parent route
|
|
357
|
-
// /home -> /
|
|
358
|
-
// /docs/getting-started -> /docs
|
|
359
|
-
const segments = this.route.split('/').filter(Boolean)
|
|
360
|
-
if (segments.length <= 1) {
|
|
361
|
-
return '/'
|
|
362
|
-
}
|
|
363
|
-
return '/' + segments.slice(0, -1).join('/')
|
|
354
|
+
return this.route
|
|
364
355
|
}
|
|
365
356
|
|
|
366
357
|
/**
|
|
@@ -494,18 +485,27 @@ export default class Page {
|
|
|
494
485
|
/**
|
|
495
486
|
* Check if this page or any descendant matches the given route.
|
|
496
487
|
* Useful for highlighting parent nav items when a child page is active.
|
|
497
|
-
*
|
|
488
|
+
*
|
|
489
|
+
* For index pages, uses sourcePath (original folder path) for ancestor checking
|
|
490
|
+
* to avoid false positives. E.g., homepage at '/' shouldn't be ancestor of '/about'.
|
|
498
491
|
*
|
|
499
492
|
* @param {string} currentRoute - Current route to compare against
|
|
500
493
|
* @returns {boolean} True if this page or a descendant is active
|
|
501
494
|
*
|
|
502
495
|
* @example
|
|
503
|
-
* // Page route: '/docs'
|
|
504
|
-
* // Current route: 'docs/
|
|
505
|
-
* page.isActiveOrAncestor('docs/
|
|
496
|
+
* // Page route: '/docs' (index page with sourcePath: '/docs/intro')
|
|
497
|
+
* // Current route: '/docs/api'
|
|
498
|
+
* page.isActiveOrAncestor('/docs/api') // false (not under /docs/intro)
|
|
506
499
|
*/
|
|
507
500
|
isActiveOrAncestor(currentRoute) {
|
|
508
|
-
|
|
501
|
+
// Exact match on canonical route
|
|
502
|
+
if (this.website.isRouteActive(this.route, currentRoute)) {
|
|
503
|
+
return true
|
|
504
|
+
}
|
|
505
|
+
// Ancestor check uses sourcePath (folder-based path) to avoid false positives
|
|
506
|
+
// For index pages, sourcePath differs from route
|
|
507
|
+
const pathForAncestorCheck = this.sourcePath || this.route
|
|
508
|
+
return this.website.isRouteActiveOrAncestor(pathForAncestorCheck, currentRoute)
|
|
509
509
|
}
|
|
510
510
|
|
|
511
511
|
// ─────────────────────────────────────────────────────────────────
|