@uniweb/build 1.10.14 → 1.11.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 +7 -7
- package/src/i18n/extract.js +71 -0
- package/src/i18n/merge.js +75 -3
- package/src/site/advanced-processors.js +15 -57
- package/src/site/asset-processor.js +12 -3
- package/src/site/assets.js +34 -23
- package/src/site/build-site-data.js +2 -3
- package/src/site/content-collector.js +10 -14
- package/src/site/dev-media.js +49 -0
- package/src/site/icons.js +10 -37
- package/src/site/plugin.js +27 -35
- package/src/uwx/authored-preview.js +24 -0
- package/src/uwx/index.js +3 -0
- package/src/uwx/locale-sync.js +57 -3
- package/src/uwx/located-media.js +150 -0
- package/src/uwx/site-project.js +36 -17
- package/src/uwx/site.js +44 -40
- package/src/uwx/sync-package.js +23 -7
- package/src/validate-data.js +10 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -56,15 +56,15 @@
|
|
|
56
56
|
"js-yaml": "^4.3.2",
|
|
57
57
|
"sharp": "^0.35.5",
|
|
58
58
|
"yaml": "^2.5.0",
|
|
59
|
+
"@uniweb/schemas": "~1.6.5",
|
|
59
60
|
"@uniweb/content-reader": "~1.5.7",
|
|
60
|
-
"@uniweb/projections": "~1.2.7",
|
|
61
|
-
"@uniweb/content-writer": "~1.3.1",
|
|
62
|
-
"@uniweb/semantic-parser": "~1.13.0",
|
|
63
61
|
"@uniweb/theming": "~1.2.1",
|
|
64
|
-
"@uniweb/
|
|
62
|
+
"@uniweb/semantic-parser": "~1.13.0",
|
|
63
|
+
"@uniweb/content-writer": "~1.3.1",
|
|
64
|
+
"@uniweb/projections": "~1.2.7"
|
|
65
65
|
},
|
|
66
66
|
"optionalDependencies": {
|
|
67
|
-
"@uniweb/runtime": "~1.2.
|
|
67
|
+
"@uniweb/runtime": "~1.2.13"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@vitejs/plugin-react": "^4.0.0 || ^5.0.0",
|
|
75
75
|
"vite-plugin-svgr": "^4.0.0",
|
|
76
76
|
"@uniweb/core": "~1.4.12",
|
|
77
|
-
"@uniweb/runtime": "~1.2.
|
|
77
|
+
"@uniweb/runtime": "~1.2.13"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"vite": {
|
package/src/i18n/extract.js
CHANGED
|
@@ -172,6 +172,7 @@ function extractFromSection(section, pageRoute, units, dataModel = null) {
|
|
|
172
172
|
if (section.content?.type === 'doc') {
|
|
173
173
|
extractFromProseMirrorDoc(section.content, context, units)
|
|
174
174
|
extractFromDataBlocks(section.content, context, units, (tag) => dataModel?.(section.type, tag) ?? null)
|
|
175
|
+
extractFromImages(section.content, context, units)
|
|
175
176
|
}
|
|
176
177
|
|
|
177
178
|
// Recursively process subsections
|
|
@@ -236,6 +237,76 @@ export function dataBlockNodes(doc) {
|
|
|
236
237
|
return out
|
|
237
238
|
}
|
|
238
239
|
|
|
240
|
+
/**
|
|
241
|
+
* A section's IMAGES, one unit each, keyed by its alt text (2026-10-28). The translation of one is
|
|
242
|
+
* words — its alt text in that language — or an image, which also names that language's files:
|
|
243
|
+
* `` (`merge.js::translateImages`).
|
|
244
|
+
*
|
|
245
|
+
* Keyed by the alt text alone, as every unit is keyed by its words (`hash.js`): the file is not in
|
|
246
|
+
* the key because the build, the dev server and a push each hold a different address for it by the
|
|
247
|
+
* time they translate. So two images with the same alt text share a translation, and a place that
|
|
248
|
+
* needs another one takes an override.
|
|
249
|
+
*
|
|
250
|
+
* ⭐ Separate from `extractFromProseMirrorDoc` for the reason `extractFromDataBlocks` is: that is
|
|
251
|
+
* the block-element keying the editor shares, pinned by tests/i18n/structural-keying-vectors.json,
|
|
252
|
+
* and an image is not a block element's text. A pull reads an image's translation back pairwise
|
|
253
|
+
* (`uwx/locale-sync.js`). ⛔ Until 2026-10-28 no image was offered for translation: a translated
|
|
254
|
+
* page kept its source alt text, and could not name a screenshot of its own.
|
|
255
|
+
*/
|
|
256
|
+
function extractFromImages(doc, context, units) {
|
|
257
|
+
imageNodes(doc).forEach((node, index) => {
|
|
258
|
+
const alt = typeof node.attrs?.alt === 'string' ? node.attrs.alt.trim() : ''
|
|
259
|
+
if (!alt) return
|
|
260
|
+
addUnit(units, alt, index === 0 ? 'image' : `image.${index}`, context, imageMarkup(node))
|
|
261
|
+
})
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Every block image in a doc, in document order — inside a container or a list item too — but not
|
|
266
|
+
* an icon, which is a name rather than a file. An image in a paragraph is that paragraph's: its
|
|
267
|
+
* unit's markup carries it.
|
|
268
|
+
*/
|
|
269
|
+
export function imageNodes(doc) {
|
|
270
|
+
const out = []
|
|
271
|
+
const walk = (nodes) => {
|
|
272
|
+
for (const node of nodes || []) {
|
|
273
|
+
if (!node) continue
|
|
274
|
+
if (node.type === 'image') {
|
|
275
|
+
if (node.attrs?.role !== 'icon') out.push(node)
|
|
276
|
+
} else if (CONTAINER_BLOCKS.has(node.type)) {
|
|
277
|
+
walk(node.content)
|
|
278
|
+
} else if (node.type === 'bulletList' || node.type === 'orderedList') {
|
|
279
|
+
for (const listItem of node.content || []) walk(listItem.content)
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
walk(doc?.content)
|
|
284
|
+
return out
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** What a translation may give an image: its words, and the files it shows. */
|
|
288
|
+
export const TRANSLATED_IMAGE_ATTRS = ['alt', 'caption', 'src', 'poster', 'preview']
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* An image as a translator is shown it and a pull writes one back: inline markdown of its role and
|
|
292
|
+
* of what a translation may give it — never the identity a push stamps beside a URL.
|
|
293
|
+
*
|
|
294
|
+
* @param {Object} node - an image node
|
|
295
|
+
* @returns {string|null}
|
|
296
|
+
*/
|
|
297
|
+
export function imageMarkup(node) {
|
|
298
|
+
const attrs = node?.attrs || {}
|
|
299
|
+
const shown = { role: attrs.role }
|
|
300
|
+
for (const key of TRANSLATED_IMAGE_ATTRS) {
|
|
301
|
+
if (attrs[key] != null && attrs[key] !== '') shown[key] = attrs[key]
|
|
302
|
+
}
|
|
303
|
+
try {
|
|
304
|
+
return serializeInlineContent([{ type: 'image', attrs: shown }]).trim() || null
|
|
305
|
+
} catch {
|
|
306
|
+
return null
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
239
310
|
/**
|
|
240
311
|
* Extract translatable strings from ProseMirror document
|
|
241
312
|
* @param {Object} doc - ProseMirror document
|
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 } from './extract.js'
|
|
17
|
+
import { elementText, blockElements, translationContext, 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
|
|
|
@@ -293,6 +293,7 @@ function translateSectionSync(section, pageRoute, translations, fallbackToSource
|
|
|
293
293
|
if (section.content?.type === 'doc') {
|
|
294
294
|
translateProseMirrorDoc(section.content, context, translations, fallbackToSource)
|
|
295
295
|
translateDataBlocks(section.content, context, translations, fallbackToSource, (tag) => dataModel?.(section.type, tag) ?? null)
|
|
296
|
+
translateImages(section.content, context, translations, fallbackToSource)
|
|
296
297
|
}
|
|
297
298
|
|
|
298
299
|
// Recursively translate subsections
|
|
@@ -325,6 +326,7 @@ async function translateSectionAsync(section, page, translations, options) {
|
|
|
325
326
|
if (section.content?.type === 'doc') {
|
|
326
327
|
translateProseMirrorDoc(section.content, context, translations, fallbackToSource)
|
|
327
328
|
translateDataBlocks(section.content, context, translations, fallbackToSource, (tag) => dataModel?.(section.type, tag) ?? null)
|
|
329
|
+
translateImages(section.content, context, translations, fallbackToSource)
|
|
328
330
|
}
|
|
329
331
|
}
|
|
330
332
|
|
|
@@ -399,9 +401,23 @@ function applyElementTranslation(node, context, translations, fallbackToSource)
|
|
|
399
401
|
export function translatedInline(source, value) {
|
|
400
402
|
const fragment = inlineMarkdownToFragment(value)
|
|
401
403
|
if (!fragment) return null
|
|
404
|
+
// ⭐ A value that is only an image, for an element whose source holds none, reads as its words —
|
|
405
|
+
// its alt text. An image's unit is its alt text (`extract.js::extractFromImages`), which a
|
|
406
|
+
// heading or a paragraph of the same words shares, and the file such a value names is the image's.
|
|
407
|
+
const image = loneImage(fragment)
|
|
408
|
+
if (image && !(source || []).some((node) => node?.type === 'image')) {
|
|
409
|
+
const alt = typeof image.attrs?.alt === 'string' ? image.attrs.alt.trim() : ''
|
|
410
|
+
return alt ? [{ type: 'text', text: alt }] : null
|
|
411
|
+
}
|
|
402
412
|
return asLinkLabels(source, fragment, value) || fragment
|
|
403
413
|
}
|
|
404
414
|
|
|
415
|
+
// The one image an inline fragment is, around any spaces — or null.
|
|
416
|
+
function loneImage(fragment) {
|
|
417
|
+
const nodes = (fragment || []).filter((node) => !(node?.type === 'text' && !node.text?.trim()))
|
|
418
|
+
return nodes.length === 1 && nodes[0].type === 'image' ? nodes[0] : null
|
|
419
|
+
}
|
|
420
|
+
|
|
405
421
|
/**
|
|
406
422
|
* Does a translation keep the inline markup of its source element? The merge's own answer —
|
|
407
423
|
* what `translatedInline` makes of the value — so the audit can neither report a loss the merge
|
|
@@ -412,7 +428,10 @@ export function translatedInline(source, value) {
|
|
|
412
428
|
* @returns {boolean}
|
|
413
429
|
*/
|
|
414
430
|
export function translationKeepsMarkup(markup, value) {
|
|
415
|
-
const
|
|
431
|
+
const source = inlineMarkdownToFragment(markup) || []
|
|
432
|
+
// An image keeps its image whatever its translation says: words are its alt text (`translateImages`).
|
|
433
|
+
if (loneImage(source)) return true
|
|
434
|
+
const result = translatedInline(source, value) || []
|
|
416
435
|
return result.some((node) => node.type !== 'text' || (node.marks && node.marks.length > 0))
|
|
417
436
|
}
|
|
418
437
|
|
|
@@ -604,6 +623,58 @@ function translateDataBlocks(doc, context, translations, fallbackToSource, model
|
|
|
604
623
|
return changed
|
|
605
624
|
}
|
|
606
625
|
|
|
626
|
+
/**
|
|
627
|
+
* Translate a section's IMAGES in place — the other half of `extract.js::extractFromImages`. Each
|
|
628
|
+
* image whose alt text has a translation takes what it gives (`translatedImage`): words, its alt
|
|
629
|
+
* text; an image, its alt text and the files and caption it names. A file is the value's address as
|
|
630
|
+
* written, so it serves where the source's would: a `/` path is a file in `public/`.
|
|
631
|
+
*
|
|
632
|
+
* Called from the build's two section walks and from `resolveDocForLocale`, the push's, so a site
|
|
633
|
+
* a static host serves and one published with Uniweb show the same image in each language.
|
|
634
|
+
*
|
|
635
|
+
* @returns {boolean} whether an image changed
|
|
636
|
+
*/
|
|
637
|
+
function translateImages(doc, context, translations, fallbackToSource) {
|
|
638
|
+
let changed = false
|
|
639
|
+
for (const node of imageNodes(doc)) {
|
|
640
|
+
const key = typeof node.attrs?.alt === 'string' ? node.attrs.alt.trim() : ''
|
|
641
|
+
if (!key) continue
|
|
642
|
+
const value = lookupTranslation(key, context, translations, fallbackToSource)
|
|
643
|
+
if (value === key) continue
|
|
644
|
+
for (const [attr, given] of Object.entries(translatedImage(value) || {})) {
|
|
645
|
+
if (node.attrs[attr] !== given) {
|
|
646
|
+
node.attrs[attr] = given
|
|
647
|
+
changed = true
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
return changed
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* What a translation gives an image. A value that is an image (`{poster=…}`):
|
|
656
|
+
* its alt text, and the file, caption, poster or preview it names — what it leaves out stays the
|
|
657
|
+
* source's. Any other value: its words, as the alt text. Null for an empty value.
|
|
658
|
+
*
|
|
659
|
+
* @param {string} value - the translation, inline markdown
|
|
660
|
+
* @returns {Object|null} the attributes to give the image
|
|
661
|
+
*/
|
|
662
|
+
export function translatedImage(value) {
|
|
663
|
+
const fragment = inlineMarkdownToFragment(value)
|
|
664
|
+
if (!fragment) return null
|
|
665
|
+
const image = loneImage(fragment)
|
|
666
|
+
if (image) {
|
|
667
|
+
const given = {}
|
|
668
|
+
for (const attr of TRANSLATED_IMAGE_ATTRS) {
|
|
669
|
+
const v = image.attrs?.[attr]
|
|
670
|
+
if (v != null && v !== '') given[attr] = v
|
|
671
|
+
}
|
|
672
|
+
return given
|
|
673
|
+
}
|
|
674
|
+
const words = toPlainText(value).trim()
|
|
675
|
+
return words ? { alt: words } : null
|
|
676
|
+
}
|
|
677
|
+
|
|
607
678
|
/**
|
|
608
679
|
* Resolve ONE ProseMirror content doc for a single target locale: a deep clone of
|
|
609
680
|
* the source doc with each whole-element translated (inline content replaced from
|
|
@@ -621,7 +692,8 @@ export function resolveDocForLocale(sourceDoc, table, context = { page: '', sect
|
|
|
621
692
|
const doc = JSON.parse(JSON.stringify(sourceDoc))
|
|
622
693
|
const elements = translateProseMirrorDoc(doc, context, table, true)
|
|
623
694
|
const data = translateDataBlocks(doc, context, table, true, modelFor)
|
|
624
|
-
|
|
695
|
+
const images = translateImages(doc, context, table, true)
|
|
696
|
+
return elements || data || images ? doc : null
|
|
625
697
|
}
|
|
626
698
|
|
|
627
699
|
// Parse an inline-markdown translation value into a ProseMirror inline fragment: one element's
|
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
* Advanced Asset Processors
|
|
3
3
|
*
|
|
4
4
|
* Optional processors for advanced asset types:
|
|
5
|
-
* - Video poster extraction (requires ffmpeg)
|
|
6
|
-
* - PDF
|
|
5
|
+
* - Video poster extraction (requires ffmpeg), for a site's videos
|
|
6
|
+
* - A PDF's placeholder card (requires pdf-lib), for a file record's preview (`./file-records.js`)
|
|
7
7
|
*
|
|
8
8
|
* These features gracefully degrade if dependencies aren't available.
|
|
9
9
|
*
|
|
10
|
+
* ⛔ A site's own PDFs got that card too, until 2026-10-28, and no page used it: a document's
|
|
11
|
+
* preview is the one its author names (`{preview=…}`).
|
|
12
|
+
*
|
|
10
13
|
* @module @uniweb/build/site
|
|
11
14
|
*/
|
|
12
15
|
|
|
@@ -150,9 +153,10 @@ export async function extractVideoPoster(videoPath, outputPath, options = {}) {
|
|
|
150
153
|
}
|
|
151
154
|
|
|
152
155
|
/**
|
|
153
|
-
*
|
|
156
|
+
* A placeholder card for a PDF — "PDF · N pages", sized as its first page — not a render of
|
|
157
|
+
* the file. A file record's preview (`./file-records.js`).
|
|
154
158
|
*
|
|
155
|
-
* Uses pdf-lib to
|
|
159
|
+
* Uses pdf-lib to read the page count and first page's size, and sharp to draw the card.
|
|
156
160
|
* Falls back gracefully if pdf-lib is not available.
|
|
157
161
|
*
|
|
158
162
|
* @param {string} pdfPath - Path to the PDF file
|
|
@@ -254,19 +258,18 @@ export async function generatePdfThumbnail(pdfPath, outputPath, options = {}) {
|
|
|
254
258
|
}
|
|
255
259
|
|
|
256
260
|
/**
|
|
257
|
-
* Process a video
|
|
261
|
+
* Process a video asset, extracting its poster
|
|
258
262
|
*
|
|
259
263
|
* @param {Object} asset - Asset info
|
|
260
264
|
* @param {Object} options - Processing options
|
|
261
265
|
* @param {string} [options.basePath='/'] - Site base path for subdirectory deployments
|
|
262
|
-
* @returns {Promise<Object>} Processing result with poster
|
|
266
|
+
* @returns {Promise<Object>} Processing result with the poster's URL
|
|
263
267
|
*/
|
|
264
268
|
export async function processAdvancedAsset(asset, options = {}) {
|
|
265
269
|
const {
|
|
266
270
|
outputDir,
|
|
267
271
|
assetsSubdir = 'assets',
|
|
268
272
|
videoPosters = true,
|
|
269
|
-
pdfThumbnails = true,
|
|
270
273
|
quality = 80,
|
|
271
274
|
basePath = '/'
|
|
272
275
|
} = options
|
|
@@ -311,54 +314,27 @@ export async function processAdvancedAsset(asset, options = {}) {
|
|
|
311
314
|
}
|
|
312
315
|
}
|
|
313
316
|
|
|
314
|
-
//
|
|
315
|
-
if (isPdfFile(resolved) && pdfThumbnails) {
|
|
316
|
-
const thumbFilename = `${name}-thumb-${hash}.webp`
|
|
317
|
-
const thumbPath = join(outputDir, assetsSubdir, thumbFilename)
|
|
318
|
-
|
|
319
|
-
const result = await generatePdfThumbnail(resolved, thumbPath, { quality })
|
|
320
|
-
|
|
321
|
-
if (result.success) {
|
|
322
|
-
return {
|
|
323
|
-
processed: true,
|
|
324
|
-
type: 'pdf',
|
|
325
|
-
thumbnail: `${prefix}/${assetsSubdir}/${thumbFilename}`,
|
|
326
|
-
pageCount: result.pageCount,
|
|
327
|
-
placeholder: result.placeholder
|
|
328
|
-
}
|
|
329
|
-
} else if (result.skipped) {
|
|
330
|
-
// pdf-lib not available - not an error, just skip
|
|
331
|
-
return { processed: false, skipped: true, reason: result.error }
|
|
332
|
-
} else {
|
|
333
|
-
return { processed: false, error: result.error }
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// Not a video or PDF, or processing disabled
|
|
317
|
+
// Not a video, or processing disabled
|
|
338
318
|
return { processed: false, skipped: true, reason: 'Not an advanced asset type' }
|
|
339
319
|
}
|
|
340
320
|
|
|
341
321
|
/**
|
|
342
|
-
* Process all advanced assets in a manifest
|
|
322
|
+
* Process all advanced assets in a manifest: a poster for each video its author gave none
|
|
343
323
|
*
|
|
344
324
|
* @param {Object} assetManifest - Asset manifest
|
|
345
325
|
* @param {Object} options - Processing options
|
|
346
326
|
* @param {Set} [options.hasExplicitPoster] - Set of video paths with explicit poster attributes
|
|
347
|
-
* @
|
|
348
|
-
* @returns {Promise<Object>} Results with poster/thumbnail mappings
|
|
327
|
+
* @returns {Promise<Object>} Results with the poster mapping
|
|
349
328
|
*/
|
|
350
329
|
export async function processAdvancedAssets(assetManifest, options = {}) {
|
|
351
330
|
const {
|
|
352
331
|
hasExplicitPoster = new Set(),
|
|
353
|
-
hasExplicitPreview = new Set(),
|
|
354
332
|
...processingOptions
|
|
355
333
|
} = options
|
|
356
334
|
|
|
357
335
|
const posterMapping = {} // video src -> poster url
|
|
358
|
-
const thumbnailMapping = {} // pdf src -> thumbnail url
|
|
359
336
|
const results = {
|
|
360
|
-
videos: { processed: 0, skipped: 0, explicit: 0 }
|
|
361
|
-
pdfs: { processed: 0, skipped: 0, explicit: 0 }
|
|
337
|
+
videos: { processed: 0, skipped: 0, explicit: 0 }
|
|
362
338
|
}
|
|
363
339
|
|
|
364
340
|
for (const [originalPath, asset] of Object.entries(assetManifest)) {
|
|
@@ -376,26 +352,8 @@ export async function processAdvancedAssets(assetManifest, options = {}) {
|
|
|
376
352
|
} else {
|
|
377
353
|
results.videos.skipped++
|
|
378
354
|
}
|
|
379
|
-
} else if (isPdfFile(asset.resolved || '')) {
|
|
380
|
-
// Skip auto-generation if explicit preview was provided
|
|
381
|
-
if (hasExplicitPreview.has(originalPath)) {
|
|
382
|
-
results.pdfs.explicit++
|
|
383
|
-
continue
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
const result = await processAdvancedAsset(asset, processingOptions)
|
|
387
|
-
if (result.processed && result.thumbnail) {
|
|
388
|
-
thumbnailMapping[originalPath] = {
|
|
389
|
-
url: result.thumbnail,
|
|
390
|
-
pageCount: result.pageCount,
|
|
391
|
-
placeholder: result.placeholder
|
|
392
|
-
}
|
|
393
|
-
results.pdfs.processed++
|
|
394
|
-
} else {
|
|
395
|
-
results.pdfs.skipped++
|
|
396
|
-
}
|
|
397
355
|
}
|
|
398
356
|
}
|
|
399
357
|
|
|
400
|
-
return { posterMapping,
|
|
358
|
+
return { posterMapping, results }
|
|
401
359
|
}
|
|
@@ -228,9 +228,11 @@ function rewriteDataPaths(data, pathMapping) {
|
|
|
228
228
|
* @param {Object} content - ProseMirror document
|
|
229
229
|
* @param {Object} pathMapping - Map of original paths to new paths
|
|
230
230
|
* @param {Object} [files] - what the build knows of each file it copied (`processAssets`)
|
|
231
|
+
* @param {{ posters?: Object }} [made] - what the build made for a file, by the reference as
|
|
232
|
+
* written: `posters`, a video's poster frame (`processAdvancedAssets`)
|
|
231
233
|
* @returns {Object} Content with rewritten paths
|
|
232
234
|
*/
|
|
233
|
-
export function rewriteContentPaths(content, pathMapping, files = null) {
|
|
235
|
+
export function rewriteContentPaths(content, pathMapping, files = null, made = null) {
|
|
234
236
|
if (!content) return content
|
|
235
237
|
|
|
236
238
|
// Deep clone to avoid mutating original
|
|
@@ -251,6 +253,12 @@ export function rewriteContentPaths(content, pathMapping, files = null) {
|
|
|
251
253
|
node.attrs[attr] = newPath
|
|
252
254
|
}
|
|
253
255
|
}
|
|
256
|
+
// The poster the build made for a video its author gave none, on the node — where an
|
|
257
|
+
// authored `{poster=…}` is — so `content.videos[i].poster` carries it. ⛔ Until 2026-10-28
|
|
258
|
+
// it went to a top-level `_assetMeta.posters` that nothing read, keyed by the reference
|
|
259
|
+
// the node no longer held: the frame was made, and no page showed it.
|
|
260
|
+
const poster = made?.posters?.[original]
|
|
261
|
+
if (poster && !node.attrs.poster) node.attrs.poster = poster
|
|
254
262
|
// A document whose file the build copied: the file's name as the author gave it — the
|
|
255
263
|
// address now holds a hashed one — its size, and its type (2026-09-29). Only on the built
|
|
256
264
|
// output, never on what an author stored; a value written on the node stays.
|
|
@@ -329,15 +337,16 @@ export function rewriteParamPaths(params, pathMapping) {
|
|
|
329
337
|
* @param {Object} siteContent - Full site content object
|
|
330
338
|
* @param {Object} pathMapping - Map of original paths to new paths
|
|
331
339
|
* @param {Object} [files] - what the build knows of each file it copied (`processAssets`)
|
|
340
|
+
* @param {{ posters?: Object }} [made] - what the build made for a file (`rewriteContentPaths`)
|
|
332
341
|
* @returns {Object} Site content with rewritten paths
|
|
333
342
|
*/
|
|
334
|
-
export function rewriteSiteContentPaths(siteContent, pathMapping, files = null) {
|
|
343
|
+
export function rewriteSiteContentPaths(siteContent, pathMapping, files = null, made = null) {
|
|
335
344
|
// Deep clone
|
|
336
345
|
const result = JSON.parse(JSON.stringify(siteContent))
|
|
337
346
|
|
|
338
347
|
function processSection(section) {
|
|
339
348
|
if (section.content) {
|
|
340
|
-
section.content = rewriteContentPaths(section.content, pathMapping, files)
|
|
349
|
+
section.content = rewriteContentPaths(section.content, pathMapping, files, made)
|
|
341
350
|
}
|
|
342
351
|
if (section.params) {
|
|
343
352
|
section.params = rewriteParamPaths(section.params, pathMapping)
|
package/src/site/assets.js
CHANGED
|
@@ -149,13 +149,23 @@ function walkDataBlockAssets(doc, visitor) {
|
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
/** The code `resolveAssetPath` refuses a `/x` with when only the retired `assets/` folder holds it. */
|
|
153
|
+
export const ASSETS_FOLDER_RETIRED = 'ASSETS_FOLDER_RETIRED'
|
|
154
|
+
|
|
152
155
|
/**
|
|
153
156
|
* Resolve an asset path to absolute file system path
|
|
154
157
|
*
|
|
158
|
+
* ⛔ `/x` NAMES `public/x`, AND ONLY THAT. Until 2026-10-28 `assets/` was a second home for it,
|
|
159
|
+
* searched after `public/`; it is retired [Diego: "We don't need too many ways of doing the same
|
|
160
|
+
* thing"]. A `/x` only `assets/` holds is refused by name, never read as missing, and the move it
|
|
161
|
+
* names is into `public/`, where the address the content names stays the same. A file beside the
|
|
162
|
+
* page that shows it serves as well, on every host (`uwx/located-media.js`).
|
|
163
|
+
*
|
|
155
164
|
* @param {string} src - Original source path from content
|
|
156
165
|
* @param {string} contextPath - Path of the file containing the reference
|
|
157
166
|
* @param {string} siteRoot - Site root directory
|
|
158
167
|
* @returns {Object} Resolution result
|
|
168
|
+
* @throws {Error} `code: ASSETS_FOLDER_RETIRED` — a `/x` that only `assets/` holds
|
|
159
169
|
*/
|
|
160
170
|
export function resolveAssetPath(src, contextPath, siteRoot) {
|
|
161
171
|
// External URLs - don't process
|
|
@@ -176,19 +186,11 @@ export function resolveAssetPath(src, contextPath, siteRoot) {
|
|
|
176
186
|
const contextDir = dirname(contextPath)
|
|
177
187
|
resolved = normalize(join(contextDir, src))
|
|
178
188
|
}
|
|
179
|
-
// Absolute site paths: /images/hero.png
|
|
189
|
+
// Absolute site paths: /images/hero.png — a file in public/, whether or not it exists yet
|
|
180
190
|
else if (src.startsWith('/')) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (existsSync(publicPath)) {
|
|
186
|
-
resolved = publicPath
|
|
187
|
-
} else if (existsSync(assetsPath)) {
|
|
188
|
-
resolved = assetsPath
|
|
189
|
-
} else {
|
|
190
|
-
// Default to public folder path even if it doesn't exist yet
|
|
191
|
-
resolved = publicPath
|
|
191
|
+
resolved = join(siteRoot, 'public', src)
|
|
192
|
+
if (!existsSync(resolved) && existsSync(join(siteRoot, 'assets', src))) {
|
|
193
|
+
throw assetsFolderRetired(src, contextPath, siteRoot)
|
|
192
194
|
}
|
|
193
195
|
}
|
|
194
196
|
|
|
@@ -202,6 +204,22 @@ export function resolveAssetPath(src, contextPath, siteRoot) {
|
|
|
202
204
|
}
|
|
203
205
|
}
|
|
204
206
|
|
|
207
|
+
/**
|
|
208
|
+
* The refusal of a `/x` that only `assets/` holds, naming the file and where it goes — and the
|
|
209
|
+
* file that wrote it, when there is one (a site's config is read through a stand-in path).
|
|
210
|
+
*/
|
|
211
|
+
function assetsFolderRetired(src, contextPath, siteRoot) {
|
|
212
|
+
const where = contextPath ? relative(siteRoot, contextPath).split(sep).join('/') : ''
|
|
213
|
+
const named = where && !where.startsWith('..') && existsSync(contextPath) ? ` (in ${where})` : ''
|
|
214
|
+
const file = src.replace(/^\/+/, '')
|
|
215
|
+
const err = new Error(
|
|
216
|
+
`${src}${named} names assets/${file}, and a site no longer keeps media in assets/. ` +
|
|
217
|
+
`Move the file to public/${file}: the address stays ${src}.`
|
|
218
|
+
)
|
|
219
|
+
err.code = ASSETS_FOLDER_RETIRED
|
|
220
|
+
return err
|
|
221
|
+
}
|
|
222
|
+
|
|
205
223
|
/**
|
|
206
224
|
* Walk a ProseMirror document and collect all asset references
|
|
207
225
|
*
|
|
@@ -253,7 +271,6 @@ export function walkContentAssets(doc, visitor, path = '') {
|
|
|
253
271
|
* @returns {Object} Asset collection result
|
|
254
272
|
* - assets: Asset manifest mapping original paths to resolved info
|
|
255
273
|
* - hasExplicitPoster: Set of video src paths that have explicit poster attributes
|
|
256
|
-
* - hasExplicitPreview: Set of PDF src paths that have explicit preview attributes
|
|
257
274
|
* - uses: every co-located reference, with the file it resolved to and a setter
|
|
258
275
|
* for the place it is written — what `disambiguateAssetRefs` needs to rename
|
|
259
276
|
* one. In memory only; never part of the site content.
|
|
@@ -261,11 +278,10 @@ export function walkContentAssets(doc, visitor, path = '') {
|
|
|
261
278
|
export function collectSectionAssets(section, markdownPath, siteRoot) {
|
|
262
279
|
const assets = {}
|
|
263
280
|
const hasExplicitPoster = new Set()
|
|
264
|
-
const hasExplicitPreview = new Set()
|
|
265
281
|
const uses = []
|
|
266
282
|
|
|
267
283
|
// One entry per reference. `set` writes a new reference where this one stands;
|
|
268
|
-
// `flags` carries the explicit-poster
|
|
284
|
+
// `flags` carries the explicit-poster mark a renamed video must keep.
|
|
269
285
|
const add = (ref, set, flags = null) => {
|
|
270
286
|
const result = resolveAssetPath(ref, markdownPath, siteRoot)
|
|
271
287
|
if (result.external || !result.resolved) return
|
|
@@ -287,10 +303,9 @@ export function collectSectionAssets(section, markdownPath, siteRoot) {
|
|
|
287
303
|
const ref = node.attrs.src
|
|
288
304
|
let flags = null
|
|
289
305
|
if (attrName === 'src') {
|
|
290
|
-
//
|
|
306
|
+
// A video with its own poster gets none made for it
|
|
291
307
|
if (node.attrs.poster) hasExplicitPoster.add(ref)
|
|
292
|
-
|
|
293
|
-
flags = { poster: !!node.attrs.poster, preview: !!node.attrs.preview }
|
|
308
|
+
flags = { poster: !!node.attrs.poster }
|
|
294
309
|
}
|
|
295
310
|
add(ref, holder ? (v) => { holder[attrName] = v } : null, flags)
|
|
296
311
|
})
|
|
@@ -326,7 +341,7 @@ export function collectSectionAssets(section, markdownPath, siteRoot) {
|
|
|
326
341
|
walkDataBlockAssets(section.content, (assetPath, set) => add(assetPath, set))
|
|
327
342
|
}
|
|
328
343
|
|
|
329
|
-
return { assets, hasExplicitPoster,
|
|
344
|
+
return { assets, hasExplicitPoster, uses }
|
|
330
345
|
}
|
|
331
346
|
|
|
332
347
|
/**
|
|
@@ -364,7 +379,6 @@ export function disambiguateAssetRefs(collection, siteRoot) {
|
|
|
364
379
|
const entry = collection.assets[use.ref]
|
|
365
380
|
collection.assets[key] = { ...entry, original: key, resolved: use.resolved }
|
|
366
381
|
if (use.flags?.poster) collection.hasExplicitPoster?.add(key)
|
|
367
|
-
if (use.flags?.preview) collection.hasExplicitPreview?.add(key)
|
|
368
382
|
use.set(key)
|
|
369
383
|
renamed++
|
|
370
384
|
}
|
|
@@ -373,7 +387,6 @@ export function disambiguateAssetRefs(collection, siteRoot) {
|
|
|
373
387
|
if (files.size < 2) continue
|
|
374
388
|
delete collection.assets[ref]
|
|
375
389
|
collection.hasExplicitPoster?.delete(ref)
|
|
376
|
-
collection.hasExplicitPreview?.delete(ref)
|
|
377
390
|
}
|
|
378
391
|
return renamed
|
|
379
392
|
}
|
|
@@ -450,7 +463,6 @@ export function mergeAssetCollections(...collections) {
|
|
|
450
463
|
const merged = {
|
|
451
464
|
assets: {},
|
|
452
465
|
hasExplicitPoster: new Set(),
|
|
453
|
-
hasExplicitPreview: new Set(),
|
|
454
466
|
uses: []
|
|
455
467
|
}
|
|
456
468
|
|
|
@@ -460,7 +472,6 @@ export function mergeAssetCollections(...collections) {
|
|
|
460
472
|
Object.assign(merged.assets, collection.assets)
|
|
461
473
|
if (collection.uses) merged.uses.push(...collection.uses)
|
|
462
474
|
collection.hasExplicitPoster?.forEach(p => merged.hasExplicitPoster.add(p))
|
|
463
|
-
collection.hasExplicitPreview?.forEach(p => merged.hasExplicitPreview.add(p))
|
|
464
475
|
} else {
|
|
465
476
|
// Legacy: plain asset manifest
|
|
466
477
|
Object.assign(merged.assets, collection)
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
* actually consumed). Both paths use
|
|
20
20
|
* the same underlying building blocks (`collectSiteContent`,
|
|
21
21
|
* `processQueries`, etc.), so behavior stays consistent without forcing
|
|
22
|
-
* one path through the other's lifecycle. Media processing — WebP copies
|
|
23
|
-
* video posters
|
|
22
|
+
* one path through the other's lifecycle. Media processing — WebP copies and
|
|
23
|
+
* video posters — is the bundle path's alone (below).
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import { writeFile, mkdir, cp } from 'node:fs/promises'
|
|
@@ -164,7 +164,6 @@ export async function buildSiteData({
|
|
|
164
164
|
// Strip internal-only properties that don't serialize (Sets don't
|
|
165
165
|
// JSON-roundtrip): the collector records them for media processing.
|
|
166
166
|
delete finalContent.hasExplicitPoster
|
|
167
|
-
delete finalContent.hasExplicitPreview
|
|
168
167
|
|
|
169
168
|
// ⛔ `config.icons` is a HOST-owned slot on this lane — drop it.
|
|
170
169
|
//
|