@uniweb/build 0.2.0 → 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/build",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -50,8 +50,8 @@
50
50
  "sharp": "^0.33.2"
51
51
  },
52
52
  "optionalDependencies": {
53
- "@uniweb/content-reader": "1.0.4",
54
- "@uniweb/runtime": "0.2.20"
53
+ "@uniweb/content-reader": "1.0.5",
54
+ "@uniweb/runtime": "0.3.0"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
@@ -60,7 +60,7 @@
60
60
  "@tailwindcss/vite": "^4.0.0",
61
61
  "@vitejs/plugin-react": "^4.0.0 || ^5.0.0",
62
62
  "vite-plugin-svgr": "^4.0.0",
63
- "@uniweb/core": "0.2.0"
63
+ "@uniweb/core": "0.2.2"
64
64
  },
65
65
  "peerDependenciesMeta": {
66
66
  "vite": {
package/src/prerender.js CHANGED
@@ -458,18 +458,9 @@ export async function prerenderSite(siteDir, options = {}) {
458
458
  const website = uniweb.activeWebsite
459
459
 
460
460
  for (const page of pages) {
461
- // Determine which routes to render this page at
462
- // Index pages are rendered at both their actual route and their nav route
463
- const routesToRender = [page.route]
464
- if (page.isIndex) {
465
- const navRoute = page.getNavRoute()
466
- if (navRoute !== page.route) {
467
- routesToRender.push(navRoute)
468
- }
469
- }
470
-
471
- // Render once, output to multiple paths
472
- onProgress(`Rendering ${routesToRender[0]}...`)
461
+ // Each page has a single canonical route
462
+ // Index pages already have their parent route as their canonical route
463
+ onProgress(`Rendering ${page.route}...`)
473
464
 
474
465
  // Set this as the active page
475
466
  uniweb.activeWebsite.setActivePage(page.route)
@@ -493,15 +484,13 @@ export async function prerenderSite(siteDir, options = {}) {
493
484
  // Inject into shell
494
485
  const html = injectContent(htmlShell, renderedContent, page, siteContent)
495
486
 
496
- // Output to all routes for this page
497
- for (const route of routesToRender) {
498
- const outputPath = getOutputPath(distDir, route)
499
- await mkdir(dirname(outputPath), { recursive: true })
500
- await writeFile(outputPath, html)
487
+ // Output to the canonical route
488
+ const outputPath = getOutputPath(distDir, page.route)
489
+ await mkdir(dirname(outputPath), { recursive: true })
490
+ await writeFile(outputPath, html)
501
491
 
502
- renderedFiles.push(outputPath)
503
- onProgress(` → ${outputPath.replace(distDir, 'dist')}`)
504
- }
492
+ renderedFiles.push(outputPath)
493
+ onProgress(` → ${outputPath.replace(distDir, 'dist')}`)
505
494
  }
506
495
 
507
496
  onProgress(`Pre-rendered ${renderedFiles.length} pages`)
@@ -479,24 +479,31 @@ async function processPage(pagePath, pageName, siteRoot, { isIndex = false, pare
479
479
  }
480
480
 
481
481
  // Determine route
482
- // All pages get their actual folder-based route (no special treatment for index)
483
- // The isIndex flag marks which page should also be accessible at the parent route
484
- let route
482
+ // Index pages get the parent route as their canonical route (no dual routes)
483
+ // sourcePath stores the original folder-based path for ancestor checking
485
484
  const isDynamic = isDynamicRoute(pageName)
486
485
  const paramName = isDynamic ? extractRouteParam(pageName) : null
487
486
 
487
+ // First, calculate the folder-based route (what the route would be without index handling)
488
+ let folderRoute
488
489
  if (pageName.startsWith('@')) {
489
490
  // Special pages (layout areas) keep their @ prefix
490
- route = parentRoute === '/' ? `/@${pageName.slice(1)}` : `${parentRoute}/@${pageName.slice(1)}`
491
+ folderRoute = parentRoute === '/' ? `/@${pageName.slice(1)}` : `${parentRoute}/@${pageName.slice(1)}`
491
492
  } else if (isDynamic) {
492
493
  // Dynamic routes: /blog/[slug] → /blog/:slug (for route matching)
493
- // The actual routes like /blog/my-post are generated at prerender time
494
- route = parentRoute === '/' ? `/:${paramName}` : `${parentRoute}/:${paramName}`
494
+ folderRoute = parentRoute === '/' ? `/:${paramName}` : `${parentRoute}/:${paramName}`
495
495
  } else {
496
496
  // Normal pages get parent + their name
497
- route = parentRoute === '/' ? `/${pageName}` : `${parentRoute}/${pageName}`
497
+ folderRoute = parentRoute === '/' ? `/${pageName}` : `${parentRoute}/${pageName}`
498
498
  }
499
499
 
500
+ // For index pages, the canonical route is the parent route
501
+ // For non-index pages, the canonical route is the folder-based route
502
+ const route = isIndex ? parentRoute : folderRoute
503
+ // sourcePath is the original folder-based path (used for ancestor checking)
504
+ // Only set for index pages where it differs from route
505
+ const sourcePath = isIndex ? folderRoute : null
506
+
500
507
  // Extract configuration
501
508
  const { seo = {}, layout = {}, ...restConfig } = pageConfig
502
509
 
@@ -510,8 +517,9 @@ async function processPage(pagePath, pageName, siteRoot, { isIndex = false, pare
510
517
  return {
511
518
  page: {
512
519
  route,
520
+ sourcePath, // Original folder-based path (for ancestor checking in navigation)
513
521
  id: pageConfig.id || null, // Stable page ID for page: links (survives reorganization)
514
- isIndex, // Marks this page as the index for its parent route (accessible at parentRoute)
522
+ isIndex, // Marks this page as the index for its parent route
515
523
  title: pageConfig.title || pageName,
516
524
  description: pageConfig.description || '',
517
525
  label: pageConfig.label || null, // Short label for navigation (defaults to title)
@@ -668,7 +676,12 @@ async function collectPagesRecursive(dirPath, parentRoute, siteRoot, orderConfig
668
676
 
669
677
  // For latest version, use parent route directly
670
678
  // For other versions, add version prefix to route
671
- const versionRoute = isLatest ? parentRoute : `${parentRoute}/${entry}`
679
+ // Handle root scope specially to avoid double slash (//v1 → /v1)
680
+ const versionRoute = isLatest
681
+ ? parentRoute
682
+ : parentRoute === '/'
683
+ ? `/${entry}`
684
+ : `${parentRoute}/${entry}`
672
685
 
673
686
  // Recurse into version folder with version context
674
687
  const subResult = await collectPagesRecursive(