@uniweb/build 1.17.0 → 1.17.1
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 +4 -4
- package/src/uwx/asset-map.js +66 -1
- package/src/uwx/locale-sync.js +22 -10
- package/src/uwx/located-media.js +3 -2
- package/src/uwx/project-writer.js +20 -1
- package/src/uwx/site-project.js +23 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.1",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
"js-yaml": "^4.3.2",
|
|
57
57
|
"sharp": "^0.35.5",
|
|
58
58
|
"yaml": "^2.5.0",
|
|
59
|
+
"@uniweb/content-writer": "~1.3.1",
|
|
59
60
|
"@uniweb/content-reader": "~1.5.9",
|
|
60
|
-
"@uniweb/schemas": "~1.6.10",
|
|
61
61
|
"@uniweb/semantic-parser": "~1.13.2",
|
|
62
|
-
"@uniweb/
|
|
62
|
+
"@uniweb/schemas": "~1.6.10",
|
|
63
63
|
"@uniweb/projections": "~1.2.11",
|
|
64
|
-
"@uniweb/
|
|
64
|
+
"@uniweb/theming": "~1.2.1"
|
|
65
65
|
},
|
|
66
66
|
"optionalDependencies": {
|
|
67
67
|
"@uniweb/runtime": "~1.4.5"
|
package/src/uwx/asset-map.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Asset reference helpers —
|
|
2
|
+
* Asset reference helpers — pure functions, no file.
|
|
3
3
|
*
|
|
4
4
|
* ⚠️ **The MAP moved to `sync.json` on 2026-09-20** (`sync-store.js`,
|
|
5
5
|
* `backends.<origin>.assets`). It lived here as `assets.json`, a single flat
|
|
@@ -23,12 +23,18 @@
|
|
|
23
23
|
* ⭐ **`restoreAssetRefs` no-ops on an empty map**, which is what makes the store's
|
|
24
24
|
* `backend` parameter honest: a projection not tied to a backend has no known
|
|
25
25
|
* assets, so it restores nothing rather than guessing.
|
|
26
|
+
* - **`sameStoredFile`** / **`keepAuthoredRefs`** — keep the author's path where the
|
|
27
|
+
* files already name one of the same bytes. A backend keeps a file by its content, so
|
|
28
|
+
* two such files are one asset, and `restoreAssetRefs` can give each reference only
|
|
29
|
+
* the first of their paths.
|
|
26
30
|
*
|
|
27
31
|
* @module
|
|
28
32
|
*/
|
|
29
33
|
|
|
30
34
|
import { createHash } from 'node:crypto'
|
|
35
|
+
import { dirname, resolve } from 'node:path'
|
|
31
36
|
import { ASSET_SLOTS } from '@uniweb/semantic-parser'
|
|
37
|
+
import { siteFileKey } from './located-media.js'
|
|
32
38
|
|
|
33
39
|
/**
|
|
34
40
|
* The fingerprint the asset map in `sync.json` keeps of the URL a host serves an
|
|
@@ -148,3 +154,62 @@ export function restoreAssetRefs(document, map) {
|
|
|
148
154
|
|
|
149
155
|
// Only a string that could be a served address is worth hashing.
|
|
150
156
|
const looksLikeAddress = (v) => v.startsWith('/') || /^https?:\/\//i.test(v)
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Whether two references name the same stored file: the same string, or two references the map gives
|
|
160
|
+
* one asset id. A backend keeps a file by its bytes, so two files with the same bytes are one asset, with
|
|
161
|
+
* one id and one served address. A stored reference to it says nothing of which path it came from, and
|
|
162
|
+
* `restoreAssetRefs` gives it the first path the map lists.
|
|
163
|
+
*
|
|
164
|
+
* A relative reference is read from the file it is written in (`fromFile`), as the push keyed it
|
|
165
|
+
* (`located-media.js::siteFileKey`).
|
|
166
|
+
*
|
|
167
|
+
* ⛔ Measured 2026-11-05 on a docs site whose French screenshot was the English one's bytes: the French
|
|
168
|
+
* translation's image came back as the English path, so the pull wrote the translation as its words
|
|
169
|
+
* alone, and took that as the app's change.
|
|
170
|
+
*
|
|
171
|
+
* @param {Record<string, { id: string }>} map - `sync.json`'s assets for the backend
|
|
172
|
+
* @param {{ siteRoot?: string|null, tree?: () => Array<[string, string]> }} [opts] - for a relative
|
|
173
|
+
* reference: the site's folder, and its tree (`located-media.js::siteTree`)
|
|
174
|
+
* @returns {(a: string, b: string, fromFile?: string|null) => boolean}
|
|
175
|
+
*/
|
|
176
|
+
export function sameStoredFile(map, { siteRoot = null, tree = () => [] } = {}) {
|
|
177
|
+
const idOf = (ref, fromFile) => {
|
|
178
|
+
if (typeof ref !== 'string' || !ref) return null
|
|
179
|
+
const own = map?.[ref]?.id
|
|
180
|
+
if (own) return own
|
|
181
|
+
if (!siteRoot || !fromFile || ref.startsWith('/') || /^[a-z][a-z0-9+.-]*:/i.test(ref)) return null
|
|
182
|
+
const key = siteFileKey(siteRoot, resolve(dirname(fromFile), ref), tree())
|
|
183
|
+
return (key && map?.[key]?.id) || null
|
|
184
|
+
}
|
|
185
|
+
return (a, b, fromFile = null) => {
|
|
186
|
+
if (a === b) return true
|
|
187
|
+
const id = idOf(a, fromFile)
|
|
188
|
+
return !!id && id === idOf(b, fromFile)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* A value a pull writes over an authored one, with each reference that names the same stored file as
|
|
194
|
+
* the authored value at the same place given back as the author wrote it (`sameStoredFile`). Nothing
|
|
195
|
+
* else changes, so a file the app changed to another asset is written.
|
|
196
|
+
*
|
|
197
|
+
* @param {*} incoming - what the pull writes: a document, frontmatter, a config
|
|
198
|
+
* @param {*} authored - what the file says now, in the same shape
|
|
199
|
+
* @param {(a: string, b: string) => boolean} same
|
|
200
|
+
* @returns {*} `incoming`, or a copy with those references kept
|
|
201
|
+
*/
|
|
202
|
+
export function keepAuthoredRefs(incoming, authored, same) {
|
|
203
|
+
if (typeof incoming === 'string') {
|
|
204
|
+
return typeof authored === 'string' && incoming !== authored && same(incoming, authored) ? authored : incoming
|
|
205
|
+
}
|
|
206
|
+
if (Array.isArray(incoming)) {
|
|
207
|
+
return Array.isArray(authored) ? incoming.map((v, i) => keepAuthoredRefs(v, authored[i], same)) : incoming
|
|
208
|
+
}
|
|
209
|
+
if (incoming && typeof incoming === 'object' && authored && typeof authored === 'object' && !Array.isArray(authored)) {
|
|
210
|
+
const out = {}
|
|
211
|
+
for (const [key, value] of Object.entries(incoming)) out[key] = keepAuthoredRefs(value, authored[key], same)
|
|
212
|
+
return out
|
|
213
|
+
}
|
|
214
|
+
return incoming
|
|
215
|
+
}
|
package/src/uwx/locale-sync.js
CHANGED
|
@@ -485,8 +485,11 @@ export function isLocalizedContent(value) {
|
|
|
485
485
|
* With `languages` (`documentLanguages`), a value in any other language is left out of the
|
|
486
486
|
* translation files, and the language is named in `outside` for the caller to report. A whole document
|
|
487
487
|
* in one is kept (`keepLanguage`, `readKept`), so a push sends it back.
|
|
488
|
+
*
|
|
489
|
+
* With `sameFile` (`asset-map.js::sameStoredFile`), an image an author's entry names by a file of the
|
|
490
|
+
* same bytes as the one the pull read says the same thing, and the entry is kept (`saysImage`).
|
|
488
491
|
*/
|
|
489
|
-
export function createTranslationCollector(sourceLocale, { siteRoot = null, languages = null } = {}) {
|
|
492
|
+
export function createTranslationCollector(sourceLocale, { siteRoot = null, languages = null, sameFile = null } = {}) {
|
|
490
493
|
const byLocale = {} // { locale: { hash: target } }
|
|
491
494
|
const outside = new Set() // the languages read that the site does not have
|
|
492
495
|
const kept = {} // { place: { '@'?, languages? } }, what `readKept` gives back
|
|
@@ -601,7 +604,7 @@ export function createTranslationCollector(sourceLocale, { siteRoot = null, lang
|
|
|
601
604
|
return null
|
|
602
605
|
}
|
|
603
606
|
|
|
604
|
-
return { add, addStructuralMap, noteFreeform, keptFreeform, keepMeta, keepLanguage, has, byLocale, says, marks, freeformPending, outside, kept, keptRead }
|
|
607
|
+
return { add, addStructuralMap, noteFreeform, keptFreeform, keepMeta, keepLanguage, has, byLocale, says, marks, freeformPending, outside, kept, keptRead, sameFile }
|
|
605
608
|
}
|
|
606
609
|
|
|
607
610
|
/**
|
|
@@ -625,7 +628,7 @@ export function createTranslationCollector(sourceLocale, { siteRoot = null, lang
|
|
|
625
628
|
* ⭐ TWO ROWS OF ONE SOURCE TEXT THAT READ DIFFERENTLY cannot be said by one entry, so the target is
|
|
626
629
|
* free-form. ⛔ Until 2026-10-31 the last one won: `(zh_A, zh_B)` became `(zh_B, zh_B)` on the next push.
|
|
627
630
|
*/
|
|
628
|
-
function deriveStructuralMap(sourceDoc, targetDoc, modelFor = () => null, checks = {}, notes = { cleared: {}, outdated: {} }, olderSource = () => null) {
|
|
631
|
+
function deriveStructuralMap(sourceDoc, targetDoc, modelFor = () => null, checks = {}, notes = { cleared: {}, outdated: {} }, olderSource = () => null, sameFile = null) {
|
|
629
632
|
if (!isProseMirrorDoc(sourceDoc) || !isProseMirrorDoc(targetDoc)) return null
|
|
630
633
|
const src = blockElements(sourceDoc)
|
|
631
634
|
const tgt = blockElements(targetDoc)
|
|
@@ -657,7 +660,7 @@ function deriveStructuralMap(sourceDoc, targetDoc, modelFor = () => null, checks
|
|
|
657
660
|
return null
|
|
658
661
|
}
|
|
659
662
|
const withData = addDataBlockStrings(map, sourceDoc, targetDoc, modelFor, checks)
|
|
660
|
-
return withData && addImageTranslations(withData, sourceDoc, targetDoc, checks)
|
|
663
|
+
return withData && addImageTranslations(withData, sourceDoc, targetDoc, checks, sameFile)
|
|
661
664
|
}
|
|
662
665
|
|
|
663
666
|
// ⭐ AN IMAGE's translation, read pairwise — what a translation may give it (`merge.js::translateImages`):
|
|
@@ -666,7 +669,7 @@ function deriveStructuralMap(sourceDoc, targetDoc, modelFor = () => null, checks
|
|
|
666
669
|
// A target whose images differ in anything else — their number, a role, a size — or that changed an
|
|
667
670
|
// image with no alt text cannot be said per image, and the whole translation is free-form.
|
|
668
671
|
// ⛔ Until 2026-10-28 an image was not read here, and its translation was not sent either.
|
|
669
|
-
function addImageTranslations(map, sourceDoc, targetDoc, checks = null) {
|
|
672
|
+
function addImageTranslations(map, sourceDoc, targetDoc, checks = null, sameFile = null) {
|
|
670
673
|
const src = imageNodes(sourceDoc)
|
|
671
674
|
const tgt = imageNodes(targetDoc)
|
|
672
675
|
if (src.length !== tgt.length) return null
|
|
@@ -685,7 +688,7 @@ function addImageTranslations(map, sourceDoc, targetDoc, checks = null) {
|
|
|
685
688
|
// words match, and a text element reads an image value as its words (`merge.js::translatedInline`).
|
|
686
689
|
if (map[key] !== undefined && map[key] !== value && toPlainText(map[key]).trim() !== words) return null
|
|
687
690
|
map[key] = value
|
|
688
|
-
if (checks) checks[key] = saysImage(s, t)
|
|
691
|
+
if (checks) checks[key] = saysImage(s, t, sameFile)
|
|
689
692
|
}
|
|
690
693
|
return map
|
|
691
694
|
}
|
|
@@ -702,13 +705,22 @@ function untranslated(attrs) {
|
|
|
702
705
|
return out
|
|
703
706
|
}
|
|
704
707
|
|
|
705
|
-
// Whether a value, pushed onto the source image, gives it what the pull read.
|
|
706
|
-
|
|
708
|
+
// Whether a value, pushed onto the source image, gives it what the pull read. ⭐ A file of the same
|
|
709
|
+
// bytes as the one read is that file (`sameFile`, `asset-map.js::sameStoredFile`): a backend keeps both
|
|
710
|
+
// as one asset, and the pull reads it back as the first path it knows. ⛔ Until 2026-11-06 a file was
|
|
711
|
+
// its path, and an entry naming its language's copy of the source's image was replaced by its words.
|
|
712
|
+
const IMAGE_FILES = new Set(['src', 'poster', 'preview'])
|
|
713
|
+
function saysImage(source, read, sameFile = null) {
|
|
707
714
|
return (value) => {
|
|
708
715
|
if (typeof value !== 'string') return false
|
|
709
716
|
const given = translatedImage(value)
|
|
710
717
|
if (!given) return false
|
|
711
|
-
return TRANSLATED_IMAGE_ATTRS.every((attr) =>
|
|
718
|
+
return TRANSLATED_IMAGE_ATTRS.every((attr) => {
|
|
719
|
+
const said = given[attr] ?? source[attr] ?? null
|
|
720
|
+
const got = read[attr] ?? null
|
|
721
|
+
if (said === got) return true
|
|
722
|
+
return !!sameFile && IMAGE_FILES.has(attr) && typeof said === 'string' && typeof got === 'string' && sameFile(said, got)
|
|
723
|
+
})
|
|
712
724
|
}
|
|
713
725
|
}
|
|
714
726
|
|
|
@@ -846,7 +858,7 @@ export function unwrapLocalizedContent(content, sourceLocale, collector, freefor
|
|
|
846
858
|
const kept = collector?.keptFreeform?.(locale, freeformCandidates || freeformRelPath) || null
|
|
847
859
|
const checks = {}
|
|
848
860
|
const notes = { cleared: {}, outdated: {} }
|
|
849
|
-
const map = kept ? null : deriveStructuralMap(source, value, modelFor, checks, notes, olderSourceOf(content['@'], locale))
|
|
861
|
+
const map = kept ? null : deriveStructuralMap(source, value, modelFor, checks, notes, olderSourceOf(content['@'], locale), collector?.sameFile ?? null)
|
|
850
862
|
if (map) collector?.addStructuralMap?.(locale, map, context, checks, notes)
|
|
851
863
|
else collector?.noteFreeform?.(locale, value, source, kept || freeformRelPath)
|
|
852
864
|
} else {
|
package/src/uwx/located-media.js
CHANGED
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
* so a site that showed its media under `uniweb dev` and in a static build lost it when published.
|
|
18
18
|
*
|
|
19
19
|
* ⚠️ A file outside both the site's folder and every folder its `paths:` names has no such key, and
|
|
20
|
-
* stays warned and skipped. Two files with the same bytes are one asset
|
|
21
|
-
*
|
|
20
|
+
* stays warned and skipped. Two files with the same bytes are one asset. A pull keeps the path a
|
|
21
|
+
* section, its translations and `site.yml` already name (`asset-map.js::sameStoredFile`). A reference
|
|
22
|
+
* new to the files, and a record's, takes the first path `sync.json` lists.
|
|
22
23
|
*/
|
|
23
24
|
|
|
24
25
|
import { existsSync } from 'node:fs'
|
|
@@ -20,6 +20,7 @@ import { markdownToProseMirror } from '@uniweb/content-reader'
|
|
|
20
20
|
import { parseFrontmatter } from './entity-source.js'
|
|
21
21
|
import { canonicalJson, sameMarkdownDocument } from './same-content.js'
|
|
22
22
|
import { spliceBody } from './body-splice.js'
|
|
23
|
+
import { keepAuthoredRefs } from './asset-map.js'
|
|
23
24
|
import { fileLinksIn } from '../site/file-links.js'
|
|
24
25
|
import { parseNumericPrefix } from '../utils/numeric-prefix.js'
|
|
25
26
|
import { renderEntityDocument } from './backfill.js'
|
|
@@ -184,9 +185,11 @@ function readsTo(body) {
|
|
|
184
185
|
* @param {Set<string>} [opts.reserved] - keys preserved when already present
|
|
185
186
|
* @param {object} [opts.implied] - `{ key: value }` a file means by leaving `key` out; an incoming
|
|
186
187
|
* value equal to it is not written into an existing file that leaves the key out
|
|
188
|
+
* @param {(a: string, b: string) => boolean} [opts.sameFile] - whether two references name the same
|
|
189
|
+
* stored file, read from this file (`asset-map.js::sameStoredFile`)
|
|
187
190
|
* @returns {'updated'|'unchanged'}
|
|
188
191
|
*/
|
|
189
|
-
export function writeSectionFile({ filePath, content, params, declaration, reserved = DEFAULT_RESERVED_FRONTMATTER, implied = null, fileLinks = null }) {
|
|
192
|
+
export function writeSectionFile({ filePath, content, params, declaration, reserved = DEFAULT_RESERVED_FRONTMATTER, implied = null, fileLinks = null, sameFile = null }) {
|
|
190
193
|
let existing = ''
|
|
191
194
|
try {
|
|
192
195
|
existing = readFileSync(filePath, 'utf8')
|
|
@@ -194,6 +197,13 @@ export function writeSectionFile({ filePath, content, params, declaration, reser
|
|
|
194
197
|
// new file
|
|
195
198
|
}
|
|
196
199
|
const { frontmatter, body: existingBody } = parseFrontmatter(existing, filePath)
|
|
200
|
+
// ⭐ A FILE OF THE SAME BYTES AS ONE THIS FILE NAMES IS THAT FILE (`sameFile`, `asset-map.js::sameStoredFile`):
|
|
201
|
+
// a backend keeps both as one asset, and the pull reads it back as the first path it knows, so the
|
|
202
|
+
// file keeps its own. ⛔ Until 2026-11-06 a pull wrote that first path over the author's.
|
|
203
|
+
if (sameFile && existing) {
|
|
204
|
+
if (params) params = keepAuthoredRefs(params, frontmatter, sameFile)
|
|
205
|
+
if (content && existingBody) content = keepAuthoredRefs(content, authoredDocument(existingBody), sameFile)
|
|
206
|
+
}
|
|
197
207
|
|
|
198
208
|
const nextFrontmatter = { ...frontmatter }
|
|
199
209
|
if (params) {
|
|
@@ -244,6 +254,15 @@ export function writeSectionFile({ filePath, content, params, declaration, reser
|
|
|
244
254
|
}
|
|
245
255
|
|
|
246
256
|
|
|
257
|
+
// A body as the push reads it, or null where it cannot be read.
|
|
258
|
+
function authoredDocument(body) {
|
|
259
|
+
try {
|
|
260
|
+
return markdownToProseMirror(body)
|
|
261
|
+
} catch {
|
|
262
|
+
return null
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
247
266
|
// Shallow-merge `changes` into a YAML config file and write idempotently. A key
|
|
248
267
|
// whose value is null/undefined is deleted; an object value is shallow-merged one
|
|
249
268
|
// level deep (so partial `theme` / `build` updates don't drop sibling keys) unless
|
package/src/uwx/site-project.js
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
import { foldOpenGraph } from './open-graph.js'
|
|
37
37
|
import { isAuthoredPreview } from './authored-preview.js'
|
|
38
38
|
import { join, relative, extname, basename, dirname, parse, sep } from 'node:path'
|
|
39
|
-
import { restoreAssetRefs } from './asset-map.js'
|
|
39
|
+
import { restoreAssetRefs, sameStoredFile, keepAuthoredRefs } from './asset-map.js'
|
|
40
40
|
import { mapPageRefs, pageRefIndex, pageRefPages, writtenPageRef } from './page-refs.js'
|
|
41
41
|
import { siteFileKeys, siteTree, writtenRefs } from './located-media.js'
|
|
42
42
|
import { readBackendState, updateBackendState } from './sync-store.js'
|
|
@@ -236,7 +236,7 @@ function readAuthoredYaml(filePath) {
|
|
|
236
236
|
* @returns {{ siteConfig: string, theme?: string, headHtml?: string }} per-file
|
|
237
237
|
* write status ('updated' | 'unchanged')
|
|
238
238
|
*/
|
|
239
|
-
export function siteInfoToConfig({ document, siteRoot, backend = null, sourceLocale = documentSourceLocale(document), collector, keepAuthoredFoundation = false }) {
|
|
239
|
+
export function siteInfoToConfig({ document, siteRoot, backend = null, sourceLocale = documentSourceLocale(document), collector, keepAuthoredFoundation = false, sameFile = null }) {
|
|
240
240
|
const info = document?.info || {}
|
|
241
241
|
const settingsSection = document?.settings || {}
|
|
242
242
|
|
|
@@ -363,7 +363,12 @@ export function siteInfoToConfig({ document, siteRoot, backend = null, sourceLoc
|
|
|
363
363
|
// back where the translation files the pull wrote made the same one, so a clone of a site that
|
|
364
364
|
// declared `languages: [en, fr]` had no `languages:` at all — and followed its translation files
|
|
365
365
|
// where the site it came from had a fixed list.
|
|
366
|
-
|
|
366
|
+
// ⭐ A file of the same bytes as one `site.yml` names is that file (`asset-map.js::sameStoredFile`): a
|
|
367
|
+
// favicon, a preview, a share image stays as the author wrote it.
|
|
368
|
+
const siteYmlPath = join(siteRoot, 'site.yml')
|
|
369
|
+
const authoredSite = sameFile ? readAuthoredYaml(siteYmlPath) : null
|
|
370
|
+
const written = authoredSite ? keepAuthoredRefs(siteChanges, authoredSite, (a, b) => sameFile(a, b, siteYmlPath)) : siteChanges
|
|
371
|
+
const result = { siteConfig: writeSiteConfig(siteRoot, written) }
|
|
367
372
|
|
|
368
373
|
// theme (whole object) → theme.yml.
|
|
369
374
|
if (settingsSection.theme && typeof settingsSection.theme === 'object') {
|
|
@@ -412,7 +417,7 @@ export function siteInfoToConfig({ document, siteRoot, backend = null, sourceLoc
|
|
|
412
417
|
* site (`siteDefaultSectionType`), which a file leaves out
|
|
413
418
|
* @returns {'updated'|'unchanged'}
|
|
414
419
|
*/
|
|
415
|
-
export function sectionRecordToFile({ filePath, record, sourceLocale = LOCALIZED_FIELD_ASSUMPTION.defaultSourceLocale, collector, freeformRelPath, freeformCandidates = null, writeId = true, context = null, dataModel = null, impliedType = DEFAULT_SECTION_TYPE, media = null, fileLinks = null }) {
|
|
420
|
+
export function sectionRecordToFile({ filePath, record, sourceLocale = LOCALIZED_FIELD_ASSUMPTION.defaultSourceLocale, collector, freeformRelPath, freeformCandidates = null, writeId = true, context = null, dataModel = null, impliedType = DEFAULT_SECTION_TYPE, media = null, fileLinks = null, sameFile = null }) {
|
|
416
421
|
// ⛔ A stored `preset` or `input` is not written back: neither has an effect, and the build
|
|
417
422
|
// would only warn about it (2026-09-27).
|
|
418
423
|
// ⛔ No `background` / `theme_override` / `insets` / `fetch`: the site-content Model dropped all
|
|
@@ -460,6 +465,8 @@ export function sectionRecordToFile({ filePath, record, sourceLocale = LOCALIZED
|
|
|
460
465
|
implied: { type: impliedType },
|
|
461
466
|
// The links the file writes as files, as the push reads them (`pageFileTargets`).
|
|
462
467
|
fileLinks,
|
|
468
|
+
// A file of the same bytes as one this file names is that file (`asset-map.js::sameStoredFile`).
|
|
469
|
+
sameFile: sameFile ? (a, b) => sameFile(a, b, filePath) : null,
|
|
463
470
|
})
|
|
464
471
|
}
|
|
465
472
|
|
|
@@ -607,6 +614,7 @@ export function pageSectionsToFiles({ pageDir, pageSections, ctx, pageContext })
|
|
|
607
614
|
writeId: fileSectionName(filePath) !== stableId,
|
|
608
615
|
context: pageContext ? translationContext({ stableId }, pageContext.route) : null,
|
|
609
616
|
media: ctx?.media ?? null,
|
|
617
|
+
sameFile: ctx?.sameFile ?? null,
|
|
610
618
|
fileLinks: ctx?.fileLinks ?? null,
|
|
611
619
|
})
|
|
612
620
|
written.push(filePath)
|
|
@@ -1077,6 +1085,7 @@ function writeMdPage({ record, place, route, ctx, report, pageContext, sourceLoc
|
|
|
1077
1085
|
writeId: stableId !== name,
|
|
1078
1086
|
context: translationContext({ stableId }, pageContext.route),
|
|
1079
1087
|
media: ctx?.media ?? null,
|
|
1088
|
+
sameFile: ctx?.sameFile ?? null,
|
|
1080
1089
|
fileLinks: ctx?.fileLinks ?? null,
|
|
1081
1090
|
})
|
|
1082
1091
|
report.sections.push(place.file)
|
|
@@ -1797,6 +1806,7 @@ function projectLayout(layoutSections, layoutBaseDir, report, prune, ctx) {
|
|
|
1797
1806
|
freeformCandidates: stableId ? freeformPathsFor({ stableId }, page) : null,
|
|
1798
1807
|
context: translationContext({ stableId }, page.route),
|
|
1799
1808
|
media: ctx?.media ?? null,
|
|
1809
|
+
sameFile: ctx?.sameFile ?? null,
|
|
1800
1810
|
})
|
|
1801
1811
|
report.layout.push(filePath)
|
|
1802
1812
|
written.push(filePath)
|
|
@@ -1910,10 +1920,6 @@ export function siteContentDocumentToProject({ document, siteRoot, backend = nul
|
|
|
1910
1920
|
|
|
1911
1921
|
const report = { config: null, collections: null, locales: null, assets: null, pages: [], sections: [], layout: [], deleted: [], renamed: [], leftAlone: [], held: [], mountedPages: [], mountRoutes: [] }
|
|
1912
1922
|
|
|
1913
|
-
// Collects target-locale translations of localized scalars as they're projected;
|
|
1914
|
-
// flushed to locales/{locale}.json at the end (the manifest stays derivable).
|
|
1915
|
-
const collector = createTranslationCollector(sourceLocale, { siteRoot, languages: documentLanguages(document, sourceLocale) })
|
|
1916
|
-
|
|
1917
1923
|
// Put the author's own asset paths back before anything is serialized. Stored
|
|
1918
1924
|
// content carries an id and a serve URL; only the committed map knows the ref
|
|
1919
1925
|
// the author wrote. Without this a push/pull cycle rewrites every image in a
|
|
@@ -1924,7 +1930,14 @@ export function siteContentDocumentToProject({ document, siteRoot, backend = nul
|
|
|
1924
1930
|
// not tied to one has no known assets and restores nothing. Every caller that
|
|
1925
1931
|
// pulls has an origin; the ones that do not are projecting a document in the
|
|
1926
1932
|
// abstract.
|
|
1933
|
+
// ⭐ Two files of the same bytes are one asset, so `restoreAssetRefs` gives every reference to it the
|
|
1934
|
+
// first of their paths, and each writer keeps the one the files name (`sameStoredFile`).
|
|
1927
1935
|
const assetMap = backend ? readBackendState(siteRoot, backend).assets || {} : {}
|
|
1936
|
+
|
|
1937
|
+
// Collects target-locale translations of localized scalars as they're projected;
|
|
1938
|
+
// flushed to locales/{locale}.json at the end (the manifest stays derivable).
|
|
1939
|
+
const collector = createTranslationCollector(sourceLocale, { siteRoot, languages: documentLanguages(document, sourceLocale), sameFile: sameStoredFile(assetMap) })
|
|
1940
|
+
|
|
1928
1941
|
report.assets = restoreAssetRefs(document, assetMap)
|
|
1929
1942
|
// ⭐ And each stored link to a page as the page's path (`page-refs.js`): what a file shows, where
|
|
1930
1943
|
// the store keeps the id an editor links by.
|
|
@@ -1934,7 +1947,7 @@ export function siteContentDocumentToProject({ document, siteRoot, backend = nul
|
|
|
1934
1947
|
// section's writer to make relative to its own file (`located-media.js`).
|
|
1935
1948
|
const mediaKeys = siteFileKeys(assetMap)
|
|
1936
1949
|
|
|
1937
|
-
report.config = siteInfoToConfig({ document, siteRoot, backend, sourceLocale, collector, keepAuthoredFoundation })
|
|
1950
|
+
report.config = siteInfoToConfig({ document, siteRoot, backend, sourceLocale, collector, keepAuthoredFoundation, sameFile: sameStoredFile(assetMap, { siteRoot }) })
|
|
1938
1951
|
report.queries = declarationsToQueriesYml({ document, siteRoot, scope })
|
|
1939
1952
|
|
|
1940
1953
|
// The uuid identity index (gitignored `.uniweb/`): read the prior map to anchor
|
|
@@ -1942,6 +1955,7 @@ export function siteContentDocumentToProject({ document, siteRoot, backend = nul
|
|
|
1942
1955
|
// re-projected (deleted) drop out naturally. `collector` rides along to capture
|
|
1943
1956
|
// localized scalars during the page walk.
|
|
1944
1957
|
const ctx = { siteRoot, oldIndex: readPullIndex(siteRoot), newIndex: {}, report, collector, sourceLocale, sectionFiles: new Map(), dataModel, sectionType, media: mediaKeys.size ? { siteRoot, keys: mediaKeys } : null }
|
|
1958
|
+
ctx.sameFile = sameStoredFile(assetMap, { siteRoot, tree: () => ctx.media?.tree ?? [] })
|
|
1945
1959
|
// Where the site keeps its localized URLs — `site.yml`'s map, when it has one (`pageSlugToYml`).
|
|
1946
1960
|
const siteMap = readAuthoredYaml(join(siteRoot, 'site.yml'))?.i18n?.routeTranslations
|
|
1947
1961
|
ctx.routes = { siteMap: isPlainRecord(siteMap) && Object.keys(siteMap).length ? siteMap : null, slugs: new Map() }
|