@uniweb/build 1.16.3 → 1.17.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/build",
3
- "version": "1.16.3",
3
+ "version": "1.17.0",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -57,11 +57,11 @@
57
57
  "sharp": "^0.35.5",
58
58
  "yaml": "^2.5.0",
59
59
  "@uniweb/content-reader": "~1.5.9",
60
- "@uniweb/content-writer": "~1.3.1",
61
60
  "@uniweb/schemas": "~1.6.10",
62
- "@uniweb/projections": "~1.2.11",
63
61
  "@uniweb/semantic-parser": "~1.13.2",
64
- "@uniweb/theming": "~1.2.1"
62
+ "@uniweb/theming": "~1.2.1",
63
+ "@uniweb/projections": "~1.2.11",
64
+ "@uniweb/content-writer": "~1.3.1"
65
65
  },
66
66
  "optionalDependencies": {
67
67
  "@uniweb/runtime": "~1.4.5"
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * ⭐ WHAT A PUSH LEAVES OUT: a page or a section a pull HELD. The app changed it in a way its files
3
- * cannot say — a second section in a folder of single-section pages, a setting an `.md` page has no
3
+ * cannot say — a second section on an atomic page, a setting an `.md` page has no
4
4
  * place for, a move to where a page cannot sit — so the pull wrote nothing for it, and the site keeps
5
5
  * the app's version (`site-project.js`, `report.held`).
6
6
  *
@@ -1,18 +1,27 @@
1
1
  /**
2
- * A route's `mode` on the site-content document: what its pages may hold, which the app honours, and
3
- * not how the files hold them.
2
+ * A page's `mode` on the site-content document: what the page itself is, which the app honours, read from
3
+ * the page and never from its parent [Diego, 2026-11-05]:
4
4
  *
5
- * - `single-section`: each page under the route holds one section and no page of its own, as a folder
6
- * in folder mode keeps them, one `.md` file each. A route under it that holds no section is
7
- * `single-section` too, and the route holds no section of its own, except a page above a mounted
8
- * folder of `.md` pages.
9
- * - `page`: any other route.
5
+ * - `atomic`: a page that holds exactly one section and no child page, as the files hold it, one `.md`
6
+ * file in folder mode;
7
+ * - `atomic-parent`: a page with no section whose child pages are atomic pages or atomic-parents, as the
8
+ * files hold it, a directory in folder mode — its own `folder.yml`, or below one;
9
+ * - `regular`: every other page, a page with no section yet included.
10
10
  *
11
- * A push writes each route's own value, so nothing says "inherit" (`site.js::walkPagesNested`). A pull
12
- * reads it only for a route its files do not hold yet; a route they hold takes its form from them
13
- * (`site-project.js`). `folder` is the old spelling, which a stored document carries until its site's
14
- * next push: only a unit's identity reads it (`site-diff.js::walkSiteUnits`).
11
+ * A push writes each page's own value from where its files keep it (`site.js::walkPagesNested`). A pull
12
+ * places a page the files don't hold yet by it, and follows the app's switch of an empty page between
13
+ * `atomic-parent` and `regular` (`site-project.js`). A value it doesn't know reads as `regular`.
14
+ * ⛔ Until 2026-11-05 the value was the parent's: `single-section` on a page whose child pages were in
15
+ * folder mode, and `page` on every other, the pages under it included.
15
16
  *
16
17
  * A leaf, with no imports.
17
18
  */
18
- export const SINGLE_SECTION = 'single-section'
19
+ export const REGULAR = 'regular'
20
+ export const ATOMIC = 'atomic'
21
+ export const ATOMIC_PARENT = 'atomic-parent'
22
+
23
+ /** The page's own mode, or null for a value this framework doesn't know, which reads as `regular`. */
24
+ export function knownMode(record) {
25
+ const mode = record?.mode
26
+ return mode === REGULAR || mode === ATOMIC || mode === ATOMIC_PARENT ? mode : null
27
+ }
@@ -49,7 +49,7 @@
49
49
  import { entityContentHash } from './records.js'
50
50
  import { sectionFileBases, pageDirName, layoutSectionPaths } from './site-project.js'
51
51
  import { documentSourceLocale } from './source-locale.js'
52
- import { SINGLE_SECTION } from './route-mode.js'
52
+ import { ATOMIC_PARENT } from './route-mode.js'
53
53
 
54
54
  // A unit's own content, with the nested collections that are their own units
55
55
  // removed — so editing a section never also marks its page (or its parent
@@ -113,11 +113,10 @@ export function walkSiteUnits(doc, cb, sourceLocale = documentSourceLocale(doc))
113
113
  const dirName = pageDirName(record, sourceLocale)
114
114
  if (!dirName) continue
115
115
  const dir = `${parentDir}/${dirName}`
116
- // A route of single-section pages is its `folder.yml`, in either spelling: `folder` is the one a
117
- // push wrote until 2026-11-04, which a stored document carries until its site's next push, and a
118
- // unit keyed otherwise would read as one the app changed. Delete `folder` here once no synced site's
119
- // document carries it.
120
- cb(`${dir}/${record.mode === SINGLE_SECTION || record.mode === 'folder' ? 'folder.yml' : 'page.yml'}`, record, 'page')
116
+ // An atomic-parent is its `folder.yml`; every other page its `page.yml`, an atomic page's `.md` file
117
+ // included, as these keys have always named them. ⛔ Until 2026-11-05 the parent's `single-section`,
118
+ // or `folder` before it, named the `folder.yml`.
119
+ cb(`${dir}/${record.mode === ATOMIC_PARENT ? 'folder.yml' : 'page.yml'}`, record, 'page')
121
120
  walkSections(record.page_sections, dir)
122
121
  walkPages(record.$children, dir)
123
122
  }
@@ -50,7 +50,7 @@ import { writeSiteConfig, writeSitePaths, writeThemeFile, writeIfChanged, writeS
50
50
  import { mountEntriesOf } from '../site/mount-entries.js'
51
51
  import { declarationsToQueriesYml } from './records-project.js'
52
52
  import { buildRouteOf } from './site.js'
53
- import { SINGLE_SECTION } from './route-mode.js'
53
+ import { ATOMIC_PARENT, knownMode } from './route-mode.js'
54
54
  import { fileLinkTargets } from '../site/file-links.js'
55
55
  import { DEFAULT_SECTION_TYPE } from '@uniweb/core/section-type'
56
56
  import { translationContext, SITE_META_CONTEXT } from '../i18n/extract.js'
@@ -968,16 +968,18 @@ function projectPages(pages, pagesDir, sourceLocale, report, prune, ctx) {
968
968
  // its `page.yml`, is read in folder mode, its sections as pages. A folder-mode folder is a folder.
969
969
  // ⛔ Until 2026-11-04 every page went to its slug's folder: `pages/2-about/` came back as `about/`.
970
970
  //
971
- // In a folder-mode level a route is a folder only where the files keep one in folder mode, where it is
972
- // or where the app moved it from (`oldForm`), or, new to them, where its `mode` is `single-section`. A
973
- // page folder is no form there: a parametric page, or a page its file cannot hold, is `cannot`.
971
+ // In a folder-mode level a page is a directory only when it is an atomic-parent: by its own mode, or,
972
+ // where its mode is none this framework knows, by the form the files kept it in where the app moved it
973
+ // from (`oldForm`). Any other page is an `.md` file there when it can be one. A page folder is no form
974
+ // there: a parametric page, or a page its file cannot hold, is `cannot`.
974
975
  function placeOf(ctx, record, route, levelDir, levelMode, sourceLocale) {
975
976
  const found = ctx.files?.page(route)
976
977
  if (found) return found
977
978
  if (levelMode === 'pages') {
978
- if (record.is_dynamic) return { kind: 'cannot', what: ['a parametric page, which a route of single-section pages holds none of'] }
979
- const was = oldForm(ctx, record)
980
- if (was ? was !== 'pages' : !isSingleSection(record)) {
979
+ if (record.is_dynamic) return { kind: 'cannot', what: ['a parametric page, which an atomic-parent holds none of'] }
980
+ const mode = knownMode(record)
981
+ const parent = mode ? mode === ATOMIC_PARENT : oldForm(ctx, record) === 'pages'
982
+ if (!parent) {
981
983
  const name = unwrapLocalized(record.slug, sourceLocale)
982
984
  const what = mdPageCannotHold(record, { name, sourceLocale })
983
985
  return what.length ? { kind: 'cannot', what } : { kind: 'md', file: join(levelDir, `${name}.md`), dir: levelDir }
@@ -1008,23 +1010,41 @@ function oldPlace(ctx, uuid) {
1008
1010
  return place?.kind === 'md' ? place.file : place?.dir ?? null
1009
1011
  }
1010
1012
 
1011
- // ⭐ A route whose pages are single-section, in either spelling: `folder` is the one a push wrote until
1012
- // 2026-11-04, which a stored document carries until its site's next push. A route new to the files takes
1013
- // its form from this — in a fresh clone, every route. ⛔ Until 2026-11-05 only `single-section` read so,
1014
- // and a clone of a site last pushed before then wrote its single-section routes in page mode.
1015
- const isSingleSection = (record) => record?.mode === SINGLE_SECTION || record?.mode === 'folder'
1016
-
1017
- // ⭐ A FOLDER'S FORM IS ITS FILES' WHERE THEY HOLD IT — folder mode (`pages`) or page mode (`sections`):
1018
- // a mount's route by the mount, a folder the files hold by its own config, one the app moved by the form
1019
- // it had. Only a route new to the files takes the form its `mode` asks for, a route the app made. ⛔ Until
1020
- // 2026-11-04 every folder took its `mode`'s form, so a stored route in another spelling would have had
1021
- // a `page.yml` written beside its `folder.yml`.
1013
+ // ⭐ A DIRECTORY'S FORM — folder mode (`pages`) or page mode (`sections`) — by the page's own mode: an
1014
+ // atomic-parent's is folder mode, any other page's page mode (`route-mode.js`). Where the files hold the
1015
+ // page, their form stands, but for the switch the app makes on an empty page, between atomic-parent and
1016
+ // regular: there is nothing to convert, so the page's config follows. A mount's
1017
+ // route is the mount's. Where its mode is none this framework knows, a page the app moved keeps the form
1018
+ // the files kept it in where it was, and a page new to them is regular.
1019
+ // ⛔ Until 2026-11-05 the form came from the files alone wherever they held the page, and a mode was read
1020
+ // only for a page new to them, as `single-section` on its parent.
1022
1021
  function formOf(ctx, record, route, place, levelMode) {
1023
1022
  if (place.mount) return place.mount.mode
1024
- if (ctx.files?.page(route) === place) return ctx.files.levelMode(place.dir) ?? folderModeOf(place.dir, levelMode)
1023
+ const mode = knownMode(record)
1024
+ const asked = mode === ATOMIC_PARENT ? 'pages' : mode ? 'sections' : null
1025
+ if (ctx.files?.page(route) === place) {
1026
+ const held = ctx.files.levelMode(place.dir) ?? folderModeOf(place.dir, levelMode)
1027
+ // A regular page has no place inside folder mode (`refusePageInFolderMode`), so there the files stand.
1028
+ const fits = asked === 'pages' || levelMode !== 'pages'
1029
+ return asked && asked !== held && fits && isEmptyPage(record, place.dir) ? asked : held
1030
+ }
1031
+ if (asked) return asked
1025
1032
  const was = oldForm(ctx, record)
1026
1033
  if (was === 'pages' || was === 'sections') return was
1027
- return isSingleSection(record) ? 'pages' : 'sections'
1034
+ return 'sections'
1035
+ }
1036
+
1037
+ // A page with no section and no child page, on the site and in the files: the only one the app switches
1038
+ // between atomic-parent and regular, and the only one a pull changes the form of in place.
1039
+ function isEmptyPage(record, dir) {
1040
+ if ((record?.page_sections || []).length || (record?.$children || []).length) return false
1041
+ let entries
1042
+ try {
1043
+ entries = readdirSync(dir, { withFileTypes: true })
1044
+ } catch {
1045
+ return false
1046
+ }
1047
+ return !entries.some((e) => (e.isFile() && isMarkdownFile(e.name)) || (e.isDirectory() && !isIgnoredFolder(e.name)))
1028
1048
  }
1029
1049
 
1030
1050
  // ⭐ A FOLDER-MODE `.md` PAGE, WRITTEN BACK IN PLACE: the file is the page and its one section, so the
@@ -1152,12 +1172,12 @@ function writePagesTree(pages, pagesDir, sourceLocale, report, ctx, routePrefix
1152
1172
  filesGiveTopOrder = r.filesGiveTopOrder
1153
1173
  report.sections.push(...r.written)
1154
1174
  } else if (Array.isArray(record.page_sections) && record.page_sections.length) {
1155
- // ⛔ A route of single-section pages holds no section of its own: its folder's `.md` files are its
1156
- // pages. One the app gives it is held, and the route and its pages are written as they are. Until
1157
- // 2026-11-04 it was dropped, and the next push removed it from the site.
1175
+ // ⛔ An atomic-parent holds no section: its directory's `.md` files are its child pages. One the app
1176
+ // gives it is held, and the page and its child pages are written as they are. Until 2026-11-04 it was
1177
+ // dropped, and the next push removed it from the site.
1158
1178
  const uuids = record.page_sections.flatMap((s) => subtreeUuids(s))
1159
1179
  keepWhereTheFilesAre(ctx, uuids)
1160
- report.held?.push({ route, uuids, what: ['a section, which a route of single-section pages holds none of'] })
1180
+ report.held?.push({ route, uuids, what: ['a section, which an atomic-parent holds none of'] })
1161
1181
  report.leftAlone?.push(route)
1162
1182
  }
1163
1183
 
@@ -1175,6 +1195,13 @@ function writePagesTree(pages, pagesDir, sourceLocale, report, ctx, routePrefix
1175
1195
 
1176
1196
  const ymlName = form === 'pages' ? 'folder.yml' : 'page.yml'
1177
1197
  const ymlPath = join(pageDir, ymlName)
1198
+ // ⭐ THE APP'S SWITCH ON AN EMPTY PAGE (`formOf`): its config file takes the other name, as the author
1199
+ // wrote it, so the directory is read in the form the app made it — folder mode for an atomic-parent.
1200
+ const oldYmlPath = join(pageDir, ymlName === 'folder.yml' ? 'page.yml' : 'folder.yml')
1201
+ if (existsSync(oldYmlPath) && !existsSync(ymlPath)) {
1202
+ renameSync(oldYmlPath, ymlPath)
1203
+ report.deleted.push(oldYmlPath)
1204
+ }
1178
1205
  // Merge (not full-dump) so author-added keys survive a pull; the projector
1179
1206
  // owns only PAGE_YML_MANAGED_KEYS.
1180
1207
  const existing = readAuthoredYaml(ymlPath)
@@ -1216,7 +1243,7 @@ function subtreeUuids(record) {
1216
1243
  // hold it is not written there, so its files at the old place are the files' version of it, and the prune
1217
1244
  // must keep them: found by the rename index this copy wrote, else, for a page, by the route its sync state
1218
1245
  // last saw it at (`ctx.itemRoutes`). ⛔ Until 2026-11-04 the prune took them: a page of two sections moved
1219
- // into a folder of single-section pages was held there and deleted where it was.
1246
+ // into an atomic-parent was held there and deleted where it was.
1220
1247
  function keepWhereTheFilesAre(ctx, uuids) {
1221
1248
  if (!ctx?.kept) return
1222
1249
  for (const uuid of uuids) {
package/src/uwx/site.js CHANGED
@@ -47,7 +47,7 @@
47
47
 
48
48
  import { readdir, readFile } from 'node:fs/promises'
49
49
  import { dataBlockModels } from '../i18n/data-models.js'
50
- import { SINGLE_SECTION } from './route-mode.js'
50
+ import { ATOMIC, ATOMIC_PARENT, REGULAR } from './route-mode.js'
51
51
  import { existsSync } from 'node:fs'
52
52
  import { join, parse, relative } from 'node:path'
53
53
  import {
@@ -811,7 +811,8 @@ async function folderModePageRecords(ctx, dirPath, orderConfig, isRoot) {
811
811
  const data = buildPageData(config, {
812
812
  where: relative(siteRoot, filePath),
813
813
  slug: name,
814
- mode: 'page',
814
+ // One `.md` file in folder mode: a page of exactly one section and no child page (`route-mode.js`).
815
+ mode: ATOMIC,
815
816
  isDynamic: false,
816
817
  isRoot,
817
818
  siteIndex,
@@ -853,11 +854,12 @@ async function walkPagesNested(ctx, dirPath, parentSlugPath, inheritedMode, pare
853
854
  // ONE page whose sections were its `.md` files while the build rendered each as a
854
855
  // page of its own. Nothing warned, and a pull then wrote a `page.yml` into the
855
856
  // folder, converting the author's own site to the wrong shape.
856
- // ⭐ WHAT ITS PAGES MAY HOLD, not how the files hold them: `single-section` where they are a folder-mode
857
- // folder's `.md` files, one section each, else `page`. The mode its PAGES are read in (`childMode`), so
858
- // a page above a mounted folder of `.md` pages says it too, with its own sections. The app reads it to
859
- // offer no second section there. ⛔ Until 2026-11-04 it was the folder's own mode, spelled `folder`.
860
- const mode = f.childMode === 'pages' ? SINGLE_SECTION : 'page'
857
+ // ⭐ THE PAGE'S OWN MODE (`route-mode.js`): `atomic-parent` for a directory in folder mode, which holds
858
+ // no section and whose child pages are its `.md` files and directories; else `regular` — a page above
859
+ // a mounted folder of `.md` pages included, since it holds sections of its own. Its `.md` pages are
860
+ // `atomic` (`folderModePageRecords`). ⛔ Until 2026-11-05 this was what its pages may hold, read from the
861
+ // mode they are read in (`childMode`): `single-section` here, and `page` on the pages under it.
862
+ const mode = f.internalMode === 'pages' ? ATOMIC_PARENT : REGULAR
861
863
  const slugPath = parentSlugPath ? `${parentSlugPath}/${slug}` : slug
862
864
 
863
865
  const data = buildPageData(f.config, {