@uniweb/core 0.1.8 → 0.1.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": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
package/src/page.js CHANGED
@@ -11,6 +11,7 @@ export default class Page {
11
11
  constructor(pageData, id, website, pageHeader, pageFooter, pageLeft, pageRight) {
12
12
  this.id = id
13
13
  this.route = pageData.route
14
+ this.isIndex = pageData.isIndex || false // True if this page is the index for its parent route
14
15
  this.title = pageData.title || ''
15
16
  this.description = pageData.description || ''
16
17
  this.label = pageData.label || null // Short label for navigation (null = use title)
@@ -293,6 +294,26 @@ export default class Page {
293
294
  // Navigation and Layout Helpers
294
295
  // ─────────────────────────────────────────────────────────────────
295
296
 
297
+ /**
298
+ * Get the navigation route (canonical route for links)
299
+ * For index pages, returns the parent route (e.g., '/' for homepage)
300
+ * For regular pages, returns the actual route
301
+ * @returns {string}
302
+ */
303
+ getNavRoute() {
304
+ if (!this.isIndex) {
305
+ return this.route
306
+ }
307
+ // Index page - compute parent route
308
+ // /home -> /
309
+ // /docs/getting-started -> /docs
310
+ const segments = this.route.split('/').filter(Boolean)
311
+ if (segments.length <= 1) {
312
+ return '/'
313
+ }
314
+ return '/' + segments.slice(0, -1).join('/')
315
+ }
316
+
296
317
  /**
297
318
  * Get display label for navigation (short form of title)
298
319
  * @returns {string}
package/src/website.js CHANGED
@@ -52,8 +52,9 @@ export default class Website {
52
52
  // Build parent-child relationships based on route structure
53
53
  this.buildPageHierarchy()
54
54
 
55
+ // Find the homepage (root-level index page)
55
56
  this.activePage =
56
- this.pages.find((page) => page.route === '/' || page.route === '/index') ||
57
+ this.pages.find((page) => page.isIndex && page.getNavRoute() === '/') ||
57
58
  this.pages[0]
58
59
 
59
60
  this.pageRoutes = this.pages.map((page) => page.route)
@@ -115,22 +116,28 @@ export default class Website {
115
116
  })
116
117
 
117
118
  // Build a map of route to page for quick lookup
119
+ // Include both actual routes and nav routes (for index pages)
118
120
  const pageMap = new Map()
119
121
  for (const page of sortedPages) {
120
122
  pageMap.set(page.route, page)
123
+ // Also map the nav route for index pages so parent lookup works
124
+ if (page.isIndex) {
125
+ const navRoute = page.getNavRoute()
126
+ if (navRoute !== page.route) {
127
+ pageMap.set(navRoute, page)
128
+ }
129
+ }
121
130
  }
122
131
 
123
132
  // For each page, find its parent and add it as a child
124
133
  for (const page of sortedPages) {
125
134
  const route = page.route
126
- if (route === '/' || route === '') continue
127
-
128
- // Find parent route by removing the last segment
129
- // /getting-started/installation -> /getting-started
135
+ // Skip root-level pages (single segment like /home, /about)
130
136
  const segments = route.split('/').filter(Boolean)
131
- if (segments.length <= 1) continue // Root-level pages have no parent
137
+ if (segments.length <= 1) continue
132
138
 
133
- // Build parent route
139
+ // Build parent route by removing the last segment
140
+ // /docs/getting-started -> /docs
134
141
  const parentRoute = '/' + segments.slice(0, -1).join('/')
135
142
  const parent = pageMap.get(parentRoute)
136
143
 
@@ -150,11 +157,17 @@ export default class Website {
150
157
 
151
158
  /**
152
159
  * Get page by route
160
+ * Matches both actual routes and nav routes (for index pages)
153
161
  * @param {string} route
154
162
  * @returns {Page|undefined}
155
163
  */
156
164
  getPage(route) {
157
- return this.pages.find((page) => page.route === route)
165
+ // First try exact match on actual route
166
+ const exactMatch = this.pages.find((page) => page.route === route)
167
+ if (exactMatch) return exactMatch
168
+
169
+ // Then try matching nav route (for index pages accessible at parent route)
170
+ return this.pages.find((page) => page.isIndex && page.getNavRoute() === route)
158
171
  }
159
172
 
160
173
  /**
@@ -475,7 +488,7 @@ export default class Website {
475
488
  // Build page info objects
476
489
  const buildPageInfo = (page) => ({
477
490
  id: page.id,
478
- route: page.route === '/' ? '' : page.route,
491
+ route: page.getNavRoute(), // Use canonical nav route (e.g., '/' for index pages)
479
492
  title: page.title,
480
493
  label: page.getLabel(),
481
494
  description: page.description,