@writedocs/generator 0.15.0 → 0.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/astro.config.mjs +8 -2
- package/package.json +1 -1
- package/packages/components/src/components/CodeGroup.astro +6 -6
- package/src/cli/build.js +39 -4
- package/src/cli/dev.js +16 -0
- package/src/cli/rewrite-redirect-pages.js +8 -6
- package/src/cli/run-pagefind.js +24 -11
- package/src/cli/write-mcp-files.js +4 -1
- package/src/cli/write-redirects-file.js +9 -4
- package/src/content.config.ts +21 -1
- package/src/layout/BaseLayout.astro +38 -49
- package/src/layout/components/LockMark.astro +28 -0
- package/src/layout/components/MobileMenu.astro +13 -5
- package/src/layout/components/Sidebar.astro +3 -2
- package/src/layout/components/TopBar.astro +17 -4
- package/src/lib/appearance.js +64 -0
- package/src/lib/asset-dimensions.js +2 -1
- package/src/lib/bom.js +20 -0
- package/src/lib/config-file.js +21 -8
- package/src/lib/config-schema.js +55 -10
- package/src/lib/config-schema.ts +78 -18
- package/src/lib/config.ts +23 -11
- package/src/lib/content-check.js +54 -4
- package/src/lib/content-store-prune.js +44 -0
- package/src/lib/json-schema-descriptions.js +7 -2
- package/src/lib/llms-index.ts +5 -0
- package/src/lib/mcp-index.ts +5 -1
- package/src/lib/mintlify-convert.js +11 -1
- package/src/lib/pages.js +5 -3
- package/src/lib/protected-sections.js +238 -0
- package/src/lib/wdignore-cases.json +9 -2
- package/src/lib/wdignore.js +5 -0
- package/src/lib/writedocs-legacy-convert.js +1 -1
- package/src/pages/[...slug].astro +53 -14
- package/src/pages/llms-full.txt.ts +10 -3
- package/src/pages/llms.txt.ts +4 -4
- package/src/pages/og/[...slug].png.ts +11 -2
- package/writedocs.schema.json +478 -70
|
@@ -29,8 +29,10 @@
|
|
|
29
29
|
// several unrelated concerns in one file - see that component's own
|
|
30
30
|
// comment for the fuller rationale.
|
|
31
31
|
import { isExternalHref, type DocsConfig, type Selector, type GlobalDropdownView } from '../../lib/config';
|
|
32
|
+
import LockMark from './LockMark.astro';
|
|
32
33
|
import AppIcon from '../../../packages/components/src/components/AppIcon.astro';
|
|
33
34
|
import { logoWidth } from '../../lib/image-size.js';
|
|
35
|
+
import { showsThemeToggle } from '../../lib/appearance.js';
|
|
34
36
|
import { hasMobileMenu, currentOption } from '../../lib/selector-placement.js';
|
|
35
37
|
import '../styles/dropdown.css';
|
|
36
38
|
import '../styles/topbar.css';
|
|
@@ -92,11 +94,14 @@ const showMenu = hasMobileMenu({ sidebar: showSidebarCol, selectors, globalDropd
|
|
|
92
94
|
wires up every `.wd-theme-toggle` it finds (not just the
|
|
93
95
|
first), and both stay in sync for free since [data-theme] on
|
|
94
96
|
<html> - not per-button JS state - is what actually drives
|
|
95
|
-
which icon shows.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
<
|
|
99
|
-
|
|
97
|
+
which icon shows. Left out with `styles.appearance.strict`,
|
|
98
|
+
like the topbar's (src/lib/appearance.js). */}
|
|
99
|
+
{showsThemeToggle(config.styles.appearance) && (
|
|
100
|
+
<button type="button" class="wd-theme-toggle" aria-label="Toggle color theme">
|
|
101
|
+
<AppIcon icon="sun" class="wd-theme-icon wd-theme-icon-sun" />
|
|
102
|
+
<AppIcon icon="moon" class="wd-theme-icon wd-theme-icon-moon" />
|
|
103
|
+
</button>
|
|
104
|
+
)}
|
|
100
105
|
</div>
|
|
101
106
|
<div class="wd-mobile-menu-scroll">
|
|
102
107
|
{(selectors.some((sel) => !sel.hidden) || globalDropdowns.length > 0) && (
|
|
@@ -117,6 +122,7 @@ const showMenu = hasMobileMenu({ sidebar: showSidebarCol, selectors, globalDropd
|
|
|
117
122
|
>
|
|
118
123
|
<AppIcon icon={opt.icon} class="wd-tab-icon" />
|
|
119
124
|
<span class="wd-mobile-accordion-option-label">{opt.label}</span>
|
|
125
|
+
<LockMark locked={opt.locked} />
|
|
120
126
|
{opt.tag && <span class="wd-selector-tag">{opt.tag}</span>}
|
|
121
127
|
</a>
|
|
122
128
|
))}
|
|
@@ -129,6 +135,7 @@ const showMenu = hasMobileMenu({ sidebar: showSidebarCol, selectors, globalDropd
|
|
|
129
135
|
<summary class="wd-mobile-accordion-trigger">
|
|
130
136
|
<AppIcon icon={current.icon} class="wd-tab-icon" />
|
|
131
137
|
<span class="wd-mobile-accordion-label">{current.label}</span>
|
|
138
|
+
<LockMark locked={(current as { locked?: boolean }).locked} />
|
|
132
139
|
{current.tag && <span class="wd-selector-tag">{current.tag}</span>}
|
|
133
140
|
<svg class="wd-mobile-accordion-caret" width="12" height="12" viewBox="0 0 10 10" aria-hidden="true">
|
|
134
141
|
<path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
|
|
@@ -145,6 +152,7 @@ const showMenu = hasMobileMenu({ sidebar: showSidebarCol, selectors, globalDropd
|
|
|
145
152
|
>
|
|
146
153
|
<AppIcon icon={opt.icon} class="wd-tab-icon" />
|
|
147
154
|
<span class="wd-mobile-accordion-option-label">{opt.label}</span>
|
|
155
|
+
<LockMark locked={opt.locked} />
|
|
148
156
|
{opt.tag && <span class="wd-selector-tag">{opt.tag}</span>}
|
|
149
157
|
{opt.active && (
|
|
150
158
|
<svg class="wd-mobile-accordion-check" width="14" height="14" viewBox="0 0 14 14" aria-hidden="true">
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { isExternalHref, type NavTreeNode, type Selector } from "../../lib/config";
|
|
3
3
|
import NavTree from "./NavTree.astro";
|
|
4
4
|
import { currentOption } from "../../lib/selector-placement.js";
|
|
5
|
+
import LockMark from "./LockMark.astro";
|
|
5
6
|
import AppIcon from "../../../packages/components/src/components/AppIcon.astro";
|
|
6
7
|
// Two colorways of the same "Powered by writedocs" mark, not a
|
|
7
8
|
// theme-matched pair in the wd-logo-light/wd-logo-dark sense (that
|
|
@@ -50,7 +51,7 @@ const { navTree, hrefForSlug, currentSlug, switchers = [] } = Astro.props as Pro
|
|
|
50
51
|
<button type="button" class="wd-dropdown-trigger wd-sidebar-switcher-trigger" aria-expanded="false">
|
|
51
52
|
<AppIcon icon={current.icon} class="wd-tab-icon wd-sidebar-switcher-icon" />
|
|
52
53
|
<span class="wd-sidebar-switcher-text">
|
|
53
|
-
<span class="wd-sidebar-switcher-label">{current.label}
|
|
54
|
+
<span class="wd-sidebar-switcher-label">{current.label}<LockMark locked={(current as { locked?: boolean }).locked} inline /></span>
|
|
54
55
|
{current.description && <span class="wd-sidebar-switcher-desc">{current.description}</span>}
|
|
55
56
|
</span>
|
|
56
57
|
<svg class="wd-sidebar-switcher-chevrons" width="12" height="12" viewBox="0 0 12 12" aria-hidden="true">
|
|
@@ -69,7 +70,7 @@ const { navTree, hrefForSlug, currentSlug, switchers = [] } = Astro.props as Pro
|
|
|
69
70
|
>
|
|
70
71
|
<AppIcon icon={opt.icon} class="wd-tab-icon wd-sidebar-switcher-icon" />
|
|
71
72
|
<span class="wd-sidebar-switcher-text">
|
|
72
|
-
<span class="wd-sidebar-switcher-label">{opt.label}
|
|
73
|
+
<span class="wd-sidebar-switcher-label">{opt.label}<LockMark locked={opt.locked} inline /></span>
|
|
73
74
|
{opt.description && <span class="wd-sidebar-switcher-desc">{opt.description}</span>}
|
|
74
75
|
</span>
|
|
75
76
|
</a>
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
// comment for the fuller rationale.
|
|
14
14
|
import { isExternalHref, type DocsConfig, type Selector, type GlobalDropdownView } from '../../lib/config';
|
|
15
15
|
import AppIcon from '../../../packages/components/src/components/AppIcon.astro';
|
|
16
|
+
import LockMark from './LockMark.astro';
|
|
16
17
|
import { logoWidth } from '../../lib/image-size.js';
|
|
18
|
+
import { showsThemeToggle } from '../../lib/appearance.js';
|
|
17
19
|
import { selectorPlacements, hasMobileMenu, currentOption } from '../../lib/selector-placement.js';
|
|
18
20
|
import '../styles/dropdown.css';
|
|
19
21
|
import '../styles/topbar.css';
|
|
@@ -113,6 +115,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
113
115
|
<button type="button" class="wd-dropdown-trigger wd-switcher-trigger" aria-expanded="false">
|
|
114
116
|
<AppIcon icon={current.icon} class="wd-tab-icon" />
|
|
115
117
|
{current.label}
|
|
118
|
+
<LockMark locked={(current as { locked?: boolean }).locked} />
|
|
116
119
|
{current.tag && <span class="wd-selector-tag">{current.tag}</span>}
|
|
117
120
|
<svg class="wd-dropdown-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
|
|
118
121
|
<path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
|
|
@@ -129,6 +132,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
129
132
|
>
|
|
130
133
|
<AppIcon icon={opt.icon} class="wd-tab-icon" />
|
|
131
134
|
{opt.label}
|
|
135
|
+
<LockMark locked={opt.locked} />
|
|
132
136
|
{opt.tag && <span class="wd-selector-tag">{opt.tag}</span>}
|
|
133
137
|
</a>
|
|
134
138
|
))}
|
|
@@ -206,10 +210,13 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
206
210
|
<kbd class="wd-search-kbd">⌘K</kbd>
|
|
207
211
|
</button>
|
|
208
212
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
<
|
|
212
|
-
|
|
213
|
+
{/* Left out with `styles.appearance.strict` - src/lib/appearance.js. */}
|
|
214
|
+
{showsThemeToggle(config.styles.appearance) && (
|
|
215
|
+
<button type="button" class="wd-theme-toggle" aria-label="Toggle color theme">
|
|
216
|
+
<AppIcon icon="sun" class="wd-theme-icon wd-theme-icon-sun" />
|
|
217
|
+
<AppIcon icon="moon" class="wd-theme-icon wd-theme-icon-moon" />
|
|
218
|
+
</button>
|
|
219
|
+
)}
|
|
213
220
|
</div>
|
|
214
221
|
</div>
|
|
215
222
|
|
|
@@ -245,6 +252,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
245
252
|
>
|
|
246
253
|
<AppIcon icon={opt.icon} class="wd-tab-icon" />
|
|
247
254
|
{opt.label}
|
|
255
|
+
<LockMark locked={opt.locked} />
|
|
248
256
|
<svg class="wd-dropdown-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
|
|
249
257
|
<path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
|
|
250
258
|
</svg>
|
|
@@ -263,6 +271,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
263
271
|
<a href={siteHref(d.pageHref)} class={`wd-submenu-entry ${d.active ? 'active' : ''}`} aria-current={d.active ? 'true' : undefined}>
|
|
264
272
|
<AppIcon icon={d.icon} class="wd-tab-icon" />
|
|
265
273
|
<span class="wd-submenu-label">{d.label}</span>
|
|
274
|
+
<LockMark locked={d.locked} />
|
|
266
275
|
</a>
|
|
267
276
|
) : null}
|
|
268
277
|
<button
|
|
@@ -273,6 +282,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
273
282
|
>
|
|
274
283
|
{!d.pageHref && <AppIcon icon={d.icon} class="wd-tab-icon" />}
|
|
275
284
|
{!d.pageHref && <span class="wd-submenu-label">{d.label}</span>}
|
|
285
|
+
{!d.pageHref && <LockMark locked={d.locked} />}
|
|
276
286
|
<svg class="wd-submenu-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
|
|
277
287
|
<path d="M3.5 2L6.5 5L3.5 8" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
|
|
278
288
|
</svg>
|
|
@@ -294,6 +304,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
294
304
|
>
|
|
295
305
|
<AppIcon icon={sub.icon} class="wd-tab-icon" />
|
|
296
306
|
{sub.label}
|
|
307
|
+
<LockMark locked={sub.locked} />
|
|
297
308
|
</a>
|
|
298
309
|
))}
|
|
299
310
|
</div>
|
|
@@ -308,6 +319,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
308
319
|
>
|
|
309
320
|
<AppIcon icon={d.icon} class="wd-tab-icon" />
|
|
310
321
|
{d.label}
|
|
322
|
+
<LockMark locked={d.locked} />
|
|
311
323
|
</a>
|
|
312
324
|
)
|
|
313
325
|
)}
|
|
@@ -324,6 +336,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
324
336
|
>
|
|
325
337
|
<AppIcon icon={opt.icon} class="wd-tab-icon" />
|
|
326
338
|
{opt.label}
|
|
339
|
+
<LockMark locked={opt.locked} />
|
|
327
340
|
</a>
|
|
328
341
|
)
|
|
329
342
|
)}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// `styles.appearance` in writedocs.json: which color mode a page opens in,
|
|
2
|
+
// and whether readers can change it.
|
|
3
|
+
//
|
|
4
|
+
// default: "system" (the reader's OS setting - the default), "light" or "dark"
|
|
5
|
+
// strict: true hides the theme toggle, so every reader gets `default`
|
|
6
|
+
//
|
|
7
|
+
// The theme itself is [data-theme] on <html>, set before the first paint by
|
|
8
|
+
// the script themeScript() writes. Two places run it: every page
|
|
9
|
+
// (BaseLayout.astro's inline script, again after each client-side
|
|
10
|
+
// navigation) and the redirect pages (src/cli/rewrite-redirect-pages.js), so
|
|
11
|
+
// the two can't disagree about a reader's theme.
|
|
12
|
+
//
|
|
13
|
+
// What decides the theme, in order:
|
|
14
|
+
// 1. the reader's own choice from the toggle (localStorage "wd-theme") -
|
|
15
|
+
// skipped when `strict`: there's no toggle, so an old choice saved
|
|
16
|
+
// before the site turned `strict` on mustn't win;
|
|
17
|
+
// 2. `default`, when it's "light" or "dark";
|
|
18
|
+
// 3. the OS setting (prefers-color-scheme), for "system".
|
|
19
|
+
//
|
|
20
|
+
// Plain JavaScript with no imports: the layout imports it, and so does the
|
|
21
|
+
// redirect rewriter, which reads writedocs.json raw (no schema defaults) -
|
|
22
|
+
// resolveAppearance() accepts anything and falls back field by field.
|
|
23
|
+
|
|
24
|
+
export const APPEARANCE_MODES = ['system', 'light', 'dark'];
|
|
25
|
+
|
|
26
|
+
/** `styles.appearance` with its defaults filled in. Accepts a raw, possibly invalid value. */
|
|
27
|
+
export function resolveAppearance(appearance) {
|
|
28
|
+
const value = appearance && typeof appearance === 'object' ? appearance : {};
|
|
29
|
+
return {
|
|
30
|
+
default: APPEARANCE_MODES.includes(value.default) ? value.default : 'system',
|
|
31
|
+
strict: value.strict === true,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Whether the pages show the light/dark toggle. */
|
|
36
|
+
export function showsThemeToggle(appearance) {
|
|
37
|
+
return !resolveAppearance(appearance).strict;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The theme to write on <html data-theme> in the HTML itself, or undefined
|
|
42
|
+
* for "system" (only the reader's browser knows that one). The script sets
|
|
43
|
+
* the theme before the first paint anyway; this is what a reader without
|
|
44
|
+
* JavaScript gets - otherwise every such page is light.
|
|
45
|
+
*/
|
|
46
|
+
export function serverTheme(appearance) {
|
|
47
|
+
const mode = resolveAppearance(appearance).default;
|
|
48
|
+
return mode === 'system' ? undefined : mode;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The JavaScript that sets <html data-theme> - one self-contained statement
|
|
53
|
+
* (it declares nothing global), safe to run more than once. The settings are
|
|
54
|
+
* written into it as constants, so a page carries only the branch it uses.
|
|
55
|
+
*/
|
|
56
|
+
export function themeScript(appearance) {
|
|
57
|
+
const { default: mode, strict } = resolveAppearance(appearance);
|
|
58
|
+
const stored = strict ? '' : "try{t=localStorage.getItem('wd-theme')}catch(e){}";
|
|
59
|
+
const otherwise =
|
|
60
|
+
mode === 'system'
|
|
61
|
+
? "try{t=matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light'}catch(e){t='light'}"
|
|
62
|
+
: `t='${mode}'`;
|
|
63
|
+
return `(function(){var t=null;${stored}if(t!=='light'&&t!=='dark'){${otherwise}}document.documentElement.dataset.theme=t})();`;
|
|
64
|
+
}
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
// `.writedocs/` is never published (EXCLUDED_TOP_LEVEL_DIRS, lib/pages.js).
|
|
27
27
|
import fs from 'node:fs';
|
|
28
28
|
import path from 'node:path';
|
|
29
|
+
import { stripBom } from './bom.js';
|
|
29
30
|
|
|
30
31
|
/** Where the file is, from the project root. */
|
|
31
32
|
export const ASSET_DIMENSIONS_FILE = '.writedocs/asset-dimensions.json';
|
|
@@ -38,7 +39,7 @@ export function parseAssetDimensions(text) {
|
|
|
38
39
|
const sizes = new Map();
|
|
39
40
|
let data;
|
|
40
41
|
try {
|
|
41
|
-
data = JSON.parse(String(text)
|
|
42
|
+
data = JSON.parse(stripBom(String(text)));
|
|
42
43
|
} catch {
|
|
43
44
|
return sizes;
|
|
44
45
|
}
|
package/src/lib/bom.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// The one place a UTF-8 byte order mark is taken off a file's text.
|
|
2
|
+
//
|
|
3
|
+
// Windows editors - Notepad, PowerShell 5.1's `Out-File`/`Set-Content
|
|
4
|
+
// -Encoding utf8`, Visual Studio - save UTF-8 with a byte order mark (the
|
|
5
|
+
// bytes EF BB BF, read as the character U+FEFF). Read as text, it's an
|
|
6
|
+
// invisible first character: JSON.parse rejects it, a frontmatter `^---`
|
|
7
|
+
// doesn't match after it, and a stylesheet inlined in a <style> tag loses
|
|
8
|
+
// its first rule (the selector starts with U+FEFF). Every reader of a
|
|
9
|
+
// project's files takes it off here - writedocs.json and the other configs
|
|
10
|
+
// (config-file.js, config-schema.ts), pages, stylesheets and scripts, the
|
|
11
|
+
// ignore files, llms.txt - so a file with one reads exactly like the same
|
|
12
|
+
// file without one.
|
|
13
|
+
//
|
|
14
|
+
// No imports, nothing from Node: lib/wdignore.js and config-schema.ts use
|
|
15
|
+
// it, and the WriteDocs platform runs both in a Cloudflare Worker.
|
|
16
|
+
|
|
17
|
+
/** `text` without a leading byte order mark. One in the middle stays. */
|
|
18
|
+
export function stripBom(text) {
|
|
19
|
+
return typeof text === 'string' && text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
20
|
+
}
|
package/src/lib/config-file.js
CHANGED
|
@@ -1,25 +1,38 @@
|
|
|
1
|
-
// Reading writedocs.json (and the other JSON
|
|
2
|
-
//
|
|
3
|
-
// with plain Node - see
|
|
1
|
+
// Reading a project's text files: writedocs.json (and the other JSON
|
|
2
|
+
// configs `writedocs convert` reads), pages, stylesheets, llms.txt. Plain
|
|
3
|
+
// JavaScript, not TypeScript, so the CLI can load it with plain Node - see
|
|
4
|
+
// packages/components/src/lib/icons.js's comment.
|
|
4
5
|
//
|
|
5
6
|
// Windows editors - Notepad, PowerShell 5.1's `Out-File`/`Set-Content
|
|
6
7
|
// -Encoding utf8` - save UTF-8 with a byte order mark. JSON.parse rejects
|
|
7
8
|
// it ("Unexpected token U+FEFF"), and the error then blames commas and
|
|
8
|
-
// brackets the file doesn't have. Every reader strips it here instead
|
|
9
|
+
// brackets the file doesn't have. Every reader strips it here instead (the
|
|
10
|
+
// stripping itself is lib/bom.js).
|
|
9
11
|
import fs from 'node:fs';
|
|
10
12
|
import path from 'node:path';
|
|
13
|
+
import { stripBom } from './bom.js';
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
export { stripBom };
|
|
16
|
+
|
|
17
|
+
/** A project file's text, read as UTF-8, byte order mark removed. */
|
|
18
|
+
export function readText(file) {
|
|
19
|
+
return stripBom(fs.readFileSync(file, 'utf-8'));
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
/** A JSON config file's text, byte order mark removed. */
|
|
18
23
|
export function readJsonText(file) {
|
|
19
|
-
return
|
|
24
|
+
return readText(file);
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
/** `<contentDir>/writedocs.json`'s text, byte order mark removed. */
|
|
23
28
|
export function readConfigText(contentDir) {
|
|
24
29
|
return readJsonText(path.join(contentDir, 'writedocs.json'));
|
|
25
30
|
}
|
|
31
|
+
|
|
32
|
+
/** `<contentDir>/<name>`'s text, byte order mark removed - or null when
|
|
33
|
+
* the project has no such file (a hand-written llms.txt, say). */
|
|
34
|
+
export function readProjectText(contentDir, name) {
|
|
35
|
+
const file = path.join(contentDir, ...name.split('/'));
|
|
36
|
+
if (!fs.existsSync(file)) return null;
|
|
37
|
+
return readText(file);
|
|
38
|
+
}
|
package/src/lib/config-schema.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { findNodeAtLocation, parseTree, visit } from "jsonc-parser";
|
|
3
3
|
import { BASE_PATH_FIELD_PATTERN } from "./base-path.js";
|
|
4
|
+
import { stripBom } from "./bom.js";
|
|
4
5
|
const navPageSchema = z.string();
|
|
5
6
|
const navGroupPagesSchema = z.lazy(
|
|
6
7
|
() => z.object({
|
|
@@ -33,8 +34,17 @@ const navLinkSchema = z.object({ label: z.string(), href: z.string() }).strict()
|
|
|
33
34
|
const navItemSchema = z.lazy(
|
|
34
35
|
() => z.union([navPageSchema, navGroupSchema, navLinkSchema])
|
|
35
36
|
);
|
|
37
|
+
const ACCESS_RULE_NAME = /^[a-z0-9-]{1,40}$/;
|
|
38
|
+
const accessSchema = z.string().regex(ACCESS_RULE_NAME, `An access rule's name is 1 to 40 lowercase letters, numbers and hyphens, like "partners".`);
|
|
36
39
|
function withChildren(ownFields) {
|
|
37
|
-
const base = {
|
|
40
|
+
const base = {
|
|
41
|
+
...ownFields,
|
|
42
|
+
hidden: z.boolean().optional(),
|
|
43
|
+
searchPublic: z.boolean().optional(),
|
|
44
|
+
page: z.string().optional(),
|
|
45
|
+
access: accessSchema.optional(),
|
|
46
|
+
lock: z.boolean().optional()
|
|
47
|
+
};
|
|
38
48
|
return z.union([
|
|
39
49
|
z.object({ ...base, pages: z.array(navItemSchema) }).strict(),
|
|
40
50
|
z.object({ ...base, tabs: z.array(tabSchema).min(1) }).strict(),
|
|
@@ -117,11 +127,25 @@ const navigationSchema = z.union([
|
|
|
117
127
|
message: "An item with `href` is a link, so it has no page of its own - remove `page`, or `href`."
|
|
118
128
|
});
|
|
119
129
|
}
|
|
120
|
-
if (own2?.
|
|
130
|
+
if (own2?.access !== void 0 && own2.href !== void 0) {
|
|
131
|
+
ctx.addIssue({
|
|
132
|
+
code: "custom",
|
|
133
|
+
path: [...path, key, i, "access"],
|
|
134
|
+
message: "An item with `href` is a link, so it has no pages to protect - remove `access`, or `href`."
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (own2?.searchPublic === true && own2.hidden !== true && own2.access === void 0) {
|
|
121
138
|
ctx.addIssue({
|
|
122
139
|
code: "custom",
|
|
123
140
|
path: [...path, key, i, "searchPublic"],
|
|
124
|
-
message: '`searchPublic` only applies to a hidden item - add "hidden": true, or remove `searchPublic`.'
|
|
141
|
+
message: '`searchPublic` only applies to a hidden or protected item - add "hidden": true or an `access` rule, or remove `searchPublic`.'
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (own2?.lock === true && own2.access === void 0) {
|
|
145
|
+
ctx.addIssue({
|
|
146
|
+
code: "custom",
|
|
147
|
+
path: [...path, key, i, "lock"],
|
|
148
|
+
message: "`lock` marks a protected item, and this one has no `access` rule - add `access`, or remove `lock`."
|
|
125
149
|
});
|
|
126
150
|
}
|
|
127
151
|
const inner = key === "languages" ? String(item?.language ?? "") : language;
|
|
@@ -131,6 +155,20 @@ const navigationSchema = z.union([
|
|
|
131
155
|
}
|
|
132
156
|
};
|
|
133
157
|
walk(navigation, [], null, []);
|
|
158
|
+
const protectedIn = (node, path) => {
|
|
159
|
+
if (!node || typeof node !== "object") return;
|
|
160
|
+
if (Array.isArray(node)) return node.forEach((child, i) => protectedIn(child, [...path, i]));
|
|
161
|
+
for (const [key, value] of Object.entries(node)) {
|
|
162
|
+
if (key === "access" || key === "lock") {
|
|
163
|
+
ctx.addIssue({
|
|
164
|
+
code: "custom",
|
|
165
|
+
path: [...path, key],
|
|
166
|
+
message: `\`${key}\` doesn't apply in \`global.dropdowns\` - protect a tab, version, language, dropdown or product of the navigation instead.`
|
|
167
|
+
});
|
|
168
|
+
} else if (key !== "pages") protectedIn(value, [...path, key]);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
if (!Array.isArray(navigation)) protectedIn(navigation.global, ["global"]);
|
|
134
172
|
});
|
|
135
173
|
const DEFAULT_PRIMARY = "#6366f1";
|
|
136
174
|
const logoSchema = z.union([
|
|
@@ -270,6 +308,15 @@ const stylesSchema = z.object({
|
|
|
270
308
|
light: z.string().optional(),
|
|
271
309
|
dark: z.string().optional()
|
|
272
310
|
}).strict().optional()
|
|
311
|
+
}).strict().optional(),
|
|
312
|
+
// Which color mode a page opens in (`default`: the reader's OS setting,
|
|
313
|
+
// or always light/dark) and whether readers can switch (`strict` hides
|
|
314
|
+
// the theme toggle). Same shape as Mintlify's top-level `appearance`.
|
|
315
|
+
// Both fields optional here: resolveAppearance() (src/lib/appearance.js)
|
|
316
|
+
// fills in "system"/false, and is what everything reads it through.
|
|
317
|
+
appearance: z.object({
|
|
318
|
+
default: z.enum(["system", "light", "dark"]).optional(),
|
|
319
|
+
strict: z.boolean().optional()
|
|
273
320
|
}).strict().optional()
|
|
274
321
|
}).default({ colors: { primary: DEFAULT_PRIMARY } });
|
|
275
322
|
const topbarLinkSchema = z.object({
|
|
@@ -1082,7 +1129,7 @@ instalarCorte(
|
|
|
1082
1129
|
/* @__PURE__ */ new Set([navGroupPagesSchema._zod.innerType, navGroupOpenApiSchema, navLinkSchema])
|
|
1083
1130
|
);
|
|
1084
1131
|
function localizarCaminhos(rawText, caminhos) {
|
|
1085
|
-
rawText =
|
|
1132
|
+
rawText = stripBom(rawText);
|
|
1086
1133
|
const raiz = { filhos: /* @__PURE__ */ new Map(), alvo: false };
|
|
1087
1134
|
for (const caminho of caminhos) {
|
|
1088
1135
|
if (caminho.length === 0) continue;
|
|
@@ -1145,7 +1192,7 @@ function createJsonLocator(rawText) {
|
|
|
1145
1192
|
return criarLocalizador(rawText);
|
|
1146
1193
|
}
|
|
1147
1194
|
function criarLocalizador(rawText) {
|
|
1148
|
-
rawText =
|
|
1195
|
+
rawText = stripBom(rawText);
|
|
1149
1196
|
let arvore = null;
|
|
1150
1197
|
let inicios;
|
|
1151
1198
|
return (caminho) => {
|
|
@@ -1286,7 +1333,7 @@ function unknownRootKeyIssues(rawText) {
|
|
|
1286
1333
|
return unknownRootKeyWarnings(rawText).issues;
|
|
1287
1334
|
}
|
|
1288
1335
|
function unknownRootKeyWarnings(rawText, { all = false } = {}) {
|
|
1289
|
-
rawText =
|
|
1336
|
+
rawText = stripBom(rawText);
|
|
1290
1337
|
let raiz;
|
|
1291
1338
|
try {
|
|
1292
1339
|
raiz = JSON.parse(rawText);
|
|
@@ -1318,11 +1365,8 @@ function unknownRootKeyWarnings(rawText, { all = false } = {}) {
|
|
|
1318
1365
|
});
|
|
1319
1366
|
return { issues, issuesTotal: desconhecidas.length };
|
|
1320
1367
|
}
|
|
1321
|
-
function semBom(texto) {
|
|
1322
|
-
return texto.charCodeAt(0) === 65279 ? texto.slice(1) : texto;
|
|
1323
|
-
}
|
|
1324
1368
|
function validateDocsConfig(rawText, { all = false } = {}) {
|
|
1325
|
-
rawText =
|
|
1369
|
+
rawText = stripBom(rawText);
|
|
1326
1370
|
let raw;
|
|
1327
1371
|
try {
|
|
1328
1372
|
raw = JSON.parse(rawText);
|
|
@@ -1409,6 +1453,7 @@ function localizarEHumanizar(lista, rawText, raw, criar) {
|
|
|
1409
1453
|
}));
|
|
1410
1454
|
}
|
|
1411
1455
|
export {
|
|
1456
|
+
ACCESS_RULE_NAME,
|
|
1412
1457
|
CONTEXT_MENU_OPTIONS,
|
|
1413
1458
|
MAX_TAB_LEVELS,
|
|
1414
1459
|
MAX_TAB_MENU_LEVELS,
|
package/src/lib/config-schema.ts
CHANGED
|
@@ -36,6 +36,9 @@ import { z } from 'zod';
|
|
|
36
36
|
import { findNodeAtLocation, parseTree, visit } from 'jsonc-parser';
|
|
37
37
|
// The form of `basePath`. Plain JS with no `node:` import, like this file.
|
|
38
38
|
import { BASE_PATH_FIELD_PATTERN } from './base-path.js';
|
|
39
|
+
// A leading UTF-8 byte order mark off the text - the one copy, lib/bom.js.
|
|
40
|
+
// Plain JS with no `node:` import too.
|
|
41
|
+
import { stripBom } from './bom.js';
|
|
39
42
|
|
|
40
43
|
// ---------------------------------------------------------------------
|
|
41
44
|
// Pages & groups - the leaf content any container ultimately bottoms out
|
|
@@ -141,8 +144,21 @@ export type NavChildren =
|
|
|
141
144
|
* And any can have a `page` of its own: where choosing the item leads, in
|
|
142
145
|
* place of its first page - an overview of what's in it. In a sidebar too,
|
|
143
146
|
* it opens there; otherwise it opens inside the item (resolveLandings() in
|
|
144
|
-
* lib/config.ts).
|
|
145
|
-
|
|
147
|
+
* lib/config.ts).
|
|
148
|
+
* And any can be protected: `access` names an access rule the WriteDocs
|
|
149
|
+
* platform keeps (a password or a list of emails). Every page under the
|
|
150
|
+
* item is served only to the readers that rule lets in, and the innermost
|
|
151
|
+
* item's rule wins. `lock` shows a padlock where the item is listed. See
|
|
152
|
+
* lib/protected-sections.js. */
|
|
153
|
+
export type Hideable = { hidden?: boolean; searchPublic?: boolean; page?: string; access?: string; lock?: boolean };
|
|
154
|
+
|
|
155
|
+
/** An access rule's name: lowercase letters, numbers and hyphens, 1 to 40
|
|
156
|
+
* characters. Never a secret - it names the rule, which the platform keeps,
|
|
157
|
+
* and it's part of the paths the build writes (lib/protected-sections.js). */
|
|
158
|
+
export const ACCESS_RULE_NAME = /^[a-z0-9-]{1,40}$/;
|
|
159
|
+
const accessSchema = z
|
|
160
|
+
.string()
|
|
161
|
+
.regex(ACCESS_RULE_NAME, 'An access rule\'s name is 1 to 40 lowercase letters, numbers and hyphens, like "partners".');
|
|
146
162
|
|
|
147
163
|
export type TabItem = { tab: string; icon?: string } & Hideable & NavChildren;
|
|
148
164
|
export type VersionItem = { version: string; label?: string; tag?: string; default?: boolean } & Hideable & NavChildren;
|
|
@@ -158,7 +174,14 @@ export type ProductItem = { product: string; icon?: string; description?: string
|
|
|
158
174
|
// rule this schema exists to enforce (mirroring Mintlify's own "a tab
|
|
159
175
|
// cannot contain both anchors and groups at the same level").
|
|
160
176
|
function withChildren<Base extends z.ZodRawShape>(ownFields: Base) {
|
|
161
|
-
const base = {
|
|
177
|
+
const base = {
|
|
178
|
+
...ownFields,
|
|
179
|
+
hidden: z.boolean().optional(),
|
|
180
|
+
searchPublic: z.boolean().optional(),
|
|
181
|
+
page: z.string().optional(),
|
|
182
|
+
access: accessSchema.optional(),
|
|
183
|
+
lock: z.boolean().optional(),
|
|
184
|
+
};
|
|
162
185
|
return z.union([
|
|
163
186
|
z.object({ ...base, pages: z.array(navItemSchema) }).strict(),
|
|
164
187
|
z.object({ ...base, tabs: z.array(tabSchema).min(1) }).strict(),
|
|
@@ -280,7 +303,7 @@ const navigationSchema = z.union([
|
|
|
280
303
|
continue;
|
|
281
304
|
}
|
|
282
305
|
items.forEach((item, i) => {
|
|
283
|
-
const own = item as { hidden?: unknown; searchPublic?: unknown; page?: unknown; href?: unknown };
|
|
306
|
+
const own = item as { hidden?: unknown; searchPublic?: unknown; page?: unknown; href?: unknown; access?: unknown; lock?: unknown };
|
|
284
307
|
if (own?.page !== undefined && own.href !== undefined) {
|
|
285
308
|
ctx.addIssue({
|
|
286
309
|
code: 'custom',
|
|
@@ -288,11 +311,27 @@ const navigationSchema = z.union([
|
|
|
288
311
|
message: 'An item with `href` is a link, so it has no page of its own - remove `page`, or `href`.',
|
|
289
312
|
});
|
|
290
313
|
}
|
|
291
|
-
if (own?.
|
|
314
|
+
if (own?.access !== undefined && own.href !== undefined) {
|
|
315
|
+
ctx.addIssue({
|
|
316
|
+
code: 'custom',
|
|
317
|
+
path: [...path, key, i, 'access'],
|
|
318
|
+
message: 'An item with `href` is a link, so it has no pages to protect - remove `access`, or `href`.',
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
// A protected item is a search space of its own too
|
|
322
|
+
// (lib/protected-sections.js), so `searchPublic` applies to it.
|
|
323
|
+
if (own?.searchPublic === true && own.hidden !== true && own.access === undefined) {
|
|
292
324
|
ctx.addIssue({
|
|
293
325
|
code: 'custom',
|
|
294
326
|
path: [...path, key, i, 'searchPublic'],
|
|
295
|
-
message: '`searchPublic` only applies to a hidden item - add "hidden": true, or remove `searchPublic`.',
|
|
327
|
+
message: '`searchPublic` only applies to a hidden or protected item - add "hidden": true or an `access` rule, or remove `searchPublic`.',
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
if (own?.lock === true && own.access === undefined) {
|
|
331
|
+
ctx.addIssue({
|
|
332
|
+
code: 'custom',
|
|
333
|
+
path: [...path, key, i, 'lock'],
|
|
334
|
+
message: '`lock` marks a protected item, and this one has no `access` rule - add `access`, or remove `lock`.',
|
|
296
335
|
});
|
|
297
336
|
}
|
|
298
337
|
const inner = key === 'languages' ? String((item as { language?: unknown })?.language ?? '') : language;
|
|
@@ -302,6 +341,23 @@ const navigationSchema = z.union([
|
|
|
302
341
|
}
|
|
303
342
|
};
|
|
304
343
|
walk(navigation, [], null, []);
|
|
344
|
+
// `global.dropdowns` are on every page, outside the navigation's levels -
|
|
345
|
+
// there's no part of the site for a rule there to protect. Refused rather
|
|
346
|
+
// than ignored: a page an author meant to protect never goes out public.
|
|
347
|
+
const protectedIn = (node: unknown, path: (string | number)[]) => {
|
|
348
|
+
if (!node || typeof node !== 'object') return;
|
|
349
|
+
if (Array.isArray(node)) return node.forEach((child, i) => protectedIn(child, [...path, i]));
|
|
350
|
+
for (const [key, value] of Object.entries(node)) {
|
|
351
|
+
if (key === 'access' || key === 'lock') {
|
|
352
|
+
ctx.addIssue({
|
|
353
|
+
code: 'custom',
|
|
354
|
+
path: [...path, key],
|
|
355
|
+
message: `\`${key}\` doesn't apply in \`global.dropdowns\` - protect a tab, version, language, dropdown or product of the navigation instead.`,
|
|
356
|
+
});
|
|
357
|
+
} else if (key !== 'pages') protectedIn(value, [...path, key]);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
if (!Array.isArray(navigation)) protectedIn((navigation as { global?: unknown }).global, ['global']);
|
|
305
361
|
}) as z.ZodType<NavigationConfig>;
|
|
306
362
|
|
|
307
363
|
const DEFAULT_PRIMARY = '#6366f1';
|
|
@@ -551,6 +607,18 @@ const stylesSchema = z
|
|
|
551
607
|
})
|
|
552
608
|
.strict()
|
|
553
609
|
.optional(),
|
|
610
|
+
// Which color mode a page opens in (`default`: the reader's OS setting,
|
|
611
|
+
// or always light/dark) and whether readers can switch (`strict` hides
|
|
612
|
+
// the theme toggle). Same shape as Mintlify's top-level `appearance`.
|
|
613
|
+
// Both fields optional here: resolveAppearance() (src/lib/appearance.js)
|
|
614
|
+
// fills in "system"/false, and is what everything reads it through.
|
|
615
|
+
appearance: z
|
|
616
|
+
.object({
|
|
617
|
+
default: z.enum(['system', 'light', 'dark']).optional(),
|
|
618
|
+
strict: z.boolean().optional(),
|
|
619
|
+
})
|
|
620
|
+
.strict()
|
|
621
|
+
.optional(),
|
|
554
622
|
})
|
|
555
623
|
.default({ colors: { primary: DEFAULT_PRIMARY } });
|
|
556
624
|
|
|
@@ -2066,7 +2134,7 @@ instalarCorte(
|
|
|
2066
2134
|
* findNodeAtLocation), inclusive com chave repetida num objeto, onde vale a
|
|
2067
2135
|
* primeira; o que nao leva a nenhum caminho pedido e pulado sem callbacks. */
|
|
2068
2136
|
function localizarCaminhos(rawText: string, caminhos: (string | number)[][]): (caminho: (string | number)[]) => { line: number; column: number } | null {
|
|
2069
|
-
rawText =
|
|
2137
|
+
rawText = stripBom(rawText);
|
|
2070
2138
|
type No = { filhos: Map<string | number, No>; alvo: boolean; offset?: number };
|
|
2071
2139
|
const raiz: No = { filhos: new Map(), alvo: false };
|
|
2072
2140
|
for (const caminho of caminhos) {
|
|
@@ -2150,7 +2218,7 @@ export function createJsonLocator(rawText: string): (path: (string | number)[])
|
|
|
2150
2218
|
* '\n' (um `\r\n` e um '\n' com o '\r' no fim da linha anterior), e a coluna e
|
|
2151
2219
|
* em unidades UTF-16, como o offset do jsonc-parser - um emoji conta 2. */
|
|
2152
2220
|
function criarLocalizador(rawText: string): (caminho: (string | number)[]) => { line: number; column: number } | null {
|
|
2153
|
-
rawText =
|
|
2221
|
+
rawText = stripBom(rawText);
|
|
2154
2222
|
let arvore: ReturnType<typeof parseTree> | undefined | null = null;
|
|
2155
2223
|
let inicios: number[] | undefined;
|
|
2156
2224
|
return (caminho) => {
|
|
@@ -2356,7 +2424,7 @@ export function unknownRootKeyWarnings(
|
|
|
2356
2424
|
rawText: string,
|
|
2357
2425
|
{ all = false }: ValidationOptions = {}
|
|
2358
2426
|
): { issues: ValidationIssue[]; issuesTotal: number } {
|
|
2359
|
-
rawText =
|
|
2427
|
+
rawText = stripBom(rawText);
|
|
2360
2428
|
let raiz: unknown;
|
|
2361
2429
|
try {
|
|
2362
2430
|
raiz = JSON.parse(rawText);
|
|
@@ -2390,16 +2458,8 @@ export function unknownRootKeyWarnings(
|
|
|
2390
2458
|
return { issues, issuesTotal: desconhecidas.length };
|
|
2391
2459
|
}
|
|
2392
2460
|
|
|
2393
|
-
/** Texto sem o BOM do UTF-8 no inicio. Editores do Windows (Bloco de Notas, o
|
|
2394
|
-
* `Out-File` do PowerShell 5.1) gravam um, e o JSON.parse o rejeita com uma
|
|
2395
|
-
* mensagem que culpa virgulas e colchetes. Copia local, e nao import de
|
|
2396
|
-
* lib/config-file.js: este modulo so importa zod e jsonc-parser (ver o topo). */
|
|
2397
|
-
function semBom(texto: string): string {
|
|
2398
|
-
return texto.charCodeAt(0) === 0xfeff ? texto.slice(1) : texto;
|
|
2399
|
-
}
|
|
2400
|
-
|
|
2401
2461
|
export function validateDocsConfig(rawText: string, { all = false }: ValidationOptions = {}): ValidationResult {
|
|
2402
|
-
rawText =
|
|
2462
|
+
rawText = stripBom(rawText);
|
|
2403
2463
|
let raw: unknown;
|
|
2404
2464
|
try {
|
|
2405
2465
|
raw = JSON.parse(rawText);
|