@uniweb/build 1.21.0 → 1.22.0
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 +9 -9
- package/src/i18n/audit.js +27 -6
- package/src/i18n/extract.js +27 -5
- package/src/i18n/merge.js +28 -16
- package/src/schema.js +67 -24
- package/src/site/config.js +3 -0
- package/src/site/queries-config.js +3 -1
- package/src/uwx/locale-sync.js +35 -12
- package/src/uwx/site-project.js +6 -4
- package/src/uwx/site.js +11 -10
- package/src/validate-data.js +3 -1
- package/src/vite-foundation-plugin.js +9 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -57,15 +57,15 @@
|
|
|
57
57
|
"js-yaml": "^4.3.2",
|
|
58
58
|
"sharp": "^0.35.5",
|
|
59
59
|
"yaml": "^2.5.0",
|
|
60
|
-
"@uniweb/content-reader": "~1.5.
|
|
61
|
-
"@uniweb/content-writer": "~1.3.
|
|
62
|
-
"@uniweb/
|
|
60
|
+
"@uniweb/content-reader": "~1.5.10",
|
|
61
|
+
"@uniweb/content-writer": "~1.3.2",
|
|
62
|
+
"@uniweb/projections": "~1.2.17",
|
|
63
63
|
"@uniweb/schemas": "~1.7.1",
|
|
64
|
-
"@uniweb/
|
|
65
|
-
"@uniweb/
|
|
64
|
+
"@uniweb/semantic-parser": "~1.13.4",
|
|
65
|
+
"@uniweb/theming": "~1.3.2"
|
|
66
66
|
},
|
|
67
67
|
"optionalDependencies": {
|
|
68
|
-
"@uniweb/runtime": "~1.6.
|
|
68
|
+
"@uniweb/runtime": "~1.6.1"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
"@tailwindcss/vite": "^4.0.0",
|
|
75
75
|
"@vitejs/plugin-react": "^4.0.0 || ^5.0.0",
|
|
76
76
|
"vite-plugin-svgr": "^4.0.0",
|
|
77
|
-
"@uniweb/
|
|
78
|
-
"@uniweb/
|
|
77
|
+
"@uniweb/runtime": "~1.6.1",
|
|
78
|
+
"@uniweb/core": "~1.6.12"
|
|
79
79
|
},
|
|
80
80
|
"peerDependenciesMeta": {
|
|
81
81
|
"vite": {
|
package/src/i18n/audit.js
CHANGED
|
@@ -13,14 +13,17 @@ import { join } from 'node:path'
|
|
|
13
13
|
import { translationKeepsMarkup } from './merge.js'
|
|
14
14
|
import { KEPT_FILE } from './locales.js'
|
|
15
15
|
import { standingFlags } from '../uwx/locale-sync.js'
|
|
16
|
+
import { isInExcludedBranch } from '@uniweb/projections'
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Audit a locale file against the manifest
|
|
19
20
|
* @param {string} localesPath - Path to locales directory
|
|
20
21
|
* @param {string} locale - Locale code (e.g., 'es')
|
|
21
|
-
* @
|
|
22
|
+
* @param {Object} [options]
|
|
23
|
+
* @param {string[]} [options.exclude] - the site's `i18n.exclude`
|
|
24
|
+
* @returns {Promise<Object>} Audit result { locale, exists, total, valid, missing, stale, excluded }
|
|
22
25
|
*/
|
|
23
|
-
export async function auditLocale(localesPath, locale) {
|
|
26
|
+
export async function auditLocale(localesPath, locale, { exclude = null } = {}) {
|
|
24
27
|
const manifestPath = join(localesPath, 'manifest.json')
|
|
25
28
|
const localePath = join(localesPath, `${locale}.json`)
|
|
26
29
|
|
|
@@ -51,6 +54,7 @@ export async function auditLocale(localesPath, locale) {
|
|
|
51
54
|
const valid = []
|
|
52
55
|
const missing = []
|
|
53
56
|
const stale = []
|
|
57
|
+
const excluded = []
|
|
54
58
|
const losesMarkup = []
|
|
55
59
|
const outdated = []
|
|
56
60
|
|
|
@@ -95,10 +99,13 @@ export async function auditLocale(localesPath, locale) {
|
|
|
95
99
|
// Check for stale entries (in translations but not in manifest)
|
|
96
100
|
for (const hash of translationHashes) {
|
|
97
101
|
if (!manifestHashes.has(hash)) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
const entry = { hash, translation: getTranslationText(translations[hash]) }
|
|
103
|
+
// ⭐ One written for a place on a page the site doesn't translate (`i18n.exclude`) applies there
|
|
104
|
+
// (`extract.js::translationContext`), and the manifest, which takes no string from such a page,
|
|
105
|
+
// can't judge it: it is listed apart, and `--clean` keeps it. ⛔ Until 2026-11-11 it was stale, and
|
|
106
|
+
// `--clean` deleted what a pull had brought back of an author's translation on such a page.
|
|
107
|
+
if (namesExcludedPlace(translations[hash], exclude)) excluded.push(entry)
|
|
108
|
+
else stale.push(entry)
|
|
102
109
|
}
|
|
103
110
|
}
|
|
104
111
|
|
|
@@ -109,11 +116,22 @@ export async function auditLocale(localesPath, locale) {
|
|
|
109
116
|
valid,
|
|
110
117
|
missing,
|
|
111
118
|
stale,
|
|
119
|
+
excluded,
|
|
112
120
|
losesMarkup,
|
|
113
121
|
outdated
|
|
114
122
|
}
|
|
115
123
|
}
|
|
116
124
|
|
|
125
|
+
// Whether an entry's overrides name a place in a branch `exclude` names: `<route>:<section>`, whose
|
|
126
|
+
// route may hold a `:` of its own (`/blog/:slug:intro`).
|
|
127
|
+
function namesExcludedPlace(entry, exclude) {
|
|
128
|
+
if (!exclude || !entry || typeof entry !== 'object') return false
|
|
129
|
+
return Object.keys(entry.overrides || {}).some((place) => {
|
|
130
|
+
const at = place.lastIndexOf(':')
|
|
131
|
+
return at > 0 && isInExcludedBranch(place.slice(0, at), exclude)
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
117
135
|
/**
|
|
118
136
|
* Does the merge drop the inline markup this translation's source element carries?
|
|
119
137
|
*
|
|
@@ -199,6 +217,9 @@ export function formatAuditReport(results, options = {}) {
|
|
|
199
217
|
lines.push(` Valid: ${result.valid.length} (${coverage}%)`)
|
|
200
218
|
lines.push(` Missing: ${result.missing.length}`)
|
|
201
219
|
lines.push(` Stale: ${result.stale.length}`)
|
|
220
|
+
if (result.excluded?.length > 0) {
|
|
221
|
+
lines.push(` For pages i18n.exclude names: ${result.excluded.length} (each for one place there; --clean keeps them)`)
|
|
222
|
+
}
|
|
202
223
|
if (result.losesMarkup?.length > 0) {
|
|
203
224
|
lines.push(` Loses markup: ${result.losesMarkup.length} (links/bold in the source, plain in the translation)`)
|
|
204
225
|
}
|
package/src/i18n/extract.js
CHANGED
|
@@ -26,8 +26,8 @@ export function extractTranslatableContent(siteContent, { dataModel = null } = {
|
|
|
26
26
|
// ⭐ `i18n.exclude` — branches the site doesn't translate, such as a mounted repo's docs it shows in
|
|
27
27
|
// their own language: their pages give no strings, so `init`, `status` and the rest, which read the
|
|
28
28
|
// manifest, leave them alone. Routes as `agents.exclude` takes them (`isInExcludedBranch`). Their
|
|
29
|
-
// pages show the source in every language
|
|
30
|
-
//
|
|
29
|
+
// pages show the source in every language: only a translation written for one of their places
|
|
30
|
+
// applies there (`translationContext`).
|
|
31
31
|
const exclude = siteContent.config?.i18n?.exclude
|
|
32
32
|
|
|
33
33
|
// The site's own Open Graph title and description (`site.yml` `seo:`), in the site's context.
|
|
@@ -156,12 +156,34 @@ function extractFromPageMeta(page, pageRoute, units) {
|
|
|
156
156
|
* `1-hero.md`) — so an override moved to another section when files were renumbered, and a clone,
|
|
157
157
|
* whose files are not numbered, could not key it at all.
|
|
158
158
|
*
|
|
159
|
+
* ⭐ A PAGE IN A BRANCH THE SITE DOESN'T TRANSLATE (`i18n.exclude`, given as `exclude`) TAKES ONLY A
|
|
160
|
+
* TRANSLATION WRITTEN FOR ITS PLACE, and its context says so (`placeOnly`): an override naming the
|
|
161
|
+
* place, which is how a pull writes what an author translated there in the app, or a free-form file
|
|
162
|
+
* for it. A translation of the text wherever it appears, a plain entry or an entry's `default`, is
|
|
163
|
+
* not one. The build (`merge.js::lookupTranslation`), the push (`locale-sync.js::translationFor`) and
|
|
164
|
+
* the pull (`reconcileTranslation`) read it. ⛔ Until 2026-11-11 such a page took the site's
|
|
165
|
+
* translation of any string it shared with the site's own pages, so a mounted repo's docs, shown in
|
|
166
|
+
* English, read a sentence in Spanish where the site's home page had the same one.
|
|
167
|
+
*
|
|
159
168
|
* @param {Object} section - a section with `stableId` (and the build `id` as a fallback)
|
|
160
169
|
* @param {string} pageRoute - the route of the page (or layout area) it is on
|
|
161
|
-
* @
|
|
170
|
+
* @param {string[]} [exclude] - the site's `i18n.exclude`; none for a layout area, which is the site's own
|
|
171
|
+
* @returns {{ page: string, section: string, placeOnly?: true }}
|
|
172
|
+
*/
|
|
173
|
+
export function translationContext(section, pageRoute, exclude = null) {
|
|
174
|
+
const context = { page: pageRoute, section: section?.stableId || section?.id || 'unknown' }
|
|
175
|
+
return isInExcludedBranch(pageRoute, exclude) ? { ...context, placeOnly: true } : context
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Where a page's own words are translated — its title, label, description and keywords:
|
|
180
|
+
* `<route>:_meta`, the place an override for them names (`translationContext`).
|
|
181
|
+
*
|
|
182
|
+
* @param {string} pageRoute
|
|
183
|
+
* @param {string[]} [exclude] - the site's `i18n.exclude`
|
|
162
184
|
*/
|
|
163
|
-
export function
|
|
164
|
-
return {
|
|
185
|
+
export function pageMetaContext(pageRoute, exclude = null) {
|
|
186
|
+
return translationContext({ stableId: '_meta' }, pageRoute, exclude)
|
|
165
187
|
}
|
|
166
188
|
|
|
167
189
|
/**
|
package/src/i18n/merge.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
import { computeHash } from './hash.js'
|
|
16
16
|
import { loadFreeformTranslation } from './freeform.js'
|
|
17
|
-
import { elementText, blockElements, translationContext, SITE_META_CONTEXT, imageNodes, TRANSLATED_IMAGE_ATTRS } from './extract.js'
|
|
17
|
+
import { elementText, blockElements, translationContext, pageMetaContext, SITE_META_CONTEXT, imageNodes, TRANSLATED_IMAGE_ATTRS } from './extract.js'
|
|
18
18
|
import { visitDataBlockStrings } from './data-strings.js'
|
|
19
19
|
import { inlineMarkdownToProseMirror } from '@uniweb/content-reader'
|
|
20
20
|
|
|
@@ -63,25 +63,27 @@ function mergeTranslationsSync(siteContent, translations, fallbackToSource, data
|
|
|
63
63
|
// Deep clone to avoid mutating original
|
|
64
64
|
const translated = JSON.parse(JSON.stringify(siteContent))
|
|
65
65
|
translateSiteMeta(translated.config, translations, fallbackToSource)
|
|
66
|
+
// A page the site doesn't translate takes only a translation written for its place (`translationContext`).
|
|
67
|
+
const exclude = siteContent.config?.i18n?.exclude
|
|
66
68
|
|
|
67
69
|
for (const page of translated.pages || []) {
|
|
68
70
|
const pageRoute = page.route || '/'
|
|
69
71
|
|
|
70
72
|
// Translate page metadata
|
|
71
|
-
translatePageMeta(page, pageRoute, translations, fallbackToSource)
|
|
73
|
+
translatePageMeta(page, pageRoute, translations, fallbackToSource, exclude)
|
|
72
74
|
|
|
73
75
|
// Translate section content
|
|
74
76
|
for (const section of page.sections || []) {
|
|
75
|
-
translateSectionSync(section, pageRoute, translations, fallbackToSource, dataModel)
|
|
77
|
+
translateSectionSync(section, pageRoute, translations, fallbackToSource, dataModel, exclude)
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
// Translate 404 page (stored as top-level notFound)
|
|
80
82
|
if (translated.notFound) {
|
|
81
83
|
const pageRoute = translated.notFound.route || '/404'
|
|
82
|
-
translatePageMeta(translated.notFound, pageRoute, translations, fallbackToSource)
|
|
84
|
+
translatePageMeta(translated.notFound, pageRoute, translations, fallbackToSource, exclude)
|
|
83
85
|
for (const section of translated.notFound.sections || []) {
|
|
84
|
-
translateSectionSync(section, pageRoute, translations, fallbackToSource, dataModel)
|
|
86
|
+
translateSectionSync(section, pageRoute, translations, fallbackToSource, dataModel, exclude)
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
|
|
@@ -113,12 +115,14 @@ async function mergeTranslationsAsync(siteContent, translations, options) {
|
|
|
113
115
|
// Deep clone to avoid mutating original
|
|
114
116
|
const translated = JSON.parse(JSON.stringify(siteContent))
|
|
115
117
|
translateSiteMeta(translated.config, translations, fallbackToSource)
|
|
118
|
+
// A page the site doesn't translate takes only a translation written for its place (`translationContext`).
|
|
119
|
+
const exclude = siteContent.config?.i18n?.exclude
|
|
116
120
|
|
|
117
121
|
for (const page of translated.pages || []) {
|
|
118
122
|
const pageRoute = page.route || '/'
|
|
119
123
|
|
|
120
124
|
// Translate page metadata (always hash-based)
|
|
121
|
-
translatePageMeta(page, pageRoute, translations, fallbackToSource)
|
|
125
|
+
translatePageMeta(page, pageRoute, translations, fallbackToSource, exclude)
|
|
122
126
|
|
|
123
127
|
// Translate section content (with free-form check)
|
|
124
128
|
for (const section of page.sections || []) {
|
|
@@ -126,7 +130,8 @@ async function mergeTranslationsAsync(siteContent, translations, options) {
|
|
|
126
130
|
fallbackToSource,
|
|
127
131
|
locale,
|
|
128
132
|
localesDir,
|
|
129
|
-
dataModel
|
|
133
|
+
dataModel,
|
|
134
|
+
exclude
|
|
130
135
|
})
|
|
131
136
|
}
|
|
132
137
|
}
|
|
@@ -134,13 +139,14 @@ async function mergeTranslationsAsync(siteContent, translations, options) {
|
|
|
134
139
|
// Translate 404 page (stored as top-level notFound)
|
|
135
140
|
if (translated.notFound) {
|
|
136
141
|
const pageRoute = translated.notFound.route || '/404'
|
|
137
|
-
translatePageMeta(translated.notFound, pageRoute, translations, fallbackToSource)
|
|
142
|
+
translatePageMeta(translated.notFound, pageRoute, translations, fallbackToSource, exclude)
|
|
138
143
|
for (const section of translated.notFound.sections || []) {
|
|
139
144
|
await translateSectionAsync(section, translated.notFound, translations, {
|
|
140
145
|
fallbackToSource,
|
|
141
146
|
locale,
|
|
142
147
|
localesDir,
|
|
143
|
-
dataModel
|
|
148
|
+
dataModel,
|
|
149
|
+
exclude
|
|
144
150
|
})
|
|
145
151
|
}
|
|
146
152
|
}
|
|
@@ -242,8 +248,8 @@ function translateSiteMeta(config, translations, fallbackToSource) {
|
|
|
242
248
|
}
|
|
243
249
|
}
|
|
244
250
|
|
|
245
|
-
function translatePageMeta(page, pageRoute, translations, fallbackToSource) {
|
|
246
|
-
const context =
|
|
251
|
+
function translatePageMeta(page, pageRoute, translations, fallbackToSource, exclude = null) {
|
|
252
|
+
const context = pageMetaContext(pageRoute, exclude)
|
|
247
253
|
const translate = (value) =>
|
|
248
254
|
toPlainText(lookupTranslation(value, context, translations, fallbackToSource))
|
|
249
255
|
|
|
@@ -287,8 +293,8 @@ function translatePageMeta(page, pageRoute, translations, fallbackToSource) {
|
|
|
287
293
|
/**
|
|
288
294
|
* Translate a section's content (synchronous, hash-based only)
|
|
289
295
|
*/
|
|
290
|
-
function translateSectionSync(section, pageRoute, translations, fallbackToSource, dataModel = null) {
|
|
291
|
-
const context = translationContext(section, pageRoute)
|
|
296
|
+
function translateSectionSync(section, pageRoute, translations, fallbackToSource, dataModel = null, exclude = null) {
|
|
297
|
+
const context = translationContext(section, pageRoute, exclude)
|
|
292
298
|
|
|
293
299
|
if (section.content?.type === 'doc') {
|
|
294
300
|
translateProseMirrorDoc(section.content, context, translations, fallbackToSource)
|
|
@@ -298,7 +304,7 @@ function translateSectionSync(section, pageRoute, translations, fallbackToSource
|
|
|
298
304
|
|
|
299
305
|
// Recursively translate subsections
|
|
300
306
|
for (const subsection of section.subsections || []) {
|
|
301
|
-
translateSectionSync(subsection, pageRoute, translations, fallbackToSource, dataModel)
|
|
307
|
+
translateSectionSync(subsection, pageRoute, translations, fallbackToSource, dataModel, exclude)
|
|
302
308
|
}
|
|
303
309
|
}
|
|
304
310
|
|
|
@@ -310,9 +316,9 @@ function translateSectionSync(section, pageRoute, translations, fallbackToSource
|
|
|
310
316
|
* 2. Fall back to hash-based translation (element-by-element)
|
|
311
317
|
*/
|
|
312
318
|
async function translateSectionAsync(section, page, translations, options) {
|
|
313
|
-
const { fallbackToSource, locale, localesDir, dataModel } = options
|
|
319
|
+
const { fallbackToSource, locale, localesDir, dataModel, exclude = null } = options
|
|
314
320
|
const pageRoute = page.route || '/'
|
|
315
|
-
const context = translationContext(section, pageRoute)
|
|
321
|
+
const context = translationContext(section, pageRoute, exclude)
|
|
316
322
|
|
|
317
323
|
// Check for free-form translation first
|
|
318
324
|
const freeform = await loadFreeformTranslation(section, page, locale, localesDir)
|
|
@@ -752,6 +758,12 @@ function lookupTranslation(source, context, translations, fallbackToSource) {
|
|
|
752
758
|
return fallbackToSource ? source : source
|
|
753
759
|
}
|
|
754
760
|
|
|
761
|
+
// ⭐ On a page the site doesn't translate, only an override naming this place (`translationContext`).
|
|
762
|
+
if (context?.placeOnly) {
|
|
763
|
+
const own = typeof translation === 'object' ? translation.overrides?.[context.key ?? `${context.page}:${context.section}`] : undefined
|
|
764
|
+
return own || source
|
|
765
|
+
}
|
|
766
|
+
|
|
755
767
|
// Handle simple string translation
|
|
756
768
|
if (typeof translation === 'string') {
|
|
757
769
|
// Preserve leading/trailing whitespace from original
|
package/src/schema.js
CHANGED
|
@@ -89,6 +89,12 @@ async function loadMetaFile(filePath) {
|
|
|
89
89
|
/**
|
|
90
90
|
* Find and load meta file for a component directory
|
|
91
91
|
* Returns null if no meta file found
|
|
92
|
+
*
|
|
93
|
+
* ⭐ A `meta.js` that does not load STOPS THE BUILD, naming the file and the error [Diego,
|
|
94
|
+
* 2026-11-11: "It's okay for the foundation build to fail if it has problems in any `meta.js` or
|
|
95
|
+
* elsewhere."]. ⛔ Until then it warned and went on as if the file were not there: a type at the
|
|
96
|
+
* root of `sections/` lost everything its `meta.js` declares, its name, params, presets, labels and
|
|
97
|
+
* data keys (so it was given no records), and a nested one vanished, under a green build.
|
|
92
98
|
*/
|
|
93
99
|
export async function loadComponentMeta(componentDir) {
|
|
94
100
|
const filePath = join(componentDir, META_FILE_NAME)
|
|
@@ -99,8 +105,7 @@ export async function loadComponentMeta(componentDir) {
|
|
|
99
105
|
const meta = await loadMetaFile(filePath)
|
|
100
106
|
return { meta, fileName: META_FILE_NAME, filePath }
|
|
101
107
|
} catch (error) {
|
|
102
|
-
|
|
103
|
-
return null
|
|
108
|
+
throw new Error(`[uniweb] ${filePath} could not be loaded: ${error.message}`, { cause: error })
|
|
104
109
|
}
|
|
105
110
|
}
|
|
106
111
|
|
|
@@ -232,8 +237,9 @@ export async function loadPackageJson(srcDir) {
|
|
|
232
237
|
...normalizeSupports(pkg.uniweb?.supports, packagePath),
|
|
233
238
|
}
|
|
234
239
|
} catch (error) {
|
|
235
|
-
|
|
236
|
-
|
|
240
|
+
// A package.json that is there and cannot be read stops the build, as a `meta.js` does
|
|
241
|
+
// (`loadComponentMeta`): it holds the foundation's identity, and an empty one is a quiet lie.
|
|
242
|
+
throw new Error(`[uniweb] ${packagePath} could not be read: ${error.message}`, { cause: error })
|
|
237
243
|
}
|
|
238
244
|
}
|
|
239
245
|
|
|
@@ -1220,43 +1226,73 @@ function reportSupports(srcDir, authored, derived, emitted) {
|
|
|
1220
1226
|
}
|
|
1221
1227
|
|
|
1222
1228
|
/**
|
|
1223
|
-
*
|
|
1224
|
-
* write (`@uniweb/schemas/foundation`): an inline field map that is not a valid data schema.
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
1229
|
+
* Stop the build on a `data:` value `register` will refuse — one the normalized form it sends
|
|
1230
|
+
* cannot write (`@uniweb/schemas/foundation`): an inline field map that is not a valid data schema.
|
|
1231
|
+
* Every such value is named at once. ⛔ Until 2026-11-11 the build warned and went on, since the
|
|
1232
|
+
* site renders the map as before, and `register` was where it stopped; a foundation build now fails
|
|
1233
|
+
* on a problem in its declarations [Diego, 2026-11-11], as it already did for the other `data:`
|
|
1234
|
+
* declarations it cannot read.
|
|
1227
1235
|
*
|
|
1228
1236
|
* @param {Object} components - discovered section types, by name
|
|
1229
1237
|
* @param {Object} [layouts] - discovered layouts, by name
|
|
1230
1238
|
* @param {Object} [foundationConfig] - the foundation's `main.js`, whose `data:` reaches every section
|
|
1231
1239
|
*/
|
|
1232
|
-
export function reportUnregistrableData(components, layouts = {}, foundationConfig = {}) {
|
|
1240
|
+
export function reportUnregistrableData(components, layouts = {}, foundationConfig = {}, { strict = true } = {}) {
|
|
1233
1241
|
const owners = [
|
|
1234
1242
|
...Object.entries(components).map(([name, entry]) => [`${name} (meta.js)`, entry?.data]),
|
|
1235
1243
|
...Object.entries(layouts || {}).map(([name, entry]) => [`layout ${name} (meta.js)`, entry?.data]),
|
|
1236
1244
|
['the foundation (main.js)', foundationConfig?.data],
|
|
1237
1245
|
]
|
|
1246
|
+
const problems = []
|
|
1238
1247
|
for (const [owner, data] of owners) {
|
|
1239
1248
|
try {
|
|
1240
1249
|
normalizeData(data, { owner })
|
|
1241
1250
|
} catch (err) {
|
|
1242
|
-
|
|
1251
|
+
problems.push(`${err.message} \`uniweb register\` refuses it too.`)
|
|
1243
1252
|
}
|
|
1244
1253
|
}
|
|
1254
|
+
stopOrWarn(problems, strict)
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
/**
|
|
1258
|
+
* One error naming every declaration problem the build found, so a developer fixes them in one
|
|
1259
|
+
* pass rather than one build at a time.
|
|
1260
|
+
*
|
|
1261
|
+
* @param {string[]} problems - each a sentence that names its owner (`Hero (meta.js): …`)
|
|
1262
|
+
*/
|
|
1263
|
+
function declarationsError(problems) {
|
|
1264
|
+
return [`[uniweb] The foundation declares what its build cannot use:`, ...problems.map((p) => ` - ${p}`)].join('\n')
|
|
1245
1265
|
}
|
|
1246
1266
|
|
|
1247
1267
|
/**
|
|
1248
|
-
*
|
|
1249
|
-
*
|
|
1250
|
-
*
|
|
1268
|
+
* The foundation's build stops on them; a site reading its foundation warns of each and goes on
|
|
1269
|
+
* (`buildSchema`'s `strict`).
|
|
1270
|
+
*
|
|
1271
|
+
* @param {string[]} problems
|
|
1272
|
+
* @param {boolean} strict
|
|
1273
|
+
*/
|
|
1274
|
+
function stopOrWarn(problems, strict) {
|
|
1275
|
+
if (!problems.length) return
|
|
1276
|
+
if (strict) throw new Error(declarationsError(problems))
|
|
1277
|
+
for (const problem of problems) console.warn(`Warning: ${problem} The foundation's build stops on it.`)
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
/**
|
|
1281
|
+
* Stop the build on `content`, `children` and `params` declarations a section type cannot use:
|
|
1282
|
+
* what lowering them could not read (`@uniweb/schemas`, the grammar the editor reads them with),
|
|
1283
|
+
* and a param the component is never given. Every one is named at once [Diego, 2026-11-11: "It's
|
|
1284
|
+
* okay for the foundation build to fail if it has problems in any `meta.js` or elsewhere."]. ⛔ Until
|
|
1285
|
+
* then these were warnings under a green build, and a foundation registered with them.
|
|
1251
1286
|
*
|
|
1252
1287
|
* ⭐ A `children.types` entry must name one of this foundation's section types. A hidden
|
|
1253
1288
|
* one is not a section type at all, and a child of a type nothing provides renders
|
|
1254
|
-
* "Component not found".
|
|
1255
|
-
* this foundation cannot see — the message says so.
|
|
1289
|
+
* "Component not found". It stays a WARNING, since it has one false alarm: a type an extension
|
|
1290
|
+
* provides, which this foundation cannot see — the message says so.
|
|
1256
1291
|
*
|
|
1257
1292
|
* @param {Object} components - discovered section types, by name
|
|
1258
1293
|
*/
|
|
1259
|
-
export function reportPlacementDeclarations(components) {
|
|
1294
|
+
export function reportPlacementDeclarations(components, { strict = true } = {}) {
|
|
1295
|
+
const errors = []
|
|
1260
1296
|
for (const [name, entry] of Object.entries(components)) {
|
|
1261
1297
|
// An entry built here was lowered, and kept what it could not read aside; one handed
|
|
1262
1298
|
// in as written is read now. (A lowered entry reads as itself, with no problems.)
|
|
@@ -1267,7 +1303,7 @@ export function reportPlacementDeclarations(components) {
|
|
|
1267
1303
|
...children.problems,
|
|
1268
1304
|
]
|
|
1269
1305
|
for (const problem of problems) {
|
|
1270
|
-
|
|
1306
|
+
errors.push(`${name} (meta.js): ${problem}`)
|
|
1271
1307
|
}
|
|
1272
1308
|
for (const type of children.types || []) {
|
|
1273
1309
|
if (components[type]) continue
|
|
@@ -1285,8 +1321,8 @@ export function reportPlacementDeclarations(components) {
|
|
|
1285
1321
|
const params = entry.params && typeof entry.params === 'object' ? entry.params : {}
|
|
1286
1322
|
for (const [param, reserved] of Object.entries(SECTION_PARAMS)) {
|
|
1287
1323
|
if (reserved.component || !Object.hasOwn(params, param)) continue
|
|
1288
|
-
|
|
1289
|
-
|
|
1324
|
+
errors.push(
|
|
1325
|
+
`${name} (meta.js): params declares "${param}", a setting of the section, not of its ` +
|
|
1290
1326
|
`component — framework applies an author's ${param}: to the section and never passes it to the ` +
|
|
1291
1327
|
`component, and an editor offers it for every section (@uniweb/schemas/section). Remove it from params:.` +
|
|
1292
1328
|
(param === 'grid'
|
|
@@ -1298,12 +1334,13 @@ export function reportPlacementDeclarations(components) {
|
|
|
1298
1334
|
// takes it out before the params are stored, so a param of that name is never given one.
|
|
1299
1335
|
for (const [key, { is }] of Object.entries(SECTION_KEYS)) {
|
|
1300
1336
|
if (!Object.hasOwn(params, key)) continue
|
|
1301
|
-
|
|
1302
|
-
|
|
1337
|
+
errors.push(
|
|
1338
|
+
`${name} (meta.js): params declares "${key}", a key a section's frontmatter keeps for ` +
|
|
1303
1339
|
`itself — ${is} — so the component is never given it (@uniweb/schemas/section). Remove it from params:.`
|
|
1304
1340
|
)
|
|
1305
1341
|
}
|
|
1306
1342
|
}
|
|
1343
|
+
stopOrWarn(errors, strict)
|
|
1307
1344
|
}
|
|
1308
1345
|
|
|
1309
1346
|
/**
|
|
@@ -1319,8 +1356,14 @@ export function reportPlacementDeclarations(components) {
|
|
|
1319
1356
|
* @param {{services: string[], blind: boolean}} [derivedSupports] - what the
|
|
1320
1357
|
* module graph says this foundation reaches for (`foundation/derive-supports.js`).
|
|
1321
1358
|
* Omitted on a dev rebuild, where nothing reads the result.
|
|
1359
|
+
* @param {Object} [options]
|
|
1360
|
+
* @param {boolean} [options.strict=true] - stop on a declaration the build cannot use (the
|
|
1361
|
+
* foundation's own build, `register`). ⭐ A SITE reading its foundation's declarations passes
|
|
1362
|
+
* false (`foundationSections`, `validate`): it warns as it always did and keeps reading, since
|
|
1363
|
+
* the foundation's build is what stops, and a site step that threw would lose every
|
|
1364
|
+
* declaration in silence (it falls back to a schema.json, or to none).
|
|
1322
1365
|
*/
|
|
1323
|
-
export async function buildSchema(srcDir, sectionPaths, derivedSupports = null) {
|
|
1366
|
+
export async function buildSchema(srcDir, sectionPaths, derivedSupports = null, { strict = true } = {}) {
|
|
1324
1367
|
// Load identity from package.json
|
|
1325
1368
|
const identity = await loadPackageJson(srcDir)
|
|
1326
1369
|
|
|
@@ -1331,7 +1374,7 @@ export async function buildSchema(srcDir, sectionPaths, derivedSupports = null)
|
|
|
1331
1374
|
|
|
1332
1375
|
// Discover section types
|
|
1333
1376
|
const components = await discoverComponents(srcDir, sectionPaths)
|
|
1334
|
-
reportPlacementDeclarations(components)
|
|
1377
|
+
reportPlacementDeclarations(components, { strict })
|
|
1335
1378
|
|
|
1336
1379
|
// Resolve the data schemas the foundation DEFINES — every file in its `schemas/`
|
|
1337
1380
|
// folder (`ownSchemaRefs`) — and the ones its section bindings reference, carried
|
|
@@ -1361,7 +1404,7 @@ export async function buildSchema(srcDir, sectionPaths, derivedSupports = null)
|
|
|
1361
1404
|
dataSchemas,
|
|
1362
1405
|
srcDir,
|
|
1363
1406
|
)
|
|
1364
|
-
reportUnregistrableData(components, layouts, foundationConfig)
|
|
1407
|
+
reportUnregistrableData(components, layouts, foundationConfig, { strict })
|
|
1365
1408
|
|
|
1366
1409
|
// Determine extension role
|
|
1367
1410
|
const isExtension = !!foundationConfig.extension
|
package/src/site/config.js
CHANGED
|
@@ -334,7 +334,10 @@ export async function defineSiteConfig(options = {}) {
|
|
|
334
334
|
await generateEntryPoint(srcDir, entryPath)
|
|
335
335
|
server.ws.send({ type: 'full-reload' })
|
|
336
336
|
} catch (err) {
|
|
337
|
+
// The last good entry stays, and the page shows why it did not move: a `meta.js` that
|
|
338
|
+
// does not load, or a declaration the build cannot use, stops the build (schema.js).
|
|
337
339
|
console.warn('[site] Failed to regenerate foundation entry:', err.message)
|
|
340
|
+
server.ws.send({ type: 'error', err: { message: err.message, stack: '' } })
|
|
338
341
|
}
|
|
339
342
|
}
|
|
340
343
|
})
|
|
@@ -459,7 +459,9 @@ export async function foundationSections(siteRoot, siteYml = null) {
|
|
|
459
459
|
const srcDir = localFoundationSrcDir(siteRoot, yml)
|
|
460
460
|
if (srcDir) {
|
|
461
461
|
try {
|
|
462
|
-
|
|
462
|
+
// Not strict: a declaration the foundation's build stops on is warned of here, and read
|
|
463
|
+
// (`buildSchema`'s `strict`).
|
|
464
|
+
return await buildSchema(srcDir, undefined, null, { strict: false })
|
|
463
465
|
} catch {
|
|
464
466
|
// a foundation whose source does not read is reported by the build that builds it
|
|
465
467
|
}
|
package/src/uwx/locale-sync.js
CHANGED
|
@@ -404,9 +404,11 @@ export function localizeScalar(value, sourceLocale, translations, context = null
|
|
|
404
404
|
* @returns {string|undefined}
|
|
405
405
|
*/
|
|
406
406
|
export function translationFor(entry, context) {
|
|
407
|
-
if (typeof entry === 'string') return entry
|
|
407
|
+
if (typeof entry === 'string') return context?.placeOnly ? undefined : entry
|
|
408
408
|
if (!entry || typeof entry !== 'object') return undefined
|
|
409
409
|
const override = context ? entry.overrides?.[contextKey(context)] : undefined
|
|
410
|
+
// ⭐ On a page the site doesn't translate, only an override naming this place (`translationContext`).
|
|
411
|
+
if (context?.placeOnly) return typeof override === 'string' ? override : undefined
|
|
410
412
|
return typeof override === 'string' ? override : typeof entry.default === 'string' ? entry.default : undefined
|
|
411
413
|
}
|
|
412
414
|
|
|
@@ -495,6 +497,8 @@ export function createTranslationCollector(sourceLocale, { siteRoot = null, lang
|
|
|
495
497
|
const kept = {} // { place: { '@'?, languages? } }, what `readKept` gives back
|
|
496
498
|
const keptRead = new Set() // the places read, whether or not they keep anything
|
|
497
499
|
const marks = { cleared: {}, outdated: {} } // what `addStructuralMap` was told of each row beyond its value
|
|
500
|
+
// The places read on a page the site doesn't translate, which only an override says (`translationContext`).
|
|
501
|
+
marks.placeOnly = new Set()
|
|
498
502
|
|
|
499
503
|
function keepMeta(place, at) {
|
|
500
504
|
keptRead.add(place)
|
|
@@ -528,6 +532,7 @@ export function createTranslationCollector(sourceLocale, { siteRoot = null, lang
|
|
|
528
532
|
// says it.
|
|
529
533
|
function add(localizedValue, context = null, { plainText = false } = {}) {
|
|
530
534
|
if (!isLocalizedMap(localizedValue)) return
|
|
535
|
+
if (context?.placeOnly) marks.placeOnly.add(contextKey(context))
|
|
531
536
|
const source = localizedValue[sourceLocale]
|
|
532
537
|
if (typeof source !== 'string' || source.length === 0) return
|
|
533
538
|
const hash = computeHash(source)
|
|
@@ -558,6 +563,7 @@ export function createTranslationCollector(sourceLocale, { siteRoot = null, lang
|
|
|
558
563
|
function addStructuralMap(locale, map, context = null, checks = null, notes = null) {
|
|
559
564
|
if (locale === sourceLocale || !map || typeof map !== 'object' || Array.isArray(map) || !has(locale)) return
|
|
560
565
|
const place = context ? contextKey(context) : ''
|
|
566
|
+
if (context?.placeOnly) marks.placeOnly.add(place)
|
|
561
567
|
for (const [src, row] of Object.entries(notes?.cleared || {})) {
|
|
562
568
|
;((marks.cleared[locale] ||= {})[computeHash(src)] ||= {})[place] = row
|
|
563
569
|
}
|
|
@@ -908,18 +914,22 @@ class SeenInContexts {
|
|
|
908
914
|
// ⛔ Until 2026-10-17 values agreed only when spelled alike, and a pull rewrote an entry that says the
|
|
909
915
|
// same thing another way: `[Faire un don](/contact)` to its label, a string a heading and a link
|
|
910
916
|
// share into per-place overrides, a page title's `[Se connecter](/sign-in)` to its words.
|
|
911
|
-
|
|
917
|
+
// ⭐ A PLACE ON A PAGE THE SITE DOESN'T TRANSLATE (`placeOnly`) IS SAID BY ITS OWN OVERRIDE ALONE, as a
|
|
918
|
+
// build and a push read it (`translationContext`): it never takes the default, nor decides it. So what an
|
|
919
|
+
// author translated there in the app comes back as an override for that place, and reaches no other.
|
|
920
|
+
function reconcileTranslation(existing, seen, check = null, placeOnly = null) {
|
|
912
921
|
const own = existing && typeof existing === 'object' && existing.overrides && typeof existing.overrides === 'object' ? existing.overrides : {}
|
|
913
922
|
const authoredDefault = typeof existing === 'string' ? existing : existing && typeof existing === 'object' ? existing.default : undefined
|
|
923
|
+
const only = (k) => k !== null && !!placeOnly?.has(k)
|
|
914
924
|
// Each place read: its context's key (null where it has none), what it read, and what says that.
|
|
915
925
|
const places = [
|
|
916
926
|
...(seen.plain !== undefined ? [[null, seen.plain, check?.plain ?? saysAsIs(seen.plain)]] : []),
|
|
917
927
|
...Object.entries(seen.values).map(([k, v]) => [k, v, check?.values?.[k] ?? saysAsIs(v)]),
|
|
918
928
|
]
|
|
919
|
-
const at = (k) => (k !== null && k in own ? own[k] : authoredDefault)
|
|
929
|
+
const at = (k) => (k !== null && k in own ? own[k] : only(k) ? undefined : authoredDefault)
|
|
920
930
|
if (existing !== undefined && places.length && places.every(([k, , says]) => says(at(k)))) return existing
|
|
921
931
|
// The places the default speaks for: those with no override of the author's own.
|
|
922
|
-
const free = places.filter(([k]) => k === null || !(k in own))
|
|
932
|
+
const free = places.filter(([k]) => k === null || (!(k in own) && !only(k)))
|
|
923
933
|
let def = authoredDefault
|
|
924
934
|
if (free.length) {
|
|
925
935
|
let most = -1
|
|
@@ -928,15 +938,16 @@ function reconcileTranslation(existing, seen, check = null) {
|
|
|
928
938
|
if (agree > most) [def, most] = [candidate, agree]
|
|
929
939
|
}
|
|
930
940
|
} else if (def === undefined) {
|
|
931
|
-
def = places.find(([k]) => k !== null)?.[1]
|
|
941
|
+
def = places.find(([k]) => k !== null && !only(k))?.[1]
|
|
932
942
|
}
|
|
933
943
|
const overrides = { ...own }
|
|
934
944
|
for (const [k, read, says] of places) {
|
|
935
945
|
if (k === null) continue
|
|
936
|
-
if (says(def)) delete overrides[k]
|
|
946
|
+
if (!only(k) && says(def)) delete overrides[k]
|
|
937
947
|
else if (!(k in own && says(own[k]))) overrides[k] = read
|
|
938
948
|
}
|
|
939
|
-
|
|
949
|
+
if (!Object.keys(overrides).length) return def
|
|
950
|
+
return def === undefined ? { overrides } : { default: def, overrides }
|
|
940
951
|
}
|
|
941
952
|
|
|
942
953
|
/**
|
|
@@ -1067,13 +1078,17 @@ function jsonObjectText(entries) {
|
|
|
1067
1078
|
*
|
|
1068
1079
|
* @returns {string|object|undefined} undefined: no entry
|
|
1069
1080
|
*/
|
|
1070
|
-
function settleEntry(existing, seen, check, cleared, outdated) {
|
|
1081
|
+
function settleEntry(existing, seen, check, cleared, outdated, placeOnly = null) {
|
|
1071
1082
|
let own = existing
|
|
1072
1083
|
if (own && typeof own === 'object' && 'outdated' in own) {
|
|
1073
1084
|
const { outdated: _flag, ...rest } = own
|
|
1074
1085
|
own = rest
|
|
1075
1086
|
}
|
|
1076
|
-
|
|
1087
|
+
// ⭐ A row on a page the site doesn't translate holds its source whatever the entry's default says
|
|
1088
|
+
// (`translationContext`), so clearing it ends only an override naming its place, below.
|
|
1089
|
+
const only = (place) => !!place && !!placeOnly?.has(place)
|
|
1090
|
+
const rows = Object.entries(cleared || {}).filter(([place]) => !only(place))
|
|
1091
|
+
const placeOnlyRows = Object.entries(cleared || {}).filter(([place]) => only(place))
|
|
1077
1092
|
const places = rows.map(([place]) => place).filter(Boolean)
|
|
1078
1093
|
const reads = seen instanceof SeenInContexts ? seen : seen === undefined ? new SeenInContexts() : new SeenInContexts(seen)
|
|
1079
1094
|
// Whether the author's entry, pushed to these rows, gives them what they hold: their source. That is
|
|
@@ -1081,9 +1096,10 @@ function settleEntry(existing, seen, check, cleared, outdated) {
|
|
|
1081
1096
|
const ownSaysThem = (value) => typeof value === 'string' && rows.every(([, row]) => row.says(value))
|
|
1082
1097
|
let entry
|
|
1083
1098
|
if (reads.plain !== undefined || Object.keys(reads.values).length > 0) {
|
|
1084
|
-
entry = reconcileTranslation(own, reads, check)
|
|
1099
|
+
entry = reconcileTranslation(own, reads, check, placeOnly)
|
|
1085
1100
|
const readsElsewhere = typeof entry === 'string' ? entry : entry?.default
|
|
1086
|
-
|
|
1101
|
+
// With no default, a row holding its source is said already: nothing gives it a translation.
|
|
1102
|
+
if (places.length && readsElsewhere !== undefined && !ownSaysThem(readsElsewhere)) {
|
|
1087
1103
|
const overrides = { ...(entry && typeof entry === 'object' ? entry.overrides : {}) }
|
|
1088
1104
|
for (const [place, row] of rows) if (place) overrides[place] = row.markdown
|
|
1089
1105
|
entry = { default: readsElsewhere, overrides }
|
|
@@ -1096,6 +1112,13 @@ function settleEntry(existing, seen, check, cleared, outdated) {
|
|
|
1096
1112
|
const defaultStays = typeof own.default === 'string' && ownSaysThem(own.default)
|
|
1097
1113
|
entry = defaultStays || Object.keys(rest).length ? { ...(defaultStays ? { default: own.default } : {}), ...(Object.keys(rest).length ? { overrides: rest } : {}) } : undefined
|
|
1098
1114
|
}
|
|
1115
|
+
for (const [place, row] of placeOnlyRows) {
|
|
1116
|
+
const override = entry && typeof entry === 'object' ? entry.overrides?.[place] : undefined
|
|
1117
|
+
if (typeof override !== 'string' || row.says(override)) continue
|
|
1118
|
+
const { [place]: _cleared, ...overrides } = entry.overrides
|
|
1119
|
+
const { overrides: _all, ...rest } = entry
|
|
1120
|
+
entry = Object.keys(overrides).length ? { ...rest, overrides } : Object.keys(rest).length ? rest : undefined
|
|
1121
|
+
}
|
|
1099
1122
|
if (entry === undefined) return undefined
|
|
1100
1123
|
if (outdated && Object.keys(outdated).length) {
|
|
1101
1124
|
entry = { ...(typeof entry === 'string' ? { default: entry } : entry), outdated }
|
|
@@ -1174,7 +1197,7 @@ export function writeLocaleTranslations(siteRoot, byLocale, subdir = '', says =
|
|
|
1174
1197
|
for (const key of new Set([...Object.keys(read), ...Object.keys(cleared)])) {
|
|
1175
1198
|
// Nothing to say of a row that holds its source where the file has no entry for it, and no place reads one.
|
|
1176
1199
|
if (!(key in read) && !(key in existing)) continue
|
|
1177
|
-
entries[key] = settleEntry(existing[key], read[key], says?.[locale]?.[key], cleared[key], outdated[key])
|
|
1200
|
+
entries[key] = settleEntry(existing[key], read[key], says?.[locale]?.[key], cleared[key], outdated[key], marks?.placeOnly)
|
|
1178
1201
|
}
|
|
1179
1202
|
const fresh = Object.keys(entries).filter((key) => !(key in existing) && entries[key] !== undefined).sort()
|
|
1180
1203
|
const same = (key) => (entries[key] === undefined ? !(key in existing) : canonicalJson(existing[key]) === canonicalJson(entries[key]))
|
package/src/uwx/site-project.js
CHANGED
|
@@ -57,7 +57,7 @@ import { buildRouteOf } from './site.js'
|
|
|
57
57
|
import { ATOMIC_PARENT, knownMode } from './route-mode.js'
|
|
58
58
|
import { fileLinkTargets } from '../site/file-links.js'
|
|
59
59
|
import { DEFAULT_SECTION_TYPE } from '@uniweb/core/section-type'
|
|
60
|
-
import { translationContext, SITE_META_CONTEXT } from '../i18n/extract.js'
|
|
60
|
+
import { translationContext, pageMetaContext, SITE_META_CONTEXT } from '../i18n/extract.js'
|
|
61
61
|
import { authorableDeclaration, DECLARATION_KEYS } from '../site/fetch-shapes.js'
|
|
62
62
|
import { createTranslationCollector, writeLocaleTranslations, writeFreeformTranslations, writeKept, unwrapLocalizedContent, isProseMirrorDoc } from './locale-sync.js'
|
|
63
63
|
import { unwritableNodes } from '@uniweb/content-writer'
|
|
@@ -663,7 +663,7 @@ export function pageSectionsToFiles({ pageDir, pageSections, ctx, pageContext })
|
|
|
663
663
|
freeformRelPath,
|
|
664
664
|
freeformCandidates,
|
|
665
665
|
writeId: fileSectionName(filePath) !== stableId,
|
|
666
|
-
context: pageContext ? translationContext({ stableId }, pageContext.route) : null,
|
|
666
|
+
context: pageContext ? translationContext({ stableId }, pageContext.route, ctx?.exclude) : null,
|
|
667
667
|
media: ctx?.media ?? null,
|
|
668
668
|
sameFile: ctx?.sameFile ?? null,
|
|
669
669
|
fileLinks: ctx?.fileLinks ?? null,
|
|
@@ -1138,7 +1138,7 @@ function writeMdPage({ record, place, route, ctx, report, pageContext, sourceLoc
|
|
|
1138
1138
|
freeformRelPath: buildFreeformPath({ stableId }, pageContext),
|
|
1139
1139
|
freeformCandidates: freeformPathsFor({ stableId }, pageContext),
|
|
1140
1140
|
writeId: stableId !== name,
|
|
1141
|
-
context: translationContext({ stableId }, pageContext.route),
|
|
1141
|
+
context: translationContext({ stableId }, pageContext.route, ctx?.exclude),
|
|
1142
1142
|
media: ctx?.media ?? null,
|
|
1143
1143
|
sameFile: ctx?.sameFile ?? null,
|
|
1144
1144
|
fileLinks: ctx?.fileLinks ?? null,
|
|
@@ -1220,7 +1220,7 @@ function writePagesTree(pages, pagesDir, sourceLocale, report, ctx, routePrefix
|
|
|
1220
1220
|
// source value goes inline into page.yml below (pageRecordToYml unwraps it). In the page's
|
|
1221
1221
|
// context, as the build translates them (`<route>:_meta`), so an override for one page comes back.
|
|
1222
1222
|
// Each a plain-text field: the push sends a translation's words (`site.js::localizePageMeta`).
|
|
1223
|
-
const meta =
|
|
1223
|
+
const meta = pageMetaContext(canon, ctx.exclude)
|
|
1224
1224
|
const text = { plainText: true }
|
|
1225
1225
|
ctx.collector?.add(record.title, meta, text)
|
|
1226
1226
|
ctx.collector?.add(record.label, meta, text)
|
|
@@ -2047,6 +2047,8 @@ export function siteContentDocumentToProject({ document, siteRoot, backend = nul
|
|
|
2047
2047
|
const mountRoutes = followMountRoutes({ siteRoot, siteYml, pagesDir, document, backend, sourceLocale, prune, report })
|
|
2048
2048
|
siteYml = mountRoutes.siteYml
|
|
2049
2049
|
ctx.heldMounts = mountRoutes.held
|
|
2050
|
+
// The branches the site doesn't translate: a translation read there comes back for its place alone (`translationContext`).
|
|
2051
|
+
ctx.exclude = siteYml?.i18n?.exclude ?? null
|
|
2050
2052
|
// A writable mount stays one under its new name.
|
|
2051
2053
|
const writable = (writableMounts || []).map((segment) => mountRoutes.renamed.get(segment) ?? segment)
|
|
2052
2054
|
// ⭐ WHERE EACH PAGE IS KEPT — found in the files by the build's rules (`page-files.js`), so a page
|
package/src/uwx/site.js
CHANGED
|
@@ -93,7 +93,7 @@ import { readKept, restoreKept, contextKey, loadLocaleTranslations, localizeScal
|
|
|
93
93
|
import { unwrapLocalized } from './backfill.js'
|
|
94
94
|
import { loadFreeformTranslation } from '../i18n/freeform.js'
|
|
95
95
|
import { resolveLocaleList } from '../i18n/locales.js'
|
|
96
|
-
import { translationContext, SITE_META_CONTEXT, blockElements, elementText } from '../i18n/extract.js'
|
|
96
|
+
import { translationContext, pageMetaContext, SITE_META_CONTEXT, blockElements, elementText } from '../i18n/extract.js'
|
|
97
97
|
import { documentSourceLocale } from './source-locale.js'
|
|
98
98
|
import { splitOpenGraph, openGraphValue, seoBesideOpenGraph } from './open-graph.js'
|
|
99
99
|
import { isAuthoredPreview } from './authored-preview.js'
|
|
@@ -216,21 +216,22 @@ export function buildRouteOf(record, parentRoute, sourceLocale) {
|
|
|
216
216
|
// either a STRUCTURAL map (from locales/{locale}.json, via localizeContentDoc) or,
|
|
217
217
|
// when a FREE-FORM override file exists for that section+locale, the full body
|
|
218
218
|
// (loadFreeformTranslation) — the override wins. Async because the free-form read
|
|
219
|
-
// hits the filesystem.
|
|
220
|
-
|
|
219
|
+
// hits the filesystem. A page in a branch `exclude` names (the site's `i18n.exclude`) takes only a
|
|
220
|
+
// translation written for its place, as the build gives it (`translationContext`).
|
|
221
|
+
async function localizeContentTree(pages, layoutSections, sourceLocale, targetLocales, translations, siteRoot, exclude = null) {
|
|
221
222
|
const freeformBase = localesDir(siteRoot)
|
|
222
223
|
// What a pull kept for this push to send back (`readKept`).
|
|
223
224
|
const kept = readKept(siteRoot)
|
|
224
225
|
// What each section type declares its data blocks are, so a block is pushed as the build translates it.
|
|
225
226
|
const dataModel = await dataBlockModels(siteRoot)
|
|
226
227
|
|
|
227
|
-
const localizeSection = async (record, page) => {
|
|
228
|
+
const localizeSection = async (record, page, exclude = null) => {
|
|
228
229
|
if (!record.content) return
|
|
229
230
|
const stableId = record.stable_id || record.$id
|
|
230
231
|
// Resolved in the section's context, as the build resolves it (`translationContext`): a
|
|
231
232
|
// context-specific override applies here and nowhere else. ⛔ Until 2026-09-26 every section was
|
|
232
233
|
// resolved with none, so an override never reached a backend.
|
|
233
|
-
const context = translationContext({ stableId }, page?.route)
|
|
234
|
+
const context = translationContext({ stableId }, page?.route, exclude)
|
|
234
235
|
let localized = localizeContentDoc(record.content, sourceLocale, targetLocales, translations, context, (tag) => dataModel(record.type, tag))
|
|
235
236
|
const freeform = new Set()
|
|
236
237
|
if (page) {
|
|
@@ -251,7 +252,7 @@ async function localizeContentTree(pages, layoutSections, sourceLocale, targetLo
|
|
|
251
252
|
|
|
252
253
|
const visitSections = async (sections, page) => {
|
|
253
254
|
for (const s of sections || []) {
|
|
254
|
-
await localizeSection(s, page)
|
|
255
|
+
await localizeSection(s, page, exclude)
|
|
255
256
|
if (Array.isArray(s.$children)) await visitSections(s.$children, page)
|
|
256
257
|
}
|
|
257
258
|
}
|
|
@@ -262,7 +263,7 @@ async function localizeContentTree(pages, layoutSections, sourceLocale, targetLo
|
|
|
262
263
|
for (const p of pgs || []) {
|
|
263
264
|
const route = buildRouteOf(p, parentRoute, sourceLocale)
|
|
264
265
|
const page = { route, id: p.stable_id }
|
|
265
|
-
localizePageMeta(p, route, sourceLocale, translations)
|
|
266
|
+
localizePageMeta(p, route, sourceLocale, translations, exclude)
|
|
266
267
|
if (Array.isArray(p.page_sections)) await visitSections(p.page_sections, page)
|
|
267
268
|
if (Array.isArray(p.$children)) await visitPages(p.$children, route)
|
|
268
269
|
}
|
|
@@ -316,8 +317,8 @@ export function documentRows(doc, sourceLocale = documentSourceLocale(doc), only
|
|
|
316
317
|
// override never reached a backend — nor, until the same day, an entry's default.
|
|
317
318
|
// ⭐ Each is a plain-text slot, so a translation reaches it as text, as the build renders it
|
|
318
319
|
// (`plainTextTargets`).
|
|
319
|
-
function localizePageMeta(page, route, sourceLocale, translations) {
|
|
320
|
-
const context =
|
|
320
|
+
function localizePageMeta(page, route, sourceLocale, translations, exclude = null) {
|
|
321
|
+
const context = pageMetaContext(route, exclude)
|
|
321
322
|
const again = (value) =>
|
|
322
323
|
value && typeof value === 'object' && typeof value[sourceLocale] === 'string'
|
|
323
324
|
? plainTextTargets(localizeScalar(value[sourceLocale], sourceLocale, translations, context), sourceLocale)
|
|
@@ -1778,7 +1779,7 @@ export async function siteProjectToDocument(siteRoot, opts = {}) {
|
|
|
1778
1779
|
// language count. Guarding this on `targetLocales.length` is what used to send
|
|
1779
1780
|
// a bare doc from single-locale sites — see localizeContentDoc for why one
|
|
1780
1781
|
// field with two shapes is a store that cannot validate its own declaration.
|
|
1781
|
-
await localizeContentTree(pages, layoutSections, sourceLocale, targetLocales, translations, siteRoot)
|
|
1782
|
+
await localizeContentTree(pages, layoutSections, sourceLocale, targetLocales, translations, siteRoot, siteYml.i18n?.exclude)
|
|
1782
1783
|
|
|
1783
1784
|
// ⭐ A link to a page is stored by the page's id where it has one (`page-refs.js`), so it
|
|
1784
1785
|
// survives a rename in an editor, and a pull writes it back as the path a file shows.
|
package/src/validate-data.js
CHANGED
|
@@ -85,7 +85,9 @@ export async function validateDataInputs({ siteRoot, foundationPath }) {
|
|
|
85
85
|
if (!foundationPath) throw new Error('validateDataInputs: foundationPath is required')
|
|
86
86
|
|
|
87
87
|
const srcDir = resolveFoundationSrcPath(foundationPath)
|
|
88
|
-
|
|
88
|
+
// Not strict: validating a site's records reads its foundation's declarations, and warns of one
|
|
89
|
+
// the foundation's build stops on rather than refusing the site (`buildSchema`'s `strict`).
|
|
90
|
+
const foundation = await buildSchema(srcDir, undefined, null, { strict: false })
|
|
89
91
|
const dataSchemas = foundation.dataSchemas || {}
|
|
90
92
|
// The type each data key names — a records folder named for a typed key holds records of
|
|
91
93
|
// that type when no data schema has its name (`uwx/data-key-types.js`).
|
|
@@ -602,8 +602,15 @@ export function foundationDevPlugin(options = {}) {
|
|
|
602
602
|
if (reason) {
|
|
603
603
|
console.log(`[foundation] ${reason}, regenerating entry...`)
|
|
604
604
|
const entryPath = join(resolvedSrcDir, entryFileName)
|
|
605
|
-
|
|
606
|
-
|
|
605
|
+
try {
|
|
606
|
+
await generateEntryPoint(resolvedSrcDir, entryPath, { sectionPaths })
|
|
607
|
+
server.ws.send({ type: 'full-reload' })
|
|
608
|
+
} catch (err) {
|
|
609
|
+
// The last good entry stays, and the page shows why: a `meta.js` that does not load, or a
|
|
610
|
+
// declaration the build cannot use, stops the build (schema.js), and the dev server lives on.
|
|
611
|
+
console.warn('[foundation] Failed to regenerate the entry:', err.message)
|
|
612
|
+
server.ws.send({ type: 'error', err: { message: err.message, stack: '' } })
|
|
613
|
+
}
|
|
607
614
|
}
|
|
608
615
|
},
|
|
609
616
|
}
|