@uniweb/build 1.13.2 → 1.13.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.
- package/package.json +5 -5
- package/src/i18n/audit.js +8 -1
- package/src/i18n/index.js +20 -2
- package/src/i18n/locales.js +2 -1
- package/src/i18n/outdated.js +146 -0
- package/src/i18n/records.js +2 -1
- package/src/i18n/sync.js +21 -0
- package/src/i18n/word-overlap.js +34 -0
- package/src/site/plugin.js +5 -3
- package/src/uwx/backfill.js +4 -4
- package/src/uwx/index.js +3 -0
- package/src/uwx/locale-sync.js +320 -29
- package/src/uwx/records-project.js +4 -2
- package/src/uwx/records.js +13 -8
- package/src/uwx/site-diff.js +34 -12
- package/src/uwx/site-project.js +66 -49
- package/src/uwx/site.js +47 -4
- package/src/uwx/source-locale.js +21 -0
- package/src/uwx/sync-package.js +11 -7
package/src/uwx/site-diff.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
// Units are DISJOINT: a page's hash excludes its sections, a section's excludes its
|
|
24
24
|
// children, so a change lands in exactly one unit and is never double-reported.
|
|
25
25
|
// Naming comes from the projector's own helpers (`pageDirName`,
|
|
26
|
-
// `
|
|
26
|
+
// `sectionFileBases`) rather than a local copy, so a label always names a file
|
|
27
27
|
// that really exists.
|
|
28
28
|
//
|
|
29
29
|
// It needs TWO bases, and that is the non-obvious part.
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
// reported as unattributed rather than guessed at.
|
|
48
48
|
|
|
49
49
|
import { entityContentHash } from './records.js'
|
|
50
|
-
import {
|
|
50
|
+
import { sectionFileBases, pageDirName, layoutSectionPaths } from './site-project.js'
|
|
51
51
|
import { documentSourceLocale } from './source-locale.js'
|
|
52
52
|
|
|
53
53
|
// A unit's own content, with the nested collections that are their own units
|
|
@@ -94,17 +94,17 @@ export function collectSiteUnits(doc, sourceLocale = documentSourceLocale(doc))
|
|
|
94
94
|
* @param {(path: string, record: object, kind: 'info'|'page'|'section') => void} cb
|
|
95
95
|
*/
|
|
96
96
|
export function walkSiteUnits(doc, cb, sourceLocale = documentSourceLocale(doc)) {
|
|
97
|
-
const walkSections = (sections, dir) => {
|
|
97
|
+
const walkSections = (sections, dir, bases = sectionFileBases(sections)) => {
|
|
98
98
|
for (const record of sections || []) {
|
|
99
99
|
// The projector's own file rule — including an app-created section named from its
|
|
100
|
-
//
|
|
100
|
+
// type. ⚠️ The path NAMES the unit by its id; it is not always the author's file:
|
|
101
101
|
// a pull writes into an existing `1-about.md` or `@about.md` in place
|
|
102
102
|
// (`existingSectionFile`), so a reader mapping a unit to disk looks it up there.
|
|
103
103
|
// (This said "a unit's path here is the file it is written to" until 2026-10-07,
|
|
104
104
|
// and a push recorded no file for a numbered section.)
|
|
105
|
-
const base =
|
|
105
|
+
const base = bases.get(record)
|
|
106
106
|
if (base) cb(`${dir}/${base}.md`, record, 'section')
|
|
107
|
-
walkSections(record.$children, dir)
|
|
107
|
+
walkSections(record.$children, dir, bases)
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
const walkPages = (pages, parentDir) => {
|
|
@@ -132,6 +132,23 @@ export function walkSiteUnits(doc, cb, sourceLocale = documentSourceLocale(doc))
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
/**
|
|
136
|
+
* The sections of a document that differ from a base in its own representation: this copy's edits since
|
|
137
|
+
* the last sync, read against `unitBases.local`. A section the base does not name counts as changed.
|
|
138
|
+
*
|
|
139
|
+
* @param {object} doc
|
|
140
|
+
* @param {Object<string,string>} [base] - per-unit hashes (`computeUnitHashes`)
|
|
141
|
+
* @param {string} [sourceLocale]
|
|
142
|
+
* @returns {Set<object>} the section records of `doc`
|
|
143
|
+
*/
|
|
144
|
+
export function sectionsChangedSince(doc, base = {}, sourceLocale = documentSourceLocale(doc)) {
|
|
145
|
+
const changed = new Set()
|
|
146
|
+
walkSiteUnits(doc, (path, record, kind) => {
|
|
147
|
+
if (kind === 'section' && entityContentHash(ownContent(record, '$children')) !== base[path]) changed.add(record)
|
|
148
|
+
}, sourceLocale)
|
|
149
|
+
return changed
|
|
150
|
+
}
|
|
151
|
+
|
|
135
152
|
/** Per-unit content hashes: `{ <path>: <sha256> }`. */
|
|
136
153
|
export function computeUnitHashes(doc, sourceLocale) {
|
|
137
154
|
const out = {}
|
|
@@ -251,8 +268,8 @@ export function diffSiteUnits(localDoc, remoteDoc, bases = {}) {
|
|
|
251
268
|
// settle the question. If the remote is known to sit at its base, this unit is
|
|
252
269
|
// not contested no matter what we did to it — pushing our version is the whole
|
|
253
270
|
// point — so "differs, side unknown" would be both untrue and noise. That
|
|
254
|
-
// combination is the normal state
|
|
255
|
-
//
|
|
271
|
+
// combination is the normal state when a copy has no local base, which is exactly
|
|
272
|
+
// when a refusal is most likely, so getting it wrong
|
|
256
273
|
// buried the one contested file under a list of perfectly fine ones.
|
|
257
274
|
if (weChanged === true && theyChanged === true) out.changedBoth.push(path)
|
|
258
275
|
else if (theyChanged === true) out.changedUpstream.push(path)
|
|
@@ -268,17 +285,22 @@ export function diffSiteUnits(localDoc, remoteDoc, bases = {}) {
|
|
|
268
285
|
/**
|
|
269
286
|
* Render a diff as the lines a CLI shows after a staleness refusal, ordered by the
|
|
270
287
|
* cost of getting each one wrong. Returns `[]` when there is nothing to say.
|
|
288
|
+
*
|
|
289
|
+
* `label` says a unit as the reader knows it: a unit's path names it by its id, and the
|
|
290
|
+
* author's file may be `1-hero.md`.
|
|
271
291
|
*/
|
|
272
|
-
export function describeSiteDiff(diff, { limit = 8 } = {}) {
|
|
292
|
+
export function describeSiteDiff(diff, { limit = 8, label = (path) => path } = {}) {
|
|
273
293
|
const lines = []
|
|
274
294
|
// Never let a long list silently truncate into something that reads complete.
|
|
275
|
-
const list = (
|
|
276
|
-
|
|
295
|
+
const list = (paths) => {
|
|
296
|
+
const xs = paths.map(label)
|
|
297
|
+
return xs.length > limit ? `${xs.slice(0, limit).join(', ')} … and ${xs.length - limit} more` : xs.join(', ')
|
|
298
|
+
}
|
|
277
299
|
|
|
278
300
|
if (diff.addedUpstream.length) lines.push(`Added upstream — forcing DELETES these: ${list(diff.addedUpstream)}`)
|
|
279
301
|
if (diff.changedBoth.length) lines.push(`Changed on both sides: ${list(diff.changedBoth)}`)
|
|
280
302
|
if (diff.changedUpstream.length) lines.push(`Changed upstream — forcing discards these: ${list(diff.changedUpstream)}`)
|
|
281
|
-
if (diff.changedLocally.length) lines.push(`Changed by you
|
|
303
|
+
if (diff.changedLocally.length) lines.push(`Changed by you: ${list(diff.changedLocally)}`)
|
|
282
304
|
if (diff.changedUnattributed.length) lines.push(`Differs, side unknown: ${list(diff.changedUnattributed)}`)
|
|
283
305
|
if (diff.addedLocally.length) lines.push(`Added by you (not upstream yet): ${list(diff.addedLocally)}`)
|
|
284
306
|
|
package/src/uwx/site-project.js
CHANGED
|
@@ -52,12 +52,12 @@ import { buildRouteOf } from './site.js'
|
|
|
52
52
|
import { DEFAULT_SECTION_TYPE } from '@uniweb/core/section-type'
|
|
53
53
|
import { translationContext, SITE_META_CONTEXT } from '../i18n/extract.js'
|
|
54
54
|
import { authorableDeclaration, DECLARATION_KEYS } from '../site/fetch-shapes.js'
|
|
55
|
-
import { createTranslationCollector, writeLocaleTranslations, writeFreeformTranslations, unwrapLocalizedContent, isProseMirrorDoc } from './locale-sync.js'
|
|
55
|
+
import { createTranslationCollector, writeLocaleTranslations, writeFreeformTranslations, writeKept, unwrapLocalizedContent, isProseMirrorDoc } from './locale-sync.js'
|
|
56
56
|
import { unwritableNodes } from '@uniweb/content-writer'
|
|
57
57
|
import { buildFreeformPath, freeformPathsFor } from '../i18n/freeform.js'
|
|
58
58
|
import { unwrapLocalized, unwrapLocalizedList } from './backfill.js'
|
|
59
59
|
import { LOCALIZED_FIELD_ASSUMPTION } from './localize.js'
|
|
60
|
-
import { documentSourceLocale } from './source-locale.js'
|
|
60
|
+
import { documentLanguages, documentSourceLocale } from './source-locale.js'
|
|
61
61
|
import { siteContentDirs } from './site-dirs.js'
|
|
62
62
|
import { gitAuthoredPages } from './git-authored.js'
|
|
63
63
|
import { layoutAreaRoute, readLayoutFolderSync, DEFAULT_LAYOUT } from '../site/layout-folder.js'
|
|
@@ -480,39 +480,61 @@ export function safeStableIdFilename(stableId) {
|
|
|
480
480
|
}
|
|
481
481
|
|
|
482
482
|
/**
|
|
483
|
-
* The `.md` file base
|
|
484
|
-
* the prune keep-set and the
|
|
485
|
-
* all use, so the path a pull harvests a
|
|
486
|
-
* stamps it back onto.
|
|
483
|
+
* The `.md` file base of each section of a page, nested ones included, since they are written as
|
|
484
|
+
* flat files in the same folder — the ONE rule the projector, the prune keep-set and the
|
|
485
|
+
* push/pull unit walk (`site-diff.js::walkSiteUnits`) all use, so the path a pull harvests a
|
|
486
|
+
* `$uuid` under is the path the next push stamps it back onto.
|
|
487
487
|
*
|
|
488
|
-
* `stable_id || $id` when the record has one (unchanged). ⛔ A section with
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
* `<type-kebab>-<last 8 hex of $uuid>`, e.g. `hero-95993360`.
|
|
488
|
+
* `stable_id || $id` when the record has one (unchanged). ⛔ A section with neither — what the
|
|
489
|
+
* app's editor creates: a `$uuid` and no stable id — used to be SKIPPED, silently, by all three.
|
|
490
|
+
* A pull then left its file out, and a push after any local edit sent the page without it, which
|
|
491
|
+
* the backend deletes (a package's absence of a stored `page_sections` item under a page it sends
|
|
492
|
+
* is a delete). So such a section is named from its type, as a person would name it: `hero`, and
|
|
493
|
+
* `hero-2` beside another. ⛔ Until 2026-10-30 it took the end of its `$uuid`, `hero-e09a1923`.
|
|
495
494
|
*
|
|
496
|
-
* The derived base is already filesystem-safe and starts with a letter, so the
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
* the
|
|
500
|
-
*
|
|
495
|
+
* The derived base is already filesystem-safe and starts with a letter, so the build reads it back
|
|
496
|
+
* verbatim as the section's stable id (no numeric prefix to strip) and `safeStableIdFilename`
|
|
497
|
+
* returns it unchanged — the push path equals the pull path. The first push after such a pull
|
|
498
|
+
* therefore gives the item that stable id; the `$uuid` is re-stamped by path, so the item keeps its
|
|
499
|
+
* identity, and the name stops depending on its neighbours.
|
|
501
500
|
*
|
|
502
|
-
* @
|
|
501
|
+
* @param {object[]} pageSections - a page's section `$`-records
|
|
502
|
+
* @returns {Map<object, string>} each record's base; a record with no stable id and no `$uuid` has none
|
|
503
503
|
*/
|
|
504
|
-
export function
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
const
|
|
515
|
-
|
|
504
|
+
export function sectionFileBases(pageSections) {
|
|
505
|
+
const records = []
|
|
506
|
+
const collect = (list) => {
|
|
507
|
+
for (const record of list || []) {
|
|
508
|
+
records.push(record)
|
|
509
|
+
collect(record?.$children)
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
collect(pageSections)
|
|
513
|
+
const bases = new Map()
|
|
514
|
+
const taken = new Set()
|
|
515
|
+
for (const record of records) {
|
|
516
|
+
const id = recordStableId(record)
|
|
517
|
+
if (!id) continue
|
|
518
|
+
const base = safeStableIdFilename(id)
|
|
519
|
+
bases.set(record, base)
|
|
520
|
+
taken.add(base)
|
|
521
|
+
}
|
|
522
|
+
for (const record of records) {
|
|
523
|
+
if (bases.has(record)) continue
|
|
524
|
+
const hex = typeof record?.$uuid === 'string' ? record.$uuid.replace(/-/g, '').toLowerCase() : ''
|
|
525
|
+
if (!/^[0-9a-f]{8,}$/.test(hex)) continue
|
|
526
|
+
const kebab = String(record?.type || '')
|
|
527
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
528
|
+
.toLowerCase()
|
|
529
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
530
|
+
.replace(/^-+|-+$/g, '')
|
|
531
|
+
const stem = /^[a-z]/.test(kebab) ? kebab : 'section'
|
|
532
|
+
let base = stem
|
|
533
|
+
for (let n = 2; taken.has(base); n++) base = `${stem}-${n}`
|
|
534
|
+
bases.set(record, base)
|
|
535
|
+
taken.add(base)
|
|
536
|
+
}
|
|
537
|
+
return bases
|
|
516
538
|
}
|
|
517
539
|
|
|
518
540
|
/**
|
|
@@ -534,14 +556,15 @@ export function pageSectionsToFiles({ pageDir, pageSections, ctx, pageContext })
|
|
|
534
556
|
const files = [] // the top level's file names, in the document's order
|
|
535
557
|
const childFiles = [] // every nested section's file name
|
|
536
558
|
let nested = false
|
|
559
|
+
const fileBases = sectionFileBases(pageSections)
|
|
537
560
|
const buildEntries = (records, top) => {
|
|
538
561
|
const entries = []
|
|
539
562
|
for (const record of records || []) {
|
|
540
|
-
// Filesystem-safe filename (= stableId when already safe; derived from
|
|
563
|
+
// Filesystem-safe filename (= stableId when already safe; derived from its type
|
|
541
564
|
// for an app-created section with no stable id); the true stableId rides in
|
|
542
565
|
// frontmatter `id:`. The sections: leaf uses the same base so the producer's
|
|
543
566
|
// filename-based resolution matches.
|
|
544
|
-
const fileBase =
|
|
567
|
+
const fileBase = fileBases.get(record)
|
|
545
568
|
if (!fileBase) continue // no stable id AND no `$uuid` → nothing to name it by
|
|
546
569
|
const stableId = recordStableId(record) || fileBase
|
|
547
570
|
// The file the author keeps it in, else a new `<fileBase>.md` (`existingSectionFile`).
|
|
@@ -936,7 +959,7 @@ function subtreeRoutes(record, route, sourceLocale) {
|
|
|
936
959
|
// none, and reading that as "none" would delete what the author wrote.
|
|
937
960
|
function pageSlugToYml(record, canon, existing, sourceLocale, ctx) {
|
|
938
961
|
if (record.is_dynamic) return dynamicOwnSlug(record, existing, sourceLocale)
|
|
939
|
-
const targets = localizedTargets(record.slug, sourceLocale)
|
|
962
|
+
const targets = localizedTargets(record.slug, sourceLocale, ctx)
|
|
940
963
|
const own = isPlainRecord(existing?.slug)
|
|
941
964
|
if (!own && ctx.routes?.siteMap && !record.is_index) {
|
|
942
965
|
if (Object.keys(targets).length) ctx.routes.slugs.set(canon, targets)
|
|
@@ -961,11 +984,11 @@ function dynamicOwnSlug(record, existing, sourceLocale) {
|
|
|
961
984
|
return typeof existing?.slug === 'string' ? own : null
|
|
962
985
|
}
|
|
963
986
|
|
|
964
|
-
// The locales of a pulled localized `slug` other than the source one.
|
|
965
|
-
function localizedTargets(slug, sourceLocale) {
|
|
987
|
+
// The locales of a pulled localized `slug` other than the source one, in the languages the site has.
|
|
988
|
+
function localizedTargets(slug, sourceLocale, ctx) {
|
|
966
989
|
if (!isPlainRecord(slug)) return {}
|
|
967
990
|
return Object.fromEntries(
|
|
968
|
-
Object.entries(slug).filter(([l, v]) => l !== sourceLocale && l !== '@' && !l.startsWith('$') && typeof v === 'string' && v)
|
|
991
|
+
Object.entries(slug).filter(([l, v]) => l !== sourceLocale && l !== '@' && !l.startsWith('$') && typeof v === 'string' && v && (ctx?.collector?.has(l) ?? true))
|
|
969
992
|
)
|
|
970
993
|
}
|
|
971
994
|
|
|
@@ -1055,16 +1078,7 @@ function parentOrderList(ymlPath) {
|
|
|
1055
1078
|
// flat `<base>.md` files in the SAME page dir, so all are kept on prune. Uses the
|
|
1056
1079
|
// safe filename (= stableId when safe) so the keep-set matches the files on disk.
|
|
1057
1080
|
function collectSectionFileBases(pageSections) {
|
|
1058
|
-
|
|
1059
|
-
const walk = (records) => {
|
|
1060
|
-
for (const record of records || []) {
|
|
1061
|
-
const base = sectionFileBase(record)
|
|
1062
|
-
if (base) bases.add(base)
|
|
1063
|
-
if (Array.isArray(record.$children)) walk(record.$children)
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
walk(pageSections)
|
|
1067
|
-
return bases
|
|
1081
|
+
return new Set(sectionFileBases(pageSections).values())
|
|
1068
1082
|
}
|
|
1069
1083
|
|
|
1070
1084
|
// Pass 2 — prune orphan section files (per page dir) and orphan page dirs (per
|
|
@@ -1367,7 +1381,7 @@ export function siteContentDocumentToProject({ document, siteRoot, backend = nul
|
|
|
1367
1381
|
|
|
1368
1382
|
// Collects target-locale translations of localized scalars as they're projected;
|
|
1369
1383
|
// flushed to locales/{locale}.json at the end (the manifest stays derivable).
|
|
1370
|
-
const collector = createTranslationCollector(sourceLocale, { siteRoot })
|
|
1384
|
+
const collector = createTranslationCollector(sourceLocale, { siteRoot, languages: documentLanguages(document, sourceLocale) })
|
|
1371
1385
|
|
|
1372
1386
|
// Put the author's own asset paths back before anything is serialized. Stored
|
|
1373
1387
|
// content carries an id and a serve URL; only the committed map knows the ref
|
|
@@ -1434,9 +1448,12 @@ export function siteContentDocumentToProject({ document, siteRoot, backend = nul
|
|
|
1434
1448
|
}
|
|
1435
1449
|
projectLayout(document?.layout_sections, layoutBaseDir, report, prune, ctx)
|
|
1436
1450
|
|
|
1437
|
-
report.locales = writeLocaleTranslations(siteRoot, collector.byLocale, '', collector.says)
|
|
1451
|
+
report.locales = writeLocaleTranslations(siteRoot, collector.byLocale, '', collector.says, collector.marks)
|
|
1438
1452
|
// Target-locale FREE-FORM bodies → locales/freeform/{locale}/<relpath> + manifest.
|
|
1439
1453
|
report.freeform = writeFreeformTranslations(siteRoot, collector.freeformPending)
|
|
1454
|
+
// What the files hold no place for, kept for the push to send back: this document is the whole site.
|
|
1455
|
+
report.kept = writeKept(siteRoot, collector.kept)
|
|
1456
|
+
report.outsideLanguages = [...collector.outside].sort()
|
|
1440
1457
|
writePullIndex(siteRoot, ctx.newIndex)
|
|
1441
1458
|
return report
|
|
1442
1459
|
}
|
package/src/uwx/site.js
CHANGED
|
@@ -81,11 +81,12 @@ import { resolveDefaultLocale, validateLanguageConfig, queryDataUrl } from '@uni
|
|
|
81
81
|
import { emitEntitySyncPackage } from './entity-document.js'
|
|
82
82
|
import { locateSectionMedia, siteTree } from './located-media.js'
|
|
83
83
|
import { mapPageRefs, pageRefIndex, pageRefPages, storedPageRef } from './page-refs.js'
|
|
84
|
-
import { loadLocaleTranslations, localizeScalar, localizeScalarList, localizeContentDoc, localesDir, isLocalizedContent, plainTextTargets } from './locale-sync.js'
|
|
84
|
+
import { readKept, restoreKept, contextKey, loadLocaleTranslations, localizeScalar, localizeScalarList, localizeContentDoc, localesDir, isLocalizedContent, isProseMirrorDoc, plainTextTargets } from './locale-sync.js'
|
|
85
85
|
import { unwrapLocalized } from './backfill.js'
|
|
86
86
|
import { loadFreeformTranslation } from '../i18n/freeform.js'
|
|
87
87
|
import { resolveLocaleList } from '../i18n/locales.js'
|
|
88
|
-
import { translationContext, SITE_META_CONTEXT } from '../i18n/extract.js'
|
|
88
|
+
import { translationContext, SITE_META_CONTEXT, blockElements, elementText } from '../i18n/extract.js'
|
|
89
|
+
import { documentSourceLocale } from './source-locale.js'
|
|
89
90
|
import { splitOpenGraph, openGraphValue, seoBesideOpenGraph } from './open-graph.js'
|
|
90
91
|
import { isAuthoredPreview } from './authored-preview.js'
|
|
91
92
|
import { updateBackendState, readBackendState } from './sync-store.js'
|
|
@@ -207,6 +208,8 @@ export function buildRouteOf(record, parentRoute, sourceLocale) {
|
|
|
207
208
|
// hits the filesystem.
|
|
208
209
|
async function localizeContentTree(pages, layoutSections, sourceLocale, targetLocales, translations, siteRoot) {
|
|
209
210
|
const freeformBase = localesDir(siteRoot)
|
|
211
|
+
// What a pull kept for this push to send back (`readKept`).
|
|
212
|
+
const kept = readKept(siteRoot)
|
|
210
213
|
// What each section type declares its data blocks are, so a block is pushed as the build translates it.
|
|
211
214
|
const dataModel = await dataBlockModels(siteRoot)
|
|
212
215
|
|
|
@@ -216,7 +219,9 @@ async function localizeContentTree(pages, layoutSections, sourceLocale, targetLo
|
|
|
216
219
|
// Resolved in the section's context, as the build resolves it (`translationContext`): a
|
|
217
220
|
// context-specific override applies here and nowhere else. ⛔ Until 2026-09-26 every section was
|
|
218
221
|
// resolved with none, so an override never reached a backend.
|
|
219
|
-
|
|
222
|
+
const context = translationContext({ stableId }, page?.route)
|
|
223
|
+
let localized = localizeContentDoc(record.content, sourceLocale, targetLocales, translations, context, (tag) => dataModel(record.type, tag))
|
|
224
|
+
const freeform = new Set()
|
|
220
225
|
if (page) {
|
|
221
226
|
const section = { stableId }
|
|
222
227
|
for (const locale of targetLocales) {
|
|
@@ -227,9 +232,10 @@ async function localizeContentTree(pages, layoutSections, sourceLocale, targetLo
|
|
|
227
232
|
// override (isLocalizedContent excludes a PM doc, which is also an object).
|
|
228
233
|
if (!isLocalizedContent(localized)) localized = { [sourceLocale]: record.content }
|
|
229
234
|
localized[locale] = body // free-form full body overrides the structural map
|
|
235
|
+
freeform.add(locale)
|
|
230
236
|
}
|
|
231
237
|
}
|
|
232
|
-
record.content = localized
|
|
238
|
+
record.content = restoreKept(localized, kept[contextKey(context)], { sourceLocale, translations, context, freeform })
|
|
233
239
|
}
|
|
234
240
|
|
|
235
241
|
const visitSections = async (sections, page) => {
|
|
@@ -256,6 +262,43 @@ async function localizeContentTree(pages, layoutSections, sourceLocale, targetLo
|
|
|
256
262
|
for (const s of layoutSections || []) await localizeSection(s, { route: layoutAreaRoute(s.layout_name, s.area || s.stable_id) })
|
|
257
263
|
}
|
|
258
264
|
|
|
265
|
+
/**
|
|
266
|
+
* Each section's rows in a site-content document, ours or a backend's, by the place its translations
|
|
267
|
+
* apply (`translationContext`): the text of its block elements in the source language, as extraction
|
|
268
|
+
* keys them. The walk `localizeContentTree` makes.
|
|
269
|
+
*
|
|
270
|
+
* @param {object} doc
|
|
271
|
+
* @param {string} [sourceLocale]
|
|
272
|
+
* @param {(record: object) => boolean} [only] - the sections to read
|
|
273
|
+
* @returns {{ [place: string]: string[] }}
|
|
274
|
+
*/
|
|
275
|
+
export function documentRows(doc, sourceLocale = documentSourceLocale(doc), only = () => true) {
|
|
276
|
+
const rows = {}
|
|
277
|
+
const add = (record, route) => {
|
|
278
|
+
if (!only(record)) return
|
|
279
|
+
const source = isLocalizedContent(record.content) ? record.content[sourceLocale] : record.content
|
|
280
|
+
if (!isProseMirrorDoc(source)) return
|
|
281
|
+
const texts = blockElements(source).map((element) => elementText(element)).filter(Boolean)
|
|
282
|
+
if (texts.length) rows[contextKey(translationContext({ stableId: record.stable_id || record.$id }, route))] = texts
|
|
283
|
+
}
|
|
284
|
+
const visitSections = (sections, route) => {
|
|
285
|
+
for (const s of sections || []) {
|
|
286
|
+
add(s, route)
|
|
287
|
+
visitSections(s.$children, route)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const visitPages = (pages, parentRoute) => {
|
|
291
|
+
for (const p of pages || []) {
|
|
292
|
+
const route = buildRouteOf(p, parentRoute, sourceLocale)
|
|
293
|
+
visitSections(p.page_sections, route)
|
|
294
|
+
visitPages(p.$children, route)
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
visitPages(doc?.pages, '/')
|
|
298
|
+
for (const s of doc?.layout_sections || []) add(s, layoutAreaRoute(s.layout_name, s.area || s.stable_id))
|
|
299
|
+
return rows
|
|
300
|
+
}
|
|
301
|
+
|
|
259
302
|
// ⭐ A page's title, label, description and keywords are resolved in the page's context, as the
|
|
260
303
|
// build translates them (`i18n/merge.js::translatePageMeta`, `<route>:_meta`): an override for one
|
|
261
304
|
// page applies there and nowhere else. ⛔ Until 2026-09-26 they were resolved with no page, so an
|
package/src/uwx/source-locale.js
CHANGED
|
@@ -55,3 +55,24 @@ export function documentSourceLocale(document) {
|
|
|
55
55
|
languages: settings?.languages,
|
|
56
56
|
})
|
|
57
57
|
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* ⭐ THE LANGUAGES A DOCUMENT SAYS ITS SITE HAS — what a pull may write translations for. What
|
|
61
|
+
* `settings.languages` lists, with the source; the source alone where it lists none, since a push
|
|
62
|
+
* lists every language a site's files make (`uwx/site.js::settingsNested`). `null` for a wildcard,
|
|
63
|
+
* which leaves them to the site's translation files.
|
|
64
|
+
*
|
|
65
|
+
* A section's `content` can hold a language the site does not have: the app keeps a document per
|
|
66
|
+
* language it edits in, whichever languages the site declares. In a file a language is made by its
|
|
67
|
+
* translation file (`i18n/locales.js`), so writing one would add the language to the site.
|
|
68
|
+
*
|
|
69
|
+
* @param {object} document - the site-content `$`-document
|
|
70
|
+
* @param {string} [sourceLocale]
|
|
71
|
+
* @returns {string[]|null}
|
|
72
|
+
*/
|
|
73
|
+
export function documentLanguages(document, sourceLocale = documentSourceLocale(document)) {
|
|
74
|
+
const listed = document?.settings?.languages
|
|
75
|
+
if (listed === '*' || (Array.isArray(listed) && listed.includes('*'))) return null
|
|
76
|
+
const codes = Array.isArray(listed) ? listed.map((l) => (typeof l === 'string' ? l : l?.code)).filter(Boolean) : []
|
|
77
|
+
return [...new Set([sourceLocale, ...codes])]
|
|
78
|
+
}
|
package/src/uwx/sync-package.js
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
// changed records. An untouched site with records pushes nothing on either
|
|
20
20
|
// lane (the idempotent no-op).
|
|
21
21
|
|
|
22
|
+
import { basename } from 'node:path'
|
|
22
23
|
import { buildRecordEntities, entityContentHash } from './records.js'
|
|
23
24
|
import { recordItemLists, hasListItems, stampRecordItems } from './record-items.js'
|
|
24
25
|
import { ASSET_SLOTS } from '@uniweb/semantic-parser'
|
|
@@ -459,14 +460,11 @@ export async function emitSyncPackages(siteRoot, opts = {}) {
|
|
|
459
460
|
let itemIdentity = null
|
|
460
461
|
if (siteDoc && opts.itemUuids && typeof opts.itemUuids === 'object') {
|
|
461
462
|
itemIdentity = stampUnitUuids(siteDoc, opts.itemUuids, sourceLocale)
|
|
462
|
-
for (const path of itemIdentity.collisions) {
|
|
463
|
-
warnings.push(
|
|
464
|
-
`Two sections resolve to the same file (${path}) — their stable ids collide ` +
|
|
465
|
-
`(e.g. \`1-name.md\` and \`name.md\`). Only the first keeps its identity, and a pull ` +
|
|
466
|
-
`would collapse them into one file. Rename one.`
|
|
467
|
-
)
|
|
468
|
-
}
|
|
469
463
|
}
|
|
464
|
+
// ⭐ TWO SECTIONS OF ONE PAGE WITH ONE ID ARE REFUSED, on a first push too. ⛔ Until 2026-10-31 it was
|
|
465
|
+
// a warning and the push went on. Measured with `1-hero.md` beside `hero.md`: the store held both, a
|
|
466
|
+
// pull deleted one of the files, and from then on a push was refused as stale with nothing to pull.
|
|
467
|
+
const sameId = siteDoc ? (itemIdentity ?? stampUnitUuids(siteDoc, {}, sourceLocale)).collisions : []
|
|
470
468
|
|
|
471
469
|
// Local-media over push (Slice 5). `assetRewrite` ({ '/images/x.png': serveUrl })
|
|
472
470
|
// is supplied by the deploy's SECOND emit, after it has uploaded the files the
|
|
@@ -589,6 +587,12 @@ export async function emitSyncPackages(siteRoot, opts = {}) {
|
|
|
589
587
|
// by `$ref`, and the backend refused a reference to a record the package does not carry
|
|
590
588
|
// (measured 2026-09-26); sent, it would be a second record. A pull writes it back.
|
|
591
589
|
const refusals = [...(col.refusals || [])]
|
|
590
|
+
for (const path of sameId) {
|
|
591
|
+
refusals.push(
|
|
592
|
+
`${path}: two sections of this page have the id \`${basename(path, '.md')}\`, as \`1-name.md\` and \`name.md\` do. ` +
|
|
593
|
+
'A section is named by its file, without the number. Rename one.'
|
|
594
|
+
)
|
|
595
|
+
}
|
|
592
596
|
for (const r of recordChanged) {
|
|
593
597
|
if (r.changed || r.entity.document.$uuid) continue
|
|
594
598
|
refusals.push(
|