@uniweb/build 1.13.8 → 1.13.9
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/foundation/stale-sources.js +43 -3
- package/src/prerender.js +6 -1
- package/src/site/content-collector.js +47 -1
- package/src/site/file-links.js +143 -0
- package/src/utils/frontmatter.js +4 -1
- package/src/uwx/site.js +15 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.9",
|
|
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/content-writer": "~1.3.1",
|
|
61
59
|
"@uniweb/projections": "~1.2.9",
|
|
62
|
-
"@uniweb/
|
|
60
|
+
"@uniweb/theming": "~1.2.1",
|
|
61
|
+
"@uniweb/semantic-parser": "~1.13.1",
|
|
62
|
+
"@uniweb/content-writer": "~1.3.1",
|
|
63
63
|
"@uniweb/schemas": "~1.6.7",
|
|
64
|
-
"@uniweb/
|
|
64
|
+
"@uniweb/content-reader": "~1.5.8"
|
|
65
65
|
},
|
|
66
66
|
"optionalDependencies": {
|
|
67
|
-
"@uniweb/runtime": "~1.3.
|
|
67
|
+
"@uniweb/runtime": "~1.3.6"
|
|
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/core": "~1.5.
|
|
77
|
-
"@uniweb/runtime": "~1.3.
|
|
76
|
+
"@uniweb/core": "~1.5.2",
|
|
77
|
+
"@uniweb/runtime": "~1.3.6"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"vite": {
|
|
@@ -13,16 +13,26 @@
|
|
|
13
13
|
* into `node_modules`. A starter's `./components/**` names a folder a foundation may not have
|
|
14
14
|
* yet, and with no such folder there is nothing to lose.
|
|
15
15
|
*
|
|
16
|
+
* ⚖️ And only a line that loses something. A stylesheet the foundation imports can name a package's
|
|
17
|
+
* source itself, relative to itself, which holds wherever the package manager put it. Kit's does,
|
|
18
|
+
* so a template's line for kit that leads nowhere under npm costs nothing there, and saying the CSS
|
|
19
|
+
* is missing classes would be false. With a kit from before that, the loss is real: its stylesheet
|
|
20
|
+
* names nothing, so the line is still reported.
|
|
21
|
+
*
|
|
16
22
|
* @module @uniweb/build/foundation/stale-sources
|
|
17
23
|
*/
|
|
18
24
|
|
|
19
|
-
import { existsSync, readFileSync } from 'node:fs'
|
|
20
|
-
import {
|
|
25
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs'
|
|
26
|
+
import { createRequire } from 'node:module'
|
|
27
|
+
import { dirname, isAbsolute, join, relative, resolve } from 'node:path'
|
|
21
28
|
|
|
22
29
|
// `@source not "…"` excludes a path and `@source inline("…")` names no path: neither has a quote
|
|
23
30
|
// right after the keyword.
|
|
24
31
|
const SOURCE = /@source\s+(["'])(.+?)\1/g
|
|
25
32
|
|
|
33
|
+
// `@import url(…)` is a font on another host, with no quote right after the keyword.
|
|
34
|
+
const IMPORT = /@import\s+(["'])(.+?)\1/g
|
|
35
|
+
|
|
26
36
|
/** The part of a glob with no pattern in it: the folder it starts from. */
|
|
27
37
|
function fixedPrefix(glob) {
|
|
28
38
|
const at = glob.search(/[*?[{(!]/)
|
|
@@ -54,12 +64,42 @@ export function staleSources(stylesPath) {
|
|
|
54
64
|
for (const [, , source] of withoutComments(css).matchAll(SOURCE)) {
|
|
55
65
|
const missing = fixedPrefix(source)
|
|
56
66
|
if (missing && reachesOut(source) && !existsSync(resolve(dir, missing))) {
|
|
57
|
-
|
|
67
|
+
const foundAt = foundAbove(dir, missing)
|
|
68
|
+
if (!foundAt || !readByAnImport(css, stylesPath, resolve(dir, foundAt))) {
|
|
69
|
+
stale.push({ source, missing, foundAt })
|
|
70
|
+
}
|
|
58
71
|
}
|
|
59
72
|
}
|
|
60
73
|
return stale
|
|
61
74
|
}
|
|
62
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Does a stylesheet this one imports read that folder already, by a `@source` of its own?
|
|
78
|
+
*
|
|
79
|
+
* ⛔ Only a `.css` specifier: `tailwindcss` resolves to the package's JavaScript here, with no
|
|
80
|
+
* `style` condition to choose its stylesheet.
|
|
81
|
+
*/
|
|
82
|
+
function readByAnImport(css, stylesPath, folder) {
|
|
83
|
+
const require = createRequire(resolve(stylesPath))
|
|
84
|
+
// An import resolves to the file itself, and pnpm's copy of a package is behind a link.
|
|
85
|
+
const real = realpathSync(folder)
|
|
86
|
+
for (const [, , specifier] of withoutComments(css).matchAll(IMPORT)) {
|
|
87
|
+
if (!specifier.endsWith('.css')) continue
|
|
88
|
+
let file, imported
|
|
89
|
+
try {
|
|
90
|
+
file = require.resolve(specifier)
|
|
91
|
+
imported = readFileSync(file, 'utf8')
|
|
92
|
+
} catch {
|
|
93
|
+
continue
|
|
94
|
+
}
|
|
95
|
+
for (const [, , source] of withoutComments(imported).matchAll(SOURCE)) {
|
|
96
|
+
const rel = relative(resolve(dirname(file), fixedPrefix(source)), real)
|
|
97
|
+
if (rel === '' || (!rel.startsWith('..') && !isAbsolute(rel))) return true
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return false
|
|
101
|
+
}
|
|
102
|
+
|
|
63
103
|
/**
|
|
64
104
|
* Where a path into `node_modules` does lead, looking up from the stylesheet as a package is
|
|
65
105
|
* resolved: relative to the stylesheet, or null when that package is nowhere above it.
|
package/src/prerender.js
CHANGED
|
@@ -866,6 +866,8 @@ export async function prerenderSite(siteDir, options = {}) {
|
|
|
866
866
|
}
|
|
867
867
|
|
|
868
868
|
// Discover all locale content files
|
|
869
|
+
// Said once more at the end: a build's log is long, and these lines are in the middle of it.
|
|
870
|
+
const failedIcons = new Set()
|
|
869
871
|
const localeConfigs = await discoverLocaleContents(distDir, defaultSiteContent)
|
|
870
872
|
if (localeConfigs.length > 1) {
|
|
871
873
|
onProgress(`Found ${localeConfigs.length} locales: ${localeConfigs.map(l => l.locale).join(', ')}`)
|
|
@@ -996,7 +998,7 @@ export async function prerenderSite(siteDir, options = {}) {
|
|
|
996
998
|
const buildDataCache = new DataStore()
|
|
997
999
|
|
|
998
1000
|
// Pre-fetch icons for SSR embedding
|
|
999
|
-
await prefetchIcons(siteContent, uniweb, onProgress)
|
|
1001
|
+
for (const ref of await prefetchIcons(siteContent, uniweb, onProgress) ?? []) failedIcons.add(ref)
|
|
1000
1002
|
|
|
1001
1003
|
// Pre-render each page
|
|
1002
1004
|
const website = uniweb.activeWebsite
|
|
@@ -1270,6 +1272,9 @@ export async function prerenderSite(siteDir, options = {}) {
|
|
|
1270
1272
|
})
|
|
1271
1273
|
|
|
1272
1274
|
onProgress(`\nPre-rendered ${renderedFiles.length} pages across ${localeConfigs.length} locale(s)`)
|
|
1275
|
+
if (failedIcons.size > 0) {
|
|
1276
|
+
console.warn(`[prerender] These icons could not be fetched and are missing from the pages: ${[...failedIcons].join(', ')}`)
|
|
1277
|
+
}
|
|
1273
1278
|
|
|
1274
1279
|
return {
|
|
1275
1280
|
pages: renderedFiles.length,
|
|
@@ -26,7 +26,7 @@ import { isSectionKey } from '@uniweb/schemas/section'
|
|
|
26
26
|
import { parseNumericPrefix, compareByNumericPrefix } from '../utils/numeric-prefix.js'
|
|
27
27
|
import { isMarkdownFile, isIgnoredFolder } from '../utils/content-files.js'
|
|
28
28
|
import { readLayoutFolder, DEFAULT_LAYOUT, layoutAreaRoute } from './layout-folder.js'
|
|
29
|
-
import { join, parse, relative, resolve, sep } from 'node:path'
|
|
29
|
+
import { basename, join, parse, relative, resolve, sep } from 'node:path'
|
|
30
30
|
import { existsSync, statSync, realpathSync, readdirSync } from 'node:fs'
|
|
31
31
|
import yaml from 'js-yaml'
|
|
32
32
|
import { YAML_OPTIONS } from '../utils/yaml-schema.js'
|
|
@@ -40,6 +40,7 @@ import { resolveDefaultLocale, resolvePublishableLocales, validateLanguageConfig
|
|
|
40
40
|
import { authoredRedirectTarget } from '@uniweb/core/resolve-route'
|
|
41
41
|
import { parentRouteOf } from '@uniweb/core/route-match'
|
|
42
42
|
import { parseFrontmatter } from '../utils/frontmatter.js'
|
|
43
|
+
import { noteSectionFile, rewriteFileLinks } from './file-links.js'
|
|
43
44
|
import { valuesCutByComment } from '../utils/yaml-comment-trap.js'
|
|
44
45
|
import { parseGrid } from '@uniweb/schemas/grid'
|
|
45
46
|
import { runtimeServicesConfig, refuseRetiredServiceKeys, refuseUnreadableServices } from '../uwx/services-request.js'
|
|
@@ -941,6 +942,35 @@ function parseWildcardArray(arr) {
|
|
|
941
942
|
return { mode: 'inclusive', before, after }
|
|
942
943
|
}
|
|
943
944
|
|
|
945
|
+
/**
|
|
946
|
+
* A mounted route's pages come from the mount, so a folder beside its local stub is never read. An
|
|
947
|
+
* author's page simply isn't there, with no error, which is the worst way to learn it.
|
|
948
|
+
*/
|
|
949
|
+
async function warnOfLocalFoldersUnderAMount(localPath, name) {
|
|
950
|
+
for (const entry of await readdir(localPath)) {
|
|
951
|
+
if (isIgnoredFolder(entry)) continue
|
|
952
|
+
if ((await stat(join(localPath, entry))).isDirectory()) {
|
|
953
|
+
console.warn(`[content-collector] pages/${name}/${entry}/ is not read: pages/${name} is mounted, and a mounted route's pages come from the mount.`)
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
/**
|
|
959
|
+
* A name in an order list that matches no page does nothing, and the list reads as if it worked:
|
|
960
|
+
* every page is still there, in file order. The usual cause is a file's number, which isn't part of
|
|
961
|
+
* its name, so `01-welcome` in a list names no page. Said here, or moving an entry changes nothing
|
|
962
|
+
* and nobody knows why.
|
|
963
|
+
*/
|
|
964
|
+
function warnOfListedNamesThatMatchNothing(pageNames, parsed, dirPath) {
|
|
965
|
+
const names = new Set(pageNames)
|
|
966
|
+
for (const listed of [...parsed.before, ...parsed.after].map(extractItemName).filter(Boolean)) {
|
|
967
|
+
if (names.has(listed)) continue
|
|
968
|
+
const { name: withoutNumber } = parseNumericPrefix(listed)
|
|
969
|
+
const hint = withoutNumber && names.has(withoutNumber) ? `: its name has no number, "${withoutNumber}"` : ''
|
|
970
|
+
console.warn(`[content-collector] ${basename(dirPath)}: the page order lists "${listed}", and no page is called that${hint}`)
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
944
974
|
/**
|
|
945
975
|
* Apply wildcard-aware ordering to a list of named items.
|
|
946
976
|
*
|
|
@@ -1205,6 +1235,7 @@ async function processMarkdownFile(filePath, id, siteRoot, defaultStableId = nul
|
|
|
1205
1235
|
// Collect icons referenced in this section
|
|
1206
1236
|
const iconCollection = collectSectionIcons(section)
|
|
1207
1237
|
|
|
1238
|
+
noteSectionFile(section, filePath)
|
|
1208
1239
|
return { section, assetCollection, iconCollection }
|
|
1209
1240
|
}
|
|
1210
1241
|
|
|
@@ -1999,6 +2030,7 @@ async function collectPagesRecursive(dirPath, parentRoute, siteRoot, orderConfig
|
|
|
1999
2030
|
const mounted = mountPath ? await readFolderConfig(mountPath, 'pages') : null
|
|
2000
2031
|
const local = localPath ? await readFolderConfig(localPath, contentMode) : null
|
|
2001
2032
|
const { dirConfig, dirMode, childMode } = layerMountedFolder(name, local, mounted, contentMode)
|
|
2033
|
+
if (mountPath && localPath) await warnOfLocalFoldersUnderAMount(localPath, name)
|
|
2002
2034
|
|
|
2003
2035
|
const folderLayout = normalizeLayoutConfig(dirConfig.layout)
|
|
2004
2036
|
|
|
@@ -2034,6 +2066,11 @@ async function collectPagesRecursive(dirPath, parentRoute, siteRoot, orderConfig
|
|
|
2034
2066
|
|
|
2035
2067
|
if (pagesParsed && pagesParsed.mode !== 'all') {
|
|
2036
2068
|
orderedFolders = applyWildcardOrder(pageFolders, pagesParsed)
|
|
2069
|
+
warnOfListedNamesThatMatchNothing(
|
|
2070
|
+
[...pageFolders.map(f => f.name), ...(contentMode === 'pages' ? folderModePageFiles(entries, null).files.map(f => f.name) : [])],
|
|
2071
|
+
pagesParsed,
|
|
2072
|
+
dirPath
|
|
2073
|
+
)
|
|
2037
2074
|
if (pagesParsed.mode === 'strict') {
|
|
2038
2075
|
strictPageNames = new Set(pagesParsed.before.map(extractItemName).filter(Boolean))
|
|
2039
2076
|
}
|
|
@@ -2714,6 +2751,9 @@ export async function collectSiteContent(sitePath, options = {}) {
|
|
|
2714
2751
|
|
|
2715
2752
|
// Check if pages directory exists
|
|
2716
2753
|
if (!existsSync(pagesPath)) {
|
|
2754
|
+
if (mounts) {
|
|
2755
|
+
console.warn(`[content-collector] ${relative(sitePath, pagesPath)}/ doesn't exist, so the site has no pages, and what paths: mounts is not read. Create the folder.`)
|
|
2756
|
+
}
|
|
2717
2757
|
return {
|
|
2718
2758
|
config: payloadSiteConfig(siteConfig),
|
|
2719
2759
|
theme: {
|
|
@@ -2829,6 +2869,12 @@ export async function collectSiteContent(sitePath, options = {}) {
|
|
|
2829
2869
|
// 3. order: [array] in parent config (non-strict, backward compat)
|
|
2830
2870
|
// No global re-sort — collection order is authoritative.
|
|
2831
2871
|
|
|
2872
|
+
// Links written as files, now that every file has its page.
|
|
2873
|
+
rewriteFileLinks(pages, {
|
|
2874
|
+
siteRoot: sitePath,
|
|
2875
|
+
warn: (message) => console.warn(`[content-collector] ${message}`)
|
|
2876
|
+
})
|
|
2877
|
+
|
|
2832
2878
|
// Log asset summary
|
|
2833
2879
|
const assetCount = Object.keys(assetCollection.assets).length
|
|
2834
2880
|
const explicitCount = assetCollection.hasExplicitPoster.size
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ⭐ A LINK WRITTEN AS A FILE MEANS THE PAGE THAT FILE BECAME.
|
|
3
|
+
*
|
|
4
|
+
* Docs kept in a repo link to each other by file, `./deploying.md#setup`, because that is what
|
|
5
|
+
* works on GitHub and in an editor. Mounted into a site those files become pages, and a browser
|
|
6
|
+
* took the link as written, to `/docs/deploying.md` and a "Page not found". Nothing said so: a
|
|
7
|
+
* build, doctor and a link checker all read a path and saw a path.
|
|
8
|
+
*
|
|
9
|
+
* So each is rewritten here to the address an author would write by hand, at build and at push,
|
|
10
|
+
* since this is the one place that knows which file became which page. It costs a site nothing at
|
|
11
|
+
* render. A file link that leads to no page stays as written and is named, which is the only moment
|
|
12
|
+
* anyone can be told about it.
|
|
13
|
+
*
|
|
14
|
+
* The anchor is translated too. A link written for GitHub names GitHub's anchor for a heading, and a
|
|
15
|
+
* page's heading has its own (`headingId`, `@uniweb/kit`): "it doesn't — matter" is
|
|
16
|
+
* `it-doesnt--matter` on one and `it-doesn-t-matter` on the other.
|
|
17
|
+
*/
|
|
18
|
+
import { realpathSync } from 'node:fs'
|
|
19
|
+
import { dirname, relative, resolve } from 'node:path'
|
|
20
|
+
|
|
21
|
+
const FILES = new WeakMap()
|
|
22
|
+
|
|
23
|
+
/** Keeps the file a section was read from, off the section: it must not reach a payload. */
|
|
24
|
+
export function noteSectionFile(section, file) {
|
|
25
|
+
FILES.set(section, file)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The same file for a record made from a section, on the push's lane. */
|
|
29
|
+
export function carrySectionFile(from, to) {
|
|
30
|
+
if (FILES.has(from)) FILES.set(to, FILES.get(from))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// A relative path to a markdown file: no scheme, no leading `/`, `#` or `?`.
|
|
34
|
+
const FILE_LINK = /^(?![a-z][a-z0-9+.-]*:|[/#?])([^#?]+\.md)(?:#(.*))?$/i
|
|
35
|
+
|
|
36
|
+
const decode = (text) => {
|
|
37
|
+
try {
|
|
38
|
+
return decodeURI(text)
|
|
39
|
+
} catch {
|
|
40
|
+
return text
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// One name for a file, however it was reached: a mount is walked by its real path, a site's own
|
|
45
|
+
// pages by theirs, and a symlink between them is ordinary.
|
|
46
|
+
const real = (file) => {
|
|
47
|
+
try {
|
|
48
|
+
return realpathSync(file)
|
|
49
|
+
} catch {
|
|
50
|
+
return file
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const textOf = (node) =>
|
|
55
|
+
typeof node?.text === 'string' ? node.text : (node?.content || []).map(textOf).join('')
|
|
56
|
+
|
|
57
|
+
/** What `headingId` in `@uniweb/kit` gives a heading. `_contracts/` holds the two together. */
|
|
58
|
+
export function siteAnchor(text) {
|
|
59
|
+
return String(text).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** What GitHub gives a heading: punctuation gone, each space a hyphen, so `a — b` is `a--b`. */
|
|
63
|
+
export function githubAnchor(text) {
|
|
64
|
+
return String(text).toLowerCase().trim().replace(/[^\p{L}\p{N}\s_-]/gu, '').replace(/\s/g, '-')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Each anchor a link might name for a document's headings, and the id it has on the page. */
|
|
68
|
+
function anchorsOf(doc, anchors = new Map()) {
|
|
69
|
+
for (const node of doc?.content || []) {
|
|
70
|
+
if (node?.type === 'heading') {
|
|
71
|
+
const text = textOf(node)
|
|
72
|
+
const id = node.attrs?.id || siteAnchor(text)
|
|
73
|
+
anchors.set(id, id)
|
|
74
|
+
anchors.set(siteAnchor(text), id)
|
|
75
|
+
anchors.set(githubAnchor(text), id)
|
|
76
|
+
}
|
|
77
|
+
if (node?.content) anchorsOf(node, anchors)
|
|
78
|
+
}
|
|
79
|
+
return anchors
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function eachSection(sections, visit) {
|
|
83
|
+
for (const section of sections || []) {
|
|
84
|
+
if (!section || typeof section !== 'object') continue
|
|
85
|
+
visit(section)
|
|
86
|
+
eachSection(section.subsections, visit)
|
|
87
|
+
eachSection(section.$children, visit)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function rewriteDoc(node, rewrite) {
|
|
92
|
+
if (!node || typeof node !== 'object') return
|
|
93
|
+
if (typeof node.attrs?.href === 'string') node.attrs.href = rewrite(node.attrs.href)
|
|
94
|
+
for (const mark of node.marks || []) {
|
|
95
|
+
if (typeof mark?.attrs?.href === 'string') mark.attrs.href = rewrite(mark.attrs.href)
|
|
96
|
+
}
|
|
97
|
+
if (Array.isArray(node.content)) for (const child of node.content) rewriteDoc(child, rewrite)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Rewrites every link written as a file, in the sections of a site's pages. Mutates the sections.
|
|
102
|
+
*
|
|
103
|
+
* @param {Array<{ route: string, sections: Array<object> }>} pages - each page's route and sections,
|
|
104
|
+
* a section holding its document at `content`, with `stableId` or `$id`
|
|
105
|
+
* @param {{ siteRoot: string, warn: (message: string) => void }} options
|
|
106
|
+
*/
|
|
107
|
+
export function rewriteFileLinks(pages, { siteRoot, warn }) {
|
|
108
|
+
const files = new Map()
|
|
109
|
+
for (const { route, sections } of pages) {
|
|
110
|
+
const held = []
|
|
111
|
+
eachSection(sections, (section) => {
|
|
112
|
+
if (FILES.has(section)) held.push(section)
|
|
113
|
+
})
|
|
114
|
+
for (const section of held) {
|
|
115
|
+
files.set(real(FILES.get(section)), {
|
|
116
|
+
route,
|
|
117
|
+
// A page of several files: this file is a section of it, with an anchor of its own.
|
|
118
|
+
section: held.length > 1 ? section.stableId || section.$id || null : null,
|
|
119
|
+
anchors: anchorsOf(section.content),
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
for (const { sections } of pages) {
|
|
125
|
+
eachSection(sections, (section) => {
|
|
126
|
+
const from = FILES.get(section)
|
|
127
|
+
if (!from) return
|
|
128
|
+
rewriteDoc(section.content, (href) => {
|
|
129
|
+
const link = FILE_LINK.exec(href)
|
|
130
|
+
if (!link) return href
|
|
131
|
+
const target = files.get(real(resolve(dirname(from), decode(link[1]))))
|
|
132
|
+
if (!target) {
|
|
133
|
+
warn(`${relative(siteRoot, from)}: the link to ${href} names a file that is no page of this site, so it leads nowhere`)
|
|
134
|
+
return href
|
|
135
|
+
}
|
|
136
|
+
if (!link[2]) return target.section ? `${target.route}#section-${target.section}` : target.route
|
|
137
|
+
const anchor = target.anchors.get(decode(link[2]))
|
|
138
|
+
if (!anchor) warn(`${relative(siteRoot, from)}: the link to ${href}: that page has no such heading`)
|
|
139
|
+
return `${target.route}#${anchor ?? link[2]}`
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
}
|
package/src/utils/frontmatter.js
CHANGED
|
@@ -56,7 +56,10 @@ import { YAML_OPTIONS } from './yaml-schema.js'
|
|
|
56
56
|
* @throws {Error} when a `---` block is present and does not parse as YAML
|
|
57
57
|
*/
|
|
58
58
|
export function parseFrontmatter(raw, filepath) {
|
|
59
|
-
|
|
59
|
+
// A file saved on Windows has CRLF line endings, so its fence is `---\r\n`. With `---\n` as
|
|
60
|
+
// the only fence it read as having no frontmatter at all: the opening `---` became a divider and
|
|
61
|
+
// the block a heading, so every `type:` and `title:` in the file was lost, with no error.
|
|
62
|
+
const text = (raw ?? '').replace(/\r\n/g, '\n')
|
|
60
63
|
if (!text.trimStart().startsWith('---')) {
|
|
61
64
|
return { frontmatter: {}, body: text, yaml: '' }
|
|
62
65
|
}
|
package/src/uwx/site.js
CHANGED
|
@@ -73,6 +73,7 @@ import {
|
|
|
73
73
|
isValidSlugSegment,
|
|
74
74
|
authoredId,
|
|
75
75
|
} from '../site/content-collector.js'
|
|
76
|
+
import { carrySectionFile, rewriteFileLinks } from '../site/file-links.js'
|
|
76
77
|
import { refuseBinding, refuseUnder, refuseOutsideLanguage, warnDuplicateBindings } from '../site/data-fetcher.js'
|
|
77
78
|
import { readLayoutFolder, layoutAreaRoute } from '../site/layout-folder.js'
|
|
78
79
|
import { normalizeHideIn } from '../site/nav-visibility.js'
|
|
@@ -584,6 +585,7 @@ function fillPageSectionTypes(pages, type) {
|
|
|
584
585
|
function sectionToRecord(section, index) {
|
|
585
586
|
const secId = section.stableId || `s${index}`
|
|
586
587
|
const rec = withIdentity(secId, mapSectionData(section))
|
|
588
|
+
carrySectionFile(section, rec)
|
|
587
589
|
if (Array.isArray(section.subsections) && section.subsections.length > 0) {
|
|
588
590
|
rec.$children = section.subsections.map((c, j) => sectionToRecord(c, j))
|
|
589
591
|
}
|
|
@@ -1692,6 +1694,19 @@ export async function siteProjectToDocument(siteRoot, opts = {}) {
|
|
|
1692
1694
|
fillPageSectionTypes(pages, sectionType)
|
|
1693
1695
|
fillSectionTypes(layoutSections, sectionType)
|
|
1694
1696
|
|
|
1697
|
+
// Links written as files, now that every file has its page: the build's rule (`site/file-links.js`),
|
|
1698
|
+
// so a site reads the same pushed as built.
|
|
1699
|
+
const pagesWithRoutes = []
|
|
1700
|
+
const withRoutes = (list, parentRoute) => {
|
|
1701
|
+
for (const page of list || []) {
|
|
1702
|
+
const route = buildRouteOf(page, parentRoute, sourceLocale)
|
|
1703
|
+
pagesWithRoutes.push({ route, sections: page.page_sections })
|
|
1704
|
+
withRoutes(page.$children, route)
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
withRoutes(pages, '/')
|
|
1708
|
+
rewriteFileLinks(pagesWithRoutes, { siteRoot, warn: (message) => console.warn(`[push] ${message}`) })
|
|
1709
|
+
|
|
1695
1710
|
// Wrap each section's content into its per-locale form (source doc + target
|
|
1696
1711
|
// structural maps from locales/{locale}.json, or a free-form body override from
|
|
1697
1712
|
// locales/freeform/**). A non-invasive post-pass over the built tree.
|