@uniweb/core 0.2.2 → 0.2.4

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 +15 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/core",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
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
@@ -201,18 +201,22 @@ export default class Website {
201
201
  * @returns {Page|undefined}
202
202
  */
203
203
  getPage(route) {
204
+ // Normalize trailing slashes for consistent matching
205
+ // '/about/' and '/about' should match the same page
206
+ const normalizedRoute = route === '/' ? '/' : route.replace(/\/$/, '')
207
+
204
208
  // Priority 1: Exact match on actual route
205
- const exactMatch = this.pages.find((page) => page.route === route)
209
+ const exactMatch = this.pages.find((page) => page.route === normalizedRoute)
206
210
  if (exactMatch) return exactMatch
207
211
 
208
212
  // Priority 2: Index page nav route match
209
- const indexMatch = this.pages.find((page) => page.isIndex && page.getNavRoute() === route)
213
+ const indexMatch = this.pages.find((page) => page.isIndex && page.getNavRoute() === normalizedRoute)
210
214
  if (indexMatch) return indexMatch
211
215
 
212
216
  // Priority 3: Dynamic route pattern matching
213
217
  // Check cache first
214
- if (this._dynamicPageCache.has(route)) {
215
- return this._dynamicPageCache.get(route)
218
+ if (this._dynamicPageCache.has(normalizedRoute)) {
219
+ return this._dynamicPageCache.get(normalizedRoute)
216
220
  }
217
221
 
218
222
  // Try to match against dynamic route patterns
@@ -220,13 +224,13 @@ export default class Website {
220
224
  // Check if this is a dynamic page (has :param in route)
221
225
  if (!page.route.includes(':')) continue
222
226
 
223
- const match = this._matchDynamicRoute(page.route, route)
227
+ const match = this._matchDynamicRoute(page.route, normalizedRoute)
224
228
  if (match) {
225
229
  // Create a dynamic page instance with the concrete route and params
226
- const dynamicPage = this._createDynamicPage(page, route, match.params)
230
+ const dynamicPage = this._createDynamicPage(page, normalizedRoute, match.params)
227
231
  if (dynamicPage) {
228
232
  // Cache for future requests
229
- this._dynamicPageCache.set(route, dynamicPage)
233
+ this._dynamicPageCache.set(normalizedRoute, dynamicPage)
230
234
  return dynamicPage
231
235
  }
232
236
  }
@@ -756,6 +760,10 @@ export default class Website {
756
760
  // Always exclude special pages (header/footer are already separated)
757
761
  if (page.route.startsWith('/@')) return false
758
762
 
763
+ // Always exclude dynamic route template pages (e.g., /blog/:slug)
764
+ // These are templates for generating pages, not actual navigable pages
765
+ if (page.route.includes(':')) return false
766
+
759
767
  // Check visibility based on navigation type
760
768
  if (!includeHidden) {
761
769
  if (page.hidden) return false