@uniweb/build 1.15.4 → 1.15.6
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 +6 -6
- package/src/prerender.js +89 -4
- package/src/site/content-collector.js +31 -22
- package/src/site/file-links.js +91 -26
- package/src/site/index.js +3 -0
- package/src/site/mount-entries.js +46 -0
- package/src/uwx/body-splice.js +85 -0
- package/src/uwx/data-schema.js +4 -0
- package/src/uwx/emit-surface.json +0 -3
- package/src/uwx/index.js +3 -0
- package/src/uwx/page-files.js +255 -0
- package/src/uwx/project-writer.js +19 -3
- package/src/uwx/same-content.js +7 -4
- package/src/uwx/site-dirs.js +50 -6
- package/src/uwx/site-project.js +373 -49
- package/src/uwx/site.js +5 -2
- package/src/uwx/git-authored.js +0 -85
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// WHERE EACH PAGE OF A SITE IS KEPT — found in its files by the build's own rules, never computed from
|
|
2
|
+
// a document: a document says what a page is, not where its files are. A pull writes a page where this
|
|
3
|
+
// says it lives: `2-about/` holds /about, and `guide/1-install.md` holds /guide/install.
|
|
4
|
+
//
|
|
5
|
+
// ⛔ Until 2026-11-04 a pull named a page's folder by its slug (`pageDirName`): `pages/2-about/` came
|
|
6
|
+
// back as `pages/about/`, the numbered folder pruned. And it could not write a folder-mode `.md` page
|
|
7
|
+
// at all, so it left every one alone (`git-authored.js`, which this replaces), and an edit made to one
|
|
8
|
+
// in the app was undone by the next push.
|
|
9
|
+
//
|
|
10
|
+
// The pages a pull leaves alone are now those it may not or cannot write:
|
|
11
|
+
// · every page under a read-only `paths: { pages/<segment>: <dir> }` mount — any the site does not
|
|
12
|
+
// declare `writable: true`, or whose folder the caller may not write (`writable`). Its files are
|
|
13
|
+
// another repository's, or a folder outside the site; the local folder of that name holds only how
|
|
14
|
+
// this site presents them, and a pull writing the mounted pages into it would grow a second copy;
|
|
15
|
+
// · a route the files give two pages for — a file and a folder of one name, `topics.md` beside
|
|
16
|
+
// `topics/` — since a page in the document cannot say which of the two it is.
|
|
17
|
+
// A pull deletes neither, nor a folder that holds one (`holds`): a pull never deletes what it does not
|
|
18
|
+
// write.
|
|
19
|
+
//
|
|
20
|
+
// ⭐ A WRITABLE MOUNT'S PAGES ARE WHERE THE PUSH READS THEM: in the mounted folder, its own route layered
|
|
21
|
+
// as the push layers it (`layerMountedFolder`) — the stub's config over the mounted folder's, the
|
|
22
|
+
// route's sections in the stub when there is one, its pages in the mounted folder.
|
|
23
|
+
//
|
|
24
|
+
// A leaf, read synchronously as the pull projects (`site-project.js`), through the rules the push's
|
|
25
|
+
// walk reads with — `folderContentMode`, `folderModePageFiles`, `parseNumericPrefix`,
|
|
26
|
+
// `layerMountedFolder`, `mountDeclarationsOf` — so the pages it finds are the ones the push sends
|
|
27
|
+
// (`tests/uwx-page-files.test.js`).
|
|
28
|
+
|
|
29
|
+
import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs'
|
|
30
|
+
import { dirname, join, resolve, sep } from 'node:path'
|
|
31
|
+
import yaml from 'js-yaml'
|
|
32
|
+
import { YAML_OPTIONS } from '../utils/yaml-schema.js'
|
|
33
|
+
import { isIgnoredFolder } from '../utils/content-files.js'
|
|
34
|
+
import { extractH1, folderContentMode, folderModePageFiles, layerMountedFolder, parseNumericPrefix, prettifySlug } from '../site/content-collector.js'
|
|
35
|
+
import { mountDeclarationsOf } from '../site/mount-entries.js'
|
|
36
|
+
import { unwrapLocalized } from './backfill.js'
|
|
37
|
+
import { isProseMirrorDoc } from './locale-sync.js'
|
|
38
|
+
|
|
39
|
+
const DYNAMIC_RE = /^\[(.+)\]$/
|
|
40
|
+
|
|
41
|
+
// The collector's own reading of a config file (`parseYaml`): absent or unreadable is empty.
|
|
42
|
+
function readYaml(filePath) {
|
|
43
|
+
try {
|
|
44
|
+
return yaml.load(readFileSync(filePath, 'utf8'), YAML_OPTIONS) || {}
|
|
45
|
+
} catch {
|
|
46
|
+
return {}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A folder's mode as the build reads it now (`readFolderConfig`): `pages` — its `.md` files are pages —
|
|
52
|
+
* or `sections` — they are its page's sections. A folder with no config of its own inherits.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} dir
|
|
55
|
+
* @param {'pages'|'sections'} inheritedMode
|
|
56
|
+
* @returns {'pages'|'sections'}
|
|
57
|
+
*/
|
|
58
|
+
export function folderModeOf(dir, inheritedMode) {
|
|
59
|
+
return folderConfigOf(dir, inheritedMode).mode
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A folder's config as the build reads it (`readFolderConfig`): the config, its mode, and the file it
|
|
64
|
+
* is in — `source`, `'inherited'` when there is none.
|
|
65
|
+
*
|
|
66
|
+
* @param {string} dir
|
|
67
|
+
* @param {'pages'|'sections'} inheritedMode
|
|
68
|
+
* @returns {{ config: object, mode: 'pages'|'sections', source: 'folder.yml'|'page.yml'|'inherited' }}
|
|
69
|
+
*/
|
|
70
|
+
export function folderConfigOf(dir, inheritedMode) {
|
|
71
|
+
const folderYml = readYaml(join(dir, 'folder.yml'))
|
|
72
|
+
const pageYml = Object.keys(folderYml).length > 0 ? {} : readYaml(join(dir, 'page.yml'))
|
|
73
|
+
const { mode, source } = folderContentMode(folderYml, pageYml, existsSync(join(dir, 'folder.yml')), inheritedMode)
|
|
74
|
+
return { config: source === 'folder.yml' ? folderYml : source === 'page.yml' ? pageYml : {}, mode, source }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const isDirectory = (p) => {
|
|
78
|
+
try {
|
|
79
|
+
return statSync(p).isDirectory()
|
|
80
|
+
} catch {
|
|
81
|
+
return false
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The pages of a site, each by its route — a slug path with no leading slash (`docs/start/install`),
|
|
87
|
+
* as the pull composes a page's route from the document — and where it is kept:
|
|
88
|
+
*
|
|
89
|
+
* - `{ kind: 'folder', dir }`: a page folder, with its `page.yml` or `folder.yml` and its sections;
|
|
90
|
+
* - `{ kind: 'md', file, dir }`: a folder-mode `.md` file in the level `dir` — the page and its one section;
|
|
91
|
+
* - `{ kind: 'folder', dir, mount }`: a writable mount's own route — its sections in `dir`, the stub
|
|
92
|
+
* when there is one, else the mounted folder; its pages in `mount.dir`, walked in `mount.childMode`;
|
|
93
|
+
* its config layered from `mount.stub` over `mount.mounted`, each `folderConfigOf` with its folder;
|
|
94
|
+
* - `{ kind: 'mounted', segment }`: a route under a read-only mount, left alone;
|
|
95
|
+
* - `{ kind: 'twice', dir, file }`: a route the files give two pages for, left alone.
|
|
96
|
+
*
|
|
97
|
+
* @param {object|null} siteYml - the parsed `site.yml`
|
|
98
|
+
* @param {string} pagesDir - the site's pages directory (`siteContentDirs`)
|
|
99
|
+
* @param {{ seen?: Set<string>|null, siteRoot?: string|null, writable?: Iterable<string>|null }} [opts] -
|
|
100
|
+
* `seen`, the routes of the pages this copy has seen the backend hold: a folder holding an `.md`
|
|
101
|
+
* page it never saw is one a prune keeps (`holds`). `writable`, the segments of the mounts the
|
|
102
|
+
* caller may write — each one the site declares `writable: true` is walked into, from `siteRoot`
|
|
103
|
+
* @returns {{
|
|
104
|
+
* page: (route: string) => object|null,
|
|
105
|
+
* levelMode: (dir: string) => 'pages'|'sections'|undefined,
|
|
106
|
+
* mounted: Set<string>,
|
|
107
|
+
* writable: Map<string, string>,
|
|
108
|
+
* holds: (dir: string) => boolean,
|
|
109
|
+
* }} `mounted`, every mount's segment, whose local folder is a stub; `writable`, each writable
|
|
110
|
+
* mount's segment and folder
|
|
111
|
+
*/
|
|
112
|
+
export function sitePageFiles(siteYml, pagesDir, { seen = null, siteRoot = null, writable = null } = {}) {
|
|
113
|
+
const declared = mountDeclarationsOf(siteYml?.paths)
|
|
114
|
+
const mounted = new Set(declared.map((d) => d.segment))
|
|
115
|
+
// ⭐ A mount is written only where the site declares it `writable: true` AND the caller may write
|
|
116
|
+
// its folder — a pull decides that by the repository holding it, and any other caller writes none.
|
|
117
|
+
const allowed = new Set(writable ?? [])
|
|
118
|
+
const writableMounts = new Map()
|
|
119
|
+
for (const d of declared) {
|
|
120
|
+
if (!d.writable || !allowed.has(d.segment) || !siteRoot || typeof d.path !== 'string' || !d.path) continue
|
|
121
|
+
// The folder as the push reads it: through any link to it (`resolveMounts`).
|
|
122
|
+
const dir = resolve(siteRoot, d.path)
|
|
123
|
+
writableMounts.set(d.segment, existsSync(dir) ? realpathSync(dir) : dir)
|
|
124
|
+
}
|
|
125
|
+
const places = new Map()
|
|
126
|
+
const modes = new Map()
|
|
127
|
+
const put = (route, place) => {
|
|
128
|
+
const had = places.get(route)
|
|
129
|
+
if (!had) return places.set(route, place)
|
|
130
|
+
// A file and a folder of one name: both stay, as the push sends both.
|
|
131
|
+
places.set(route, { kind: 'twice', dir: had.kind === 'folder' ? had.dir : place.dir, file: had.kind === 'md' ? had.file : place.file })
|
|
132
|
+
}
|
|
133
|
+
// `ownMode`: the mode a level is read in when its parent decided it — a writable mount's folder, read
|
|
134
|
+
// in the mode its route gives its pages, never by its own config alone.
|
|
135
|
+
const walk = (dir, prefix, inheritedMode, ownMode = null) => {
|
|
136
|
+
let entries
|
|
137
|
+
try {
|
|
138
|
+
entries = readdirSync(dir, { withFileTypes: true })
|
|
139
|
+
} catch {
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
const mode = ownMode ?? folderModeOf(dir, inheritedMode)
|
|
143
|
+
modes.set(dir, mode)
|
|
144
|
+
if (mode === 'pages') {
|
|
145
|
+
for (const { file, name } of folderModePageFiles(entries.map((e) => e.name)).files) {
|
|
146
|
+
put(prefix + name, { kind: 'md', file: join(dir, file), dir })
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
for (const e of entries) {
|
|
150
|
+
if (!e.isDirectory() || isIgnoredFolder(e.name)) continue
|
|
151
|
+
if (!prefix && mounted.has(e.name)) continue // the whole route is the mount's
|
|
152
|
+
const dyn = e.name.match(DYNAMIC_RE)
|
|
153
|
+
const route = prefix + (dyn ? dyn[1] : parseNumericPrefix(e.name).name)
|
|
154
|
+
put(route, { kind: 'folder', dir: join(dir, e.name) })
|
|
155
|
+
walk(join(dir, e.name), `${route}/`, mode)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (existsSync(pagesDir)) walk(pagesDir, '', 'sections')
|
|
159
|
+
|
|
160
|
+
// Each writable mount's own route, as the push reads it at the site's root (`orderedSubfolders`), and
|
|
161
|
+
// its pages, walked in the mounted folder.
|
|
162
|
+
const rootMode = modes.get(pagesDir) ?? 'sections'
|
|
163
|
+
for (const [segment, mountDir] of writableMounts) {
|
|
164
|
+
const stubDir = join(pagesDir, segment)
|
|
165
|
+
const stub = isDirectory(stubDir) ? folderConfigOf(stubDir, rootMode) : null
|
|
166
|
+
const mountedConfig = folderConfigOf(mountDir, 'pages')
|
|
167
|
+
const { dirConfig, dirMode, childMode } = layerMountedFolder(segment, stub, mountedConfig, rootMode)
|
|
168
|
+
put(segment, {
|
|
169
|
+
kind: 'folder',
|
|
170
|
+
dir: stub ? stubDir : mountDir,
|
|
171
|
+
mount: { segment, dir: mountDir, stubDir, stub, mounted: mountedConfig, config: dirConfig, mode: dirMode, childMode },
|
|
172
|
+
})
|
|
173
|
+
walk(mountDir, `${segment}/`, childMode, childMode)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Each folder holding a page a prune must not take, and each one above it, up to the pages directory
|
|
177
|
+
// or the mounted folder it is in: removing any of them would remove that page with it. Those are the
|
|
178
|
+
// pages a pull leaves alone, and an `.md` page this copy never saw the backend hold — ⛔ a push before
|
|
179
|
+
// 2026-10-23 sent no folder-mode page, so a backend can lack one the files have always held, and read
|
|
180
|
+
// as deleted it would go.
|
|
181
|
+
const tops = [pagesDir, ...writableMounts.values()]
|
|
182
|
+
const holding = new Set()
|
|
183
|
+
const hold = (dir) => {
|
|
184
|
+
const top = tops.find((t) => dir === t || dir.startsWith(t + sep))
|
|
185
|
+
if (!top) return
|
|
186
|
+
for (let d = dir; d && d !== top; d = dirname(d)) holding.add(d)
|
|
187
|
+
}
|
|
188
|
+
for (const [route, place] of places) {
|
|
189
|
+
if (place.kind === 'twice') {
|
|
190
|
+
hold(place.dir)
|
|
191
|
+
hold(dirname(place.file))
|
|
192
|
+
} else if (place.kind === 'md' && !seen?.has(route)) hold(place.dir)
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
page: (route) => {
|
|
196
|
+
const segment = String(route).split('/')[0]
|
|
197
|
+
if (mounted.has(segment) && !writableMounts.has(segment)) return { kind: 'mounted', segment }
|
|
198
|
+
return places.get(route) ?? null
|
|
199
|
+
},
|
|
200
|
+
levelMode: (dir) => modes.get(dir),
|
|
201
|
+
mounted,
|
|
202
|
+
writable: writableMounts,
|
|
203
|
+
holds: (dir) => holding.has(dir),
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// The page fields a push sends for a folder-mode `.md` page are its title and `hidden`
|
|
208
|
+
// (`folderModePageRecords`, `site.js`), and `is_index` where it is the homepage. A page carrying any of
|
|
209
|
+
// these needs a page folder to hold it.
|
|
210
|
+
const NOT_IN_AN_MD_PAGE = ['description', 'label', 'keywords', 'hide_in', 'knowledge', 'track_sections', 'redirect', 'rewrite', 'layout', 'og_title', 'og_description', 'seo', 'fetch']
|
|
211
|
+
|
|
212
|
+
const isPlainObject = (v) => Boolean(v) && typeof v === 'object' && !Array.isArray(v)
|
|
213
|
+
|
|
214
|
+
// Does a field carry a value, its source locale's for a localized one?
|
|
215
|
+
function holdsValue(value, sourceLocale) {
|
|
216
|
+
if (value === undefined || value === null || value === false || value === '') return false
|
|
217
|
+
if (Array.isArray(value)) return value.length > 0
|
|
218
|
+
if (isPlainObject(value)) {
|
|
219
|
+
if (Object.prototype.hasOwnProperty.call(value, sourceLocale)) return holdsValue(value[sourceLocale], sourceLocale)
|
|
220
|
+
return Object.keys(value).length > 0
|
|
221
|
+
}
|
|
222
|
+
return true
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* What of a page a folder-mode `.md` file cannot hold — none, when it can be written as one. The file is
|
|
227
|
+
* the page and its one section: its title is its first heading, else its name prettified, and its
|
|
228
|
+
* frontmatter's `hidden:` drafts it. A second section, pages below it, a route parameter, a title its
|
|
229
|
+
* heading does not give, or any other page setting, it cannot say.
|
|
230
|
+
*
|
|
231
|
+
* ⚖️ A setting such a page might hold in its frontmatter is project-file-organization's §10 decision 1,
|
|
232
|
+
* not settled; until it is, a pull writes none.
|
|
233
|
+
*
|
|
234
|
+
* @param {object} record - the page's record
|
|
235
|
+
* @param {{ name: string, sourceLocale: string }} opts - `name`, the file's page name (`1-install.md` → `install`)
|
|
236
|
+
* @returns {string[]} what it cannot hold, in words
|
|
237
|
+
*/
|
|
238
|
+
export function mdPageCannotHold(record, { name, sourceLocale }) {
|
|
239
|
+
const out = []
|
|
240
|
+
const sections = Array.isArray(record?.page_sections) ? record.page_sections : []
|
|
241
|
+
if (sections.length !== 1) out.push(sections.length ? 'more than one section' : 'no section')
|
|
242
|
+
if (Array.isArray(record?.$children) && record.$children.length) out.push('pages below it')
|
|
243
|
+
if (record?.is_dynamic) out.push('a route parameter')
|
|
244
|
+
// Its id is its file's name; one the name does not give needs a page folder's `id:`.
|
|
245
|
+
if (typeof record?.stable_id === 'string' && record.stable_id && record.stable_id !== name) out.push('an id its file name does not give')
|
|
246
|
+
for (const key of NOT_IN_AN_MD_PAGE) if (holdsValue(record?.[key], sourceLocale)) out.push(key)
|
|
247
|
+
if (sections.length === 1) {
|
|
248
|
+
const content = sections[0]?.content
|
|
249
|
+
const doc = isProseMirrorDoc(content) ? content : unwrapLocalized(content, sourceLocale)
|
|
250
|
+
const given = extractH1(doc) || prettifySlug(name)
|
|
251
|
+
const title = unwrapLocalized(record?.title, sourceLocale)
|
|
252
|
+
if (typeof title === 'string' && title && title !== given) out.push('a title its first heading does not give')
|
|
253
|
+
}
|
|
254
|
+
return out
|
|
255
|
+
}
|
|
@@ -19,6 +19,8 @@ import { proseMirrorToMarkdown, serializeFrontmatter } from '@uniweb/content-wri
|
|
|
19
19
|
import { markdownToProseMirror } from '@uniweb/content-reader'
|
|
20
20
|
import { parseFrontmatter } from './entity-source.js'
|
|
21
21
|
import { canonicalJson, sameMarkdownDocument } from './same-content.js'
|
|
22
|
+
import { spliceBody } from './body-splice.js'
|
|
23
|
+
import { fileLinksIn } from '../site/file-links.js'
|
|
22
24
|
import { renderEntityDocument } from './backfill.js'
|
|
23
25
|
import { queriesYmlPath } from './queries-config.js'
|
|
24
26
|
import { folderYmlPath } from '../site/records-config.js'
|
|
@@ -149,6 +151,15 @@ function assembleSection(frontmatter, body) {
|
|
|
149
151
|
return ''
|
|
150
152
|
}
|
|
151
153
|
|
|
154
|
+
// The document a body reads to, or null where it reads to none.
|
|
155
|
+
function readsTo(body) {
|
|
156
|
+
try {
|
|
157
|
+
return markdownToProseMirror(body)
|
|
158
|
+
} catch {
|
|
159
|
+
return null
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
152
163
|
/**
|
|
153
164
|
* Write a section's `.md` file as the backend holds the section: its `params` and its
|
|
154
165
|
* data `declaration` replace the file's, `content` (ProseMirror) becomes the markdown
|
|
@@ -173,7 +184,7 @@ function assembleSection(frontmatter, body) {
|
|
|
173
184
|
* value equal to it is not written into an existing file that leaves the key out
|
|
174
185
|
* @returns {'updated'|'unchanged'}
|
|
175
186
|
*/
|
|
176
|
-
export function writeSectionFile({ filePath, content, params, declaration, reserved = DEFAULT_RESERVED_FRONTMATTER, implied = null }) {
|
|
187
|
+
export function writeSectionFile({ filePath, content, params, declaration, reserved = DEFAULT_RESERVED_FRONTMATTER, implied = null, fileLinks = null }) {
|
|
177
188
|
let existing = ''
|
|
178
189
|
try {
|
|
179
190
|
existing = readFileSync(filePath, 'utf8')
|
|
@@ -219,9 +230,14 @@ export function writeSectionFile({ filePath, content, params, declaration, reser
|
|
|
219
230
|
// Compared as a push reads it: the body as stored (`content-collector.js::processMarkdownFile`).
|
|
220
231
|
// ⛔ Until 2026-10-08 the trimmed copy was compared, so a body whose last line ended in a space never
|
|
221
232
|
// matched what a push had sent from it, and every pull rewrote it — trailing blank lines and all.
|
|
222
|
-
|
|
233
|
+
// ⭐ Its links as the push reads them, and back (`fileLinks`, `site/file-links.js::fileLinksIn`): a link
|
|
234
|
+
// the file writes as a file is the page link the backend holds for it, and stays as the file wrote it.
|
|
235
|
+
const links = fileLinks && existingBody ? fileLinksIn(filePath, fileLinks, readsTo(existingBody)) : null
|
|
236
|
+
const keepsBody = !content || sameMarkdownDocument(existingBody || '', content, { resolve: links?.resolve })
|
|
223
237
|
if (existing && keepsBody && canonicalJson(nextFrontmatter) === canonicalJson(frontmatter)) return 'unchanged'
|
|
224
|
-
|
|
238
|
+
// ⭐ A changed body is written block by block: what the change left keeps the author's text, and only
|
|
239
|
+
// the blocks it changed take the writer's form (`body-splice.js`) — whole only when that cannot be said.
|
|
240
|
+
const body = keepsBody ? authoredBody : (spliceBody(existingBody || '', content, { links }) ?? proseMirrorToMarkdown(links ? links.restore(content) : content))
|
|
225
241
|
return writeIfChanged(filePath, assembleSection(nextFrontmatter, body))
|
|
226
242
|
}
|
|
227
243
|
|
package/src/uwx/same-content.js
CHANGED
|
@@ -17,15 +17,18 @@ export const canonicalJson = (value) =>
|
|
|
17
17
|
)
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Does this markdown parse to `doc`, the way a push parses it?
|
|
20
|
+
* Does this markdown parse to `doc`, the way a push parses it? `resolve` reads it on, as the push does
|
|
21
|
+
* after parsing — a link written as a file, as the page link it sends (`site/file-links.js::fileLinksIn`).
|
|
21
22
|
*
|
|
22
23
|
* @param {string} markdown - an author's markdown body
|
|
23
24
|
* @param {object} doc - a ProseMirror document
|
|
25
|
+
* @param {{ resolve?: (doc: object) => object }} [opts]
|
|
24
26
|
* @returns {boolean}
|
|
25
27
|
*/
|
|
26
|
-
export function sameMarkdownDocument(markdown, doc) {
|
|
28
|
+
export function sameMarkdownDocument(markdown, doc, { resolve = null } = {}) {
|
|
27
29
|
try {
|
|
28
|
-
|
|
30
|
+
const read = markdownToProseMirror(markdown)
|
|
31
|
+
return canonicalJson(withoutDefaults(resolve ? resolve(read) : read)) === canonicalJson(withoutDefaults(doc))
|
|
29
32
|
} catch {
|
|
30
33
|
return false
|
|
31
34
|
}
|
|
@@ -34,7 +37,7 @@ export function sameMarkdownDocument(markdown, doc) {
|
|
|
34
37
|
// A document without the attributes that only restate a default: an inset's `embedKind: 'visual'`,
|
|
35
38
|
// which the parser writes and the pull's re-inlining (retired 2026-09-28) left out — so a body holding
|
|
36
39
|
// an inset never compared as unchanged (measured 2026-09-26 on the `marketing` template's hero).
|
|
37
|
-
function withoutDefaults(doc) {
|
|
40
|
+
export function withoutDefaults(doc) {
|
|
38
41
|
return JSON.parse(JSON.stringify(doc), (_, v) => {
|
|
39
42
|
if (v?.type !== 'inset_ref' || v.attrs?.embedKind !== 'visual') return v
|
|
40
43
|
const { embedKind: _visual, ...attrs } = v.attrs
|
package/src/uwx/site-dirs.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
// Where a site's
|
|
2
|
-
//
|
|
3
|
-
// (`site-
|
|
1
|
+
// Where a site's content lives — ONE definition for the push, which reads the tree from here
|
|
2
|
+
// (`site.js`), the pull, which writes it back here (`site-project.js`), and every check that asks
|
|
3
|
+
// what a push would send or a pull would merge (the CLI's `utils/site-roots.js`). A leaf module so the
|
|
4
|
+
// pull does not import the push.
|
|
4
5
|
|
|
5
|
-
import { join, resolve } from 'node:path'
|
|
6
|
+
import { join, relative, resolve, sep } from 'node:path'
|
|
7
|
+
import { mountEntriesOf } from '../site/mount-entries.js'
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* `site.yml::paths.pages` / `paths.layout`, else `pages/` and `layout/` — resolved
|
|
@@ -16,8 +18,8 @@ import { join, resolve } from 'node:path'
|
|
|
16
18
|
* current.
|
|
17
19
|
*
|
|
18
20
|
* ⭐ Reading `site.yml` rather than the document is the fix, not a detour: it is the
|
|
19
|
-
* file both readers use
|
|
20
|
-
*
|
|
21
|
+
* file both readers use. And it is the project's own: no document carries `paths` since
|
|
22
|
+
* 2026-11-04, so a pull never moves where a project keeps its files.
|
|
21
23
|
*
|
|
22
24
|
* @param {string} siteRoot
|
|
23
25
|
* @param {object|null} siteYml - the parsed `site.yml`
|
|
@@ -30,3 +32,45 @@ export function siteContentDirs(siteRoot, siteYml) {
|
|
|
30
32
|
layoutDir: paths?.layout ? resolve(siteRoot, paths.layout) : join(siteRoot, 'layout'),
|
|
31
33
|
}
|
|
32
34
|
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Every place a push reads the site's content from, each relative to the site in POSIX form — a
|
|
38
|
+
* mount's may lead out of it (`../docs`):
|
|
39
|
+
*
|
|
40
|
+
* - `config`: `site.yml`, `theme.yml`, `head.html`, `queries.yml`;
|
|
41
|
+
* - `translations`: `locales`;
|
|
42
|
+
* - `pages`, `layout`, `records`: where `paths:` puts them, else their own names;
|
|
43
|
+
* - `media`: `public`, where the files a page names are kept;
|
|
44
|
+
* - `mount`: each `paths: { pages/<segment>: <dir> }` folder, with its `segment` and `abs`.
|
|
45
|
+
*
|
|
46
|
+
* ⭐ ONE ANSWER, and the readers that kept their own drifted (2026-11-04): the push's
|
|
47
|
+
* committed-content check named no mount, so it let a mounted folder's uncommitted edits go out,
|
|
48
|
+
* while `uniweb status` counted that folder among what waits to be pushed. Which repository holds a
|
|
49
|
+
* mount — the site's own, one of its own, or none — is git's question, and the CLI's to ask.
|
|
50
|
+
*
|
|
51
|
+
* ⛔ What the walk reads and this lists must not part: `tests/site-content-roots.test.js` changes
|
|
52
|
+
* every file outside these roots and asks whether the push's document moved.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} siteRoot
|
|
55
|
+
* @param {object|null} siteYml - the parsed `site.yml`
|
|
56
|
+
* @returns {Array<{ path: string, kind: 'config'|'translations'|'pages'|'layout'|'records'|'media'|'mount', segment?: string, abs: string }>}
|
|
57
|
+
*/
|
|
58
|
+
export function siteContentRoots(siteRoot, siteYml) {
|
|
59
|
+
const paths = siteYml?.paths
|
|
60
|
+
const at = (dir) => {
|
|
61
|
+
const abs = resolve(siteRoot, String(dir))
|
|
62
|
+
return { abs, path: relative(siteRoot, abs).split(sep).join('/') || '.' }
|
|
63
|
+
}
|
|
64
|
+
const roots = []
|
|
65
|
+
for (const file of ['site.yml', 'theme.yml', 'head.html', 'queries.yml']) roots.push({ ...at(file), kind: 'config' })
|
|
66
|
+
roots.push({ ...at('locales'), kind: 'translations' })
|
|
67
|
+
roots.push({ ...at(paths?.pages || 'pages'), kind: 'pages' })
|
|
68
|
+
roots.push({ ...at(paths?.layout || 'layout'), kind: 'layout' })
|
|
69
|
+
roots.push({ ...at(paths?.records || 'records'), kind: 'records' })
|
|
70
|
+
roots.push({ ...at('public'), kind: 'media' })
|
|
71
|
+
for (const [segment, dir] of mountEntriesOf(paths)) {
|
|
72
|
+
if (typeof dir !== 'string' || !dir) continue
|
|
73
|
+
roots.push({ ...at(dir), kind: 'mount', segment })
|
|
74
|
+
}
|
|
75
|
+
return roots
|
|
76
|
+
}
|