@clarusjs/theme-docs 0.6.0 → 0.8.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 +10 -7
- package/src/callout.tscl +8 -4
- package/src/layout.tscl +31 -26
- package/src/learn-path.tscl +26 -23
- package/src/learn-progress.tscl +8 -4
- package/src/learn-status.tscl +10 -7
- package/src/lesson-bar.tscl +36 -23
- package/src/lesson.css +5 -2
- package/src/lesson.tscl +36 -29
- package/src/mermaid.tscl +5 -2
- package/src/nav.ts +40 -3
- package/src/page-head.tscl +24 -10
- package/src/pages.d.ts +6 -0
- package/src/parts/contents.tscl +11 -7
- package/src/parts/footer.tscl +7 -3
- package/src/parts/header.tscl +19 -15
- package/src/parts/icon.tscl +9 -5
- package/src/parts/page-footer.tscl +14 -10
- package/src/parts/sidebar.tscl +17 -11
- package/src/parts/version-menu.tscl +33 -0
- package/src/progress-board.tscl +11 -8
- package/src/quiz-choices.tscl +18 -14
- package/src/quiz.tscl +12 -8
- package/src/search.tscl +2 -1
- package/src/styles/theme.css +12 -0
- package/src/theme.css +68 -0
- package/src/version-list.tscl +25 -0
- package/src/versions-cli.js +229 -0
- package/src/versions.d.ts +163 -0
- package/src/versions.js +209 -0
- package/src/vite.d.ts +27 -0
- package/src/vite.js +40 -1
package/src/theme.css
CHANGED
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
--default-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
.relative {
|
|
24
|
+
position: relative;
|
|
25
|
+
}
|
|
23
26
|
.m-0 {
|
|
24
27
|
margin: 0px;
|
|
25
28
|
}
|
|
@@ -38,6 +41,9 @@
|
|
|
38
41
|
.mt-0\.5 {
|
|
39
42
|
margin-top: calc(var(--spacing) * 0.5);
|
|
40
43
|
}
|
|
44
|
+
.mt-1\.5 {
|
|
45
|
+
margin-top: calc(var(--spacing) * 1.5);
|
|
46
|
+
}
|
|
41
47
|
.mt-3 {
|
|
42
48
|
margin-top: calc(var(--spacing) * 3);
|
|
43
49
|
}
|
|
@@ -74,6 +80,9 @@
|
|
|
74
80
|
.grid {
|
|
75
81
|
display: grid;
|
|
76
82
|
}
|
|
83
|
+
.inline-flex {
|
|
84
|
+
display: inline-flex;
|
|
85
|
+
}
|
|
77
86
|
.size-2 {
|
|
78
87
|
width: calc(var(--spacing) * 2);
|
|
79
88
|
height: calc(var(--spacing) * 2);
|
|
@@ -131,6 +140,9 @@
|
|
|
131
140
|
.gap-1 {
|
|
132
141
|
gap: var(--spacing);
|
|
133
142
|
}
|
|
143
|
+
.gap-1\.5 {
|
|
144
|
+
gap: calc(var(--spacing) * 1.5);
|
|
145
|
+
}
|
|
134
146
|
.gap-2 {
|
|
135
147
|
gap: calc(var(--spacing) * 2);
|
|
136
148
|
}
|
|
@@ -222,6 +234,9 @@
|
|
|
222
234
|
.px-1\.5 {
|
|
223
235
|
padding-inline: calc(var(--spacing) * 1.5);
|
|
224
236
|
}
|
|
237
|
+
.px-2 {
|
|
238
|
+
padding-inline: calc(var(--spacing) * 2);
|
|
239
|
+
}
|
|
225
240
|
.px-2\.5 {
|
|
226
241
|
padding-inline: calc(var(--spacing) * 2.5);
|
|
227
242
|
}
|
|
@@ -364,10 +379,27 @@
|
|
|
364
379
|
:is(:where(.group):is([open], :popover-open, :open) .group-open\:rotate-90) {
|
|
365
380
|
rotate: 90deg;
|
|
366
381
|
}
|
|
382
|
+
:is(:where(.group):is([open], :popover-open, :open) .group-open\:border-accent) {
|
|
383
|
+
border-color: var(--accent);
|
|
384
|
+
}
|
|
385
|
+
:is(:where(.group):is([open], :popover-open, :open) .group-open\:text-fg) {
|
|
386
|
+
color: var(--fg);
|
|
387
|
+
}
|
|
388
|
+
.after\:text-\[10px\]::after {
|
|
389
|
+
content: var(--tw-content);
|
|
390
|
+
font-size: 10px;
|
|
391
|
+
}
|
|
392
|
+
.after\:content-\[\'▾\'\]::after {
|
|
393
|
+
--tw-content: '▾';
|
|
394
|
+
content: var(--tw-content);
|
|
395
|
+
}
|
|
367
396
|
@media (hover: hover) {
|
|
368
397
|
.hover\:border-accent:hover {
|
|
369
398
|
border-color: var(--accent);
|
|
370
399
|
}
|
|
400
|
+
.hover\:bg-surface:hover {
|
|
401
|
+
background-color: var(--surface);
|
|
402
|
+
}
|
|
371
403
|
.hover\:text-fg:hover {
|
|
372
404
|
color: var(--fg);
|
|
373
405
|
}
|
|
@@ -1298,6 +1330,36 @@ details.custom-block[open] > summary {
|
|
|
1298
1330
|
.code-group > .code-block pre {
|
|
1299
1331
|
border-top-left-radius: 0;
|
|
1300
1332
|
}
|
|
1333
|
+
:is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) {
|
|
1334
|
+
display: grid;
|
|
1335
|
+
grid-template-columns: repeat(var(--tabs, 1), 0 max-content);
|
|
1336
|
+
position: relative;
|
|
1337
|
+
overflow-x: auto;
|
|
1338
|
+
scrollbar-width: thin;
|
|
1339
|
+
container-type: inline-size;
|
|
1340
|
+
}
|
|
1341
|
+
:is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) > input {
|
|
1342
|
+
position: static;
|
|
1343
|
+
grid-row: 1;
|
|
1344
|
+
width: 0;
|
|
1345
|
+
height: 0;
|
|
1346
|
+
margin: 0;
|
|
1347
|
+
scroll-margin-inline-end: 16rem;
|
|
1348
|
+
}
|
|
1349
|
+
:is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) > label {
|
|
1350
|
+
grid-row: 1;
|
|
1351
|
+
white-space: nowrap;
|
|
1352
|
+
max-width: 16rem;
|
|
1353
|
+
overflow: hidden;
|
|
1354
|
+
text-overflow: ellipsis;
|
|
1355
|
+
}
|
|
1356
|
+
:is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) > .code-block {
|
|
1357
|
+
grid-row: 2;
|
|
1358
|
+
grid-column: 1 / -1;
|
|
1359
|
+
width: 100cqi;
|
|
1360
|
+
position: sticky;
|
|
1361
|
+
left: 0;
|
|
1362
|
+
}
|
|
1301
1363
|
@media (prefers-reduced-motion: reduce) {
|
|
1302
1364
|
*, *::before, *::after {
|
|
1303
1365
|
animation-duration: 0.01ms !important;
|
|
@@ -1621,6 +1683,11 @@ html[data-cl-navigating]::before {
|
|
|
1621
1683
|
syntax: "*";
|
|
1622
1684
|
inherits: false;
|
|
1623
1685
|
}
|
|
1686
|
+
@property --tw-content {
|
|
1687
|
+
syntax: "*";
|
|
1688
|
+
initial-value: "";
|
|
1689
|
+
inherits: false;
|
|
1690
|
+
}
|
|
1624
1691
|
@property --tw-shadow {
|
|
1625
1692
|
syntax: "*";
|
|
1626
1693
|
inherits: false;
|
|
@@ -1693,6 +1760,7 @@ html[data-cl-navigating]::before {
|
|
|
1693
1760
|
--tw-leading: initial;
|
|
1694
1761
|
--tw-font-weight: initial;
|
|
1695
1762
|
--tw-tracking: initial;
|
|
1763
|
+
--tw-content: "";
|
|
1696
1764
|
--tw-shadow: 0 0 #0000;
|
|
1697
1765
|
--tw-shadow-color: initial;
|
|
1698
1766
|
--tw-shadow-alpha: 100%;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{{--
|
|
2
|
+
Every version of the docs, for a page of its own (versioned docs; themeDocs({ versions: { all: '/versions' } }) links
|
|
3
|
+
it from the menu): the live docs, then each archived version served, with the release it was built from.
|
|
4
|
+
|
|
5
|
+
<version-list [versions]="versions" /> (import versions from 'virtual:theme-docs/versions')
|
|
6
|
+
--}}
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
import type { Versions } from './nav.ts'
|
|
9
|
+
const { versions } = props<{
|
|
10
|
+
/** The versions, as themeDocs({ versions }) serves them (virtual:theme-docs/versions). */
|
|
11
|
+
versions: Versions
|
|
12
|
+
}>()
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<table class="version-list">
|
|
16
|
+
<thead>
|
|
17
|
+
<tr><th scope="col">Version</th><th scope="col">Release</th></tr>
|
|
18
|
+
</thead>
|
|
19
|
+
<tbody>
|
|
20
|
+
<tr><td><a href="/">{{ versions.current }}</a> (latest)</td><td>{{ versions.current }}</td></tr>
|
|
21
|
+
@for (v of versions.archived; track v.version) {
|
|
22
|
+
<tr><td><a [href]="`/v${v.version}/`">v{{ v.version }}</a></td><td>{{ v.tag }}</td></tr>
|
|
23
|
+
}
|
|
24
|
+
</tbody>
|
|
25
|
+
</table>
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// clarusjs-docs-versions: versioned docs (versions.js). Run from the docs site's folder (where versions.json is).
|
|
3
|
+
//
|
|
4
|
+
// clarusjs-docs-versions snapshot <tag> build that release's docs under <base>v<version>/, marked and
|
|
5
|
+
// checked, packed into .versions/docs-v<version>.tar.gz
|
|
6
|
+
// clarusjs-docs-versions snapshot --missing every release not archived yet (the release workflow's step)
|
|
7
|
+
// --upload attach each to its GitHub release (gh) and list it in versions.json
|
|
8
|
+
// --base /docs/ the site's base path, if it has one
|
|
9
|
+
// clarusjs-docs-versions fetch [--from <dir>] after the site's build: unpack the served archives into it, and
|
|
10
|
+
// write the _redirects lines (each version's 404, retired ones)
|
|
11
|
+
// clarusjs-docs-versions list each archived version, its tag, and whether it's served
|
|
12
|
+
// @see https://clarusjs.com/docs-sites/versioned-docs
|
|
13
|
+
import { execFileSync } from 'node:child_process'
|
|
14
|
+
import { appendFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
15
|
+
import { tmpdir } from 'node:os'
|
|
16
|
+
import { dirname, join, relative, resolve } from 'node:path'
|
|
17
|
+
import { assetName, downloadUrl, lineOf, markSnapshot, newestOf, pagePath, plan, settingsOf, toArchive } from './versions.js'
|
|
18
|
+
|
|
19
|
+
const site = process.cwd()
|
|
20
|
+
const listFile = join(site, 'versions.json')
|
|
21
|
+
const args = process.argv.slice(2)
|
|
22
|
+
/** @param {string} name */
|
|
23
|
+
const flag = (name) => args.includes(name)
|
|
24
|
+
/** @param {string} name */
|
|
25
|
+
const value = (name) => (flag(name) ? args[args.indexOf(name) + 1] : undefined)
|
|
26
|
+
|
|
27
|
+
/** @param {string} cmd @param {string[]} a @param {string} [cwd] */
|
|
28
|
+
const run = (cmd, a, cwd = site) => execFileSync(cmd, a, { cwd, stdio: 'inherit' })
|
|
29
|
+
/** @param {string} cmd @param {string[]} a */
|
|
30
|
+
const read = (cmd, a) => execFileSync(cmd, a, { cwd: site, encoding: 'utf8' }).trim()
|
|
31
|
+
|
|
32
|
+
if (!existsSync(listFile)) {
|
|
33
|
+
console.error(`clarusjs-docs-versions: no versions.json in ${site}: run this from the docs site's folder`)
|
|
34
|
+
process.exit(1)
|
|
35
|
+
}
|
|
36
|
+
/** @type {import('./versions.js').VersionsFile} */
|
|
37
|
+
const file = JSON.parse(readFileSync(listFile, 'utf8'))
|
|
38
|
+
const settings = settingsOf(file, repositoryOf(site))
|
|
39
|
+
const listed = file.versions ?? []
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
if (args[0] === 'snapshot') snapshotCommand()
|
|
43
|
+
else if (args[0] === 'fetch') await fetchCommand()
|
|
44
|
+
else if (args[0] === 'list') listCommand()
|
|
45
|
+
else fail('usage: clarusjs-docs-versions snapshot <tag> | snapshot --missing [--upload] [--base /x/] | fetch [--from <dir>] | list')
|
|
46
|
+
} catch (e) {
|
|
47
|
+
// Thrown, not exited where it happened, so a snapshot's finally removes its worktree first
|
|
48
|
+
console.error(`clarusjs-docs-versions: ${e instanceof Error ? e.message : e}`)
|
|
49
|
+
process.exitCode = 1
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function listCommand() {
|
|
53
|
+
const { served, retired } = plan(file)
|
|
54
|
+
console.log(`live: ${file.latest ?? '(unknown until snapshot --missing --upload)'}`)
|
|
55
|
+
for (const a of listed) {
|
|
56
|
+
const r = retired.find((x) => x.version === a.version)
|
|
57
|
+
const status = served.includes(a.version) ? 'served' : `retired${a.retired ? '' : ' (by lines, minors or keep)'}, redirects to ${r?.to ? `/v${r.to}/` : 'the latest docs'}`
|
|
58
|
+
console.log(`v${a.version.padEnd(8)} ${a.tag.padEnd(24)} ${status}`)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function snapshotCommand() {
|
|
63
|
+
const tag = args.slice(1).find((a, i, all) => !a.startsWith('--') && all[i - 1] !== '--base')
|
|
64
|
+
const [before, after] = settings.tag.split('{version}')
|
|
65
|
+
const tags = read('git', ['tag', '-l']).split('\n')
|
|
66
|
+
const newest = newestOf(tags, settings)
|
|
67
|
+
const todo = flag('--missing')
|
|
68
|
+
? toArchive(tags, settings, listed)
|
|
69
|
+
: tag
|
|
70
|
+
? [{ version: lineOf(tag.slice(before?.length, tag.length - (after?.length ?? 0)), settings, newest[0]), tag }]
|
|
71
|
+
: fail('snapshot: name a tag, or --missing')
|
|
72
|
+
// The newest release, so deploys apply lines, minors and keep without git tags
|
|
73
|
+
if (flag('--upload') && newest.length && file.latest !== newest.join('.')) {
|
|
74
|
+
file.latest = newest.join('.')
|
|
75
|
+
writeFileSync(listFile, JSON.stringify({ ...file, versions: listed }, null, 2) + '\n')
|
|
76
|
+
}
|
|
77
|
+
if (!todo.length) console.log('Nothing to archive.')
|
|
78
|
+
for (const v of todo) {
|
|
79
|
+
const archive = snapshot(v, value('--base') ?? '/')
|
|
80
|
+
console.log(`${v.tag}: ${relative(site, archive)}`)
|
|
81
|
+
if (!flag('--upload')) continue
|
|
82
|
+
run('gh', ['release', 'upload', v.tag, archive, '--clobber'])
|
|
83
|
+
const versions = [v, ...listed.filter((a) => a.version !== v.version)]
|
|
84
|
+
versions.sort((a, b) => b.version.localeCompare(a.version, 'en', { numeric: true }))
|
|
85
|
+
listed.splice(0, listed.length, ...versions)
|
|
86
|
+
writeFileSync(listFile, JSON.stringify({ ...file, versions: listed }, null, 2) + '\n')
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Builds one release's docs in a worktree, marks every page, checks no link leaves it, packs it.
|
|
92
|
+
* @param {import('./versions.js').Archived} v
|
|
93
|
+
* @param {string} siteBase
|
|
94
|
+
*/
|
|
95
|
+
function snapshot({ version, tag }, siteBase) {
|
|
96
|
+
const base = `${siteBase}v${version}/`
|
|
97
|
+
const repo = read('git', ['rev-parse', '--show-toplevel'])
|
|
98
|
+
const tree = mkdtempSync(join(tmpdir(), 'docs-version-'))
|
|
99
|
+
try {
|
|
100
|
+
run('git', ['worktree', 'add', '--detach', tree, tag], repo)
|
|
101
|
+
const dir = join(tree, relative(repo, site))
|
|
102
|
+
const pm = packageManager(tree)
|
|
103
|
+
run('sh', ['-c', file.install ?? pm.install], tree)
|
|
104
|
+
run('sh', ['-c', (file.build ?? pm.build).replace('{base}', base)], dir)
|
|
105
|
+
const out = join(dir, settings.out)
|
|
106
|
+
/** @type {Set<string>} */
|
|
107
|
+
const escaping = new Set()
|
|
108
|
+
for (const f of readdirSync(out, { recursive: true, encoding: 'utf8' })) {
|
|
109
|
+
if (!f.endsWith('.html')) continue
|
|
110
|
+
const rel = f.replaceAll('\\', '/')
|
|
111
|
+
const html = markSnapshot(readFileSync(join(out, f), 'utf8'), { version, path: pagePath(rel), base: siteBase, name: file.name })
|
|
112
|
+
// Every root-relative link stays in the snapshot, except the banner's (to the latest docs) and a canonical link
|
|
113
|
+
// (for search engines, not followed)
|
|
114
|
+
const followed = html.replace(/<div class="old-version-banner"[\s\S]*?<\/div>/, '').replace(/<link rel="canonical"[^>]*>/g, '')
|
|
115
|
+
for (const [, url] of followed.matchAll(/(?:href|src)="(\/[^"]*)"/g)) {
|
|
116
|
+
if (!url?.startsWith(base) && !url?.startsWith('//')) escaping.add(`${rel}: ${url}`)
|
|
117
|
+
}
|
|
118
|
+
writeFileSync(join(out, f), html)
|
|
119
|
+
}
|
|
120
|
+
if (escaping.size) {
|
|
121
|
+
fail(`${tag}: ${escaping.size} links leave ${base}, so its docs don't build under a base; archive later releases ("from" in versions.json). E.g.\n ${[...escaping].slice(0, 5).join('\n ')}`)
|
|
122
|
+
}
|
|
123
|
+
mkdirSync(join(site, '.versions'), { recursive: true })
|
|
124
|
+
const archive = join(site, '.versions', assetName(version))
|
|
125
|
+
run('tar', ['-czf', archive, '-C', out, '.'])
|
|
126
|
+
return archive
|
|
127
|
+
} finally {
|
|
128
|
+
rmSync(tree, { recursive: true, force: true })
|
|
129
|
+
run('git', ['worktree', 'prune'], repo)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function fetchCommand() {
|
|
134
|
+
const from = value('--from')
|
|
135
|
+
const siteBase = value('--base') ?? '/'
|
|
136
|
+
// Vercel (clarusjs's adapter: 'vercel') reads .vercel/output, made from the build: _redirects lines and clean URLs
|
|
137
|
+
// are routes and overrides in its config.json, so they go there. Any other host: the built folder and _redirects.
|
|
138
|
+
const vercel = join(site, '.vercel/output/config.json')
|
|
139
|
+
const onVercel = existsSync(vercel)
|
|
140
|
+
const out = onVercel ? join(site, '.vercel/output/static', `.${siteBase}`) : join(site, settings.out)
|
|
141
|
+
if (!existsSync(out)) fail(`${out} doesn't exist: build the site first`)
|
|
142
|
+
/** @type {{ routes: object[], overrides: Record<string, { path: string }> }} */
|
|
143
|
+
const config = onVercel ? JSON.parse(readFileSync(vercel, 'utf8')) : { routes: [], overrides: {} }
|
|
144
|
+
/** @type {object[]} */ const redirects = []
|
|
145
|
+
/** @type {object[]} */ const notFound = []
|
|
146
|
+
/** @param {string} v */
|
|
147
|
+
const re = (v) => `^${siteBase}v${v.replaceAll('.', '\\.')}`
|
|
148
|
+
const { served, retired } = plan(file)
|
|
149
|
+
for (const { version, to } of retired) {
|
|
150
|
+
// Old links and bookmarks go on to the same page: in its major's archive if served (/v2.3/x → /v2/x), else the
|
|
151
|
+
// latest docs
|
|
152
|
+
const target = to ? `${siteBase}v${to}/` : siteBase
|
|
153
|
+
if (onVercel) redirects.push({ src: `${re(version)}(?:/(.*))?$`, status: 301, headers: { Location: `${target}$1` } })
|
|
154
|
+
else appendFileSync(join(out, '_redirects'), `${siteBase}v${version}/* ${target}:splat 301\n`)
|
|
155
|
+
console.log(`v${version}: retired, redirected to ${to ? `/v${to}/` : 'the latest docs'}`)
|
|
156
|
+
}
|
|
157
|
+
for (const entry of listed.filter((a) => served.includes(a.version))) {
|
|
158
|
+
const { version } = entry
|
|
159
|
+
const archive = from ? resolve(from, assetName(version)) : join(site, '.versions', assetName(version))
|
|
160
|
+
if (!from) {
|
|
161
|
+
const url = downloadUrl(settings, entry)
|
|
162
|
+
const bytes = await download(url)
|
|
163
|
+
mkdirSync(dirname(archive), { recursive: true })
|
|
164
|
+
writeFileSync(archive, bytes)
|
|
165
|
+
}
|
|
166
|
+
const dir = join(out, `v${version}`)
|
|
167
|
+
rmSync(dir, { recursive: true, force: true })
|
|
168
|
+
mkdirSync(dir, { recursive: true })
|
|
169
|
+
run('tar', ['-xzf', archive, '-C', dir])
|
|
170
|
+
// A page that didn't exist yet in that version: its own 404 (hosts serve files first, so only missing ones)
|
|
171
|
+
if (onVercel) {
|
|
172
|
+
notFound.push({ src: `${re(version)}/.*`, status: 404, dest: `${siteBase}v${version}/404.html` })
|
|
173
|
+
for (const f of readdirSync(dir, { recursive: true, encoding: 'utf8' })) {
|
|
174
|
+
const rel = `${siteBase.slice(1)}v${version}/${f.replaceAll('\\', '/')}`
|
|
175
|
+
if (rel.endsWith('/index.html')) config.overrides[rel] = { path: rel.replace(/\/index\.html$/, '') }
|
|
176
|
+
}
|
|
177
|
+
} else appendFileSync(join(out, '_redirects'), `${siteBase}v${version}/* ${siteBase}v${version}/404.html 404\n`)
|
|
178
|
+
console.log(`v${version} (${entry.tag})`)
|
|
179
|
+
}
|
|
180
|
+
if (!onVercel) return
|
|
181
|
+
// Retired versions first (before the filesystem); each version's 404 before the site's own
|
|
182
|
+
const error = config.routes.findIndex((r) => 'handle' in r && r.handle === 'error')
|
|
183
|
+
config.routes.splice(error < 0 ? config.routes.length : error + 1, 0, ...notFound)
|
|
184
|
+
config.routes.unshift(...redirects)
|
|
185
|
+
writeFileSync(vercel, JSON.stringify(config, null, 2))
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** The install and build commands, from the lockfile at the repository's root. @param {string} root */
|
|
189
|
+
function packageManager(root) {
|
|
190
|
+
if (existsSync(join(root, 'pnpm-lock.yaml'))) return { install: 'pnpm install --frozen-lockfile', build: 'pnpm run build --base {base}' }
|
|
191
|
+
if (existsSync(join(root, 'yarn.lock'))) return { install: 'yarn install --immutable', build: 'yarn run build --base {base}' }
|
|
192
|
+
if (existsSync(join(root, 'bun.lock')) || existsSync(join(root, 'bun.lockb'))) return { install: 'bun install --frozen-lockfile', build: 'bun run build --base {base}' }
|
|
193
|
+
return { install: 'npm ci', build: 'npm run build -- --base {base}' }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** package.json's repository, from the site's folder up. @param {string} dir @returns {string | undefined} */
|
|
197
|
+
function repositoryOf(dir) {
|
|
198
|
+
for (let d = dir; ; d = dirname(d)) {
|
|
199
|
+
const pkg = join(d, 'package.json')
|
|
200
|
+
if (existsSync(pkg)) {
|
|
201
|
+
const r = JSON.parse(readFileSync(pkg, 'utf8')).repository
|
|
202
|
+
if (r) return typeof r === 'string' ? r : r.url
|
|
203
|
+
}
|
|
204
|
+
if (dirname(d) === d) return undefined
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** @param {string} message @returns {never} */
|
|
209
|
+
function fail(message) {
|
|
210
|
+
throw new Error(message)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* An archive's bytes: 30 seconds per try, and one more try after a failure or a 5xx (a deploy shouldn't fail or hang
|
|
215
|
+
* on one bad response from the host).
|
|
216
|
+
* @param {string} url
|
|
217
|
+
*/
|
|
218
|
+
async function download(url) {
|
|
219
|
+
for (let attempt = 1; ; attempt++) {
|
|
220
|
+
try {
|
|
221
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(30_000) })
|
|
222
|
+
if (res.ok) return Buffer.from(await res.arrayBuffer())
|
|
223
|
+
if (res.status < 500 || attempt === 2) fail(`${url}: ${res.status}`)
|
|
224
|
+
} catch (e) {
|
|
225
|
+
if (attempt === 2) throw e
|
|
226
|
+
}
|
|
227
|
+
await new Promise((r) => setTimeout(r, 2000))
|
|
228
|
+
}
|
|
229
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
export type Archived = {
|
|
2
|
+
/**
|
|
3
|
+
* as shown and in the URL (/v0.19/): '0.19' before 1.0, '1' from it
|
|
4
|
+
*/
|
|
5
|
+
version: string;
|
|
6
|
+
/**
|
|
7
|
+
* the release tag it's built from
|
|
8
|
+
*/
|
|
9
|
+
tag: string;
|
|
10
|
+
/**
|
|
11
|
+
* taken down: not served or listed; its URLs redirect to the latest docs
|
|
12
|
+
*/
|
|
13
|
+
retired?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type VersionsFile = {
|
|
16
|
+
/**
|
|
17
|
+
* how releases are tagged, with {version}: 'v{version}' (the default), 'mylib@{version}'
|
|
18
|
+
*/
|
|
19
|
+
tag?: string;
|
|
20
|
+
/**
|
|
21
|
+
* the first release to archive ('0.19.0'): docs older than it may not build under a base
|
|
22
|
+
*/
|
|
23
|
+
from?: string;
|
|
24
|
+
/**
|
|
25
|
+
* how releases group into versions: 'auto' (the default) by minor before
|
|
26
|
+
* 1.0 and by major from it; 'major' or 'minor' always
|
|
27
|
+
*/
|
|
28
|
+
lines?: 'auto' | 'major' | 'minor';
|
|
29
|
+
/**
|
|
30
|
+
* by major: the newest major's latest minors are versions of their own too (2.4, 2.3 while
|
|
31
|
+
* 2.5 is live); they give way to the major's archive once the next major is out
|
|
32
|
+
*/
|
|
33
|
+
minors?: number;
|
|
34
|
+
/**
|
|
35
|
+
* serve at most this many archived versions, newest first; older ones are retired
|
|
36
|
+
*/
|
|
37
|
+
keep?: number;
|
|
38
|
+
/**
|
|
39
|
+
* the newest release, written by snapshot: deploys apply the rules above without git tags
|
|
40
|
+
*/
|
|
41
|
+
latest?: string;
|
|
42
|
+
/**
|
|
43
|
+
* where archives are, with {tag} and {asset}; default: the repository's GitHub releases
|
|
44
|
+
*/
|
|
45
|
+
download?: string;
|
|
46
|
+
/**
|
|
47
|
+
* the project's name, for the banner ("the docs for <name> 0.19")
|
|
48
|
+
*/
|
|
49
|
+
name?: string;
|
|
50
|
+
/**
|
|
51
|
+
* the built site, from the site's folder (default dist/client)
|
|
52
|
+
*/
|
|
53
|
+
out?: string;
|
|
54
|
+
/**
|
|
55
|
+
* the install command (default: from the lockfile)
|
|
56
|
+
*/
|
|
57
|
+
install?: string;
|
|
58
|
+
/**
|
|
59
|
+
* the build command; {base} is the version's base path (default: from the lockfile)
|
|
60
|
+
*/
|
|
61
|
+
build?: string;
|
|
62
|
+
/**
|
|
63
|
+
* the archived versions, newest first
|
|
64
|
+
*/
|
|
65
|
+
versions?: Archived[];
|
|
66
|
+
};
|
|
67
|
+
export type Settings = Required<Pick<VersionsFile, 'tag' | 'out'>> & VersionsFile & {
|
|
68
|
+
repository?: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* @typedef {object} Archived
|
|
72
|
+
* @property {string} version as shown and in the URL (/v0.19/): '0.19' before 1.0, '1' from it
|
|
73
|
+
* @property {string} tag the release tag it's built from
|
|
74
|
+
* @property {boolean} [retired] taken down: not served or listed; its URLs redirect to the latest docs
|
|
75
|
+
*/
|
|
76
|
+
/**
|
|
77
|
+
* @typedef {object} VersionsFile versions.json, next to the site's Vite config
|
|
78
|
+
* @property {string} [tag] how releases are tagged, with {version}: 'v{version}' (the default), 'mylib@{version}'
|
|
79
|
+
* @property {string} [from] the first release to archive ('0.19.0'): docs older than it may not build under a base
|
|
80
|
+
* @property {'auto' | 'major' | 'minor'} [lines] how releases group into versions: 'auto' (the default) by minor before
|
|
81
|
+
* 1.0 and by major from it; 'major' or 'minor' always
|
|
82
|
+
* @property {number} [minors] by major: the newest major's latest minors are versions of their own too (2.4, 2.3 while
|
|
83
|
+
* 2.5 is live); they give way to the major's archive once the next major is out
|
|
84
|
+
* @property {number} [keep] serve at most this many archived versions, newest first; older ones are retired
|
|
85
|
+
* @property {string} [latest] the newest release, written by snapshot: deploys apply the rules above without git tags
|
|
86
|
+
* @property {string} [download] where archives are, with {tag} and {asset}; default: the repository's GitHub releases
|
|
87
|
+
* @property {string} [name] the project's name, for the banner ("the docs for <name> 0.19")
|
|
88
|
+
* @property {string} [out] the built site, from the site's folder (default dist/client)
|
|
89
|
+
* @property {string} [install] the install command (default: from the lockfile)
|
|
90
|
+
* @property {string} [build] the build command; {base} is the version's base path (default: from the lockfile)
|
|
91
|
+
* @property {Archived[]} [versions] the archived versions, newest first
|
|
92
|
+
*/
|
|
93
|
+
/** @typedef {Required<Pick<VersionsFile, 'tag' | 'out'>> & VersionsFile & { repository?: string }} Settings */
|
|
94
|
+
/**
|
|
95
|
+
* The settings with their defaults; `repository` (package.json's) for the default download address.
|
|
96
|
+
* @param {VersionsFile} file
|
|
97
|
+
* @param {string} [repository]
|
|
98
|
+
* @returns {Settings}
|
|
99
|
+
*/
|
|
100
|
+
export declare function settingsOf(file: VersionsFile, repository?: string): Settings;
|
|
101
|
+
/** The archive's file name. @param {string} version */
|
|
102
|
+
export declare const assetName: (version: string) => string;
|
|
103
|
+
/**
|
|
104
|
+
* Where an archive downloads from.
|
|
105
|
+
* @param {Settings} s
|
|
106
|
+
* @param {Archived} entry
|
|
107
|
+
*/
|
|
108
|
+
export declare function downloadUrl(s: Settings, entry: Archived): string;
|
|
109
|
+
/**
|
|
110
|
+
* The line (archived version) a release belongs to: by `lines`, and the newest major's minors with `minors`.
|
|
111
|
+
* @param {string} v '2.3.1'
|
|
112
|
+
* @param {Partial<Settings>} [s]
|
|
113
|
+
* @param {number} [newestMajor]
|
|
114
|
+
*/
|
|
115
|
+
export declare function lineOf(v: string, s?: Partial<Settings>, newestMajor?: number): string;
|
|
116
|
+
/**
|
|
117
|
+
* The versions to archive that aren't listed yet, newest first: the latest patch of each line from `from`, except the
|
|
118
|
+
* newest release's line (the live docs).
|
|
119
|
+
* @param {string[]} tags the repository's tags
|
|
120
|
+
* @param {Settings} s
|
|
121
|
+
* @param {Archived[]} listed
|
|
122
|
+
* @returns {Archived[]}
|
|
123
|
+
*/
|
|
124
|
+
export declare function toArchive(tags: string[], s: Settings, listed: Archived[]): Archived[];
|
|
125
|
+
/** The newest release's version numbers ([] without any). @param {string[]} tags @param {Settings} s */
|
|
126
|
+
export declare function newestOf(tags: string[], s: Settings): number[];
|
|
127
|
+
/**
|
|
128
|
+
* What a deploy serves, from versions.json alone: the archived versions listed, less those retired by hand, minors
|
|
129
|
+
* past `minors` (or of an older major than `latest`'s), and those past `keep`. A retired minor whose major is served
|
|
130
|
+
* redirects there (/v2.3/x → /v2/x); others to the latest docs (`to` '').
|
|
131
|
+
* @param {VersionsFile} file
|
|
132
|
+
* @returns {{ served: string[], retired: { version: string, to: string }[] }}
|
|
133
|
+
*/
|
|
134
|
+
export declare function plan(file: VersionsFile): {
|
|
135
|
+
served: string[];
|
|
136
|
+
retired: {
|
|
137
|
+
version: string;
|
|
138
|
+
to: string;
|
|
139
|
+
}[];
|
|
140
|
+
};
|
|
141
|
+
/** An archived version's pages: navigations leaving its prefix (/v0.19/, under the base) load the page. @param {string} prefix */
|
|
142
|
+
export declare const archivedGuard: (prefix: string) => string;
|
|
143
|
+
/**
|
|
144
|
+
* Every page the theme renders (the live docs, and archives built with it): a navigation into another version (a
|
|
145
|
+
* /v0.19/ or /v1 segment, under any base) loads the page; within the same version it swaps as usual. A page of the
|
|
146
|
+
* site's own with such a segment would load instead of swap: slower, never wrong.
|
|
147
|
+
*/
|
|
148
|
+
export declare const LATEST_GUARD: string;
|
|
149
|
+
/**
|
|
150
|
+
* An archived page's HTML, marked: a banner after `<body…>` saying which version it is, with a link to the same page in
|
|
151
|
+
* the latest docs; in a full document, the navigation guard first in <head>, its canonical link pointed at the latest
|
|
152
|
+
* page, and noindex. Insertions only: built under its own base, its links already stay inside it.
|
|
153
|
+
* @param {string} html
|
|
154
|
+
* @param {{ version: string, path: string, base: string, name?: string }} o the page's path without the base
|
|
155
|
+
*/
|
|
156
|
+
export declare function markSnapshot(html: string, { version, path, base, name }: {
|
|
157
|
+
version: string;
|
|
158
|
+
path: string;
|
|
159
|
+
base: string;
|
|
160
|
+
name?: string;
|
|
161
|
+
}): string;
|
|
162
|
+
/** A page's path from its file in the built site: 'guide/lists/index.html' → '/guide/lists'. @param {string} file */
|
|
163
|
+
export declare function pagePath(file: string): string;
|