@uniweb/build 0.4.5 → 0.4.7
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 +3 -3
- package/src/i18n/merge.js +27 -0
- package/src/prerender.js +6 -0
- package/src/site/config.js +30 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"optionalDependencies": {
|
|
53
53
|
"@uniweb/content-reader": "1.1.2",
|
|
54
|
-
"@uniweb/runtime": "0.5.
|
|
54
|
+
"@uniweb/runtime": "0.5.9"
|
|
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.3.
|
|
63
|
+
"@uniweb/core": "0.3.9"
|
|
64
64
|
},
|
|
65
65
|
"peerDependenciesMeta": {
|
|
66
66
|
"vite": {
|
package/src/i18n/merge.js
CHANGED
|
@@ -76,6 +76,17 @@ function mergeTranslationsSync(siteContent, translations, fallbackToSource) {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
// Translate shared layout sections (header, footer, sidebars)
|
|
80
|
+
for (const layoutKey of ['header', 'footer', 'left', 'right']) {
|
|
81
|
+
const layoutPage = translated[layoutKey]
|
|
82
|
+
if (layoutPage?.sections) {
|
|
83
|
+
const pageRoute = layoutPage.route || `/@${layoutKey}`
|
|
84
|
+
for (const section of layoutPage.sections) {
|
|
85
|
+
translateSectionSync(section, pageRoute, translations, fallbackToSource)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
79
90
|
return translated
|
|
80
91
|
}
|
|
81
92
|
|
|
@@ -117,6 +128,22 @@ async function mergeTranslationsAsync(siteContent, translations, options) {
|
|
|
117
128
|
}
|
|
118
129
|
}
|
|
119
130
|
|
|
131
|
+
// Translate shared layout sections (header, footer, sidebars)
|
|
132
|
+
for (const layoutKey of ['header', 'footer', 'left', 'right']) {
|
|
133
|
+
const layoutPage = translated[layoutKey]
|
|
134
|
+
if (layoutPage?.sections) {
|
|
135
|
+
// Ensure route is set for context matching (extract uses /@header, etc.)
|
|
136
|
+
if (!layoutPage.route) layoutPage.route = `/@${layoutKey}`
|
|
137
|
+
for (const section of layoutPage.sections) {
|
|
138
|
+
await translateSectionAsync(section, layoutPage, translations, {
|
|
139
|
+
fallbackToSource,
|
|
140
|
+
locale,
|
|
141
|
+
localesDir
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
120
147
|
return translated
|
|
121
148
|
}
|
|
122
149
|
|
package/src/prerender.js
CHANGED
|
@@ -556,6 +556,12 @@ export async function prerenderSite(siteDir, options = {}) {
|
|
|
556
556
|
const uniweb = createUniweb(siteContent)
|
|
557
557
|
uniweb.setFoundation(foundation)
|
|
558
558
|
|
|
559
|
+
// Set base path from site config so components can access it during SSR
|
|
560
|
+
// (e.g., <Link reload> needs basePath to prefix hrefs for subdirectory deployments)
|
|
561
|
+
if (siteContent.config?.base && uniweb.activeWebsite?.setBasePath) {
|
|
562
|
+
uniweb.activeWebsite.setBasePath(siteContent.config.base)
|
|
563
|
+
}
|
|
564
|
+
|
|
559
565
|
// Set foundation capabilities (Layout, props, etc.)
|
|
560
566
|
if (foundation.capabilities) {
|
|
561
567
|
uniweb.setFoundationConfig(foundation.capabilities)
|
package/src/site/config.js
CHANGED
|
@@ -25,6 +25,34 @@ import { resolve, dirname, join } from 'node:path'
|
|
|
25
25
|
import yaml from 'js-yaml'
|
|
26
26
|
import { generateEntryPoint } from '../generate-entry.js'
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Normalize a base path for Vite compatibility
|
|
30
|
+
*
|
|
31
|
+
* Handles common user mistakes:
|
|
32
|
+
* - Missing leading slash: "docs/" → "/docs/"
|
|
33
|
+
* - Missing trailing slash: "/docs" → "/docs/"
|
|
34
|
+
* - Extra slashes: "//docs///" → "/docs/"
|
|
35
|
+
* - Just a slash: "/" → undefined (root, no base needed)
|
|
36
|
+
*
|
|
37
|
+
* @param {string} raw - Raw base path from site.yml, env, or option
|
|
38
|
+
* @returns {string|undefined} Normalized path with leading+trailing slash, or undefined for root
|
|
39
|
+
*/
|
|
40
|
+
function normalizeBasePath(raw) {
|
|
41
|
+
// Collapse repeated slashes and trim whitespace
|
|
42
|
+
let path = raw.trim().replace(/\/{2,}/g, '/')
|
|
43
|
+
|
|
44
|
+
// Ensure leading slash
|
|
45
|
+
if (!path.startsWith('/')) path = '/' + path
|
|
46
|
+
|
|
47
|
+
// Ensure trailing slash (Vite requirement)
|
|
48
|
+
if (!path.endsWith('/')) path = path + '/'
|
|
49
|
+
|
|
50
|
+
// Root path means no base needed
|
|
51
|
+
if (path === '/') return undefined
|
|
52
|
+
|
|
53
|
+
return path
|
|
54
|
+
}
|
|
55
|
+
|
|
28
56
|
/**
|
|
29
57
|
* Detect foundation type from the foundation config value
|
|
30
58
|
*
|
|
@@ -143,9 +171,9 @@ export async function defineSiteConfig(options = {}) {
|
|
|
143
171
|
const siteConfig = readSiteConfig(siteRoot)
|
|
144
172
|
|
|
145
173
|
// Determine base path for deployment (priority: option > env > site.yml)
|
|
146
|
-
//
|
|
174
|
+
// Normalize: ensure leading slash, collapse repeated slashes, add trailing slash for Vite
|
|
147
175
|
const rawBase = baseOption || process.env.UNIWEB_BASE || siteConfig.base
|
|
148
|
-
const base = rawBase ? (
|
|
176
|
+
const base = rawBase ? normalizeBasePath(String(rawBase)) : undefined
|
|
149
177
|
|
|
150
178
|
// Detect foundation type
|
|
151
179
|
const foundationInfo = detectFoundationType(siteConfig.foundation, siteRoot)
|