@writedocs/generator 0.13.5 → 0.15.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 (113) hide show
  1. package/astro.config.mjs +31 -69
  2. package/bin/writedocs.js +4 -1
  3. package/package.json +4 -2
  4. package/packages/components/package.json +53 -0
  5. package/{src → packages/components/src}/components/Accordion.astro +2 -2
  6. package/{src → packages/components/src}/components/AppIcon.astro +3 -3
  7. package/{src → packages/components/src}/components/Callout.astro +3 -3
  8. package/{src → packages/components/src}/components/CodeBlock.astro +8 -27
  9. package/{src → packages/components/src}/components/CodeGroup.astro +3 -3
  10. package/{src → packages/components/src}/components/Image.astro +7 -9
  11. package/{src → packages/components/src}/components/compound.ts +1 -1
  12. package/packages/components/src/host.js +24 -0
  13. package/packages/components/src/index.ts +59 -0
  14. package/packages/components/src/integration.js +151 -0
  15. package/packages/components/src/lib/base-path.js +39 -0
  16. package/{src → packages/components/src}/lib/code-line-numbers.js +1 -1
  17. package/packages/components/src/lib/code-transformers.js +45 -0
  18. package/{src → packages/components/src}/lib/icons.js +13 -7
  19. package/{src → packages/components/src}/lib/shiki-code-block.js +9 -9
  20. package/{src → packages/components/src}/lib/site-base.ts +9 -6
  21. package/packages/components/src/scripts/code-block.ts +62 -0
  22. package/packages/components/src/styles/components.css +373 -0
  23. package/packages/components/src/styles/theme.css +63 -0
  24. package/src/cli/build.js +23 -3
  25. package/src/cli/dev.js +2 -1
  26. package/src/cli/generate-api-pages.js +9 -7
  27. package/src/cli/page-list-watch.js +4 -2
  28. package/src/cli/run-astro.js +2 -2
  29. package/src/components/ApiPlayground.astro +2 -2
  30. package/src/components/ApiSchemaField.astro +1 -1
  31. package/src/components/CopyPageMenu.astro +2 -2
  32. package/src/content.config.ts +16 -0
  33. package/src/icons/README.md +1 -1
  34. package/src/layout/BaseLayout.astro +7 -2
  35. package/src/layout/components/AnalyticsScripts.astro +2 -2
  36. package/src/layout/components/Breadcrumbs.astro +1 -1
  37. package/src/layout/components/ConsentBanner.astro +1 -1
  38. package/src/layout/components/MobileMenu.astro +2 -2
  39. package/src/layout/components/NavTree.astro +16 -2
  40. package/src/layout/components/Sidebar.astro +2 -2
  41. package/src/layout/components/SiteFooter.astro +2 -2
  42. package/src/layout/components/TopBar.astro +2 -2
  43. package/src/layout/styles/base.css +4 -37
  44. package/src/lib/a11y-check.js +1 -1
  45. package/src/lib/base-path.js +4 -25
  46. package/src/lib/color.js +1 -1
  47. package/src/lib/components-host.ts +21 -0
  48. package/src/lib/config-file.js +1 -1
  49. package/src/lib/config-schema.js +12 -1
  50. package/src/lib/config-schema.ts +14 -0
  51. package/src/lib/config.ts +22 -6
  52. package/src/lib/content-check.js +6 -3
  53. package/src/lib/drafts.js +186 -0
  54. package/src/lib/link-check.js +13 -4
  55. package/src/lib/mdx-inject-builtins.js +2 -2
  56. package/src/lib/mdx-inline-react.js +1 -1
  57. package/src/lib/mdx-title-anchor-ids.js +2 -2
  58. package/src/lib/mdx-unknown-components.js +1 -1
  59. package/src/lib/mintlify-convert.js +2 -2
  60. package/src/lib/openapi-reload-integration.js +1 -1
  61. package/src/lib/pages.js +41 -7
  62. package/src/lib/project-files-integration.js +1 -1
  63. package/src/lib/rehype-base-path.js +1 -1
  64. package/src/lib/seo-tags.js +3 -1
  65. package/src/lib/writedocs-legacy-convert.js +1 -1
  66. package/src/pages/404.astro +1 -1
  67. package/src/pages/[...slug].astro +65 -417
  68. package/src/components/index.ts +0 -62
  69. /package/{src → packages/components/src}/components/AccordionGroup.astro +0 -0
  70. /package/{src → packages/components/src}/components/Badge.astro +0 -0
  71. /package/{src → packages/components/src}/components/Card.astro +0 -0
  72. /package/{src → packages/components/src}/components/CardGroup.astro +0 -0
  73. /package/{src → packages/components/src}/components/Check.astro +0 -0
  74. /package/{src → packages/components/src}/components/Color.astro +0 -0
  75. /package/{src → packages/components/src}/components/ColorItem.astro +0 -0
  76. /package/{src → packages/components/src}/components/ColorRow.astro +0 -0
  77. /package/{src → packages/components/src}/components/Column.astro +0 -0
  78. /package/{src → packages/components/src}/components/Columns.astro +0 -0
  79. /package/{src → packages/components/src}/components/Danger.astro +0 -0
  80. /package/{src → packages/components/src}/components/Expandable.astro +0 -0
  81. /package/{src → packages/components/src}/components/Frame.astro +0 -0
  82. /package/{src → packages/components/src}/components/GitHubRepo.astro +0 -0
  83. /package/{src → packages/components/src}/components/Hint.astro +0 -0
  84. /package/{src → packages/components/src}/components/Icon.astro +0 -0
  85. /package/{src → packages/components/src}/components/Info.astro +0 -0
  86. /package/{src → packages/components/src}/components/Note.astro +0 -0
  87. /package/{src → packages/components/src}/components/Panel.astro +0 -0
  88. /package/{src → packages/components/src}/components/ParamField.astro +0 -0
  89. /package/{src → packages/components/src}/components/Parameter.astro +0 -0
  90. /package/{src → packages/components/src}/components/Prompt.astro +0 -0
  91. /package/{src → packages/components/src}/components/RequestExample.astro +0 -0
  92. /package/{src → packages/components/src}/components/ResponseExample.astro +0 -0
  93. /package/{src → packages/components/src}/components/ResponseField.astro +0 -0
  94. /package/{src → packages/components/src}/components/Searchbar.astro +0 -0
  95. /package/{src → packages/components/src}/components/Step.astro +0 -0
  96. /package/{src → packages/components/src}/components/Steps.astro +0 -0
  97. /package/{src → packages/components/src}/components/Tab.astro +0 -0
  98. /package/{src → packages/components/src}/components/Tabs.astro +0 -0
  99. /package/{src → packages/components/src}/components/Tile.astro +0 -0
  100. /package/{src → packages/components/src}/components/Tip.astro +0 -0
  101. /package/{src → packages/components/src}/components/Tooltip.astro +0 -0
  102. /package/{src → packages/components/src}/components/Tree.astro +0 -0
  103. /package/{src → packages/components/src}/components/TreeFile.astro +0 -0
  104. /package/{src → packages/components/src}/components/TreeFolder.astro +0 -0
  105. /package/{src → packages/components/src}/components/Update.astro +0 -0
  106. /package/{src → packages/components/src}/components/Video.astro +0 -0
  107. /package/{src → packages/components/src}/components/View.astro +0 -0
  108. /package/{src → packages/components/src}/components/Visibility.astro +0 -0
  109. /package/{src → packages/components/src}/components/Warning.astro +0 -0
  110. /package/{src → packages/components/src}/components/class-names.ts +0 -0
  111. /package/{src → packages/components/src}/lib/cli-report.js +0 -0
  112. /package/{src → packages/components/src}/lib/inline-markdown.js +0 -0
  113. /package/{src → packages/components/src}/lib/plain-text.js +0 -0
@@ -55,6 +55,11 @@ import "../styles/global.css";
55
55
  // theme with no extra CSS needed here.
56
56
  import "katex/dist/katex.min.css";
57
57
  import "./styles/base.css";
58
+ // What the components package's components share: code blocks (every ```
59
+ // fence goes through the package's transformers - astro.config.mjs), Shiki's
60
+ // dark theme, icons given as an image. The --wd-* variables it uses are this
61
+ // layout's own (the define:vars <style> below).
62
+ import "../../packages/components/src/styles/components.css";
58
63
  import "./styles/banner.css";
59
64
  // Astro's client-side router - swaps <body> content between same-origin
60
65
  // navigations via the native View Transition API instead of a hard
@@ -85,8 +90,8 @@ import { jsonLd, serializeJsonLd } from "../lib/json-ld.js";
85
90
  import { consentOptions } from "../lib/consent.js";
86
91
  import { oncePerBuild } from "../lib/build-memo.js";
87
92
  // writedocs.json's `basePath`: every site address written below goes
88
- // through siteHref() - see lib/site-base.ts.
89
- import { BASE, siteHref } from "../lib/site-base";
93
+ // through siteHref() - see the components package's lib/site-base.ts.
94
+ import { BASE, siteHref } from "../../packages/components/src/lib/site-base";
90
95
 
91
96
  interface Props {
92
97
  config: DocsConfig;
@@ -22,7 +22,7 @@
22
22
  // it doesn't wait for consent.
23
23
  import type { DocsConfig } from '../../lib/config';
24
24
  import { analyticsTags, scriptTags, consentLoaderScript } from '../../lib/consent.js';
25
- import { siteHref } from '../../lib/site-base';
25
+ import { siteHref } from '../../../packages/components/src/lib/site-base';
26
26
 
27
27
  interface Props {
28
28
  config: DocsConfig;
@@ -35,7 +35,7 @@ interface Props {
35
35
  const { config, consent = null, gatedScripts = [] } = Astro.props as Props;
36
36
 
37
37
  // A script's `src` can be a file in the site ("/js/stats.js"): it gets the
38
- // basePath (lib/site-base.ts).
38
+ // basePath (the components package's lib/site-base.ts).
39
39
  const withSrcBase = <T extends { src?: string }>(tag: T): T => (tag.src ? { ...tag, src: siteHref(tag.src) } : tag);
40
40
  const tags = analyticsTags(config.integrations).map(withSrcBase);
41
41
  const loader = consent ? consentLoaderScript([...tags, ...scriptTags(gatedScripts).map(withSrcBase)]) : null;
@@ -20,7 +20,7 @@
20
20
  // Iconify id for the exact same Font Awesome 6 glyph as react-icons'
21
21
  // `FaHouse`, without pulling React into an otherwise-static nav element.
22
22
  import { Icon } from 'astro-icon/components';
23
- import { siteHref } from '../../lib/site-base';
23
+ import { siteHref } from '../../../packages/components/src/lib/site-base';
24
24
 
25
25
  export interface BreadcrumbItem {
26
26
  label: string;
@@ -1,5 +1,5 @@
1
1
  ---
2
- import { siteHref } from '../../lib/site-base';
2
+ import { siteHref } from '../../../packages/components/src/lib/site-base';
3
3
  // writedocs.json's `integrations.consent` - the banner that asks before the
4
4
  // analytics integrations load. It's in the page hidden; src/scripts/
5
5
  // consent.ts shows it when the reader hasn't answered yet (window.wdConsent,
@@ -29,13 +29,13 @@
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 AppIcon from '../../components/AppIcon.astro';
32
+ import AppIcon from '../../../packages/components/src/components/AppIcon.astro';
33
33
  import { logoWidth } from '../../lib/image-size.js';
34
34
  import { hasMobileMenu, currentOption } from '../../lib/selector-placement.js';
35
35
  import '../styles/dropdown.css';
36
36
  import '../styles/topbar.css';
37
37
  import '../styles/mobile-menu.css';
38
- import { siteHref } from '../../lib/site-base';
38
+ import { siteHref } from '../../../packages/components/src/lib/site-base';
39
39
 
40
40
  interface Props {
41
41
  config: DocsConfig;
@@ -1,8 +1,8 @@
1
1
  ---
2
2
  import { navTreeContainsSlug, isExternalHref, type NavTreeNode } from "../../lib/config";
3
- import AppIcon from "../../components/AppIcon.astro";
3
+ import AppIcon from "../../../packages/components/src/components/AppIcon.astro";
4
4
  import { methodClass } from "../../lib/openapi-render";
5
- import { siteHref } from '../../lib/site-base';
5
+ import { siteHref } from '../../../packages/components/src/lib/site-base';
6
6
 
7
7
  interface Props {
8
8
  nodes: NavTreeNode[];
@@ -38,6 +38,20 @@ const { nodes, hrefForSlug, currentSlug, depth = 0 } = Astro.props as Props;
38
38
  )}
39
39
  {node.icon && <AppIcon icon={node.icon} class="wd-nav-page-icon" />}
40
40
  <span class="wd-nav-title">{node.title}</span>
41
+ {
42
+ // A draft page (`draft: true` - lib/drafts.js), in `writedocs
43
+ // dev` and `build --drafts`. Its colors inline, not in the
44
+ // <style> below: that stylesheet is on every site, and a
45
+ // site with no drafts builds byte for byte as before.
46
+ node.draft && (
47
+ <span
48
+ class="wd-nav-tag"
49
+ style="color: var(--wd-text); background: color-mix(in srgb, var(--wd-text-muted) 16%, transparent)"
50
+ >
51
+ Draft
52
+ </span>
53
+ )
54
+ }
41
55
  {node.deprecated && <span class="wd-nav-tag wd-nav-tag-deprecated">Deprecated</span>}
42
56
  {node.tag && <span class="wd-nav-tag">{node.tag}</span>}
43
57
  </a>
@@ -2,7 +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 AppIcon from "../../components/AppIcon.astro";
5
+ import AppIcon from "../../../packages/components/src/components/AppIcon.astro";
6
6
  // Two colorways of the same "Powered by writedocs" mark, not a
7
7
  // theme-matched pair in the wd-logo-light/wd-logo-dark sense (that
8
8
  // convention names each file by which theme it's *shown in*) - these
@@ -17,7 +17,7 @@ import AppIcon from "../../components/AppIcon.astro";
17
17
  // src="/..."> here would 404 on every real site build.
18
18
  import watermarkForLightTheme from "../../assets/wd_watermark_dark.png";
19
19
  import watermarkForDarkTheme from "../../assets/wd_watermark.png";
20
- import { siteHref } from '../../lib/site-base';
20
+ import { siteHref } from '../../../packages/components/src/lib/site-base';
21
21
 
22
22
  // Deploy-time-only opt-out, not a writedocs.json field: a site's own writedocs.json
23
23
  // is part of its checked-in content (something the author controls), while
@@ -10,10 +10,10 @@
10
10
  // several unrelated concerns in one file - see that component's own
11
11
  // comment for the fuller rationale.
12
12
  import { isExternalHref, type DocsConfig } from '../../lib/config';
13
- import AppIcon from '../../components/AppIcon.astro';
13
+ import AppIcon from '../../../packages/components/src/components/AppIcon.astro';
14
14
  import { logoWidth } from '../../lib/image-size.js';
15
15
  import '../styles/footer.css';
16
- import { siteHref } from '../../lib/site-base';
16
+ import { siteHref } from '../../../packages/components/src/lib/site-base';
17
17
 
18
18
  interface Props {
19
19
  config: DocsConfig;
@@ -12,12 +12,12 @@
12
12
  // several unrelated concerns in one file - see that component's own
13
13
  // comment for the fuller rationale.
14
14
  import { isExternalHref, type DocsConfig, type Selector, type GlobalDropdownView } from '../../lib/config';
15
- import AppIcon from '../../components/AppIcon.astro';
15
+ import AppIcon from '../../../packages/components/src/components/AppIcon.astro';
16
16
  import { logoWidth } from '../../lib/image-size.js';
17
17
  import { selectorPlacements, hasMobileMenu, currentOption } from '../../lib/selector-placement.js';
18
18
  import '../styles/dropdown.css';
19
19
  import '../styles/topbar.css';
20
- import { siteHref } from '../../lib/site-base';
20
+ import { siteHref } from '../../../packages/components/src/lib/site-base';
21
21
 
22
22
  interface Props {
23
23
  config: DocsConfig;
@@ -218,38 +218,11 @@ pre {
218
218
  display: block;
219
219
  }
220
220
 
221
- /* Astro's Shiki output (both the built-in MDX code-fence pipeline,
222
- configured with dual themes in astro.config.mjs, and the <Code />
223
- component used for the API playground's request/response snippets)
224
- bakes the "light" theme as each element's base color/background and
225
- stashes the dark equivalents in --shiki-dark/--shiki-dark-bg custom
226
- properties. Swapping to those on [data-theme='dark'] is the officially
227
- documented way to make Shiki-highlighted code follow a manual
228
- (non-media-query) theme toggle - see
229
- https://docs.astro.build/en/guides/syntax-highlighting/#setting-light-and-dark-mode-themes.
230
- Site-wide/article-content concern, unrelated to any one layout
231
- component, which is why it lives here rather than in any of the
232
- feature-specific stylesheets.
233
- The background goes on the <pre> only: Shiki gives the spans inside no
234
- background of their own, and painting the theme's background on every
235
- span (.line included) covered the highlighted, diff, error and focus
236
- line colors and the highlighted words in dark mode. */
237
- [data-theme="dark"] .astro-code {
238
- background-color: var(--shiki-dark-bg) !important;
239
- }
240
- [data-theme="dark"] .astro-code,
241
- [data-theme="dark"] .astro-code span {
242
- color: var(--shiki-dark) !important;
243
- font-style: var(--shiki-dark-font-style) !important;
244
- font-weight: var(--shiki-dark-font-weight) !important;
245
- text-decoration: var(--shiki-dark-text-decoration) !important;
246
- }
221
+ /* Shiki's dark theme on code blocks, the code blocks themselves, and icons
222
+ given as an image are the components package's
223
+ (packages/components/src/styles/components.css, imported by
224
+ BaseLayout.astro right after this file). */
247
225
 
248
- /* An icon given as an image URL or path (resolveIcon()'s 'image' kind,
249
- rendered by AppIcon.astro) - 1em square inside its caller's own icon
250
- span, so it sizes like a glyph icon would. Lives here rather than in
251
- AppIcon.astro so it's part of the shared stylesheet, not an inline
252
- <style> added to every page. */
253
226
  /* An image the build gave its file's width and height
254
227
  (lib/rehype-image-loading.js): those attributes reserve its place while
255
228
  it loads, and this keeps its height following its width when it's shown
@@ -280,12 +253,6 @@ pre {
280
253
  :where(img[data-wd-sized]) {
281
254
  height: auto;
282
255
  }
283
- img.wd-icon-img {
284
- display: block;
285
- width: 1em;
286
- height: 1em;
287
- object-fit: contain;
288
- }
289
256
 
290
257
  /* Scrollbars of the columns beside the page - the sidebar, the table of
291
258
  contents, the mobile menu and its option lists: a thin pill in the
@@ -1,7 +1,7 @@
1
1
  // `writedocs a11y`: accessibility problems that can be found in the source,
2
2
  // without building - the ones an author introduces and can fix in a page or
3
3
  // in writedocs.json. Plain JavaScript, loaded by plain Node from an
4
- // installed package (see lib/icons.js's comment on why not TypeScript).
4
+ // installed package (see packages/components/src/lib/icons.js's comment on why not TypeScript).
5
5
  //
6
6
  // - contrast (WCAG 2 AA, 4.5:1 for text) of the colors writedocs.json sets:
7
7
  // links (styles.colors.primary) on the light and dark backgrounds, body
@@ -36,31 +36,10 @@ export function normalizeBasePath(value) {
36
36
  return value;
37
37
  }
38
38
 
39
- /** Whether `url` is a site address: a path from the site's root ("/a/b"),
40
- * not a protocol-relative "//host/a". */
41
- export function isSiteAddress(url) {
42
- return typeof url === 'string' && url.startsWith('/') && !url.startsWith('//');
43
- }
44
-
45
- /** `url` with the base in front, if it's a site address - "/a/" -> "/docs/a/",
46
- * "/" -> "/docs/". Anything else, and everything when there's no base,
47
- * comes back as it is. */
48
- export function withBase(base, url) {
49
- if (!base || !isSiteAddress(url)) return url;
50
- return base + url;
51
- }
52
-
53
- /** A `srcset` with the base in front of each site address in it. */
54
- export function srcsetWithBase(base, srcset) {
55
- if (!base || typeof srcset !== 'string') return srcset;
56
- return srcset
57
- .split(',')
58
- .map((candidate) => {
59
- const [url, ...descriptor] = candidate.trim().split(/\s+/);
60
- return [withBase(base, url), ...descriptor].join(' ');
61
- })
62
- .join(', ');
63
- }
39
+ // isSiteAddress(), withBase() and srcsetWithBase() - which addresses take the
40
+ // base, and putting it in front of them - live in the components package,
41
+ // whose components write addresses too.
42
+ export { isSiteAddress, withBase, srcsetWithBase } from '../../packages/components/src/lib/base-path.js';
64
43
 
65
44
  /** The address inside the site for a request path - "/docs/a/" -> "/a/",
66
45
  * "/docs" -> "/" - or null when the path isn't under the base. With no base,
package/src/lib/color.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // goes on a configured color, and by `writedocs a11y` (lib/a11y-check.js),
4
4
  // which checks that choice. One implementation, so the check always
5
5
  // measures what the site actually renders. Plain JavaScript, loaded by
6
- // plain Node from an installed package (see lib/icons.js's comment).
6
+ // plain Node from an installed package (see packages/components/src/lib/icons.js's comment).
7
7
 
8
8
  /** [r, g, b] for `#rgb`/`#rrggbb` (the `#` optional), or null. */
9
9
  export function parseHex(value) {
@@ -0,0 +1,21 @@
1
+ // The generator's answers to what the components package asks of its host
2
+ // (packages/components/src/host.js has the default and what each function
3
+ // means). astro.config.mjs passes this file to the package's integration,
4
+ // which puts it in place of the default. Both read the site being built:
5
+ // its writedocs.json and its files.
6
+ import { loadDocsConfig, resolveCodeblockTheme } from './config';
7
+ import { imageFileFor, imageSize as fileImageSize } from './image-size.js';
8
+
9
+ const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
10
+
11
+ /** writedocs.json's styles.codeblocks themes - read on every call, so an
12
+ * edit during `writedocs dev` reaches the next render. */
13
+ export function codeblockTheme(): { light: string; dark: string } {
14
+ return resolveCodeblockTheme(loadDocsConfig(contentDir));
15
+ }
16
+
17
+ /** The size of the project's file at `src`, or null when it isn't one. */
18
+ export function imageSize(src: string): { width: number; height: number } | null {
19
+ const file = imageFileFor(src, contentDir);
20
+ return (file && fileImageSize(file, contentDir)) || null;
21
+ }
@@ -1,6 +1,6 @@
1
1
  // Reading writedocs.json (and the other JSON configs `writedocs convert`
2
2
  // reads) as text. Plain JavaScript, not TypeScript, so the CLI can load it
3
- // with plain Node - see lib/icons.js's comment.
3
+ // with plain Node - see packages/components/src/lib/icons.js's comment.
4
4
  //
5
5
  // Windows editors - Notepad, PowerShell 5.1's `Out-File`/`Set-Content
6
6
  // -Encoding utf8` - save UTF-8 with a byte order mark. JSON.parse rejects
@@ -485,7 +485,13 @@ const pageFrontmatterSchema = z.object({
485
485
  hidden: z.boolean().optional(),
486
486
  url: z.string().optional(),
487
487
  hideFooterPagination: z.boolean().optional(),
488
- hideApiMarker: z.boolean().optional()
488
+ hideApiMarker: z.boolean().optional(),
489
+ // Docusaurus' key: a draft isn't part of the site `writedocs build`
490
+ // makes - no route, no navigation entry, not in search, the sitemap,
491
+ // llms.txt or the MCP index (lib/drafts.js). `writedocs dev` and
492
+ // `writedocs build --drafts` show it, marked, and always noindex (the
493
+ // transform below) - with `hidden` too, the draft wins.
494
+ draft: z.boolean().optional()
489
495
  }).transform(
490
496
  ({ noindex, robots, canonical, keywords, "og:image": ogImage, "og:type": ogType, "twitter:card": twitterCard, ...data }) => {
491
497
  const seo = { ...data.seo };
@@ -509,6 +515,11 @@ const pageFrontmatterSchema = z.object({
509
515
  seo.noindex = /\bnoindex\b|\bnone\b/i.test(pageRobots);
510
516
  changed = true;
511
517
  }
518
+ if (data.draft === true) {
519
+ seo.noindex = true;
520
+ seo.robots = "noindex, nofollow";
521
+ changed = true;
522
+ }
512
523
  return changed ? { ...data, seo } : data;
513
524
  }
514
525
  );
@@ -856,6 +856,12 @@ export const pageFrontmatterSchema = z.object({
856
856
  url: z.string().optional(),
857
857
  hideFooterPagination: z.boolean().optional(),
858
858
  hideApiMarker: z.boolean().optional(),
859
+ // Docusaurus' key: a draft isn't part of the site `writedocs build`
860
+ // makes - no route, no navigation entry, not in search, the sitemap,
861
+ // llms.txt or the MCP index (lib/drafts.js). `writedocs dev` and
862
+ // `writedocs build --drafts` show it, marked, and always noindex (the
863
+ // transform below) - with `hidden` too, the draft wins.
864
+ draft: z.boolean().optional(),
859
865
  }).transform(
860
866
  ({ noindex, robots, canonical, keywords, 'og:image': ogImage, 'og:type': ogType, 'twitter:card': twitterCard, ...data }) => {
861
867
  // Top-level Mintlify keys fill in `seo` only where the page's own `seo`
@@ -885,6 +891,14 @@ export const pageFrontmatterSchema = z.object({
885
891
  seo.noindex = /\bnoindex\b|\bnone\b/i.test(pageRobots);
886
892
  changed = true;
887
893
  }
894
+ // A draft is never indexed, whatever the page says: only `writedocs
895
+ // dev` and `build --drafts` render one. `robots` too: the page's own
896
+ // `robots` would decide over `noindex` (mergeSeo()).
897
+ if (data.draft === true) {
898
+ seo.noindex = true;
899
+ seo.robots = 'noindex, nofollow';
900
+ changed = true;
901
+ }
888
902
  return changed ? { ...data, seo } : data;
889
903
  },
890
904
  );
package/src/lib/config.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { EXCLUDED_TOP_LEVEL_DIRS, navPageId } from './pages.js';
3
+ import { EXCLUDED_TOP_LEVEL_DIRS, navPageId, draftsIncluded, findDraftPages, fileIdForPath } from './pages.js';
4
+ import { withoutDrafts } from './drafts.js';
4
5
  import { isHidden } from './hidden-sections.js';
5
6
  import { itemPage, childLevel, equivalentItem, resolveLandings as resolveLandingsJs } from './item-pages.js';
6
7
  import matter from 'gray-matter';
@@ -288,9 +289,10 @@ export type IconResolution =
288
289
  | { kind: 'image'; src: string } // an image URL or site path, rendered as <img>
289
290
  | { kind: 'text'; value: string }; // literal text/emoji, rendered as-is
290
291
 
291
- // The implementation lives in lib/icons.js - plain JavaScript, because
292
- // `writedocs validate` loads it with plain Node (see that file's comment).
293
- export { resolveIcon, iconExists, iconSvg } from './icons.js';
292
+ // The implementation lives in the components package's lib/icons.js -
293
+ // plain JavaScript, because `writedocs validate` loads it with plain Node
294
+ // (see that file's comment).
295
+ export { resolveIcon, iconExists, iconSvg } from '../../packages/components/src/lib/icons.js';
294
296
 
295
297
  // ---------------------------------------------------------------------
296
298
  // OpenAPI navigation expansion - turns a group's `openapi: { src, path }`
@@ -457,6 +459,14 @@ function readDocsConfig(contentDir: string): DocsConfig {
457
459
  // always run, rather than gated behind a global manifest check, since
458
460
  // there's no longer a single global spec to check for.
459
461
  result.data.navigation = withPageIds(expandOpenApiInNavigation(result.data.navigation, contentDir));
462
+ // `writedocs build` (without --drafts): no entry for a draft page, and no
463
+ // item left with no pages - everything that reads the navigation sees it
464
+ // this way (lib/drafts.js). The build prints what was left out
465
+ // (draftWarnings(), src/cli/build.js).
466
+ if (!draftsIncluded()) {
467
+ const draftIds = new Set(findDraftPages(contentDir).map((draft) => fileIdForPath(draft.file)));
468
+ result.data.navigation = withoutDrafts(result.data.navigation, draftIds).navigation;
469
+ }
460
470
  return result.data;
461
471
  }
462
472
 
@@ -1203,6 +1213,9 @@ export type NavTreeNode =
1203
1213
  icon?: string;
1204
1214
  tag?: string;
1205
1215
  deprecated?: boolean;
1216
+ // A draft page (`draft: true`): only in `writedocs dev` and `build
1217
+ // --drafts` - the build takes it out of the navigation (lib/drafts.js).
1218
+ draft?: boolean;
1206
1219
  }
1207
1220
  | { kind: 'group'; label: string; pageSlug: string | null; children: NavTreeNode[] }
1208
1221
  | { kind: 'link'; label: string; href: string };
@@ -1213,14 +1226,15 @@ export type NavTreeNode =
1213
1226
  * sidebar (e.g. "GET") or null for an ordinary page - see
1214
1227
  * NavTree.astro for how that badge renders. */
1215
1228
  /** Per-page frontmatter that changes how a page shows up in navigation -
1216
- * Mintlify's `hidden`, `url`, `icon`, `tag` and `deprecated` (see
1217
- * content.config.ts's docsSchema). */
1229
+ * Mintlify's `hidden`, `url`, `icon`, `tag` and `deprecated`, and `draft`
1230
+ * (see content.config.ts's docsSchema). */
1218
1231
  export interface NavPageMeta {
1219
1232
  hidden?: boolean;
1220
1233
  url?: string;
1221
1234
  icon?: string;
1222
1235
  tag?: string;
1223
1236
  deprecated?: boolean;
1237
+ draft?: boolean;
1224
1238
  }
1225
1239
 
1226
1240
  export function buildNavTree(
@@ -1245,6 +1259,8 @@ export function buildNavTree(
1245
1259
  icon: meta?.icon,
1246
1260
  tag: meta?.tag,
1247
1261
  deprecated: meta?.deprecated,
1262
+ // Only on a draft, so every other page's node is as it was.
1263
+ ...(meta?.draft ? { draft: true } : {}),
1248
1264
  },
1249
1265
  ];
1250
1266
  }
@@ -1,7 +1,7 @@
1
1
  // `writedocs validate`'s content pass: everything in a site's pages that
2
2
  // would break the build or silently degrade it, found in one run instead of
3
3
  // one build failure at a time. Plain JavaScript, loaded by plain Node from
4
- // an installed package (see lib/icons.js's comment on why not TypeScript).
4
+ // an installed package (see packages/components/src/lib/icons.js's comment on why not TypeScript).
5
5
  //
6
6
  // Errors - the build would fail:
7
7
  // - a page's frontmatter doesn't match the page schema (the same
@@ -31,7 +31,7 @@ import path from 'node:path';
31
31
  import matter from 'gray-matter';
32
32
  import { visit } from 'unist-util-visit';
33
33
  import { findAllPages, fileIdForPath, titleFromPath, navPageId } from './pages.js';
34
- import { iconExists } from './icons.js';
34
+ import { iconExists } from '../../packages/components/src/lib/icons.js';
35
35
  import { findUnknownComponents } from './mdx-unknown-components.js';
36
36
  import { findInteractiveComponents, simplifiedBuiltinMessage } from './mdx-inline-react.js';
37
37
  import { pageFrontmatterSchema, createJsonLocator } from './config-schema.js';
@@ -384,7 +384,10 @@ async function checkOpenApi(contentDir, config, locate, openapiRefs, errors, war
384
384
  export async function checkContent(contentDir, configText) {
385
385
  const errors = [];
386
386
  const warnings = [];
387
- const pages = findAllPages(contentDir);
387
+ // Drafts too (`draft: true`): the build leaves them out, but they're the
388
+ // project's pages - checked like any other, and the navigation can list
389
+ // them (the build takes those entries out, with a warning).
390
+ const pages = findAllPages(contentDir, { drafts: true });
388
391
  const openapiRefs = [];
389
392
  for (const rel of pages) await checkPage(contentDir, rel, errors, warnings, openapiRefs);
390
393