@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/core",
3
- "version": "0.2.1",
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.13"
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
@@ -233,7 +233,8 @@ export default class Block {
233
233
  videos: c.videos || [],
234
234
  lists: c.lists || [],
235
235
  buttons: c.buttons || [],
236
- items: c.items || []
236
+ items: c.items || [],
237
+ data: c.data || {}
237
238
  }
238
239
  }
239
240
 
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
- * For index pages, returns the parent route (e.g., '/' for homepage)
349
- * For regular pages, returns the actual route
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
- if (!this.isIndex) {
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
- * Delegates to Website.isRouteActiveOrAncestor() for consistent logic.
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/getting-started/installation'
505
- * page.isActiveOrAncestor('docs/getting-started/installation') // true
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
- return this.website.isRouteActiveOrAncestor(this.route, currentRoute)
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
  // ─────────────────────────────────────────────────────────────────