@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
@@ -0,0 +1,373 @@
1
+ /* The stylesheet the components share, beside each one's own scoped
2
+ <style>: code blocks (a <CodeBlock>, the blocks in a <CodeGroup>, and in
3
+ the generator every ``` fence too), Shiki's dark theme, and icons given as
4
+ an image. Global - the markup it styles is built by Shiki transformers
5
+ (lib/shiki-code-block.js), not by one component's template, so a scoped
6
+ style couldn't reach it. Everything uses the --wd-* variables: the
7
+ generator sets them from writedocs.json (BaseLayout.astro), anywhere else
8
+ theme.css gives them defaults. The generator imports this file in
9
+ BaseLayout.astro; the integration adds it to every page of any other
10
+ project. */
11
+
12
+ /* Astro's Shiki output (both the built-in MDX code-fence pipeline,
13
+ configured with dual themes in the generator's astro.config.mjs, and the
14
+ <Code /> component - <CodeBlock>, and the generator's API playground)
15
+ bakes the "light" theme as each element's base color/background and
16
+ stashes the dark equivalents in --shiki-dark/--shiki-dark-bg custom
17
+ properties. Swapping to those on [data-theme='dark'] is the officially
18
+ documented way to make Shiki-highlighted code follow a manual
19
+ (non-media-query) theme toggle - see
20
+ https://docs.astro.build/en/guides/syntax-highlighting/#setting-light-and-dark-mode-themes.
21
+ The background goes on the <pre> only: Shiki gives the spans inside no
22
+ background of their own, and painting the theme's background on every
23
+ span (.line included) covered the highlighted, diff, error and focus
24
+ line colors and the highlighted words in dark mode. */
25
+ [data-theme="dark"] .astro-code {
26
+ background-color: var(--shiki-dark-bg) !important;
27
+ }
28
+ [data-theme="dark"] .astro-code,
29
+ [data-theme="dark"] .astro-code span {
30
+ color: var(--shiki-dark) !important;
31
+ font-style: var(--shiki-dark-font-style) !important;
32
+ font-weight: var(--shiki-dark-font-weight) !important;
33
+ text-decoration: var(--shiki-dark-text-decoration) !important;
34
+ }
35
+
36
+ /* An icon given as an image URL or path (resolveIcon()'s 'image' kind,
37
+ rendered by AppIcon.astro) - 1em square inside its caller's own icon
38
+ span, so it sizes like a glyph icon would. Lives here rather than in
39
+ AppIcon.astro so it's part of the shared stylesheet, not an inline
40
+ <style> added to every page. */
41
+ img.wd-icon-img {
42
+ display: block;
43
+ width: 1em;
44
+ height: 1em;
45
+ object-fit: contain;
46
+ }
47
+
48
+ /* The "#" link beside a title - a Callout's or an Accordion's (each shows
49
+ it on hover of its own title, in its scoped <style>), and in the
50
+ generator a page heading's ([...slug].astro adds those and shows them on
51
+ hover of the heading). Hidden until then, and when it has focus. */
52
+ .wd-heading-anchor {
53
+ display: inline-block;
54
+ margin-left: 0.5rem;
55
+ color: var(--wd-text-muted);
56
+ opacity: 0;
57
+ text-decoration: none;
58
+ font-weight: 400;
59
+ transition: opacity 0.1s ease;
60
+ }
61
+ .wd-heading-anchor:focus {
62
+ opacity: 1;
63
+ }
64
+
65
+ /* Fenced (```) code blocks - codeBlockTransformer
66
+ (lib/shiki-code-block.js) wraps every one's <pre> in this
67
+ .wd-code-block div at build time (plus an optional .wd-code-title
68
+ bar, and the copy/expand buttons - see below). The card-like chrome
69
+ (border/radius/background) lives on the wrapper rather than the
70
+ <pre> itself so a title bar, when present, can sit flush above it
71
+ inside the same box; Astro's Shiki pipeline (dual light/dark themes)
72
+ already supplies the <pre>'s own background/text colors via inline
73
+ styles. Matches both a standalone block (direct child of .wd-article)
74
+ and one nested inside <CodeGroup> (which re-targets the margin/radius
75
+ itself via its own more specific `.wd-codegroup > .wd-code-block` rule
76
+ in CodeGroup.astro).
77
+ The panel rule below is scoped to the generator's .wd-article, as it
78
+ always was - a request/response example docked beside the article
79
+ isn't in it. theme.css gives a project's own pages the same panel.
80
+ The layout follows Mintlify's: a frame (the wrapper - border, surface
81
+ background, a 0.125rem inset) holding the title bar, and the code in
82
+ its own rounded panel inside it (the <pre>, in the code theme's
83
+ background). --wd-code-pad-x is the panel's side padding: the
84
+ highlighted and diff lines below stretch past it by the same amount
85
+ to reach the panel's edges. */
86
+ .wd-code-block {
87
+ --wd-code-pad-x: 1rem;
88
+ position: relative;
89
+ margin: 1.25rem 0 2rem;
90
+ padding: 0.125rem;
91
+ border: 1px solid var(--wd-border);
92
+ border-radius: 1rem;
93
+ background: var(--wd-surface);
94
+ }
95
+ .wd-article pre.astro-code {
96
+ margin: 0;
97
+ padding: 0.75rem var(--wd-code-pad-x);
98
+ border: none;
99
+ border-radius: 0.875rem;
100
+ font-size: 0.875rem;
101
+ line-height: 1.5rem;
102
+ }
103
+ /* On the frame, above the panel - room on the right for the copy
104
+ button, which moves into this bar when there is one (below). */
105
+ .wd-code-title {
106
+ padding: 0.25rem 2.75rem 0.25rem var(--wd-code-pad-x);
107
+ font-size: 0.75rem;
108
+ font-weight: 500;
109
+ line-height: 1.5rem;
110
+ color: var(--wd-text);
111
+ white-space: nowrap;
112
+ overflow: hidden;
113
+ text-overflow: ellipsis;
114
+ }
115
+ /* A fence's `icon="..."` (shiki-code-block.js) - the icon's own SVG
116
+ arrives as a data URL in --wd-code-icon and is used as a mask, so it
117
+ paints in the title's text color instead of the SVG's own fill. */
118
+ .wd-code-title-icon {
119
+ display: inline-block;
120
+ width: 1em;
121
+ height: 1em;
122
+ margin-right: 0.45rem;
123
+ vertical-align: -0.125em;
124
+ background: currentColor;
125
+ -webkit-mask: var(--wd-code-icon) center / contain no-repeat;
126
+ mask: var(--wd-code-icon) center / contain no-repeat;
127
+ }
128
+ /* Without a title bar, the copy button sits in the panel's top-right
129
+ corner and shows on hover or keyboard focus. */
130
+ .wd-code-copy-btn {
131
+ position: absolute;
132
+ top: 0.625rem;
133
+ right: 0.625rem;
134
+ z-index: 1;
135
+ display: inline-flex;
136
+ align-items: center;
137
+ justify-content: center;
138
+ width: 1.75rem;
139
+ height: 1.75rem;
140
+ padding: 0;
141
+ border-radius: 0.5rem;
142
+ border: 1px solid var(--wd-border);
143
+ background: var(--wd-surface);
144
+ color: var(--wd-text-muted);
145
+ font-size: 0.9rem;
146
+ line-height: 1;
147
+ cursor: pointer;
148
+ opacity: 0;
149
+ transition:
150
+ opacity 0.15s ease,
151
+ color 0.15s ease,
152
+ background 0.15s ease,
153
+ border-color 0.15s ease;
154
+ }
155
+ .wd-code-block:hover .wd-code-copy-btn,
156
+ .wd-code-copy-btn:focus-visible {
157
+ opacity: 1;
158
+ }
159
+ .wd-code-copy-btn:hover {
160
+ color: var(--wd-text);
161
+ background: var(--wd-background);
162
+ }
163
+ /* With a title bar, it's an always-visible icon at the bar's right end,
164
+ like Mintlify's: centered in the 2rem bar, inside the frame's inset. */
165
+ .wd-code-title ~ .wd-code-copy-btn {
166
+ top: 0.375rem;
167
+ right: 0.5rem;
168
+ width: 1.5rem;
169
+ height: 1.5rem;
170
+ border-color: transparent;
171
+ background: transparent;
172
+ opacity: 1;
173
+ }
174
+ .wd-code-title ~ .wd-code-copy-btn:hover {
175
+ background: color-mix(in srgb, var(--wd-text) 8%, transparent);
176
+ }
177
+ .wd-code-copy-btn.wd-code-copied {
178
+ opacity: 1;
179
+ color: #16a34a;
180
+ border-color: #16a34a;
181
+ }
182
+ /* ```js wrap - opts a single block into wrapping long lines instead
183
+ of horizontal-scrolling (the default). */
184
+ .wd-code-wrap pre.astro-code,
185
+ .wd-code-wrap pre.astro-code code {
186
+ white-space: pre-wrap;
187
+ word-break: break-word;
188
+ overflow-x: hidden;
189
+ }
190
+ /* ```js lines (or showLineNumbers) - a CSS-counter gutter, no markup
191
+ needed beyond a class since every line is already its own .line
192
+ span. The column is --wd-code-digits characters wide (set on the
193
+ wrapper by shiki-code-block.js from the line count), so the numbers
194
+ start at the panel's padding and stay right-aligned past nine lines. */
195
+ .wd-code-lines pre.astro-code code {
196
+ counter-reset: wd-code-line;
197
+ }
198
+ .wd-code-lines pre.astro-code .line {
199
+ counter-increment: wd-code-line;
200
+ }
201
+ .wd-code-lines pre.astro-code .line::before {
202
+ content: counter(wd-code-line);
203
+ display: inline-block;
204
+ width: calc(var(--wd-code-digits, 2) * 1ch);
205
+ margin-right: 1.25rem;
206
+ text-align: right;
207
+ color: var(--wd-text-muted);
208
+ user-select: none;
209
+ }
210
+ /* ```js expandable - collapses to its first 12 lines (plus the panel's
211
+ top padding) with a "Show more" button below; toggled via
212
+ .wd-code-expanded, added by the click handler in
213
+ scripts/code-block.ts. A block that already fits gets .wd-code-fits
214
+ from the same script instead, and is never collapsed: no fade, no
215
+ button. */
216
+ .wd-code-expandable:not(.wd-code-expanded, .wd-code-fits) pre.astro-code {
217
+ max-height: calc(12 * 1.5rem + 0.75rem);
218
+ overflow-y: hidden;
219
+ }
220
+ /* The fade over the last visible lines: a strip at the end of the code,
221
+ stuck to the bottom of the clipped panel (and to its left edge, if
222
+ the block is scrolled sideways), three lines tall and solid over the
223
+ last one, so no line shows cut in half. It's the panel's own background -
224
+ `inherit` takes the <pre>'s computed color, the dark theme's in dark
225
+ mode - masked from transparent to solid, so it fades into whatever
226
+ code theme the site uses. */
227
+ .wd-code-expandable:not(.wd-code-expanded, .wd-code-fits) pre.astro-code::after {
228
+ content: "";
229
+ position: sticky;
230
+ /* Sticky offsets count from inside the <pre>'s padding: minus the
231
+ padding puts the strip on the panel's edges, over the padding too. */
232
+ bottom: -0.75rem;
233
+ left: calc(-1 * var(--wd-code-pad-x));
234
+ display: block;
235
+ width: calc(100% + 2 * var(--wd-code-pad-x));
236
+ height: 4.5rem;
237
+ margin: -4.5rem calc(-1 * var(--wd-code-pad-x)) 0;
238
+ background-color: inherit;
239
+ -webkit-mask-image: linear-gradient(to bottom, transparent, #000 70%);
240
+ mask-image: linear-gradient(to bottom, transparent, #000 70%);
241
+ pointer-events: none;
242
+ }
243
+ .wd-code-fits .wd-code-expand-btn {
244
+ display: none;
245
+ }
246
+ /* Below the panel, on the frame, with a chevron that turns up once
247
+ the block is open. */
248
+ .wd-code-expand-btn {
249
+ display: flex;
250
+ align-items: center;
251
+ justify-content: center;
252
+ gap: 0.5rem;
253
+ width: 100%;
254
+ padding: 0.25rem;
255
+ border: none;
256
+ border-radius: 0 0 0.875rem 0.875rem;
257
+ background: transparent;
258
+ color: var(--wd-text-muted);
259
+ font-family: inherit;
260
+ font-size: 0.75rem;
261
+ font-weight: 500;
262
+ line-height: 1.5rem;
263
+ cursor: pointer;
264
+ transition:
265
+ color 0.15s ease,
266
+ background 0.15s ease;
267
+ }
268
+ .wd-code-expand-btn::after {
269
+ content: "";
270
+ width: 0.375rem;
271
+ height: 0.375rem;
272
+ border-right: 1.5px solid currentColor;
273
+ border-bottom: 1.5px solid currentColor;
274
+ transform: translateY(-0.1rem) rotate(45deg);
275
+ transition: transform 0.15s ease;
276
+ }
277
+ .wd-code-expanded .wd-code-expand-btn::after {
278
+ transform: translateY(0.1rem) rotate(-135deg);
279
+ }
280
+ .wd-code-expand-btn:hover {
281
+ color: var(--wd-text);
282
+ background: color-mix(in srgb, var(--wd-text) 6%, transparent);
283
+ }
284
+ /* Line/word annotation classes added by the official
285
+ @shikijs/transformers transformers configured alongside
286
+ codeBlockTransformer (lib/code-transformers.js):
287
+ .line.highlighted - transformerMetaHighlight
288
+ (```js {1,3-5}) and
289
+ transformerNotationHighlight
290
+ (// [!code highlight]/[!code hl])
291
+ .line.diff.add / .diff.remove - transformerNotationDiff
292
+ (// [!code ++] / // [!code --])
293
+ .line.error / .warning / .info - transformerNotationErrorLevel
294
+ (// [!code error]/[!code warning])
295
+ (also carries .highlighted)
296
+ pre.has-focused, .line.focused - transformerNotationFocus
297
+ (// [!code focus])
298
+ .highlighted-word - transformerMetaWordHighlight
299
+ (```js /someWord/) and
300
+ transformerNotationWordHighlight
301
+ (// [!code word:someWord])
302
+ Every .line needs display:inline-block + full width for its
303
+ highlight background to stretch edge-to-edge (by default a <span>
304
+ only extends as wide as its own text) - harmless for plain lines,
305
+ since inline-block with no other styling renders identically to
306
+ the browser's normal inline flow here. */
307
+ .astro-code .line {
308
+ display: inline-block;
309
+ width: 100%;
310
+ }
311
+ .astro-code .line.highlighted {
312
+ background: color-mix(in srgb, var(--wd-primary) 12%, transparent);
313
+ margin: 0 calc(-1 * var(--wd-code-pad-x, 1rem));
314
+ padding: 0 var(--wd-code-pad-x, 1rem);
315
+ width: calc(100% + 2 * var(--wd-code-pad-x, 1rem));
316
+ }
317
+ .astro-code .line.diff {
318
+ margin: 0 calc(-1 * var(--wd-code-pad-x, 1rem));
319
+ padding: 0 var(--wd-code-pad-x, 1rem);
320
+ width: calc(100% + 2 * var(--wd-code-pad-x, 1rem));
321
+ position: relative;
322
+ }
323
+ .astro-code .line.diff.add {
324
+ background: color-mix(in srgb, #16a34a 15%, transparent);
325
+ }
326
+ .astro-code .line.diff.remove {
327
+ background: color-mix(in srgb, #dc2626 15%, transparent);
328
+ opacity: 0.85;
329
+ }
330
+ .astro-code .line.diff.add::before,
331
+ .astro-code .line.diff.remove::before {
332
+ position: absolute;
333
+ left: 0.3rem;
334
+ font-weight: 700;
335
+ }
336
+ .astro-code .line.diff.add::before {
337
+ content: "+";
338
+ color: #16a34a;
339
+ }
340
+ .astro-code .line.diff.remove::before {
341
+ content: "-";
342
+ color: #dc2626;
343
+ }
344
+ .astro-code .line.error {
345
+ background: color-mix(in srgb, #dc2626 15%, transparent);
346
+ }
347
+ .astro-code .line.warning {
348
+ background: color-mix(in srgb, #d97706 15%, transparent);
349
+ }
350
+ .astro-code .line.info {
351
+ background: color-mix(in srgb, #2563eb 12%, transparent);
352
+ }
353
+ pre.astro-code.has-focused .line {
354
+ opacity: 0.45;
355
+ filter: blur(0.3px);
356
+ transition:
357
+ opacity 0.2s ease,
358
+ filter 0.2s ease;
359
+ }
360
+ pre.astro-code.has-focused .line.focused {
361
+ opacity: 1;
362
+ filter: none;
363
+ }
364
+ pre.astro-code.has-focused:hover .line {
365
+ opacity: 1;
366
+ filter: none;
367
+ }
368
+ .astro-code .highlighted-word {
369
+ background: color-mix(in srgb, var(--wd-primary) 20%, transparent);
370
+ border-radius: 0.25rem;
371
+ padding: 0.05rem 0.2rem;
372
+ margin: -0.05rem -0.15rem;
373
+ }
@@ -0,0 +1,63 @@
1
+ /* The theme the components read, for a project that isn't a writedocs site:
2
+ the --wd-* variables, light and dark, with the values a writedocs site
3
+ gets when its writedocs.json sets no colors (BaseLayout.astro's define:vars
4
+ <style> - the generator sets them itself and doesn't load this file). The
5
+ integration adds it to every page; to use other colors, set the variables
6
+ again in the project's own CSS, on :root or on any element around the
7
+ components. Dark mode follows data-theme="dark" on <html>, like a
8
+ writedocs site. */
9
+ :root {
10
+ --wd-primary: #6366f1;
11
+ /* The text color on a --wd-primary background - readableTextOn() in the
12
+ generator's src/lib/color.js picks it from the primary color. */
13
+ --wd-on-primary: #ffffff;
14
+ --wd-background: #ffffff;
15
+ --wd-text: #404045;
16
+ --wd-text-muted: #64748b;
17
+ --wd-heading: #18191d;
18
+ --wd-border: #e2e8f0;
19
+ --wd-surface: #f8fafc;
20
+ }
21
+ :root[data-theme="dark"] {
22
+ --wd-background: #0b1120;
23
+ --wd-text: #a0a0a5;
24
+ --wd-text-muted: #94a3b8;
25
+ --wd-heading: #e0e0e5;
26
+ --wd-border: #1e293b;
27
+ --wd-surface: #131a2b;
28
+ }
29
+
30
+ /* What a writedocs site's own stylesheet (the generator's
31
+ src/layout/styles/base.css and [...slug].astro) gives the code inside the
32
+ components. :where() adds no specificity, so the project's own rules for
33
+ these elements win. */
34
+ :where(code) {
35
+ background: var(--wd-surface);
36
+ border: 1px solid var(--wd-border);
37
+ padding: 0.15em 0.45em;
38
+ border-radius: 0.35em;
39
+ font-size: 1em;
40
+ font-weight: 500;
41
+ }
42
+ :where(pre code) {
43
+ background: none;
44
+ border: none;
45
+ padding: 0;
46
+ font-weight: normal;
47
+ }
48
+ :where(pre) {
49
+ padding: 1rem;
50
+ border-radius: 0.5rem;
51
+ overflow-x: auto;
52
+ }
53
+ /* A code block's panel. The generator scopes this rule to its article
54
+ (.wd-article pre.astro-code in components.css); here every code block
55
+ gets it. */
56
+ .wd-code-block pre.astro-code {
57
+ margin: 0;
58
+ padding: 0.75rem var(--wd-code-pad-x);
59
+ border: none;
60
+ border-radius: 0.875rem;
61
+ font-size: 0.875rem;
62
+ line-height: 1.5rem;
63
+ }
package/src/cli/build.js CHANGED
@@ -17,8 +17,14 @@ import { siteDirFor, moveRootFiles } from './base-path-layout.js';
17
17
  import { log, step, plural, duration, displayPath, formatProblems, color, CliExit } from './output.js';
18
18
  import { describeError, builtRoute, authorWarning, verboseLine } from './astro-output.js';
19
19
  import { reportApiPages } from './api-pages-output.js';
20
+ import { findDraftPages } from '../lib/pages.js';
21
+ import { draftWarnings } from '../lib/drafts.js';
22
+ import { createJsonLocator } from '../lib/config-schema.js';
20
23
 
21
- export async function runBuild({ contentDir, packageRoot, verbose = false }) {
24
+ /** `drafts` (`writedocs build --drafts`): draft pages are part of the site -
25
+ * marked, noindex, out of the sitemap, llms.txt and the MCP index, the way
26
+ * `writedocs dev` shows them (lib/drafts.js). Without it they're left out. */
27
+ export async function runBuild({ contentDir, packageRoot, verbose = false, drafts = false }) {
22
28
  // One spelling of each folder throughout - see lib/canonical-path.js.
23
29
  contentDir = canonicalPath(contentDir);
24
30
  packageRoot = canonicalPath(packageRoot);
@@ -38,10 +44,22 @@ export async function runBuild({ contentDir, packageRoot, verbose = false }) {
38
44
  warnings.push({ where, message });
39
45
  };
40
46
 
41
- const api = await generateApiPages({ contentDir });
47
+ const api = await generateApiPages({ contentDir, drafts });
42
48
  sameDriveCheck(contentDir, packageRoot, { generatedPages: api.groups.length > 0 });
43
49
  reportApiPages(api);
44
50
  api.warnings.forEach((message) => addWarning(null, message));
51
+ // The draft pages the build leaves out (lib/drafts.js) - and what that
52
+ // took out of the navigation, or leaves a redirect or "/" pointing at.
53
+ // With --drafts, only how many it kept.
54
+ const draftPages = findDraftPages(contentDir);
55
+ if (drafts) {
56
+ if (draftPages.length) notes.push(`${plural(draftPages.length, 'draft page')} built (--drafts): marked, noindex, and out of the sitemap, llms.txt and the MCP index.`);
57
+ } else {
58
+ const configText = readConfigText(contentDir);
59
+ const drafted = draftWarnings({ configText, drafts: draftPages, locate: createJsonLocator(configText) });
60
+ drafted.warnings.forEach(({ where, message }) => addWarning(where, message));
61
+ notes.push(...drafted.notes);
62
+ }
45
63
 
46
64
  const building = step('Building pages');
47
65
  const buildStarted = Date.now();
@@ -57,7 +75,9 @@ export async function runBuild({ contentDir, packageRoot, verbose = false }) {
57
75
  const { exited } = runAstro('build', {
58
76
  packageRoot,
59
77
  contentDir,
60
- env: { WRITEDOCS_OG_CARDS_FILE: ogCardsFile },
78
+ // WRITEDOCS_DRAFTS: draftsIncluded() in lib/pages.js - set either way, so
79
+ // one left in the shell's environment can't decide it.
80
+ env: { WRITEDOCS_OG_CARDS_FILE: ogCardsFile, WRITEDOCS_DRAFTS: drafts ? '1' : '' },
61
81
  onEvent(event) {
62
82
  if (verbose) {
63
83
  const line = verboseLine(event);
package/src/cli/dev.js CHANGED
@@ -52,7 +52,8 @@ export async function runDev({ contentDir, packageRoot, port, verbose = false, o
52
52
  writeLock(packageRoot, { contentDir, url: null });
53
53
  process.on('exit', () => removeLock(packageRoot));
54
54
 
55
- const api = await generateApiPages({ contentDir });
55
+ // Draft pages are pages in the preview (lib/drafts.js).
56
+ const api = await generateApiPages({ contentDir, drafts: true });
56
57
  sameDriveCheck(contentDir, packageRoot, { generatedPages: api.groups.length > 0 });
57
58
  reportApiPages(api);
58
59
  api.warnings.forEach((message) => log.warn(message));
@@ -339,8 +339,8 @@ async function generateApiPagesForGroup({ contentDir, generatedDocsDir, group, o
339
339
  * warnings: [message], sources: [every local spec file read, $refs
340
340
  * included], written: [paths], removed: [paths] }.
341
341
  */
342
- export async function generateApiPages({ contentDir, keepEmptyFolders = false }) {
343
- const { summary, files, roots } = await planApiPages({ contentDir });
342
+ export async function generateApiPages({ contentDir, keepEmptyFolders = false, drafts }) {
343
+ const { summary, files, roots } = await planApiPages({ contentDir, drafts });
344
344
  const { written, removed } = writeGeneratedFiles(roots, files, { keepEmptyFolders });
345
345
  return { ...summary, written, removed };
346
346
  }
@@ -348,8 +348,10 @@ export async function generateApiPages({ contentDir, keepEmptyFolders = false })
348
348
  /** Everything generateApiPages() would write, without writing it:
349
349
  * `{ summary, files, roots }` - `files` maps each absolute path to its
350
350
  * content, `roots` are the two folders it owns (generated-docs/ first).
351
- * `writedocs dev` writes it in two steps (lib/openapi-reload-integration.js). */
352
- export async function planApiPages({ contentDir }) {
351
+ * `writedocs dev` writes it in two steps (lib/openapi-reload-integration.js).
352
+ * `drafts`: whether draft pages are pages (findAllPages()) - the specs they
353
+ * name are parsed then; by default, as draftsIncluded() says. */
354
+ export async function planApiPages({ contentDir, drafts }) {
353
355
  const summary = { groups: [], pageSpecs: [], warnings: [], sources: [] };
354
356
  const generatedDocsDir = path.join(writedocsTempDir(contentDir), 'generated-docs');
355
357
  const openapiOutDir = path.join(writedocsTempDir(contentDir), 'openapi');
@@ -394,7 +396,7 @@ export async function planApiPages({ contentDir }) {
394
396
  if (moved.length) files.set(movedApiPagesFile(contentDir), JSON.stringify(moved, null, 2));
395
397
 
396
398
  const groupSpecs = groups.map((g) => path.resolve(contentDir, g.openapi.src));
397
- const pageSpecs = await parsePageSpecs({ contentDir, openapiOutDir, groupSpecs, summary, files, sources });
399
+ const pageSpecs = await parsePageSpecs({ contentDir, openapiOutDir, groupSpecs, summary, files, sources, drafts });
398
400
  // Every spec the site reads, as paths from the project root: these are
399
401
  // how the site is built, not files it publishes (lib/project-files.js).
400
402
  if (groupSpecs.length || pageSpecs.length) {
@@ -471,9 +473,9 @@ export function writeGeneratedFiles(roots, files, { keepEmptyFolders = false } =
471
473
  * pages are generated - the pages that name the spec are the pages. A
472
474
  * spec that's missing or doesn't parse is a warning, not a build failure:
473
475
  * its pages show the playground's own "no operation found" notice. */
474
- async function parsePageSpecs({ contentDir, openapiOutDir, groupSpecs, summary, files, sources }) {
476
+ async function parsePageSpecs({ contentDir, openapiOutDir, groupSpecs, summary, files, sources, drafts }) {
475
477
  const specs = new Set();
476
- for (const rel of findAllPages(contentDir)) {
478
+ for (const rel of findAllPages(contentDir, { drafts })) {
477
479
  let data;
478
480
  try {
479
481
  ({ data } = matter(fs.readFileSync(path.join(contentDir, rel), 'utf-8')));
@@ -32,12 +32,14 @@ export function mayChangePages(relative) {
32
32
  /** Starts watching; returns `{ close }`. `onChange({ added, removed })` gets
33
33
  * the page files (relative paths) that came and went. */
34
34
  export function watchPageList(contentDir, onChange, { settleMs = SETTLE_MS } = {}) {
35
- let current = new Set(findAllPages(contentDir));
35
+ // Drafts included, as in the preview (lib/drafts.js): `draft: true` coming
36
+ // or going doesn't change the list.
37
+ let current = new Set(findAllPages(contentDir, { drafts: true }));
36
38
  let timer = null;
37
39
  const check = () => {
38
40
  let next;
39
41
  try {
40
- next = new Set(findAllPages(contentDir));
42
+ next = new Set(findAllPages(contentDir, { drafts: true }));
41
43
  } catch {
42
44
  return; // mid-save, or a folder being moved - the next event checks again
43
45
  }
@@ -12,7 +12,7 @@ const workerPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'astr
12
12
  *
13
13
  * { type: 'astro-log', level, label, message } - an Astro/Vite log line
14
14
  * { type: 'report', level, message, where } - writedocs' own code
15
- * (lib/cli-report.js)
15
+ * (packages/components/src/lib/cli-report.js)
16
16
  * { type: 'raw', stream, line } - anything printed directly
17
17
  * { type: 'ready', urls } / { type: 'done' } / { type: 'fatal', error }
18
18
  *
@@ -20,7 +20,7 @@ const workerPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'astr
20
20
  * console.warn that doesn't go through cli-report.js still shows up.
21
21
  *
22
22
  * `env` adds variables for the child only (build.js's
23
- * WRITEDOCS_OG_CARDS_FILE).
23
+ * WRITEDOCS_OG_CARDS_FILE, and WRITEDOCS_DRAFTS with --drafts).
24
24
  *
25
25
  * Returns { child, exited } - `exited` resolves with the exit code.
26
26
  */
@@ -1,8 +1,8 @@
1
1
  ---
2
2
  import fs from 'node:fs';
3
3
  import ApiSchemaField from './ApiSchemaField.astro';
4
- import Tabs from './Tabs.astro';
5
- import Tab from './Tab.astro';
4
+ import Tabs from '../../packages/components/src/components/Tabs.astro';
5
+ import Tab from '../../packages/components/src/components/Tab.astro';
6
6
  import {
7
7
  schemaRows,
8
8
  exampleFromSchema,
@@ -18,7 +18,7 @@
18
18
  // the same way NavTree.astro's own nested sidebar groups do - same
19
19
  // established pattern in this codebase for "a tree of unknown depth, one
20
20
  // component handles every level."
21
- import Expandable from './Expandable.astro';
21
+ import Expandable from '../../packages/components/src/components/Expandable.astro';
22
22
  import type { SchemaRow } from '../lib/openapi-render';
23
23
  import { descriptionHtml } from '../lib/openapi-markdown';
24
24
 
@@ -34,7 +34,7 @@
34
34
  import { Icon } from 'astro-icon/components';
35
35
  import type { ContextMenuOption } from '../lib/config';
36
36
  import { mcpServerUrl, cursorInstallLink, vscodeInstallLink } from '../lib/mcp-links.js';
37
- import { siteHref } from '../lib/site-base';
37
+ import { siteHref } from '../../packages/components/src/lib/site-base';
38
38
 
39
39
  interface Props {
40
40
  currentPath: string; // e.g. "/" or "/guides/foo/" - see hrefForSlug() in [...slug].astro
@@ -52,7 +52,7 @@ const { currentPath, siteUrl, siteName, options } = Astro.props as Props;
52
52
  // slug with a literal ".md" appended instead of the trailing slash).
53
53
  const mdPath = currentPath === '/' ? '/index.md' : `${currentPath.replace(/\/$/, '')}.md`;
54
54
  const mdAbsoluteUrl = siteUrl ? `${siteUrl}${mdPath}` : null;
55
- // The .md's address as the page links it - with the basePath (lib/site-base.ts).
55
+ // The .md's address as the page links it - with the basePath (the components package's lib/site-base.ts).
56
56
  const mdHref = siteHref(mdPath);
57
57
  const mcpUrl = siteUrl ? mcpServerUrl(siteUrl) : null;
58
58
 
@@ -3,6 +3,7 @@ import { glob } from 'astro/loaders';
3
3
  import type { Loader } from 'astro/loaders';
4
4
  import fs from 'node:fs';
5
5
  import path from 'node:path';
6
+ import { createHash } from 'node:crypto';
6
7
  import { fileURLToPath, pathToFileURL } from 'node:url';
7
8
  import { pageFrontmatterSchema, findAllPages } from './lib/config';
8
9
  import { titleFromPath } from './lib/pages.js';
@@ -76,10 +77,25 @@ function skipIfMissing(inner: Loader): Loader {
76
77
  // a migrated page that relied on it builds with the same title. See
77
78
  // titleFromPath() in lib/pages.js; `writedocs validate` applies the same
78
79
  // default (lib/content-check.js).
80
+ //
81
+ // And each page's digest - what Astro's content store, kept between runs in
82
+ // writedocsTempDir()'s cache/, compares to reuse a page's data instead of
83
+ // parsing it again - also covers the frontmatter schema (config-schema.ts).
84
+ // With the file's text alone, a page that hadn't changed kept the data an
85
+ // earlier writedocs parsed: after an upgrade that added `draft`, a draft
86
+ // page came back without it - no strip in `writedocs dev`, and not noindex
87
+ // in `build --drafts`. Astro clears the store only when content.config.ts's
88
+ // own text, the Astro config or Astro's version changes.
89
+ const schemaDigest = createHash('sha256')
90
+ .update(fs.readFileSync(path.join(process.env.WRITEDOCS_PACKAGE_ROOT || process.cwd(), 'src', 'lib', 'config-schema.ts')))
91
+ .digest('hex')
92
+ .slice(0, 16);
93
+
79
94
  type LoaderContext = Parameters<Loader['load']>[0];
80
95
  function withTitleFallback(context: LoaderContext): LoaderContext {
81
96
  return {
82
97
  ...context,
98
+ generateDigest: (data) => context.generateDigest(typeof data === 'string' ? `${schemaDigest}\n${data}` : data),
83
99
  parseData: (props) =>
84
100
  context.parseData({
85
101
  ...props,
@@ -8,5 +8,5 @@ and `writedocs build`:
8
8
  Failed to load icons from "src/icons": ENOENT: no such file or directory
9
9
 
10
10
  writedocs has no local icons: every icon comes from the installed icon sets
11
- (see src/lib/icons.js). Don't delete the folder; `scripts/package-files.test.js`
11
+ (see packages/components/src/lib/icons.js). Don't delete the folder; `scripts/package-files.test.js`
12
12
  checks it ships in the npm package.