uniweb 1.34.6 → 1.34.7
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uniweb",
|
|
3
|
-
"version": "1.34.
|
|
3
|
+
"version": "1.34.7",
|
|
4
4
|
"description": "Create structured Vite + React sites with content/code separation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -41,15 +41,15 @@
|
|
|
41
41
|
"js-yaml": "^4.3.2",
|
|
42
42
|
"prompts": "^2.4.2",
|
|
43
43
|
"tar": "^7.5.21",
|
|
44
|
-
"@uniweb/schemas": "~1.7.4",
|
|
45
|
-
"@uniweb/core": "~1.6.12",
|
|
46
44
|
"@uniweb/content-writer": "~1.3.2",
|
|
47
|
-
"@uniweb/
|
|
45
|
+
"@uniweb/core": "~1.6.13",
|
|
46
|
+
"@uniweb/schemas": "~1.7.4",
|
|
47
|
+
"@uniweb/semantic-parser": "~1.13.5"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@uniweb/
|
|
51
|
-
"@uniweb/semantic-parser": "~1.13.
|
|
52
|
-
"@uniweb/
|
|
50
|
+
"@uniweb/content-reader": "~1.5.10",
|
|
51
|
+
"@uniweb/semantic-parser": "~1.13.5",
|
|
52
|
+
"@uniweb/build": "~1.23.6"
|
|
53
53
|
},
|
|
54
54
|
"peerDependenciesMeta": {
|
|
55
55
|
"@uniweb/build": {
|
|
@@ -131,7 +131,7 @@ Image attributes: `{width=800 height=600 loading=lazy fit=cover position=center
|
|
|
131
131
|
|
|
132
132
|
**Section links:** `page:about#team` → `/about#section-team`; `page:/#features` → a homepage section. The id is the file name without its number (`2-features.md` → `features`) or `id:` in frontmatter.
|
|
133
133
|
|
|
134
|
-
**Where media lives.** `./x` is beside the page, `/x` is in `public/`; both reach a static build and a published site. Keep a page's media beside it, and in `public/` what belongs to the whole site: the favicon, fonts. **Only a static host gives a file a fixed address** at the site root. A site published with Uniweb serves a file that something names from an address the upload gives it, and nothing at `/x` — so for a file other sites or scripts fetch by URL, keep it somewhere with its own address and add a page whose `redirect:` goes there. A static build copies `public/` whole and adds its own copy of each file a page names there
|
|
134
|
+
**Where media lives.** `./x` is beside the page, `/x` is in `public/`; both reach a static build and a published site. Keep a page's media beside it, and in `public/` what belongs to the whole site: the favicon, fonts. **Only a static host gives a file a fixed address** at the site root. A site published with Uniweb serves a file that something names from an address the upload gives it, and nothing at `/x` — so for a file other sites or scripts fetch by URL, keep it somewhere with its own address and add a page whose `redirect:` goes there. A static build copies `public/` whole, a photo's location included, and adds its own copy of each file a page names there: keep a phone's photos beside their page. **A picture is made ready before it is stored or shipped:** `uniweb push` and `uniweb publish` upload, and a static build copies, a PNG, JPEG or GIF as a WebP when that is at least 10% smaller (a TIFF or HEIC always), turned upright and without its location and camera data; a WebP stays one, without that data. The favicon, the touch icon, the site's card and its social images go up in their own format, without their location and camera data; a static build serves them from `public/` as they are. A picture keeps its pixels, so add one no wider than a page shows it; a HEIC from a phone that can't be converted here goes up as it is, with a note: export it as JPEG. `uniweb push` uploads a file beside a page wherever the page is (mounted directories included); a file outside the site and its mounts is not uploaded — put that in `public/`. There is no `assets/` directory for media; a build stops on a `/x` only `assets/` holds.
|
|
135
135
|
|
|
136
136
|
**Placement** (`{placement=left|right|wide|full}`) on an image or video, or on a table's caption line, which follows the table after a blank line (`: Plans and prices {placement=wide #tbl-plans}`, which also sets caption and id; with no blank line it becomes a row). It's the author's intent, honoured by kit's `<Render>`, `<Prose>` and `<Article>` and ignored by other components; a section type declares which it honours in `meta.js` (`sequence: { placement: true }`) and the build warns on a mismatch.
|
|
137
137
|
|
|
@@ -18,6 +18,7 @@ import { existsSync, readFileSync } from 'node:fs'
|
|
|
18
18
|
import { basename } from 'node:path'
|
|
19
19
|
import { resolveAssetPath } from '@uniweb/build/site'
|
|
20
20
|
import { servedFingerprint } from '@uniweb/build/uwx'
|
|
21
|
+
import { prepareImage, isPreparableImage } from '@uniweb/build/images'
|
|
21
22
|
import { contentTypeFor } from '../utils/code-upload.js'
|
|
22
23
|
import { humanBytes } from '../utils/bytes.js'
|
|
23
24
|
|
|
@@ -27,11 +28,14 @@ import { humanBytes } from '../utils/bytes.js'
|
|
|
27
28
|
* @param {string} siteDir - the site root (site-root refs resolve under public/)
|
|
28
29
|
* @param {Array<string|{ ref: string, path: string, contentType?: string }>} refs - site-root local
|
|
29
30
|
* asset refs (`/images/x.png`), or files already located (a file record's)
|
|
30
|
-
* @param {{ siteUuid?: string|null, onProgress?: (m: string) => void, warn?: (m: string) => void }} [opts]
|
|
31
|
+
* @param {{ siteUuid?: string|null, onProgress?: (m: string) => void, warn?: (m: string) => void, recorded?: Record<string, object> }} [opts]
|
|
31
32
|
* `siteUuid` is the owner the uploaded bytes are charged to. Callers create the
|
|
32
33
|
* site before uploading precisely so this is set — an unowned upload is charged
|
|
33
34
|
* and cannot be freed, because freeing means deleting the owning entity.
|
|
34
|
-
*
|
|
35
|
+
* `recorded` is this backend's asset map from `sync.json`, which says what each ref was stored as.
|
|
36
|
+
* `keepFormat` names the pictures other software fetches by their address, which keep their format
|
|
37
|
+
* and lose only their location and camera data (`prepareImage`'s `keepFormat`).
|
|
38
|
+
* @returns {Promise<{ map: Record<string,string>, ids: Record<string,{id:string,ext:string,source?:string,size?:number}>, missing: string[], served: string[], failed: Array<{path:string,status:number,detail?:string}> }>}
|
|
35
39
|
* `map` is ref → serve URL for refs that resolved AND uploaded. The two failure
|
|
36
40
|
* kinds are reported SEPARATELY because callers must treat them differently:
|
|
37
41
|
* `missing` is a ref with no file under the site — an authoring mistake, already
|
|
@@ -47,7 +51,7 @@ export async function uploadSiteMedia(
|
|
|
47
51
|
client,
|
|
48
52
|
siteDir,
|
|
49
53
|
refs,
|
|
50
|
-
{ siteUuid = null, onProgress, warn } = {}
|
|
54
|
+
{ siteUuid = null, onProgress, warn, recorded = {}, keepFormat = new Set() } = {}
|
|
51
55
|
) {
|
|
52
56
|
if (!refs?.length) return { map: {}, ids: {}, missing: [], served: [], failed: [] }
|
|
53
57
|
|
|
@@ -74,18 +78,56 @@ export async function uploadSiteMedia(
|
|
|
74
78
|
continue
|
|
75
79
|
}
|
|
76
80
|
const bytes = readFileSync(resolved)
|
|
77
|
-
|
|
81
|
+
const declared = typeof item === 'object' ? item.contentType : null
|
|
82
|
+
const file = {
|
|
78
83
|
path: ref.replace(/^\/+/, ''), // bookkeeping key into the plan (must be unique)
|
|
79
|
-
content_type:
|
|
84
|
+
content_type: declared || contentTypeFor(basename(resolved)),
|
|
80
85
|
size: bytes.length,
|
|
81
|
-
sha256:
|
|
86
|
+
sha256: sha256(bytes),
|
|
82
87
|
localUrl: ref, // the rewrite key — the original content ref
|
|
83
88
|
diskPath: resolved
|
|
84
|
-
}
|
|
89
|
+
}
|
|
90
|
+
// ⭐ A picture is prepared before it is stored (`prepareImage`). Not a file record's file, which
|
|
91
|
+
// declares its own type: that is a download, kept as its author gave it. A picture other software
|
|
92
|
+
// fetches by its address (`keepFormat`: the favicon, the touch icon, the site's card and its social
|
|
93
|
+
// images) keeps its format, since a home screen takes a PNG and a link preview a JPEG or PNG, and
|
|
94
|
+
// loses only its location and camera data. ⛔ Until 2026-11-12 those went up as they were, so a
|
|
95
|
+
// phone's photo made a social image kept where it was taken, on its page too.
|
|
96
|
+
const ext = extOf(resolved)
|
|
97
|
+
const prepare = !declared && isPreparableImage(ext)
|
|
98
|
+
const options = { keepFormat: keepFormat.has(ref) }
|
|
99
|
+
files.push(prepare ? await preparedFile(file, bytes, ext, recorded?.[ref], warn, options) : file)
|
|
85
100
|
}
|
|
86
101
|
if (!files.length) return { map: {}, ids: {}, missing, served, failed: [] }
|
|
87
102
|
|
|
88
|
-
|
|
103
|
+
let result = await client.uploadSiteAssets({ files, siteUuid, onProgress })
|
|
104
|
+
// A recorded preparation the backend no longer holds, whose file now prepares to other bytes
|
|
105
|
+
// (the rule changed since): prepared anew, and planned again.
|
|
106
|
+
const stale = (result.failed || []).filter((f) => f.stale)
|
|
107
|
+
if (stale.length) {
|
|
108
|
+
const again = []
|
|
109
|
+
for (const f of stale) {
|
|
110
|
+
const was = files.find((x) => x.path === f.path)
|
|
111
|
+
if (!was) continue
|
|
112
|
+
const bytes = readFileSync(was.diskPath)
|
|
113
|
+
const file = {
|
|
114
|
+
path: was.key,
|
|
115
|
+
content_type: contentTypeFor(basename(was.diskPath)),
|
|
116
|
+
size: bytes.length,
|
|
117
|
+
sha256: sha256(bytes),
|
|
118
|
+
localUrl: was.localUrl,
|
|
119
|
+
diskPath: was.diskPath
|
|
120
|
+
}
|
|
121
|
+
again.push(await preparedFile(file, bytes, extOf(was.diskPath), null, warn, { keepFormat: was.keepFormat }))
|
|
122
|
+
}
|
|
123
|
+
const retry = await client.uploadSiteAssets({ files: again, siteUuid, onProgress })
|
|
124
|
+
result = {
|
|
125
|
+
...result,
|
|
126
|
+
failed: [...result.failed.filter((f) => !f.stale), ...(retry.failed || [])],
|
|
127
|
+
assetsByLocalUrl: { ...result.assetsByLocalUrl, ...retry.assetsByLocalUrl }
|
|
128
|
+
}
|
|
129
|
+
for (const f of again) files[files.findIndex((x) => x.localUrl === f.localUrl)] = f
|
|
130
|
+
}
|
|
89
131
|
const failed = [...(result.failed || [])]
|
|
90
132
|
for (const f of failed)
|
|
91
133
|
warn?.(`local-media: upload failed for ${f.path} (HTTP ${f.status})`)
|
|
@@ -104,10 +146,14 @@ export async function uploadSiteMedia(
|
|
|
104
146
|
// id beside it (`info.preview`, `seo.image`, a section param); the header of
|
|
105
147
|
// `@uniweb/build`'s asset-map.js says why a hash and not the URL.
|
|
106
148
|
if (entry.id) {
|
|
149
|
+
// A prepared picture also records the file it was made from and its stored size, so the next
|
|
150
|
+
// push reuses it rather than preparing the file again (`preparedFile`).
|
|
151
|
+
const sent = files.find((f) => f.localUrl === ref)
|
|
107
152
|
ids[ref] = {
|
|
108
153
|
id: entry.id,
|
|
109
154
|
ext: entry.ext || '',
|
|
110
|
-
...(entry.serveUrl ? { served: servedFingerprint(entry.serveUrl) } : {})
|
|
155
|
+
...(entry.serveUrl ? { served: servedFingerprint(entry.serveUrl) } : {}),
|
|
156
|
+
...(sent?.source ? { source: sent.source, size: sent.size } : {})
|
|
111
157
|
}
|
|
112
158
|
}
|
|
113
159
|
// The backend's canonical serve URL, READ — never composed. An entry without
|
|
@@ -135,6 +181,72 @@ export async function uploadSiteMedia(
|
|
|
135
181
|
return { map, ids, missing, served, failed }
|
|
136
182
|
}
|
|
137
183
|
|
|
184
|
+
const sha256 = (bytes) => createHash('sha256').update(bytes).digest('hex')
|
|
185
|
+
const extOf = (path) => (basename(path).match(/\.([^.]+)$/)?.[1] || '').toLowerCase()
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The plan entry for a picture a page shows, stored as `prepareImage` makes it. Three cases, by what
|
|
189
|
+
* this backend's asset map records for the ref:
|
|
190
|
+
*
|
|
191
|
+
* - **Prepared before, from these same bytes** (`source` is their hash): planned by the identity it
|
|
192
|
+
* recorded, with no bytes, so nothing is prepared again. The backend still holding it, the plan
|
|
193
|
+
* says so and nothing moves. If it doesn't, `load` prepares the file again. So a change to the
|
|
194
|
+
* rule never prepares, uploads or charges an unchanged picture again, and its pages don't change.
|
|
195
|
+
* - **Stored as it is, before pictures were prepared** (no `source`, and the id is these bytes'
|
|
196
|
+
* hash, the asset plan's content address): left as it is, and its source recorded.
|
|
197
|
+
* - **New or changed:** prepared now.
|
|
198
|
+
*
|
|
199
|
+
* @param {object} file - the plan entry for the file as it is
|
|
200
|
+
* @param {Buffer} bytes - the file
|
|
201
|
+
* @param {string} ext - its extension
|
|
202
|
+
* @param {object|undefined|null} prior - its entry in the asset map
|
|
203
|
+
* @param {(m: string) => void} [warn]
|
|
204
|
+
* @param {{ keepFormat?: boolean }} [options] - a picture other software fetches by its address
|
|
205
|
+
*/
|
|
206
|
+
async function preparedFile(file, bytes, ext, prior, warn, { keepFormat = false } = {}) {
|
|
207
|
+
const source = file.sha256
|
|
208
|
+
const key = file.path
|
|
209
|
+
if (prior?.source === source && prior.id && prior.ext && Number.isInteger(prior.size)) {
|
|
210
|
+
return {
|
|
211
|
+
...file,
|
|
212
|
+
key,
|
|
213
|
+
path: storedPath(key, ext, prior.ext),
|
|
214
|
+
content_type: contentTypeFor(`x.${prior.ext}`),
|
|
215
|
+
size: prior.size,
|
|
216
|
+
sha256: prior.id,
|
|
217
|
+
source,
|
|
218
|
+
keepFormat,
|
|
219
|
+
load: async () => (await prepareImage(bytes, ext, { keepFormat })).bytes
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (prior && !prior.source && prior.id === source) return { ...file, key, source }
|
|
223
|
+
|
|
224
|
+
const prepared = await prepareImage(bytes, ext, { keepFormat })
|
|
225
|
+
if (prepared.unreadable) {
|
|
226
|
+
warn?.(`local-media: ${file.localUrl} is uploaded as it is: it can't be converted here, and some browsers can't show it`)
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
...file,
|
|
230
|
+
key,
|
|
231
|
+
path: storedPath(key, ext, prepared.ext),
|
|
232
|
+
content_type: contentTypeFor(`x.${prepared.ext}`),
|
|
233
|
+
size: prepared.bytes.length,
|
|
234
|
+
sha256: sha256(prepared.bytes),
|
|
235
|
+
bytes: prepared.bytes,
|
|
236
|
+
source,
|
|
237
|
+
keepFormat
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* The plan's key for a prepared file. The backend types an upload by its extension, so a picture
|
|
243
|
+
* stored as a WebP goes by one ending in `.webp`: its own key with the extension added, which keeps
|
|
244
|
+
* it apart from every other file's.
|
|
245
|
+
*/
|
|
246
|
+
function storedPath(key, ext, storedExt) {
|
|
247
|
+
return storedExt === ext ? key : `${key}.${storedExt}`
|
|
248
|
+
}
|
|
249
|
+
|
|
138
250
|
// ─── Asset-plan refusals ──────────────────────────────────────────────────────
|
|
139
251
|
//
|
|
140
252
|
// There is deliberately NO status-based refusal predicate here, and re-adding
|
package/src/commands/publish.js
CHANGED
|
@@ -791,7 +791,11 @@ export async function publish(args = []) {
|
|
|
791
791
|
{
|
|
792
792
|
siteUuid: site.uuid,
|
|
793
793
|
onProgress: (m) => say.dim(` ${m}`),
|
|
794
|
-
warn: (m) => say.dim(`! ${m}`)
|
|
794
|
+
warn: (m) => say.dim(`! ${m}`),
|
|
795
|
+
// What each picture was stored as, so an unchanged one is not prepared again.
|
|
796
|
+
recorded: readBackendState(siteDir, client.origin).assets || {},
|
|
797
|
+
// The pictures other software fetches (favicon, touch icon, card, social images): in their format.
|
|
798
|
+
keepFormat: new Set(probe.outsideAssets || [])
|
|
795
799
|
}
|
|
796
800
|
)
|
|
797
801
|
// A ref whose bytes did not land must NOT be published: the content would go
|
package/src/commands/push.js
CHANGED
|
@@ -516,6 +516,8 @@ export async function push(args = [], deps = {}) {
|
|
|
516
516
|
let created = null
|
|
517
517
|
if (!output && !dryRun) {
|
|
518
518
|
let mediaRefs = []
|
|
519
|
+
// The pictures other software fetches (favicon, touch icon, card, social images): uploaded as they are.
|
|
520
|
+
let outsideRefs = new Set()
|
|
519
521
|
let refusals = []
|
|
520
522
|
let held = null
|
|
521
523
|
try {
|
|
@@ -531,6 +533,7 @@ export async function push(args = [], deps = {}) {
|
|
|
531
533
|
})
|
|
532
534
|
// Site-root media, and each file record's file (`@uniweb/file` — `{ ref, path, contentType }`).
|
|
533
535
|
mediaRefs = [...(probe.localAssets || []), ...(probe.localFiles || [])]
|
|
536
|
+
outsideRefs = new Set(probe.outsideAssets || [])
|
|
534
537
|
refusals = probe.refusals || []
|
|
535
538
|
held = probe
|
|
536
539
|
} catch (err) {
|
|
@@ -573,7 +576,10 @@ export async function push(args = [], deps = {}) {
|
|
|
573
576
|
{
|
|
574
577
|
siteUuid: site.uuid,
|
|
575
578
|
onProgress: (m) => note(` ${m}`),
|
|
576
|
-
warn: (m) => note(`! ${m}`)
|
|
579
|
+
warn: (m) => note(`! ${m}`),
|
|
580
|
+
// What each picture was stored as, so an unchanged one is not prepared again.
|
|
581
|
+
recorded: readBackendState(siteDir, client.origin).assets || {},
|
|
582
|
+
keepFormat: outsideRefs
|
|
577
583
|
}
|
|
578
584
|
)
|
|
579
585
|
// Bytes that did not land must not be pushed around: the content would go
|
package/src/framework-index.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"generatedAt": "2026-11-
|
|
3
|
+
"generatedAt": "2026-11-12T22:48:58.824Z",
|
|
4
4
|
"packages": {
|
|
5
5
|
"@uniweb/api": {
|
|
6
6
|
"version": "1.7.0"
|
|
7
7
|
},
|
|
8
8
|
"@uniweb/build": {
|
|
9
|
-
"version": "1.23.
|
|
9
|
+
"version": "1.23.6"
|
|
10
10
|
},
|
|
11
11
|
"@uniweb/content-reader": {
|
|
12
12
|
"version": "1.5.10"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"version": "1.3.2"
|
|
16
16
|
},
|
|
17
17
|
"@uniweb/core": {
|
|
18
|
-
"version": "1.6.
|
|
18
|
+
"version": "1.6.13"
|
|
19
19
|
},
|
|
20
20
|
"@uniweb/frame-bridge": {
|
|
21
21
|
"version": "1.0.4"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"version": "1.2.17"
|
|
37
37
|
},
|
|
38
38
|
"@uniweb/runtime": {
|
|
39
|
-
"version": "1.6.
|
|
39
|
+
"version": "1.6.5"
|
|
40
40
|
},
|
|
41
41
|
"@uniweb/scene": {
|
|
42
42
|
"version": "1.0.1"
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"version": "1.1.3"
|
|
49
49
|
},
|
|
50
50
|
"@uniweb/semantic-parser": {
|
|
51
|
-
"version": "1.13.
|
|
51
|
+
"version": "1.13.5"
|
|
52
52
|
},
|
|
53
53
|
"@uniweb/snapshot": {
|
|
54
54
|
"version": "1.1.2"
|
|
@@ -206,6 +206,20 @@ export async function uploadSiteAssets({
|
|
|
206
206
|
continue
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
// The bytes to send: held, read from the file, or made again. A file a push prepared before
|
|
210
|
+
// is planned by the identity it recorded, with no bytes; when the backend no longer holds them,
|
|
211
|
+
// `load` prepares the file again, which must give the recorded bytes. Bytes that differ (the
|
|
212
|
+
// rule changed since) are `stale`, for the caller to plan as a new preparation.
|
|
213
|
+
let body = src.bytes
|
|
214
|
+
if (!body && typeof src.load === 'function') {
|
|
215
|
+
body = await src.load()
|
|
216
|
+
if (createHash('sha256').update(body).digest('hex') !== src.sha256) {
|
|
217
|
+
failed.push({ path: src.path, status: 0, detail: 'prepares to other bytes than recorded', stale: true })
|
|
218
|
+
continue
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (!body) body = readFileSync(src.diskPath)
|
|
222
|
+
|
|
209
223
|
const headers = { ...(up.headers || {}), 'x-uniweb-sha256': src.sha256 }
|
|
210
224
|
// Direct-mode PUTs are authed requests to the backend; presigned URLs are
|
|
211
225
|
// self-signed, so a foreign auth header can break the SigV4 target. This is
|
|
@@ -228,7 +242,7 @@ export async function uploadSiteAssets({
|
|
|
228
242
|
putRes = await fetchWithRetry(new URL(up.url, origin), {
|
|
229
243
|
method: up.method || 'PUT',
|
|
230
244
|
headers,
|
|
231
|
-
body
|
|
245
|
+
body
|
|
232
246
|
}, { timeoutMs: 120_000, retryOnStatus: isTransientStatus })
|
|
233
247
|
} catch (err) {
|
|
234
248
|
failed.push({ path: src.path, status: 0, detail: err.message })
|