@uniweb/build 1.12.1 → 1.13.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/uwx/page-refs.js +171 -0
- package/src/uwx/site-project.js +5 -0
- package/src/uwx/site.js +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -57,14 +57,14 @@
|
|
|
57
57
|
"sharp": "^0.35.5",
|
|
58
58
|
"yaml": "^2.5.0",
|
|
59
59
|
"@uniweb/content-reader": "~1.5.7",
|
|
60
|
-
"@uniweb/content-writer": "~1.3.1",
|
|
61
|
-
"@uniweb/projections": "~1.2.8",
|
|
62
60
|
"@uniweb/theming": "~1.2.1",
|
|
61
|
+
"@uniweb/content-writer": "~1.3.1",
|
|
63
62
|
"@uniweb/semantic-parser": "~1.13.0",
|
|
64
|
-
"@uniweb/schemas": "~1.6.7"
|
|
63
|
+
"@uniweb/schemas": "~1.6.7",
|
|
64
|
+
"@uniweb/projections": "~1.2.8"
|
|
65
65
|
},
|
|
66
66
|
"optionalDependencies": {
|
|
67
|
-
"@uniweb/runtime": "~1.
|
|
67
|
+
"@uniweb/runtime": "~1.3.0"
|
|
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/core": "~1.5.0",
|
|
77
|
+
"@uniweb/runtime": "~1.3.0"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"vite": {
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ⭐ A LINK TO A PAGE IS A PATH IN FILES AND AN ID IN THE STORE (2026-10-29) [Diego: "When working
|
|
3
|
+
* on the app, it is convenient. but with md content, it's easier to see paths than ids"].
|
|
4
|
+
*
|
|
5
|
+
* An editor links a page by its stable id (`page:3f58142d`): an author picks the page from a list,
|
|
6
|
+
* and the id keeps the link when the page is renamed there, since a store keeps a link as written.
|
|
7
|
+
* A file is read and typed, and `page:ai` says where it goes. So the sync translates where it
|
|
8
|
+
* already reads rich text: a push stores a link by its page's id when the page has one
|
|
9
|
+
* (`storedPageRef`), and a pull writes a stored link as its page's path (`writtenPageRef`). A pull
|
|
10
|
+
* and then a push change nothing, each turning back what the other wrote.
|
|
11
|
+
*
|
|
12
|
+
* ⭐ ONLY A CODE IS TRANSLATED. An id an author chose is a word (`installation`, `home`), reads as
|
|
13
|
+
* well as a path, and is kept as written both ways; translating it would rewrite a file a round trip
|
|
14
|
+
* should leave alone (measured: a docs site's ten files, on the round trip that caught it). A code
|
|
15
|
+
* (`isCodeId`: hex with a digit, as an editor mints it) is what a file shows as the page's path, and
|
|
16
|
+
* what a push stores for a path to a page that has one. A code an author typed into a file comes
|
|
17
|
+
* back the page's path after one pull.
|
|
18
|
+
*
|
|
19
|
+
* Both read a reference as the runtime does (`core/src/website.js`, `_pageIdMap`): by a page's
|
|
20
|
+
* stable id, else by its route, the homepage's being `page:/`. So a path written into a file names
|
|
21
|
+
* the page its id named. A path that another page's id claims, and a parametric page, stay ids.
|
|
22
|
+
*
|
|
23
|
+
* A reference lives in a link or button mark's `href`, a linked image's `href`, any string in a
|
|
24
|
+
* section's params that is one `page:` reference (a `detailPage`, a button's link), and a page's
|
|
25
|
+
* `redirect`. ⛔ Never in text: a code span that reads `page:about` is words about a link.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const PAGE_REF = /^page:([^#]*)(#.*)?$/
|
|
29
|
+
|
|
30
|
+
/** A route as a `page:` reference names it: no leading or trailing slash, the homepage `''`. */
|
|
31
|
+
const routeKey = (route) => String(route).replace(/^\/+/, '').replace(/\/+$/, '')
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Whether a page's id is a code rather than a word: eight or more hex characters with a digit
|
|
35
|
+
* among them, the shape an editor mints (`3f58142d`). `installation`, `home` and `v1-guide` are
|
|
36
|
+
* words, and so is `cafe`.
|
|
37
|
+
*
|
|
38
|
+
* @param {string|null} id
|
|
39
|
+
* @returns {boolean}
|
|
40
|
+
*/
|
|
41
|
+
export function isCodeId(id) {
|
|
42
|
+
return typeof id === 'string' && /^(?=[0-9a-f]*[0-9])[0-9a-f]{8,}$/.test(id)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The site's pages, each with the route a build gives it, in page order.
|
|
47
|
+
*
|
|
48
|
+
* @param {Array<object>} pages - page records (`stable_id`, `slug`, `$children`, …)
|
|
49
|
+
* @param {string} sourceLocale
|
|
50
|
+
* @param {(record: object, parentRoute: string, sourceLocale: string) => string} routeOf -
|
|
51
|
+
* `buildRouteOf`, passed in so this module stays a leaf
|
|
52
|
+
* @returns {Array<{ id: string|null, route: string, dynamic: boolean }>}
|
|
53
|
+
*/
|
|
54
|
+
export function pageRefPages(pages, sourceLocale, routeOf) {
|
|
55
|
+
const out = []
|
|
56
|
+
const walk = (list, parentRoute) => {
|
|
57
|
+
for (const record of list || []) {
|
|
58
|
+
if (!record || typeof record !== 'object') continue
|
|
59
|
+
const route = routeOf(record, parentRoute, sourceLocale)
|
|
60
|
+
out.push({ id: typeof record.stable_id === 'string' && record.stable_id ? record.stable_id : null, route, dynamic: record.is_dynamic === true })
|
|
61
|
+
walk(record.$children, route)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
walk(pages, '/')
|
|
65
|
+
return out
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* What a `page:` reference resolves to among a site's pages, by the runtime's rule: a page's id
|
|
70
|
+
* (which wins over any route), else its route, a target read the way a route is.
|
|
71
|
+
*
|
|
72
|
+
* @param {Array<{ id: string|null, route: string, dynamic: boolean }>} pages - `pageRefPages`
|
|
73
|
+
* @returns {{ resolve: (target: string) => object|undefined }}
|
|
74
|
+
*/
|
|
75
|
+
export function pageRefIndex(pages) {
|
|
76
|
+
const byName = new Map()
|
|
77
|
+
for (const page of pages) {
|
|
78
|
+
if (page.id) byName.set(page.id, page)
|
|
79
|
+
const key = routeKey(page.route)
|
|
80
|
+
if (!byName.has(key)) byName.set(key, page)
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
resolve: (target) =>
|
|
84
|
+
typeof target === 'string' ? (byName.get(target) ?? byName.get(routeKey(target))) : undefined,
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* A push's form of a reference: `page:<code>` when the page it names has a code for its id
|
|
90
|
+
* (`isCodeId`), else as written — a path to a page whose id is a word, or none, stays a path. A
|
|
91
|
+
* section after `#` rides along unchanged.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} ref
|
|
94
|
+
* @param {{ resolve: Function }} index - `pageRefIndex`
|
|
95
|
+
* @returns {string}
|
|
96
|
+
*/
|
|
97
|
+
export function storedPageRef(ref, index) {
|
|
98
|
+
const m = typeof ref === 'string' ? PAGE_REF.exec(ref) : null
|
|
99
|
+
const page = m && index.resolve(m[1])
|
|
100
|
+
return isCodeId(page?.id) ? `page:${page.id}${m[2] || ''}` : ref
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A pull's form of a reference that names its page by a code: `page:<path>`, when that path
|
|
105
|
+
* names the same page back, else as stored. Any other reference — a path, a word id — is written
|
|
106
|
+
* as stored. The homepage is `page:/`.
|
|
107
|
+
*
|
|
108
|
+
* @param {string} ref
|
|
109
|
+
* @param {{ resolve: Function }} index - `pageRefIndex`
|
|
110
|
+
* @returns {string}
|
|
111
|
+
*/
|
|
112
|
+
export function writtenPageRef(ref, index) {
|
|
113
|
+
const m = typeof ref === 'string' ? PAGE_REF.exec(ref) : null
|
|
114
|
+
const page = m && index.resolve(m[1])
|
|
115
|
+
if (!page || page.dynamic || m[1] !== page.id || !isCodeId(page.id)) return ref
|
|
116
|
+
const path = routeKey(page.route) || '/'
|
|
117
|
+
return index.resolve(path) === page ? `page:${path}${m[2] || ''}` : ref
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Every page reference in a site's page and layout records, through `map`: each section's content
|
|
122
|
+
* in every language, its params and its subsections, and each page's `redirect` and child pages.
|
|
123
|
+
* Mutates the records.
|
|
124
|
+
*
|
|
125
|
+
* @param {{ pages?: Array<object>, layoutSections?: Array<object> }} records
|
|
126
|
+
* @param {(ref: string) => string} map - `storedPageRef` or `writtenPageRef`, bound to an index
|
|
127
|
+
*/
|
|
128
|
+
export function mapPageRefs({ pages, layoutSections }, map) {
|
|
129
|
+
const section = (record) => {
|
|
130
|
+
if (!record || typeof record !== 'object') return
|
|
131
|
+
if (record.content && typeof record.content === 'object') mapContent(record.content, map)
|
|
132
|
+
if (record.params && typeof record.params === 'object') record.params = mapValue(record.params, map)
|
|
133
|
+
for (const child of record.$children || []) section(child)
|
|
134
|
+
}
|
|
135
|
+
const page = (record) => {
|
|
136
|
+
if (!record || typeof record !== 'object') return
|
|
137
|
+
if (typeof record.redirect === 'string') record.redirect = map(record.redirect)
|
|
138
|
+
for (const s of record.page_sections || []) section(s)
|
|
139
|
+
for (const child of record.$children || []) page(child)
|
|
140
|
+
}
|
|
141
|
+
for (const record of pages || []) page(record)
|
|
142
|
+
for (const record of layoutSections || []) section(record)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** A section's content: one document, or one per language (`{ en: doc, fr: doc }`). */
|
|
146
|
+
function mapContent(content, map) {
|
|
147
|
+
if (content.type === 'doc') return mapDoc(content, map)
|
|
148
|
+
for (const doc of Object.values(content)) if (doc?.type === 'doc') mapDoc(doc, map)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Each `href` on a node or a mark in a rich-text document — a link, a button, a linked image. */
|
|
152
|
+
function mapDoc(node, map) {
|
|
153
|
+
if (!node || typeof node !== 'object') return
|
|
154
|
+
if (typeof node.attrs?.href === 'string') node.attrs.href = map(node.attrs.href)
|
|
155
|
+
for (const mark of node.marks || []) {
|
|
156
|
+
if (typeof mark?.attrs?.href === 'string') mark.attrs.href = map(mark.attrs.href)
|
|
157
|
+
}
|
|
158
|
+
if (Array.isArray(node.content)) for (const child of node.content) mapDoc(child, map)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** A params value, with each string that is one `page:` reference through `map`. */
|
|
162
|
+
function mapValue(value, map) {
|
|
163
|
+
if (typeof value === 'string') return PAGE_REF.test(value) ? map(value) : value
|
|
164
|
+
if (Array.isArray(value)) return value.map((v) => mapValue(v, map))
|
|
165
|
+
if (value && typeof value === 'object') {
|
|
166
|
+
const out = {}
|
|
167
|
+
for (const [key, v] of Object.entries(value)) out[key] = mapValue(v, map)
|
|
168
|
+
return out
|
|
169
|
+
}
|
|
170
|
+
return value
|
|
171
|
+
}
|
package/src/uwx/site-project.js
CHANGED
|
@@ -37,6 +37,7 @@ import { foldOpenGraph } from './open-graph.js'
|
|
|
37
37
|
import { isAuthoredPreview } from './authored-preview.js'
|
|
38
38
|
import { join, relative, extname, basename, dirname } from 'node:path'
|
|
39
39
|
import { restoreAssetRefs } from './asset-map.js'
|
|
40
|
+
import { mapPageRefs, pageRefIndex, pageRefPages, writtenPageRef } from './page-refs.js'
|
|
40
41
|
import { siteFileKeys, siteTree, writtenRefs } from './located-media.js'
|
|
41
42
|
import { readBackendState, updateBackendState } from './sync-store.js'
|
|
42
43
|
import { servicesFromDocument, heldServices } from './services-request.js'
|
|
@@ -1380,6 +1381,10 @@ export function siteContentDocumentToProject({ document, siteRoot, backend = nul
|
|
|
1380
1381
|
// abstract.
|
|
1381
1382
|
const assetMap = backend ? readBackendState(siteRoot, backend).assets || {} : {}
|
|
1382
1383
|
report.assets = restoreAssetRefs(document, assetMap)
|
|
1384
|
+
// ⭐ And each stored link to a page as the page's path (`page-refs.js`): what a file shows, where
|
|
1385
|
+
// the store keeps the id an editor links by.
|
|
1386
|
+
const refIndex = pageRefIndex(pageRefPages(document?.pages, sourceLocale, buildRouteOf))
|
|
1387
|
+
mapPageRefs({ pages: document?.pages, layoutSections: document?.layout_sections }, (ref) => writtenPageRef(ref, refIndex))
|
|
1383
1388
|
// The keys among them that name a site file — a co-located file a push uploaded — for each
|
|
1384
1389
|
// section's writer to make relative to its own file (`located-media.js`).
|
|
1385
1390
|
const mediaKeys = siteFileKeys(assetMap)
|
package/src/uwx/site.js
CHANGED
|
@@ -80,6 +80,7 @@ import { siteDefaultSectionType } from '../site/queries-config.js'
|
|
|
80
80
|
import { resolveDefaultLocale, validateLanguageConfig, queryDataUrl } from '@uniweb/core'
|
|
81
81
|
import { emitEntitySyncPackage } from './entity-document.js'
|
|
82
82
|
import { locateSectionMedia, siteTree } from './located-media.js'
|
|
83
|
+
import { mapPageRefs, pageRefIndex, pageRefPages, storedPageRef } from './page-refs.js'
|
|
83
84
|
import { loadLocaleTranslations, localizeScalar, localizeScalarList, localizeContentDoc, localesDir, isLocalizedContent, plainTextTargets } from './locale-sync.js'
|
|
84
85
|
import { unwrapLocalized } from './backfill.js'
|
|
85
86
|
import { loadFreeformTranslation } from '../i18n/freeform.js'
|
|
@@ -1659,6 +1660,11 @@ export async function siteProjectToDocument(siteRoot, opts = {}) {
|
|
|
1659
1660
|
// field with two shapes is a store that cannot validate its own declaration.
|
|
1660
1661
|
await localizeContentTree(pages, layoutSections, sourceLocale, targetLocales, translations, siteRoot)
|
|
1661
1662
|
|
|
1663
|
+
// ⭐ A link to a page is stored by the page's id where it has one (`page-refs.js`), so it
|
|
1664
|
+
// survives a rename in an editor, and a pull writes it back as the path a file shows.
|
|
1665
|
+
const refIndex = pageRefIndex(pageRefPages(pages, sourceLocale, buildRouteOf))
|
|
1666
|
+
mapPageRefs({ pages, layoutSections }, (ref) => storedPageRef(ref, refIndex))
|
|
1667
|
+
|
|
1662
1668
|
// Collection DECLARATIONS — the merged collections.yml + site.yml::collections
|
|
1663
1669
|
// config (the records themselves are separate entities; this is just the config).
|
|
1664
1670
|
const colConfig = await resolveQueriesConfig(siteRoot, { siteYml })
|