@uniweb/build 1.23.7 → 1.23.8

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/README.md CHANGED
@@ -161,9 +161,10 @@ This processing is a static build's (`uniweb build`, `uniweb export`, `uniweb de
161
161
 
162
162
  **Image processing:**
163
163
  - PNG, JPG, JPEG, GIF → A WebP at quality 85 when it is at least 10% smaller, otherwise the file as it is. Either way it is turned upright as the photo's orientation says, keeps its transparency and animation, and loses its location and camera data. A WebP's colour is converted to sRGB with no profile embedded; a kept file keeps its own
164
- - TIFF, HEIC → Always a WebP, since most browsers can't show them (a HEIC this machine can't decode, and a BMP, is copied as it is, with a warning)
164
+ - TIFF, HEIC → Always a WebP, since most browsers can't show them (a HEIC this machine can't decode is copied without its location and camera data, and a BMP as it is, each with a warning)
165
165
  - WebP → Copied without its location and camera data, or turned and made again when its orientation says to turn it
166
- - SVG, AVIF → Copied as-is
166
+ - AVIF → Copied without its location and camera data, its EXIF and XMP zeroed in place
167
+ - SVG → Copied as-is
167
168
  - `public/` is copied as it is beside these copies, so a photo there keeps its metadata in that copy
168
169
  - All processed assets get content-hashed filenames for cache busting
169
170
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/build",
3
- "version": "1.23.7",
3
+ "version": "1.23.8",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -57,11 +57,11 @@
57
57
  "js-yaml": "^4.3.2",
58
58
  "sharp": "^0.35.5",
59
59
  "yaml": "^2.5.0",
60
- "@uniweb/projections": "~1.2.17",
61
60
  "@uniweb/content-reader": "~1.5.10",
62
- "@uniweb/schemas": "~1.7.4",
63
61
  "@uniweb/content-writer": "~1.3.2",
62
+ "@uniweb/schemas": "~1.7.4",
64
63
  "@uniweb/semantic-parser": "~1.13.5",
64
+ "@uniweb/projections": "~1.2.17",
65
65
  "@uniweb/theming": "~1.3.2"
66
66
  },
67
67
  "optionalDependencies": {
@@ -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/runtime": "~1.6.5",
78
- "@uniweb/core": "~1.6.13"
77
+ "@uniweb/core": "~1.6.13",
78
+ "@uniweb/runtime": "~1.6.5"
79
79
  },
80
80
  "peerDependenciesMeta": {
81
81
  "vite": {
@@ -18,7 +18,7 @@ import { existsSync } from 'node:fs'
18
18
  import { join, dirname } from 'node:path'
19
19
  import { createHash } from 'node:crypto'
20
20
 
21
- const MANIFEST_FILENAME = '.manifest.json'
21
+ import { FREEFORM_MANIFEST as MANIFEST_FILENAME } from './locales.js'
22
22
 
23
23
  /**
24
24
  * Compute a hash of a ProseMirror document for staleness detection
@@ -16,6 +16,36 @@ import { normalizeLanguageList, resolveDefaultLocale } from '@uniweb/core/locale
16
16
  export const KEPT_FILE = '_kept.json'
17
17
  export const RESERVED_LOCALE_FILES = new Set(['manifest.json', '_memory.json', KEPT_FILE])
18
18
 
19
+ // Where record translations are kept, inside the locales directory: `locales/records/`.
20
+ export const RECORD_LOCALES_DIR = 'records'
21
+
22
+ // A free-form language's record of the source each of its bodies was translated from:
23
+ // `locales/freeform/{locale}/.manifest.json`.
24
+ export const FREEFORM_MANIFEST = '.manifest.json'
25
+
26
+ /**
27
+ * The files in a site's translations directory that are its tools' own, never part of what a push
28
+ * sends, as paths from the site (POSIX; `*` stands for a language): each reserved file but
29
+ * `_kept.json`, which a push sends back, beside the site's translations and its records', and each
30
+ * free-form language's manifest.
31
+ *
32
+ * ⭐ A CHANGE TO ONE IS NOT A CHANGE THE BACKEND LACKS. `i18n extract` refreshes `manifest.json`, and
33
+ * a commit that only did that was taken for a records change: a pull's merge then started from an older
34
+ * sync point than the one the backend named, and a teammate's own published work came back as the
35
+ * app's, in conflict with itself (measured on a site's pull, 2026-11-12).
36
+ *
37
+ * @param {string} [dir] - the translations directory, from the site
38
+ * @returns {string[]}
39
+ */
40
+ export function unsentTranslationFiles(dir = 'locales') {
41
+ const own = [...RESERVED_LOCALE_FILES].filter((f) => f !== KEPT_FILE)
42
+ return [
43
+ ...own.map((f) => `${dir}/${f}`),
44
+ ...own.map((f) => `${dir}/${RECORD_LOCALES_DIR}/${f}`),
45
+ `${dir}/freeform/*/${FREEFORM_MANIFEST}`,
46
+ ]
47
+ }
48
+
19
49
  /**
20
50
  * The locales a directory holds translations for — one per `<locale>.json` — sorted.
21
51
  *
@@ -13,7 +13,7 @@
13
13
  */
14
14
 
15
15
  import { readFile, writeFile, readdir, mkdir, rm } from 'fs/promises'
16
- import { RESERVED_LOCALE_FILES } from './locales.js'
16
+ import { RESERVED_LOCALE_FILES, RECORD_LOCALES_DIR } from './locales.js'
17
17
  import { existsSync } from 'node:fs'
18
18
  import { join, resolve, sep } from 'node:path'
19
19
  import { DATA_DIR, resolveDefaultLocale } from '@uniweb/core'
@@ -55,7 +55,7 @@ import {
55
55
  // ⚠️ `RECORD_LOCALES_DIR`, and not `RECORDS_DIR`, since 2026-09-21: that name is the
56
56
  // site's own `records/` directory now (`site/entity-pool.js`), and this one is
57
57
  // `locales/records/` — two directories, one word, so the constant says which.
58
- export const RECORD_LOCALES_DIR = 'records'
58
+ export { RECORD_LOCALES_DIR }
59
59
 
60
60
  // ---------------------------------------------------------------------------
61
61
  // A record's model — what a push sends it as
@@ -15,17 +15,17 @@
15
15
  * kept but needs turning is converted instead, so no picture a page draws depends on a tag to
16
16
  * stand up.
17
17
  * 5. **Location and camera data are dropped**, from a kept file too, which loses them without being
18
- * re-encoded (`withoutPrivateMetadata`). Its orientation stays, alone, since that is what turns
19
- * it. **A WebP's colour is converted to sRGB, with no profile embedded**, as a host converting a
18
+ * re-encoded (`withoutPrivateMetadata`), a HEIC this machine can't decode and an AVIF included.
19
+ * Its orientation stays, alone, since that is what turns it. **A WebP's colour is converted to sRGB, with no profile embedded**, as a host converting a
20
20
  * picture that wasn't prepared does, so the two agree: a phone's Display P3 photo keeps its
21
21
  * colours, managed into sRGB, and loses the wider gamut. A kept file keeps its own profile, since
22
22
  * it isn't re-encoded and dropping the profile alone would shift its colours.
23
23
  * 6. **No size cap.** A prepared file is the only copy kept, so it keeps its pixels.
24
24
  * 7. **Which files.** JPEG, PNG, GIF, TIFF, HEIC and BMP are converted under the keep test. A WebP is
25
- * kept without its location and camera data, unless its EXIF says to turn it. SVG, ICO and AVIF
26
- * are left as they are, an AVIF's metadata included. A file this machine can't decode (HEIC with
27
- * HEVC, and BMP, which sharp's builds don't read) is left as it is and reported `unreadable`, for
28
- * its caller to say so.
25
+ * kept without its location and camera data, unless its EXIF says to turn it, and so is an AVIF.
26
+ * SVG and ICO are left as they are. A file this machine can't decode (HEIC with HEVC, and BMP,
27
+ * which sharp's builds don't read) is kept without its private data and reported `unreadable`,
28
+ * for its caller to say so.
29
29
  * 8. **A picture other software fetches by its address** (`keepFormat`: a favicon, a touch icon, a
30
30
  * social image) stays in its format, since a home screen takes a PNG and a link preview a JPEG or
31
31
  * PNG. It only loses its location and camera data.
@@ -49,7 +49,7 @@ export const IMAGE_RULE = Object.freeze({
49
49
  })
50
50
 
51
51
  /** Formats the rule prepares, by extension. */
52
- const PREPARED = new Set(['jpg', 'jpeg', 'png', 'gif', 'tif', 'tiff', 'heic', 'heif', 'bmp', 'webp'])
52
+ const PREPARED = new Set(['jpg', 'jpeg', 'png', 'gif', 'tif', 'tiff', 'heic', 'heif', 'bmp', 'webp', 'avif'])
53
53
 
54
54
  /** Formats every browser draws: kept when the WebP saves too little. */
55
55
  const DRAWN_EVERYWHERE = new Set(['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'])
@@ -82,7 +82,8 @@ export async function prepareImage(bytes, ext, { quality = IMAGE_RULE.quality, k
82
82
  const kind = extOf(ext)
83
83
  if (!PREPARED.has(kind)) return { bytes, ext: kind, converted: false }
84
84
  const kept = () => ({ bytes: withoutPrivateMetadata(bytes, kind), ext: kind, converted: false })
85
- if (keepFormat || (kind === 'png' && isAnimatedPng(bytes))) return kept()
85
+ // An AVIF is drawn everywhere already, and its turn is a property of the image, not a tag.
86
+ if (keepFormat || kind === 'avif' || (kind === 'png' && isAnimatedPng(bytes))) return kept()
86
87
 
87
88
  let meta
88
89
  let webp
@@ -101,7 +102,7 @@ export async function prepareImage(bytes, ext, { quality = IMAGE_RULE.quality, k
101
102
  // nothing here could read, is reported, since a page may not show it.
102
103
  const drawn = DRAWN_EVERYWHERE.has(kind)
103
104
  return {
104
- bytes: drawn ? withoutPrivateMetadata(bytes, kind) : bytes,
105
+ bytes: withoutPrivateMetadata(bytes, kind),
105
106
  ext: kind,
106
107
  converted: false,
107
108
  ...(drawn && meta ? {} : { unreadable: true }),
@@ -126,6 +127,8 @@ export async function prepareImage(bytes, ext, { quality = IMAGE_RULE.quality, k
126
127
  * after the image data turns nothing in a browser, so its orientation goes with it.
127
128
  * - **WebP:** drops its `EXIF` and `XMP ` chunks and the flags that announce them, and keeps every
128
129
  * other chunk.
130
+ * - **HEIC, AVIF:** zeroes the bytes of its EXIF and XMP items where they lie (`stripHeif`), every
131
+ * size and offset unchanged, its colour profile and turn untouched.
129
132
  * - Anything else, or a file that doesn't parse as its format, is returned as it is.
130
133
  *
131
134
  * @param {Buffer} bytes
@@ -137,6 +140,7 @@ export function withoutPrivateMetadata(bytes, ext) {
137
140
  if (kind === 'jpg' || kind === 'jpeg') return stripJpeg(bytes) ?? bytes
138
141
  if (kind === 'png') return stripPng(bytes) ?? bytes
139
142
  if (kind === 'webp') return stripWebp(bytes) ?? bytes
143
+ if (kind === 'heic' || kind === 'heif' || kind === 'avif') return stripHeif(bytes) ?? bytes
140
144
  return bytes
141
145
  }
142
146
 
@@ -312,6 +316,131 @@ function isAnimatedPng(buf) {
312
316
  return animated
313
317
  }
314
318
 
319
+ // ── HEIF: HEIC and AVIF ──────────────────────────────────────────────────────────────────────────
320
+
321
+ /** An ISOBMFF box at `at`: its type and where its payload starts and ends, or null past `end`. */
322
+ function isoBox(buf, at, end) {
323
+ if (at + 8 > end) return null
324
+ let size = buf.readUInt32BE(at)
325
+ let head = 8
326
+ if (size === 1) {
327
+ if (at + 16 > end) return null
328
+ size = Number(buf.readBigUInt64BE(at + 8))
329
+ head = 16
330
+ } else if (size === 0) size = end - at
331
+ if (size < head || at + size > end) return null
332
+ return { type: buf.toString('latin1', at + 4, at + 8), start: at + head, end: at + size }
333
+ }
334
+
335
+ /** Every box between `from` and `end`, or null when one doesn't parse. */
336
+ function isoBoxes(buf, from, end) {
337
+ const boxes = []
338
+ for (let at = from; at < end; ) {
339
+ const box = isoBox(buf, at, end)
340
+ if (!box) return null
341
+ boxes.push(box)
342
+ at = box.end
343
+ }
344
+ return boxes
345
+ }
346
+
347
+ /** An unsigned number of 0, 2, 4 or 8 bytes, as an `iloc` box sizes its fields. */
348
+ function readSized(buf, at, size) {
349
+ if (size === 0) return 0
350
+ if (size === 2) return buf.readUInt16BE(at)
351
+ if (size === 4) return buf.readUInt32BE(at)
352
+ if (size === 8) return Number(buf.readBigUInt64BE(at))
353
+ return NaN
354
+ }
355
+
356
+ /** The ids of a HEIF file's private items: its EXIF, and XMP stored as a `mime` item. */
357
+ function privateHeifItems(buf, iinf) {
358
+ const version = buf[iinf.start]
359
+ const first = iinf.start + 4 + (version === 0 ? 2 : 4)
360
+ const entries = isoBoxes(buf, first, iinf.end)
361
+ if (!entries) return null
362
+ const ids = new Set()
363
+ for (const infe of entries) {
364
+ if (infe.type !== 'infe') continue
365
+ const v = buf[infe.start]
366
+ if (v < 2) continue // versions 0 and 1 name no item type
367
+ let at = infe.start + 4
368
+ const id = v === 2 ? buf.readUInt16BE(at) : buf.readUInt32BE(at)
369
+ at += (v === 2 ? 2 : 4) + 2 // the id, then its protection index
370
+ const type = buf.toString('latin1', at, at + 4)
371
+ at += 4
372
+ const nameEnd = buf.indexOf(0, at)
373
+ if (nameEnd < 0 || nameEnd >= infe.end) continue
374
+ if (type === 'Exif') ids.add(id)
375
+ if (type === 'mime') {
376
+ const contentEnd = buf.indexOf(0, nameEnd + 1)
377
+ const content = buf.toString('latin1', nameEnd + 1, contentEnd < 0 ? infe.end : Math.min(contentEnd, infe.end))
378
+ if (/xmp|rdf\+xml/i.test(content)) ids.add(id)
379
+ }
380
+ }
381
+ return ids
382
+ }
383
+
384
+ /**
385
+ * A HEIF file (a HEIC or an AVIF) without its EXIF and XMP. Each is an item whose bytes lie in
386
+ * `mdat` or `idat`, where `iloc` says; those bytes are zeroed in place, so no size or offset moves.
387
+ * The picture's colour profile (`colr`) and turn (`irot`) are properties of the image item, which
388
+ * this leaves alone, and an item's EXIF is not what turns a HEIF picture. Null when the file doesn't
389
+ * parse, or an item's place can't be read.
390
+ */
391
+ function stripHeif(buf) {
392
+ const top = isoBoxes(buf, 0, buf.length)
393
+ const meta = top?.find((b) => b.type === 'meta')
394
+ if (!meta) return null
395
+ const children = isoBoxes(buf, meta.start + 4, meta.end)
396
+ if (!children) return null
397
+ const iinf = children.find((b) => b.type === 'iinf')
398
+ const iloc = children.find((b) => b.type === 'iloc')
399
+ const idat = children.find((b) => b.type === 'idat')
400
+ if (!iinf || !iloc) return null
401
+ const ids = privateHeifItems(buf, iinf)
402
+ if (!ids) return null
403
+ if (ids.size === 0) return buf
404
+
405
+ const out = Buffer.from(buf)
406
+ const version = buf[iloc.start]
407
+ let at = iloc.start + 4
408
+ const offsetSize = buf[at] >> 4
409
+ const lengthSize = buf[at] & 15
410
+ const baseSize = buf[at + 1] >> 4
411
+ const indexSize = version === 1 || version === 2 ? buf[at + 1] & 15 : 0
412
+ at += 2
413
+ const wide = version === 2
414
+ const count = wide ? buf.readUInt32BE(at) : buf.readUInt16BE(at)
415
+ at += wide ? 4 : 2
416
+ for (let i = 0; i < count; i++) {
417
+ if (at > iloc.end) return null
418
+ const id = wide ? buf.readUInt32BE(at) : buf.readUInt16BE(at)
419
+ at += wide ? 4 : 2
420
+ const method = version === 1 || version === 2 ? buf.readUInt16BE(at) & 15 : 0
421
+ if (version === 1 || version === 2) at += 2
422
+ at += 2 // the data reference index
423
+ const base = readSized(buf, at, baseSize)
424
+ at += baseSize
425
+ const extents = buf.readUInt16BE(at)
426
+ at += 2
427
+ for (let e = 0; e < extents; e++) {
428
+ at += indexSize
429
+ const offset = readSized(buf, at, offsetSize)
430
+ at += offsetSize
431
+ const length = readSized(buf, at, lengthSize)
432
+ at += lengthSize
433
+ if (!ids.has(id)) continue
434
+ // Where the item's bytes are: in the file (method 0) or in `idat` (method 1). A length of 0
435
+ // would mean "to the end", which is never a metadata item's, so it is left alone.
436
+ const from = method === 0 ? base + offset : method === 1 && idat ? idat.start + base + offset : NaN
437
+ if (!Number.isFinite(from) || !(length > 0) || from + length > out.length) return null
438
+ out.fill(0, from, from + length)
439
+ }
440
+ }
441
+ return out
442
+ }
443
+
315
444
  // ── WebP ─────────────────────────────────────────────────────────────────────────────────────────
316
445
 
317
446
  /** The flags in a `VP8X` chunk that say an `EXIF` and an `XMP ` chunk follow. */
@@ -25,6 +25,7 @@ import { resolveQueriesConfig, toConfigQueries, dataKeyTyping, foundationSection
25
25
  import { isSectionKey } from '@uniweb/schemas/section'
26
26
  import { parseNumericPrefix, compareByNumericPrefix } from '../utils/numeric-prefix.js'
27
27
  import { isMarkdownFile, isIgnoredFolder } from '../utils/content-files.js'
28
+ import { sectionFilesNamedTwice, describeSectionsNamedTwice } from './section-files.js'
28
29
  import { readLayoutFolder, DEFAULT_LAYOUT, layoutAreaRoute } from './layout-folder.js'
29
30
  import { mountEntriesOf } from './mount-entries.js'
30
31
  import { basename, join, parse, relative, resolve, sep } from 'node:path'
@@ -1626,6 +1627,17 @@ async function processPage(pagePath, pageName, siteRoot, { isIndex = false, pare
1626
1627
  }
1627
1628
  }
1628
1629
 
1630
+ // ⛔ One section, one file: `1-lost.md` beside `lost.md` is the section `lost` twice, which a merge
1631
+ // leaves without a word (`section-files.js`). A build draws both, so it says so and goes on, as a
1632
+ // build does; a push refuses the page (`sync-package.js`), and a pull names it after its merge.
1633
+ const twice = sectionFilesNamedTwice(await readdir(pagePath))
1634
+ if (twice.length) {
1635
+ console.warn(
1636
+ `[content-collector] ${describeSectionsNamedTwice(relative(siteRoot, pagePath).split(sep).join('/'), twice)}. ` +
1637
+ 'A number orders a section and never names it, so a push refuses this page: give each its own name, or keep one.'
1638
+ )
1639
+ }
1640
+
1629
1641
  let hierarchicalSections = []
1630
1642
  let pageAssetCollection = {
1631
1643
  assets: {},
package/src/site/index.js CHANGED
@@ -59,4 +59,6 @@ export {
59
59
  mergeDataIntoContent
60
60
  } from './data-fetcher.js'
61
61
  export { loadDeployYml, resolveTarget, resolvePublishTarget } from './deploy-config.js'
62
+ // One section, one file: what a page holds twice, for the build and a pull to say alike.
63
+ export { sectionFilesNamedTwice, describeSectionsNamedTwice } from './section-files.js'
62
64
  export { recordLastDeploy, recordTarget, forgetDeploys, forgetDeployYml, retireDeployYmlKeys } from './deploy-config-writer.js'
@@ -0,0 +1,51 @@
1
+ /**
2
+ * ONE SECTION, ONE FILE.
3
+ *
4
+ * A section's name is its file's stem without the number that orders it (`parseNumericPrefix`):
5
+ * `1-lost.md` holds the section `lost`, and so does `lost.md`. Two such files in one page are one
6
+ * section twice. A merge leaves them side by side without a word when each side added the section
7
+ * under its own name, and the page then shows it twice. A build draws both and says so: a static site
8
+ * has nothing to lose by it, and a site build gives a note, never a gate. A push refuses the page
9
+ * (`uwx/sync-package.js`), since a synced site's sections are known by their names, and a pull names
10
+ * both files the moment its merge leaves them (`uniweb pull`).
11
+ *
12
+ * ⛔ That happened on 2026-11-12. A pull merged a teammate's `pages/404/1-lost.md` with the backend's
13
+ * `pages/404/lost.md`, the same hero, and nothing said so: it was found by looking at the files.
14
+ *
15
+ * A child section keeps its `@` apart: `@card.md` is a child, `card.md` a section of the page's own.
16
+ */
17
+ import { parseNumericPrefix } from '../utils/numeric-prefix.js'
18
+ import { isMarkdownFile } from '../utils/content-files.js'
19
+
20
+ /**
21
+ * The sections a page directory holds in more than one file.
22
+ *
23
+ * @param {string[]} files - the directory's entries
24
+ * @returns {Array<{ name: string, files: string[] }>} each such section, `@` kept for a child, its files sorted
25
+ */
26
+ export function sectionFilesNamedTwice(files) {
27
+ const byName = new Map()
28
+ for (const file of files) {
29
+ if (!isMarkdownFile(file)) continue
30
+ const stem = file.slice(0, -'.md'.length)
31
+ const at = stem.match(/^@+/)?.[0] || ''
32
+ const bare = stem.slice(at.length)
33
+ const key = `${at}${parseNumericPrefix(bare).name || bare}`
34
+ if (!byName.has(key)) byName.set(key, [])
35
+ byName.get(key).push(file)
36
+ }
37
+ return [...byName].filter(([, list]) => list.length > 1).map(([name, list]) => ({ name, files: list.sort() }))
38
+ }
39
+
40
+ /**
41
+ * Say which sections a page holds twice, in the words the build and a pull both use.
42
+ *
43
+ * @param {string} dir - the page's directory, as the person knows it (`pages/404`)
44
+ * @param {Array<{ name: string, files: string[] }>} twice - `sectionFilesNamedTwice`'s answer
45
+ * @returns {string}
46
+ */
47
+ export function describeSectionsNamedTwice(dir, twice) {
48
+ return twice
49
+ .map(({ name, files }) => `${dir} holds the section "${name.replace(/^@+/, '')}" in ${files.length} files: ${files.join(', ')}`)
50
+ .join('\n')
51
+ }
@@ -29,10 +29,9 @@ import { ASSET_SLOTS } from '@uniweb/semantic-parser'
29
29
  import { computeSourceHash, manifestText } from '../i18n/freeform-manifest.js'
30
30
  import { sameMarkdownDocument, canonicalJson } from './same-content.js'
31
31
  import { parseFrontmatter } from '../utils/frontmatter.js'
32
- import { KEPT_FILE, RESERVED_LOCALE_FILES } from '../i18n/locales.js'
32
+ import { KEPT_FILE, RESERVED_LOCALE_FILES, FREEFORM_MANIFEST } from '../i18n/locales.js'
33
33
  import { isSmallEdit, wordOverlap } from '../i18n/word-overlap.js'
34
34
 
35
- const FREEFORM_MANIFEST = '.manifest.json'
36
35
 
37
36
  // The directory a site keeps its translations in — `site.yml`'s `i18n.localesDir`, else `locales`,
38
37
  // the rule the build and `uniweb i18n` read it by — for the push and the pull alike. `subdir` scopes a
@@ -32,7 +32,7 @@
32
32
  // site-content uuid. Nothing is silently dropped: an unplaceable or unresolvable
33
33
  // record is reported.
34
34
 
35
- import { readBackendState, updateBackendMap } from './sync-store.js'
35
+ import { readBackendState, updateBackendMap, setBackendMap } from './sync-store.js'
36
36
  import { restoreAssetRefs } from './asset-map.js'
37
37
  import { documentSchema } from './entity-document.js'
38
38
  import { readFileSync, readdirSync, existsSync, unlinkSync, writeFileSync } from 'node:fs'
@@ -105,6 +105,37 @@ export function findRecordFileByUuid(poolDir, uuid) {
105
105
  return null
106
106
  }
107
107
 
108
+ /**
109
+ * Every single-record file under the records directory, by the own id it holds — a mounted type's
110
+ * folder left out, since its files are another site's. A list file (BibTeX) is no single record.
111
+ *
112
+ * @returns {Map<string, string>} own id → path
113
+ */
114
+ function recordFilesByOwnId(recordsRoot, mountedDirs) {
115
+ const byOwnId = new Map()
116
+ const walk = (dir) => {
117
+ let entries
118
+ try {
119
+ entries = readdirSync(dir, { withFileTypes: true })
120
+ } catch {
121
+ return
122
+ }
123
+ for (const e of entries) {
124
+ if (e.name.startsWith('_') || e.name.startsWith('.')) continue
125
+ const path = join(dir, e.name)
126
+ if (e.isDirectory()) {
127
+ if (!mountedDirs.has(resolve(path))) walk(path)
128
+ continue
129
+ }
130
+ const format = formatForExt(extname(e.name).toLowerCase())
131
+ const own = format ? readFileUuid(path, format) : null
132
+ if (typeof own === 'string' && own && !byOwnId.has(own)) byOwnId.set(own, path)
133
+ }
134
+ }
135
+ walk(recordsRoot)
136
+ return byOwnId
137
+ }
138
+
108
139
  // ⭐ A RECORD KEPT IN A BIBTEX FILE — several entries in one — is found by its entry's `$uuid`, so
109
140
  // a pull does not write it again as a file of its own beside the list. ⛔ Until 2026-09-27 a JSON or
110
141
  // YAML array was such a list too; a file holds one record now (`site/record-file.js`).
@@ -738,7 +769,9 @@ function holdsPattern(abs) {
738
769
  * @param {{ own: Set<string>|null, keyTypes: Map<string, string>|null }} [params.opts.foundation] - what the
739
770
  * site's foundation declares, as `readSiteFoundationDeclarations` reads it; absent, its built schema
740
771
  * @param {string} [params.opts.sourceLocale]
741
- * @returns {{ updated: string[], placed: string[], unchanged: string[], skipped: object[], warnings: string[], locales: object }}
772
+ * @param {boolean} [params.opts.prune] - remove the file of a record this backend held and no longer
773
+ * holds, and its mapping: a record removed in the app (`removed`)
774
+ * @returns {{ updated: string[], placed: string[], unchanged: string[], removed: string[], skipped: object[], warnings: string[], locales: object }}
742
775
  */
743
776
  export function recordsToProject({ folderDoc, recordDocs = [], siteRoot, opts = {} }) {
744
777
  // The site's language, as its `site.yml` says it — written by the pull of the site's content, which
@@ -956,6 +989,42 @@ export function recordsToProject({ folderDoc, recordDocs = [], siteRoot, opts =
956
989
  for (const [theirs, rel] of pulledFiles.pathByUuid) poolPathByUuid.set(theirs, rel)
957
990
  warnings.push(...pulledFiles.warnings)
958
991
 
992
+ // ⭐ A RECORD REMOVED IN THE APP IS REMOVED HERE (`opts.prune`), as a page or a section is. A record
993
+ // this backend held — its own id mapped to the entity it became — and no longer holds anywhere in the
994
+ // folder it answered with was removed there: its file goes, and its mapping with it, so a file kept
995
+ // anyway goes up as a new record on the next push. In a repository the pull writes this onto its
996
+ // stand-in, so git merges the removal, or stops on it where the record was changed here too. A record
997
+ // never pushed to this backend has no mapping and is never touched, and a pull that took no folder
998
+ // removes nothing. ⛔ Until 2026-11-13 the file stayed, and a push called it unchanged, since nothing
999
+ // in it had changed: a record its owner deleted in the app stayed in a static build of the same files,
1000
+ // and the copy and the site disagreed with nothing to say so (measured on a site, 2026-11-12).
1001
+ const removed = []
1002
+ if (opts.prune && folderDoc && opts.backend) {
1003
+ const held = new Set([...recordDocs.map((d) => d?.$uuid).filter(Boolean), ...folderIndex.keys(), ...poolPathByUuid.keys()])
1004
+ const goneOwnIds = Object.entries(recordMap)
1005
+ .filter(([, theirs]) => typeof theirs === 'string' && theirs && !held.has(theirs))
1006
+ .map(([own]) => own)
1007
+ if (goneOwnIds.length && !held.size) {
1008
+ // ⛔ AN ANSWER HOLDING NO RECORD REMOVES NONE, as an empty level of pages removes none
1009
+ // (`site-project.js`), so a malformed or partial answer can't empty the records directory. Said,
1010
+ // since a site whose records were all removed in the app still has them in its files.
1011
+ warnings.push(
1012
+ `the backend's folder holds no records, so this pull removed none of the ${goneOwnIds.length} this copy has pushed. ` +
1013
+ 'If they were all removed in the app, delete their files'
1014
+ )
1015
+ } else if (goneOwnIds.length) {
1016
+ const files = recordFilesByOwnId(recordsRoot, new Set(mounts.map((m) => resolve(m.at))))
1017
+ for (const own of goneOwnIds) {
1018
+ const path = files.get(own)
1019
+ if (!path) continue
1020
+ unlinkSync(path)
1021
+ removed.push(path)
1022
+ }
1023
+ const gone = new Set(goneOwnIds)
1024
+ setBackendMap(siteRoot, opts.backend, 'records', Object.fromEntries(Object.entries(recordMap).filter(([own]) => !gone.has(own))))
1025
+ }
1026
+ }
1027
+
959
1028
  const records = folderToFolderYml({ folderDoc, siteRoot, poolPathByUuid, sourceLocale })
960
1029
  warnings.push(...records.warnings)
961
1030
  for (const path of keptBib) {
@@ -977,7 +1046,7 @@ export function recordsToProject({ folderDoc, recordDocs = [], siteRoot, opts =
977
1046
  }
978
1047
 
979
1048
  return {
980
- updated, placed, unchanged, skipped, warnings, locales, freeform, records: records.status, recordsFile: records.file,
1049
+ updated, placed, unchanged, removed, skipped, warnings, locales, freeform, records: records.status, recordsFile: records.file,
981
1050
  // The file records' bytes to fetch — `{ url, path, poolPath }` each (`./file-records.js`).
982
1051
  fileDownloads: pulledFiles.downloads,
983
1052
  // Mounted records, another site's files, which this pull read and left as they are.
@@ -5,6 +5,7 @@
5
5
 
6
6
  import { join, relative, resolve, sep } from 'node:path'
7
7
  import { mountEntriesOf } from '../site/mount-entries.js'
8
+ import { unsentTranslationFiles } from '../i18n/locales.js'
8
9
 
9
10
  /**
10
11
  * `site.yml::paths.pages` / `paths.layout`, else `pages/` and `layout/` — resolved
@@ -38,7 +39,8 @@ export function siteContentDirs(siteRoot, siteYml) {
38
39
  * mount's may lead out of it (`../docs`):
39
40
  *
40
41
  * - `config`: `site.yml`, `theme.yml`, `head.html`, `queries.yml`;
41
- * - `translations`: `locales`;
42
+ * - `translations`: `site.yml`'s `i18n.localesDir`, else `locales`, with `unsent`: the files there a push
43
+ * never sends, its tools' own (`unsentTranslationFiles`);
42
44
  * - `pages`, `layout`, `records`: where `paths:` puts them, else their own names;
43
45
  * - `media`: `public`, where the files a page names are kept;
44
46
  * - `mount`: each `paths: { pages/<segment>: <dir> }` folder, with its `segment` and `abs`.
@@ -53,7 +55,11 @@ export function siteContentDirs(siteRoot, siteYml) {
53
55
  *
54
56
  * @param {string} siteRoot
55
57
  * @param {object|null} siteYml - the parsed `site.yml`
56
- * @returns {Array<{ path: string, kind: 'config'|'translations'|'pages'|'layout'|'records'|'media'|'mount', segment?: string, abs: string }>}
58
+ * ⛔ Until 2026-11-13 the translations were always `locales`, whatever `i18n.localesDir` said, while the
59
+ * push read them where it said: a site that moved them had its translations outside what a push
60
+ * checks is committed, what `uniweb status` counts, and what a pull merges.
61
+ *
62
+ * @returns {Array<{ path: string, kind: 'config'|'translations'|'pages'|'layout'|'records'|'media'|'mount', segment?: string, abs: string, unsent?: string[] }>}
57
63
  */
58
64
  export function siteContentRoots(siteRoot, siteYml) {
59
65
  const paths = siteYml?.paths
@@ -63,7 +69,9 @@ export function siteContentRoots(siteRoot, siteYml) {
63
69
  }
64
70
  const roots = []
65
71
  for (const file of ['site.yml', 'theme.yml', 'head.html', 'queries.yml']) roots.push({ ...at(file), kind: 'config' })
66
- roots.push({ ...at('locales'), kind: 'translations' })
72
+ const localesDir = typeof siteYml?.i18n?.localesDir === 'string' && siteYml.i18n.localesDir.trim() ? siteYml.i18n.localesDir.trim() : 'locales'
73
+ const translations = at(localesDir)
74
+ roots.push({ ...translations, kind: 'translations', unsent: unsentTranslationFiles(translations.path) })
67
75
  roots.push({ ...at(paths?.pages || 'pages'), kind: 'pages' })
68
76
  roots.push({ ...at(paths?.layout || 'layout'), kind: 'layout' })
69
77
  roots.push({ ...at(paths?.records || 'records'), kind: 'records' })
@@ -125,9 +125,10 @@ const isReadersText = (node, key) => key === 'text' && node.type === 'text'
125
125
  /**
126
126
  * The site-root pictures that software other than the site's pages fetches by their address: the
127
127
  * favicon, the touch icon a phone puts on its home screen, the site's card picture (`info.preview`),
128
- * and every social image (`seo`, the site's and each page's). A push uploads them as they are,
129
- * because what fetches them takes a PNG icon or a JPEG or PNG picture, not the WebP a page's
130
- * picture is prepared to.
128
+ * and every social image (`seo`, the site's and each page's). A push uploads them in their own
129
+ * format, without their location and camera data (`prepareImage`'s `keepFormat`), because what
130
+ * fetches them takes a PNG icon or a JPEG or PNG picture, not the WebP a page's picture is prepared
131
+ * to. ⛔ Until 2026-11-12 they went up exactly as they were, location included.
131
132
  *
132
133
  * @param {object|null} siteDoc - the site-content document
133
134
  * @returns {Set<string>}