@uniweb/build 1.10.14 → 1.11.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 +8 -8
- package/src/i18n/extract.js +71 -0
- package/src/i18n/index.js +24 -5
- package/src/i18n/locales.js +28 -2
- package/src/i18n/merge.js +75 -3
- package/src/prerender.js +3 -0
- package/src/site/advanced-processors.js +15 -57
- package/src/site/asset-processor.js +12 -3
- package/src/site/assets.js +104 -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 +69 -37
- 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.1",
|
|
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/content-reader": "~1.5.7",
|
|
60
|
-
"@uniweb/projections": "~1.2.7",
|
|
61
59
|
"@uniweb/content-writer": "~1.3.1",
|
|
62
|
-
"@uniweb/
|
|
60
|
+
"@uniweb/schemas": "~1.6.5",
|
|
63
61
|
"@uniweb/theming": "~1.2.1",
|
|
64
|
-
"@uniweb/
|
|
62
|
+
"@uniweb/content-reader": "~1.5.7",
|
|
63
|
+
"@uniweb/projections": "~1.2.7",
|
|
64
|
+
"@uniweb/semantic-parser": "~1.13.0"
|
|
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",
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
"@tailwindcss/vite": "^4.0.0",
|
|
74
74
|
"@vitejs/plugin-react": "^4.0.0 || ^5.0.0",
|
|
75
75
|
"vite-plugin-svgr": "^4.0.0",
|
|
76
|
-
"@uniweb/
|
|
77
|
-
"@uniweb/
|
|
76
|
+
"@uniweb/runtime": "~1.2.13",
|
|
77
|
+
"@uniweb/core": "~1.4.12"
|
|
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/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { existsSync } from 'node:fs'
|
|
|
12
12
|
import { join, dirname } from 'node:path'
|
|
13
13
|
|
|
14
14
|
import { computeHash, normalizeText } from './hash.js'
|
|
15
|
-
import { availableLocales, resolveLocaleList } from './locales.js'
|
|
15
|
+
import { availableLocales, resolveLocaleList, localesToBuild } from './locales.js'
|
|
16
16
|
import { extractTranslatableContent } from './extract.js'
|
|
17
17
|
import { dataBlockModels } from './data-models.js'
|
|
18
18
|
import { syncManifests, formatSyncReport } from './sync.js'
|
|
@@ -82,6 +82,7 @@ export {
|
|
|
82
82
|
// Locale resolution
|
|
83
83
|
getAvailableLocales,
|
|
84
84
|
resolveLocales,
|
|
85
|
+
localesToBuild,
|
|
85
86
|
|
|
86
87
|
// Free-form translation functions
|
|
87
88
|
loadFreeformTranslation,
|
|
@@ -444,15 +445,21 @@ export async function buildLocalizedContent(siteRoot, options = {}) {
|
|
|
444
445
|
// What each section type declares its data blocks are, so a block translates what extraction offered.
|
|
445
446
|
const dataModel = await dataBlockModels(siteRoot)
|
|
446
447
|
|
|
448
|
+
// ⭐ Where the bundle put each file a page names, a translation's among them (`site/plugin.js::
|
|
449
|
+
// generateBundle`, `collectTranslatedAssets`): a language's page shows the build's copy of the
|
|
450
|
+
// file its translation names, as the default language's page does. The bundle's note to this
|
|
451
|
+
// step, taken out of the payload here, since no page reads it.
|
|
452
|
+
const builtAssets = siteContent.builtAssets
|
|
453
|
+
delete siteContent.builtAssets
|
|
454
|
+
|
|
447
455
|
// ⭐ The DEFAULT locale's payload needs the same stamp. It is not written in
|
|
448
456
|
// this loop — it is the source this function reads — but a visitor landing on
|
|
449
457
|
// `/` gets a Website built from it, and without the set that page loses its
|
|
450
458
|
// language switcher while every translated page has one.
|
|
451
459
|
const stampedLanguages = declaredLanguages(siteContent.config, defaultLocale, locales)
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}
|
|
460
|
+
const restamp = JSON.stringify(siteContent.config?.languages) !== JSON.stringify(stampedLanguages)
|
|
461
|
+
if (restamp) siteContent.config = { ...siteContent.config, languages: stampedLanguages }
|
|
462
|
+
if (restamp || builtAssets) await writeFile(siteContentPath, JSON.stringify(siteContent, null, 2))
|
|
456
463
|
|
|
457
464
|
// The paths the site's source holds a section at, drafts included — read once, and only
|
|
458
465
|
// when a translation translates nothing this build publishes (`warnAboutFreeformIssues`).
|
|
@@ -513,6 +520,8 @@ export async function buildLocalizedContent(siteRoot, options = {}) {
|
|
|
513
520
|
})
|
|
514
521
|
}
|
|
515
522
|
|
|
523
|
+
if (builtAssets) translated = await builtCopies(translated, builtAssets)
|
|
524
|
+
|
|
516
525
|
// Mark the active locale in the translated content, and stamp the resolved
|
|
517
526
|
// locale set so the runtime does not have to re-derive it — see
|
|
518
527
|
// `declaredLanguages`.
|
|
@@ -537,6 +546,16 @@ export async function buildLocalizedContent(siteRoot, options = {}) {
|
|
|
537
546
|
return outputs
|
|
538
547
|
}
|
|
539
548
|
|
|
549
|
+
/**
|
|
550
|
+
* A language's content with each file its translations name pointed at the build's copy
|
|
551
|
+
* (`builtAssets`, `{ paths, files }` by the reference as written). The bundle's own rewrite, loaded
|
|
552
|
+
* only on the lane that processed media, which is the one that left the note.
|
|
553
|
+
*/
|
|
554
|
+
async function builtCopies(content, builtAssets) {
|
|
555
|
+
const { rewriteSiteContentPaths } = await import('../site/asset-processor.js')
|
|
556
|
+
return rewriteSiteContentPaths(content, builtAssets.paths || {}, builtAssets.files || null)
|
|
557
|
+
}
|
|
558
|
+
|
|
540
559
|
/**
|
|
541
560
|
* Check for stale/orphaned free-form translations and emit warnings
|
|
542
561
|
* @param {string} locale - Locale code
|
package/src/i18n/locales.js
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
// which has none — was pushed as a one-language site, and none of its translations left the
|
|
7
7
|
// machine, while the build of the same site produced every one of them.
|
|
8
8
|
//
|
|
9
|
-
// A leaf, with nothing but `node:fs`
|
|
10
|
-
// the rest of the i18n module.
|
|
9
|
+
// A leaf, with nothing but `node:fs` and core's locale rules (a leaf too) beneath it, so the sync
|
|
10
|
+
// lane can use it without pulling in the rest of the i18n module.
|
|
11
11
|
|
|
12
12
|
import { existsSync, readdirSync } from 'node:fs'
|
|
13
|
+
import { normalizeLanguageList, resolveDefaultLocale } from '@uniweb/core/locale-config'
|
|
13
14
|
|
|
14
15
|
// Files in the locales directory that are not a locale's translations.
|
|
15
16
|
export const RESERVED_LOCALE_FILES = new Set(['manifest.json', '_memory.json'])
|
|
@@ -49,3 +50,28 @@ export function resolveLocaleList(configLocales, localesPath) {
|
|
|
49
50
|
}
|
|
50
51
|
return availableLocales(localesPath)
|
|
51
52
|
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The languages a build makes pages in besides its default: the site's locales
|
|
56
|
+
* (`resolveLocaleList`), only those `publishLanguages:` lists when it lists any, never the default,
|
|
57
|
+
* which is the root tree. One rule for `uniweb build`, which makes each one's pages, and for the
|
|
58
|
+
* bundle, which processes the files their translations name (`site/plugin.js`), so the second
|
|
59
|
+
* never processes for a language the first does not make, nor misses one it does.
|
|
60
|
+
*
|
|
61
|
+
* @param {Object} siteConfig - `site.yml`, as written
|
|
62
|
+
* @param {string} localesPath - the locales directory
|
|
63
|
+
* @returns {{ locales: string[], skipped: string[], defaultLocale: string }} the languages a build
|
|
64
|
+
* makes, and those `publishLanguages:` leaves out
|
|
65
|
+
*/
|
|
66
|
+
export function localesToBuild(siteConfig, localesPath) {
|
|
67
|
+
const config = siteConfig || {}
|
|
68
|
+
let locales = resolveLocaleList(config.languages, localesPath)
|
|
69
|
+
let skipped = []
|
|
70
|
+
if (config.publishLanguages != null) {
|
|
71
|
+
const publish = new Set(normalizeLanguageList(config.publishLanguages))
|
|
72
|
+
skipped = locales.filter((l) => !publish.has(l))
|
|
73
|
+
locales = locales.filter((l) => publish.has(l))
|
|
74
|
+
}
|
|
75
|
+
const defaultLocale = resolveDefaultLocale(config)
|
|
76
|
+
return { locales: locales.filter((l) => l !== defaultLocale), skipped, defaultLocale }
|
|
77
|
+
}
|
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
|
package/src/prerender.js
CHANGED
|
@@ -721,6 +721,9 @@ export function injectBuildData(html, siteContent, { splitContent = false, curre
|
|
|
721
721
|
// Inject site content as JSON for hydration
|
|
722
722
|
// Strip CSS and font links from theme (both are already in <head>)
|
|
723
723
|
let contentForJson = { ...siteContent }
|
|
724
|
+
// The bundle's note to the step that makes each other language's pages, which takes it out
|
|
725
|
+
// (`i18n/index.js::buildLocalizedContent`) — and no page's, if that step failed.
|
|
726
|
+
delete contentForJson.builtAssets
|
|
724
727
|
if (contentForJson.theme?.css || contentForJson.theme?.links) {
|
|
725
728
|
contentForJson.theme = { ...contentForJson.theme }
|
|
726
729
|
delete contentForJson.theme.css
|
|
@@ -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)
|