@writedocs/generator 0.16.0 → 0.18.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.
Files changed (40) hide show
  1. package/astro.config.mjs +43 -3
  2. package/package.json +4 -1
  3. package/src/cli/build.js +39 -3
  4. package/src/cli/dev.js +16 -0
  5. package/src/cli/generate-api-pages.js +94 -3
  6. package/src/cli/run-pagefind.js +67 -22
  7. package/src/cli/write-redirects-file.js +7 -1
  8. package/src/components/ApiReferencePanel.astro +16 -3
  9. package/src/components/NoScalarReference.astro +6 -0
  10. package/src/components/NoScalarTryIt.astro +5 -0
  11. package/src/components/ScalarReference.astro +80 -0
  12. package/src/components/ScalarTryIt.astro +76 -0
  13. package/src/layout/BaseLayout.astro +7 -0
  14. package/src/layout/components/LockMark.astro +28 -0
  15. package/src/layout/components/MobileMenu.astro +4 -0
  16. package/src/layout/components/Sidebar.astro +3 -2
  17. package/src/layout/components/TopBar.astro +9 -0
  18. package/src/lib/config-schema.js +58 -6
  19. package/src/lib/config-schema.ts +75 -8
  20. package/src/lib/config.ts +40 -13
  21. package/src/lib/content-check.js +18 -3
  22. package/src/lib/json-schema-descriptions.js +5 -1
  23. package/src/lib/llms-index.ts +5 -0
  24. package/src/lib/mcp-index.ts +5 -1
  25. package/src/lib/moved-api-pages.js +16 -1
  26. package/src/lib/openapi-render.ts +5 -0
  27. package/src/lib/protected-sections.js +238 -0
  28. package/src/lib/scalar-anchors.js +56 -0
  29. package/src/lib/scalar-document.js +63 -0
  30. package/src/lib/scalar-fetch.js +89 -0
  31. package/src/lib/scalar-reference-alias.js +32 -0
  32. package/src/lib/scalar-reference.js +105 -0
  33. package/src/lib/scalar-theme.js +175 -0
  34. package/src/lib/scalar-try-it-alias.js +31 -0
  35. package/src/pages/[...slug].astro +133 -23
  36. package/src/pages/llms-full.txt.ts +4 -0
  37. package/src/pages/og/[...slug].png.ts +11 -2
  38. package/src/scripts/scalar-reference.ts +151 -0
  39. package/src/scripts/scalar-try-it.ts +145 -0
  40. package/writedocs.schema.json +476 -71
@@ -0,0 +1,80 @@
1
+ ---
2
+ // The page of an OpenAPI group with `openapi.renderer: "scalar"`: Scalar's
3
+ // API reference, inside the site's layout - [...slug].astro renders it in
4
+ // place of the page's content, through the `writedocs/scalar-reference`
5
+ // alias (lib/scalar-reference-alias.js).
6
+ //
7
+ // What the page carries: the group's spec, bundled (generate-api-pages.js,
8
+ // lib/scalar-reference.js), in a <script type="application/json"> - inside
9
+ // the page and never a file of its own, so a group in a protected section
10
+ // stays behind the section's rule - and the small script below, which
11
+ // import()s Scalar (src/scripts/scalar-reference.ts) and mounts it.
12
+ import fs from 'node:fs';
13
+ import { jsonForScript } from '../lib/scalar-document.js';
14
+ import { scalarDocumentFile } from '../lib/scalar-reference.js';
15
+ import { SCALAR_REFERENCE_CLASS } from '../lib/scalar-theme.js';
16
+
17
+ interface Props {
18
+ contentDir: string;
19
+ /** The reference's address, without slashes ("api"). */
20
+ slug: string;
21
+ /** writedocs.json's `api.proxy`. */
22
+ proxy: boolean;
23
+ /** Whether readers may download the spec: not in a protected section. */
24
+ download: boolean;
25
+ }
26
+ const { contentDir, slug, proxy, download } = Astro.props as Props;
27
+ const json = jsonForScript(JSON.parse(fs.readFileSync(scalarDocumentFile(contentDir, slug), 'utf-8')));
28
+ ---
29
+
30
+ <div class={SCALAR_REFERENCE_CLASS} data-wd-scalar-reference data-proxy={String(proxy)} data-download={String(download)}>
31
+ <script type="application/json" is:inline data-wd-scalar-reference-document set:html={json} />
32
+ <div class="wd-scalar-reference-mount"></div>
33
+ <p class="wd-scalar-reference-loading" data-pagefind-ignore>Loading the API reference…</p>
34
+ <noscript>
35
+ <p class="wd-scalar-reference-loading">The API reference needs JavaScript. Every operation also has a page of its own:</p>
36
+ <div class="wd-scalar-reference-list" data-pagefind-ignore><slot /></div>
37
+ </noscript>
38
+ </div>
39
+
40
+ <script>
41
+ // Mounts the reference when the page loads - and again after a
42
+ // client-side navigation back to it.
43
+ async function initScalarReference() {
44
+ const root = document.querySelector<HTMLElement>('[data-wd-scalar-reference]');
45
+ const source = root?.querySelector<HTMLScriptElement>('script[data-wd-scalar-reference-document]');
46
+ const mount = root?.querySelector<HTMLElement>('.wd-scalar-reference-mount');
47
+ if (!root || !source || !mount || root.dataset.wdInit) return;
48
+ root.dataset.wdInit = 'true';
49
+ try {
50
+ const { mountReference } = await import('../scripts/scalar-reference');
51
+ mountReference({
52
+ el: mount,
53
+ document: JSON.parse(source.textContent ?? '{}'),
54
+ proxy: root.dataset.proxy === 'true',
55
+ download: root.dataset.download === 'true',
56
+ });
57
+ root.querySelector('.wd-scalar-reference-loading')?.remove();
58
+ } catch (err) {
59
+ console.error('[writedocs] Could not open the API reference.', err);
60
+ }
61
+ }
62
+ initScalarReference();
63
+ document.addEventListener('astro:page-load', initScalarReference);
64
+ </script>
65
+
66
+ <style is:global>
67
+ /* Only in a build with a Scalar reference (this component isn't imported
68
+ otherwise - lib/scalar-reference-alias.js). */
69
+ .wd-scalar-reference {
70
+ width: 100%;
71
+ min-width: 0;
72
+ }
73
+ .wd-scalar-reference-loading {
74
+ padding: 1.5rem;
75
+ color: var(--wd-text-muted);
76
+ }
77
+ .wd-scalar-reference-list {
78
+ padding: 0 1.5rem 2rem;
79
+ }
80
+ </style>
@@ -0,0 +1,76 @@
1
+ ---
2
+ // The "Try it" of an API page with writedocs.json `api.playground: "scalar"`
3
+ // - rendered by ApiReferencePanel.astro in place of writedocs' own modal.
4
+ //
5
+ // What the page carries: the operation as an OpenAPI document
6
+ // (lib/scalar-document.js) in a <script type="application/json">, and the
7
+ // small script below. Scalar itself (src/scripts/scalar-try-it.ts, with Vue
8
+ // and its CSS) is import()ed on the first click of the panel's Try button,
9
+ // so a page nobody clicks Try it on downloads none of it. The document is
10
+ // in the page, not a file of its own: it's served with the page, and on a
11
+ // page of a protected section (`access`) stays behind the same rule.
12
+ import { scalarDocument, jsonForScript } from '../lib/scalar-document.js';
13
+ import type { OpenApiOperation } from '../lib/openapi-render';
14
+
15
+ interface Props {
16
+ op: OpenApiOperation;
17
+ proxy: boolean;
18
+ title: string;
19
+ }
20
+ const { op, proxy, title } = Astro.props as Props;
21
+ const json = jsonForScript(scalarDocument(op, { title }));
22
+ ---
23
+
24
+ <script type="application/json" is:inline data-wd-scalar-document data-method={op.method} data-path={op.path} data-proxy={String(proxy)} set:html={json} />
25
+
26
+ <script>
27
+ // The Try button (data-role="open-scalar", in ApiReferencePanel.astro)
28
+ // loads Scalar on its first click and opens it on this page's operation.
29
+ function initScalarTryIt(root: ParentNode) {
30
+ root.querySelectorAll<HTMLButtonElement>('[data-role="open-scalar"]').forEach((button) => {
31
+ if (button.dataset.wdInit) return;
32
+ button.dataset.wdInit = 'true';
33
+ button.addEventListener('click', async () => {
34
+ const source = document.querySelector<HTMLScriptElement>('script[data-wd-scalar-document]');
35
+ if (!source || button.getAttribute('aria-busy') === 'true') return;
36
+ button.setAttribute('aria-busy', 'true');
37
+ // The first click downloads the client (~1 MB): on a slow connection
38
+ // that's seconds, so the button says so - only if it takes a moment,
39
+ // so an already-loaded client doesn't flash it.
40
+ const label = button.innerHTML;
41
+ const loading = setTimeout(() => {
42
+ button.textContent = 'Loading…';
43
+ }, 150);
44
+ try {
45
+ const { openTryIt } = await import('../scripts/scalar-try-it');
46
+ const method = source.dataset.method ?? 'GET';
47
+ const path = source.dataset.path ?? '/';
48
+ await openTryIt({
49
+ document: JSON.parse(source.textContent ?? '{}'),
50
+ method,
51
+ path,
52
+ proxy: source.dataset.proxy === 'true',
53
+ key: `${location.pathname} ${method} ${path}`,
54
+ });
55
+ } catch (err) {
56
+ console.error('[writedocs] Could not open Try it.', err);
57
+ } finally {
58
+ clearTimeout(loading);
59
+ button.innerHTML = label;
60
+ button.removeAttribute('aria-busy');
61
+ }
62
+ });
63
+ });
64
+ }
65
+ initScalarTryIt(document);
66
+ document.addEventListener('astro:page-load', () => initScalarTryIt(document));
67
+ </script>
68
+
69
+ <style is:global>
70
+ /* Only in a build with Scalar's Try it (this component isn't imported
71
+ otherwise - lib/scalar-try-it-alias.js). */
72
+ .wd-api-try-inline[aria-busy='true'] {
73
+ cursor: progress;
74
+ opacity: 0.75;
75
+ }
76
+ </style>
@@ -147,6 +147,11 @@ interface Props {
147
147
  breadcrumbs?: { name: string; href: string }[];
148
148
  // An OpenAPI page: its structured data says APIReference.
149
149
  isApi?: boolean;
150
+ // A script run first thing, in <head> - the operation page of a Scalar
151
+ // group sends its reader on to the reference with it
152
+ // (lib/scalar-reference.js). Again after a client-side navigation to the
153
+ // page (data-astro-rerun).
154
+ headScript?: string;
150
155
  }
151
156
  const {
152
157
  config,
@@ -161,6 +166,7 @@ const {
161
166
  alternates = [],
162
167
  breadcrumbs = [],
163
168
  isApi = false,
169
+ headScript,
164
170
  } = Astro.props as Props;
165
171
  const showSidebarCol = mode === "default" || mode === "wide";
166
172
  const showTocCol = mode === "default";
@@ -515,6 +521,7 @@ const fontExtraCss = [fontFaceCss, fontFallbackCss, fontWeightCss].filter(Boolea
515
521
  <head>
516
522
  <meta charset="UTF-8" />
517
523
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
524
+ {headScript && <script is:inline data-astro-rerun set:html={headScript} />}
518
525
  {/* Marks the pages writedocs renders - the build checks each has the site's styles (cli/check-built-styles.js). */}
519
526
  <meta name="generator" content="writedocs" />
520
527
  <title>{head.title}</title>
@@ -0,0 +1,28 @@
1
+ ---
2
+ // The padlock beside a protected navigation item's name - one with
3
+ // `"lock": true` next to its `access` rule (lib/protected-sections.js) -
4
+ // wherever the item is listed: the tabs, a tab's menu, the switchers in the
5
+ // top bar and the sidebar, and the mobile menu. Renders nothing otherwise.
6
+ //
7
+ // Lucide's "lock", the icon set the generator already has, drawn inline with
8
+ // its size in a style attribute - a rule in the site's stylesheet would be on
9
+ // every site, and a site without `access` builds byte for byte as it did
10
+ // before. role="img" and aria-label put "Requires sign-in" in the link's
11
+ // accessible name; <title> shows it on hover.
12
+ import { iconSvg } from '../../lib/config';
13
+
14
+ interface Props {
15
+ locked?: boolean;
16
+ // Inside a line of text rather than a flex row with its own gap: a space
17
+ // before it.
18
+ inline?: boolean;
19
+ }
20
+ const LABEL = 'Requires sign-in';
21
+ const svg = Astro.props.locked ? iconSvg('lock') : null;
22
+ const margin = Astro.props.inline ? 'margin-inline-start:.35em;' : '';
23
+ const html = svg?.replace(
24
+ /^<svg ([^>]*)>/,
25
+ `<svg $1 class="wd-lock" role="img" aria-label="${LABEL}" width="12" height="12" style="${margin}width:.8em;height:.8em;flex-shrink:0;opacity:.7;vertical-align:-.05em"><title>${LABEL}</title>`
26
+ );
27
+ ---
28
+ {html && <Fragment set:html={html} />}
@@ -29,6 +29,7 @@
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';
34
35
  import { showsThemeToggle } from '../../lib/appearance.js';
@@ -121,6 +122,7 @@ const showMenu = hasMobileMenu({ sidebar: showSidebarCol, selectors, globalDropd
121
122
  >
122
123
  <AppIcon icon={opt.icon} class="wd-tab-icon" />
123
124
  <span class="wd-mobile-accordion-option-label">{opt.label}</span>
125
+ <LockMark locked={opt.locked} />
124
126
  {opt.tag && <span class="wd-selector-tag">{opt.tag}</span>}
125
127
  </a>
126
128
  ))}
@@ -133,6 +135,7 @@ const showMenu = hasMobileMenu({ sidebar: showSidebarCol, selectors, globalDropd
133
135
  <summary class="wd-mobile-accordion-trigger">
134
136
  <AppIcon icon={current.icon} class="wd-tab-icon" />
135
137
  <span class="wd-mobile-accordion-label">{current.label}</span>
138
+ <LockMark locked={(current as { locked?: boolean }).locked} />
136
139
  {current.tag && <span class="wd-selector-tag">{current.tag}</span>}
137
140
  <svg class="wd-mobile-accordion-caret" width="12" height="12" viewBox="0 0 10 10" aria-hidden="true">
138
141
  <path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
@@ -149,6 +152,7 @@ const showMenu = hasMobileMenu({ sidebar: showSidebarCol, selectors, globalDropd
149
152
  >
150
153
  <AppIcon icon={opt.icon} class="wd-tab-icon" />
151
154
  <span class="wd-mobile-accordion-option-label">{opt.label}</span>
155
+ <LockMark locked={opt.locked} />
152
156
  {opt.tag && <span class="wd-selector-tag">{opt.tag}</span>}
153
157
  {opt.active && (
154
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}</span>
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}</span>
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,6 +13,7 @@
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';
17
18
  import { showsThemeToggle } from '../../lib/appearance.js';
18
19
  import { selectorPlacements, hasMobileMenu, currentOption } from '../../lib/selector-placement.js';
@@ -114,6 +115,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
114
115
  <button type="button" class="wd-dropdown-trigger wd-switcher-trigger" aria-expanded="false">
115
116
  <AppIcon icon={current.icon} class="wd-tab-icon" />
116
117
  {current.label}
118
+ <LockMark locked={(current as { locked?: boolean }).locked} />
117
119
  {current.tag && <span class="wd-selector-tag">{current.tag}</span>}
118
120
  <svg class="wd-dropdown-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
119
121
  <path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
@@ -130,6 +132,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
130
132
  >
131
133
  <AppIcon icon={opt.icon} class="wd-tab-icon" />
132
134
  {opt.label}
135
+ <LockMark locked={opt.locked} />
133
136
  {opt.tag && <span class="wd-selector-tag">{opt.tag}</span>}
134
137
  </a>
135
138
  ))}
@@ -249,6 +252,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
249
252
  >
250
253
  <AppIcon icon={opt.icon} class="wd-tab-icon" />
251
254
  {opt.label}
255
+ <LockMark locked={opt.locked} />
252
256
  <svg class="wd-dropdown-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
253
257
  <path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
254
258
  </svg>
@@ -267,6 +271,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
267
271
  <a href={siteHref(d.pageHref)} class={`wd-submenu-entry ${d.active ? 'active' : ''}`} aria-current={d.active ? 'true' : undefined}>
268
272
  <AppIcon icon={d.icon} class="wd-tab-icon" />
269
273
  <span class="wd-submenu-label">{d.label}</span>
274
+ <LockMark locked={d.locked} />
270
275
  </a>
271
276
  ) : null}
272
277
  <button
@@ -277,6 +282,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
277
282
  >
278
283
  {!d.pageHref && <AppIcon icon={d.icon} class="wd-tab-icon" />}
279
284
  {!d.pageHref && <span class="wd-submenu-label">{d.label}</span>}
285
+ {!d.pageHref && <LockMark locked={d.locked} />}
280
286
  <svg class="wd-submenu-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
281
287
  <path d="M3.5 2L6.5 5L3.5 8" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
282
288
  </svg>
@@ -298,6 +304,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
298
304
  >
299
305
  <AppIcon icon={sub.icon} class="wd-tab-icon" />
300
306
  {sub.label}
307
+ <LockMark locked={sub.locked} />
301
308
  </a>
302
309
  ))}
303
310
  </div>
@@ -312,6 +319,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
312
319
  >
313
320
  <AppIcon icon={d.icon} class="wd-tab-icon" />
314
321
  {d.label}
322
+ <LockMark locked={d.locked} />
315
323
  </a>
316
324
  )
317
325
  )}
@@ -328,6 +336,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
328
336
  >
329
337
  <AppIcon icon={opt.icon} class="wd-tab-icon" />
330
338
  {opt.label}
339
+ <LockMark locked={opt.locked} />
331
340
  </a>
332
341
  )
333
342
  )}
@@ -26,7 +26,16 @@ const navGroupOpenApiSchema = z.object({
26
26
  // so two openapi groups in the same writedocs.json must use different
27
27
  // `path` values - generate-api-pages.js throws a clear error if
28
28
  // they collide.
29
- path: z.string()
29
+ path: z.string(),
30
+ // How readers see the group: "writedocs" (the default) - a page per
31
+ // operation, grouped by tag - or "scalar": one page at `path` with
32
+ // Scalar's API reference (lib/scalar-reference.js). The per-operation
33
+ // pages are still built for a "scalar" group - search, llms.txt, MCP
34
+ // and the .md copies read them - but out of the sidebar, noindex, and
35
+ // sent on to their operation in the reference. Optional rather than
36
+ // defaulted, so a writedocs.json without it validates to the same data
37
+ // as before the field existed.
38
+ renderer: z.enum(["writedocs", "scalar"]).optional()
30
39
  }).strict()
31
40
  }).strict();
32
41
  const navGroupSchema = z.union([navGroupPagesSchema, navGroupOpenApiSchema]);
@@ -34,8 +43,17 @@ const navLinkSchema = z.object({ label: z.string(), href: z.string() }).strict()
34
43
  const navItemSchema = z.lazy(
35
44
  () => z.union([navPageSchema, navGroupSchema, navLinkSchema])
36
45
  );
46
+ const ACCESS_RULE_NAME = /^[a-z0-9-]{1,40}$/;
47
+ const accessSchema = z.string().regex(ACCESS_RULE_NAME, `An access rule's name is 1 to 40 lowercase letters, numbers and hyphens, like "partners".`);
37
48
  function withChildren(ownFields) {
38
- const base = { ...ownFields, hidden: z.boolean().optional(), searchPublic: z.boolean().optional(), page: z.string().optional() };
49
+ const base = {
50
+ ...ownFields,
51
+ hidden: z.boolean().optional(),
52
+ searchPublic: z.boolean().optional(),
53
+ page: z.string().optional(),
54
+ access: accessSchema.optional(),
55
+ lock: z.boolean().optional()
56
+ };
39
57
  return z.union([
40
58
  z.object({ ...base, pages: z.array(navItemSchema) }).strict(),
41
59
  z.object({ ...base, tabs: z.array(tabSchema).min(1) }).strict(),
@@ -118,11 +136,25 @@ const navigationSchema = z.union([
118
136
  message: "An item with `href` is a link, so it has no page of its own - remove `page`, or `href`."
119
137
  });
120
138
  }
121
- if (own2?.searchPublic === true && own2.hidden !== true) {
139
+ if (own2?.access !== void 0 && own2.href !== void 0) {
140
+ ctx.addIssue({
141
+ code: "custom",
142
+ path: [...path, key, i, "access"],
143
+ message: "An item with `href` is a link, so it has no pages to protect - remove `access`, or `href`."
144
+ });
145
+ }
146
+ if (own2?.searchPublic === true && own2.hidden !== true && own2.access === void 0) {
122
147
  ctx.addIssue({
123
148
  code: "custom",
124
149
  path: [...path, key, i, "searchPublic"],
125
- message: '`searchPublic` only applies to a hidden item - add "hidden": true, or remove `searchPublic`.'
150
+ message: '`searchPublic` only applies to a hidden or protected item - add "hidden": true or an `access` rule, or remove `searchPublic`.'
151
+ });
152
+ }
153
+ if (own2?.lock === true && own2.access === void 0) {
154
+ ctx.addIssue({
155
+ code: "custom",
156
+ path: [...path, key, i, "lock"],
157
+ message: "`lock` marks a protected item, and this one has no `access` rule - add `access`, or remove `lock`."
126
158
  });
127
159
  }
128
160
  const inner = key === "languages" ? String(item?.language ?? "") : language;
@@ -132,6 +164,20 @@ const navigationSchema = z.union([
132
164
  }
133
165
  };
134
166
  walk(navigation, [], null, []);
167
+ const protectedIn = (node, path) => {
168
+ if (!node || typeof node !== "object") return;
169
+ if (Array.isArray(node)) return node.forEach((child, i) => protectedIn(child, [...path, i]));
170
+ for (const [key, value] of Object.entries(node)) {
171
+ if (key === "access" || key === "lock") {
172
+ ctx.addIssue({
173
+ code: "custom",
174
+ path: [...path, key],
175
+ message: `\`${key}\` doesn't apply in \`global.dropdowns\` - protect a tab, version, language, dropdown or product of the navigation instead.`
176
+ });
177
+ } else if (key !== "pages") protectedIn(value, [...path, key]);
178
+ }
179
+ };
180
+ if (!Array.isArray(navigation)) protectedIn(navigation.global, ["global"]);
135
181
  });
136
182
  const DEFAULT_PRIMARY = "#6366f1";
137
183
  const logoSchema = z.union([
@@ -543,8 +589,13 @@ const apiSchema = z.object({
543
589
  // call fails for most real APIs - see the send handler and
544
590
  // PROXY_BASE_URL in ApiReferencePanel.astro. Defaults to enabled; a
545
591
  // site can set this to `false` to never involve a third party.
546
- proxy: z.boolean().default(true)
547
- }).strict().default({ proxy: true });
592
+ proxy: z.boolean().default(true),
593
+ // Which client the "Try it" button opens: writedocs' own modal
594
+ // (ApiReferencePanel.astro, the default) or Scalar's API client
595
+ // (ScalarTryIt.astro + src/scripts/scalar-try-it.ts), loaded only when a
596
+ // reader clicks. The API pages themselves are the same either way.
597
+ playground: z.enum(["writedocs", "scalar"]).default("writedocs")
598
+ }).strict().default({ proxy: true, playground: "writedocs" });
548
599
  const CONTEXT_MENU_OPTIONS = ["copy", "view", "chatgpt", "claude", "perplexity", "mcp", "cursor", "vscode"];
549
600
  const ASSISTANT_OPTIONS = ["chatgpt", "claude", "perplexity"];
550
601
  const MCP_MENU_OPTIONS = ["mcp", "cursor", "vscode"];
@@ -1416,6 +1467,7 @@ function localizarEHumanizar(lista, rawText, raw, criar) {
1416
1467
  }));
1417
1468
  }
1418
1469
  export {
1470
+ ACCESS_RULE_NAME,
1419
1471
  CONTEXT_MENU_OPTIONS,
1420
1472
  MAX_TAB_LEVELS,
1421
1473
  MAX_TAB_MENU_LEVELS,
@@ -88,13 +88,22 @@ const navGroupOpenApiSchema = z.object({
88
88
  // `path` values - generate-api-pages.js throws a clear error if
89
89
  // they collide.
90
90
  path: z.string(),
91
+ // How readers see the group: "writedocs" (the default) - a page per
92
+ // operation, grouped by tag - or "scalar": one page at `path` with
93
+ // Scalar's API reference (lib/scalar-reference.js). The per-operation
94
+ // pages are still built for a "scalar" group - search, llms.txt, MCP
95
+ // and the .md copies read them - but out of the sidebar, noindex, and
96
+ // sent on to their operation in the reference. Optional rather than
97
+ // defaulted, so a writedocs.json without it validates to the same data
98
+ // as before the field existed.
99
+ renderer: z.enum(['writedocs', 'scalar']).optional(),
91
100
  })
92
101
  .strict(),
93
102
  }).strict();
94
103
 
95
104
  export type GroupNavItem =
96
105
  | { group: string; page?: string; pages: NavItem[] }
97
- | { group: string; openapi: { src: string; path: string } };
106
+ | { group: string; openapi: { src: string; path: string; renderer?: 'writedocs' | 'scalar' } };
98
107
 
99
108
  const navGroupSchema: z.ZodType<GroupNavItem> = z.union([navGroupPagesSchema, navGroupOpenApiSchema]);
100
109
 
@@ -144,8 +153,21 @@ export type NavChildren =
144
153
  * And any can have a `page` of its own: where choosing the item leads, in
145
154
  * place of its first page - an overview of what's in it. In a sidebar too,
146
155
  * it opens there; otherwise it opens inside the item (resolveLandings() in
147
- * lib/config.ts). */
148
- export type Hideable = { hidden?: boolean; searchPublic?: boolean; page?: string };
156
+ * lib/config.ts).
157
+ * And any can be protected: `access` names an access rule the WriteDocs
158
+ * platform keeps (a password or a list of emails). Every page under the
159
+ * item is served only to the readers that rule lets in, and the innermost
160
+ * item's rule wins. `lock` shows a padlock where the item is listed. See
161
+ * lib/protected-sections.js. */
162
+ export type Hideable = { hidden?: boolean; searchPublic?: boolean; page?: string; access?: string; lock?: boolean };
163
+
164
+ /** An access rule's name: lowercase letters, numbers and hyphens, 1 to 40
165
+ * characters. Never a secret - it names the rule, which the platform keeps,
166
+ * and it's part of the paths the build writes (lib/protected-sections.js). */
167
+ export const ACCESS_RULE_NAME = /^[a-z0-9-]{1,40}$/;
168
+ const accessSchema = z
169
+ .string()
170
+ .regex(ACCESS_RULE_NAME, 'An access rule\'s name is 1 to 40 lowercase letters, numbers and hyphens, like "partners".');
149
171
 
150
172
  export type TabItem = { tab: string; icon?: string } & Hideable & NavChildren;
151
173
  export type VersionItem = { version: string; label?: string; tag?: string; default?: boolean } & Hideable & NavChildren;
@@ -161,7 +183,14 @@ export type ProductItem = { product: string; icon?: string; description?: string
161
183
  // rule this schema exists to enforce (mirroring Mintlify's own "a tab
162
184
  // cannot contain both anchors and groups at the same level").
163
185
  function withChildren<Base extends z.ZodRawShape>(ownFields: Base) {
164
- const base = { ...ownFields, hidden: z.boolean().optional(), searchPublic: z.boolean().optional(), page: z.string().optional() };
186
+ const base = {
187
+ ...ownFields,
188
+ hidden: z.boolean().optional(),
189
+ searchPublic: z.boolean().optional(),
190
+ page: z.string().optional(),
191
+ access: accessSchema.optional(),
192
+ lock: z.boolean().optional(),
193
+ };
165
194
  return z.union([
166
195
  z.object({ ...base, pages: z.array(navItemSchema) }).strict(),
167
196
  z.object({ ...base, tabs: z.array(tabSchema).min(1) }).strict(),
@@ -283,7 +312,7 @@ const navigationSchema = z.union([
283
312
  continue;
284
313
  }
285
314
  items.forEach((item, i) => {
286
- const own = item as { hidden?: unknown; searchPublic?: unknown; page?: unknown; href?: unknown };
315
+ const own = item as { hidden?: unknown; searchPublic?: unknown; page?: unknown; href?: unknown; access?: unknown; lock?: unknown };
287
316
  if (own?.page !== undefined && own.href !== undefined) {
288
317
  ctx.addIssue({
289
318
  code: 'custom',
@@ -291,11 +320,27 @@ const navigationSchema = z.union([
291
320
  message: 'An item with `href` is a link, so it has no page of its own - remove `page`, or `href`.',
292
321
  });
293
322
  }
294
- if (own?.searchPublic === true && own.hidden !== true) {
323
+ if (own?.access !== undefined && own.href !== undefined) {
324
+ ctx.addIssue({
325
+ code: 'custom',
326
+ path: [...path, key, i, 'access'],
327
+ message: 'An item with `href` is a link, so it has no pages to protect - remove `access`, or `href`.',
328
+ });
329
+ }
330
+ // A protected item is a search space of its own too
331
+ // (lib/protected-sections.js), so `searchPublic` applies to it.
332
+ if (own?.searchPublic === true && own.hidden !== true && own.access === undefined) {
295
333
  ctx.addIssue({
296
334
  code: 'custom',
297
335
  path: [...path, key, i, 'searchPublic'],
298
- message: '`searchPublic` only applies to a hidden item - add "hidden": true, or remove `searchPublic`.',
336
+ message: '`searchPublic` only applies to a hidden or protected item - add "hidden": true or an `access` rule, or remove `searchPublic`.',
337
+ });
338
+ }
339
+ if (own?.lock === true && own.access === undefined) {
340
+ ctx.addIssue({
341
+ code: 'custom',
342
+ path: [...path, key, i, 'lock'],
343
+ message: '`lock` marks a protected item, and this one has no `access` rule - add `access`, or remove `lock`.',
299
344
  });
300
345
  }
301
346
  const inner = key === 'languages' ? String((item as { language?: unknown })?.language ?? '') : language;
@@ -305,6 +350,23 @@ const navigationSchema = z.union([
305
350
  }
306
351
  };
307
352
  walk(navigation, [], null, []);
353
+ // `global.dropdowns` are on every page, outside the navigation's levels -
354
+ // there's no part of the site for a rule there to protect. Refused rather
355
+ // than ignored: a page an author meant to protect never goes out public.
356
+ const protectedIn = (node: unknown, path: (string | number)[]) => {
357
+ if (!node || typeof node !== 'object') return;
358
+ if (Array.isArray(node)) return node.forEach((child, i) => protectedIn(child, [...path, i]));
359
+ for (const [key, value] of Object.entries(node)) {
360
+ if (key === 'access' || key === 'lock') {
361
+ ctx.addIssue({
362
+ code: 'custom',
363
+ path: [...path, key],
364
+ message: `\`${key}\` doesn't apply in \`global.dropdowns\` - protect a tab, version, language, dropdown or product of the navigation instead.`,
365
+ });
366
+ } else if (key !== 'pages') protectedIn(value, [...path, key]);
367
+ }
368
+ };
369
+ if (!Array.isArray(navigation)) protectedIn((navigation as { global?: unknown }).global, ['global']);
308
370
  }) as z.ZodType<NavigationConfig>;
309
371
 
310
372
  const DEFAULT_PRIMARY = '#6366f1';
@@ -934,9 +996,14 @@ const apiSchema = z
934
996
  // PROXY_BASE_URL in ApiReferencePanel.astro. Defaults to enabled; a
935
997
  // site can set this to `false` to never involve a third party.
936
998
  proxy: z.boolean().default(true),
999
+ // Which client the "Try it" button opens: writedocs' own modal
1000
+ // (ApiReferencePanel.astro, the default) or Scalar's API client
1001
+ // (ScalarTryIt.astro + src/scripts/scalar-try-it.ts), loaded only when a
1002
+ // reader clicks. The API pages themselves are the same either way.
1003
+ playground: z.enum(['writedocs', 'scalar']).default('writedocs'),
937
1004
  })
938
1005
  .strict()
939
- .default({ proxy: true });
1006
+ .default({ proxy: true, playground: 'writedocs' });
940
1007
 
941
1008
  // The "Copy page" menu shown next to a page's title - copy the page's
942
1009
  // Markdown, view it, or open it in an AI assistant - and the .md copy of