@writedocs/generator 0.14.0 → 0.16.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 (120) hide show
  1. package/astro.config.mjs +31 -69
  2. package/package.json +4 -2
  3. package/packages/components/package.json +53 -0
  4. package/{src → packages/components/src}/components/Accordion.astro +2 -2
  5. package/{src → packages/components/src}/components/AppIcon.astro +3 -3
  6. package/{src → packages/components/src}/components/Callout.astro +3 -3
  7. package/{src → packages/components/src}/components/CodeBlock.astro +8 -27
  8. package/{src → packages/components/src}/components/CodeGroup.astro +9 -9
  9. package/{src → packages/components/src}/components/Image.astro +7 -9
  10. package/{src → packages/components/src}/components/compound.ts +1 -1
  11. package/packages/components/src/host.js +24 -0
  12. package/packages/components/src/index.ts +59 -0
  13. package/packages/components/src/integration.js +151 -0
  14. package/packages/components/src/lib/base-path.js +39 -0
  15. package/{src → packages/components/src}/lib/code-line-numbers.js +1 -1
  16. package/packages/components/src/lib/code-transformers.js +45 -0
  17. package/{src → packages/components/src}/lib/icons.js +13 -7
  18. package/{src → packages/components/src}/lib/shiki-code-block.js +9 -9
  19. package/{src → packages/components/src}/lib/site-base.ts +9 -6
  20. package/packages/components/src/scripts/code-block.ts +62 -0
  21. package/packages/components/src/styles/components.css +373 -0
  22. package/packages/components/src/styles/theme.css +63 -0
  23. package/src/cli/build.js +1 -1
  24. package/src/cli/rewrite-redirect-pages.js +8 -6
  25. package/src/cli/run-astro.js +1 -1
  26. package/src/cli/write-mcp-files.js +4 -1
  27. package/src/cli/write-redirects-file.js +4 -3
  28. package/src/components/ApiPlayground.astro +2 -2
  29. package/src/components/ApiSchemaField.astro +1 -1
  30. package/src/components/CopyPageMenu.astro +2 -2
  31. package/src/content.config.ts +21 -1
  32. package/src/icons/README.md +1 -1
  33. package/src/layout/BaseLayout.astro +45 -51
  34. package/src/layout/components/AnalyticsScripts.astro +2 -2
  35. package/src/layout/components/Breadcrumbs.astro +1 -1
  36. package/src/layout/components/ConsentBanner.astro +1 -1
  37. package/src/layout/components/MobileMenu.astro +11 -7
  38. package/src/layout/components/NavTree.astro +2 -2
  39. package/src/layout/components/Sidebar.astro +2 -2
  40. package/src/layout/components/SiteFooter.astro +2 -2
  41. package/src/layout/components/TopBar.astro +10 -6
  42. package/src/layout/styles/base.css +4 -37
  43. package/src/lib/a11y-check.js +1 -1
  44. package/src/lib/appearance.js +64 -0
  45. package/src/lib/asset-dimensions.js +2 -1
  46. package/src/lib/base-path.js +4 -25
  47. package/src/lib/bom.js +20 -0
  48. package/src/lib/color.js +1 -1
  49. package/src/lib/components-host.ts +21 -0
  50. package/src/lib/config-file.js +21 -8
  51. package/src/lib/config-schema.js +14 -7
  52. package/src/lib/config-schema.ts +19 -12
  53. package/src/lib/config.ts +4 -3
  54. package/src/lib/content-check.js +38 -3
  55. package/src/lib/content-store-prune.js +44 -0
  56. package/src/lib/json-schema-descriptions.js +4 -1
  57. package/src/lib/link-check.js +2 -2
  58. package/src/lib/mdx-inject-builtins.js +2 -2
  59. package/src/lib/mdx-inline-react.js +1 -1
  60. package/src/lib/mdx-title-anchor-ids.js +2 -2
  61. package/src/lib/mdx-unknown-components.js +1 -1
  62. package/src/lib/mintlify-convert.js +13 -3
  63. package/src/lib/openapi-reload-integration.js +1 -1
  64. package/src/lib/pages.js +6 -4
  65. package/src/lib/project-files-integration.js +1 -1
  66. package/src/lib/rehype-base-path.js +1 -1
  67. package/src/lib/wdignore-cases.json +9 -2
  68. package/src/lib/wdignore.js +5 -0
  69. package/src/lib/writedocs-legacy-convert.js +2 -2
  70. package/src/pages/404.astro +1 -1
  71. package/src/pages/[...slug].astro +53 -416
  72. package/src/pages/llms-full.txt.ts +6 -3
  73. package/src/pages/llms.txt.ts +4 -4
  74. package/writedocs.schema.json +23 -0
  75. package/src/components/index.ts +0 -62
  76. /package/{src → packages/components/src}/components/AccordionGroup.astro +0 -0
  77. /package/{src → packages/components/src}/components/Badge.astro +0 -0
  78. /package/{src → packages/components/src}/components/Card.astro +0 -0
  79. /package/{src → packages/components/src}/components/CardGroup.astro +0 -0
  80. /package/{src → packages/components/src}/components/Check.astro +0 -0
  81. /package/{src → packages/components/src}/components/Color.astro +0 -0
  82. /package/{src → packages/components/src}/components/ColorItem.astro +0 -0
  83. /package/{src → packages/components/src}/components/ColorRow.astro +0 -0
  84. /package/{src → packages/components/src}/components/Column.astro +0 -0
  85. /package/{src → packages/components/src}/components/Columns.astro +0 -0
  86. /package/{src → packages/components/src}/components/Danger.astro +0 -0
  87. /package/{src → packages/components/src}/components/Expandable.astro +0 -0
  88. /package/{src → packages/components/src}/components/Frame.astro +0 -0
  89. /package/{src → packages/components/src}/components/GitHubRepo.astro +0 -0
  90. /package/{src → packages/components/src}/components/Hint.astro +0 -0
  91. /package/{src → packages/components/src}/components/Icon.astro +0 -0
  92. /package/{src → packages/components/src}/components/Info.astro +0 -0
  93. /package/{src → packages/components/src}/components/Note.astro +0 -0
  94. /package/{src → packages/components/src}/components/Panel.astro +0 -0
  95. /package/{src → packages/components/src}/components/ParamField.astro +0 -0
  96. /package/{src → packages/components/src}/components/Parameter.astro +0 -0
  97. /package/{src → packages/components/src}/components/Prompt.astro +0 -0
  98. /package/{src → packages/components/src}/components/RequestExample.astro +0 -0
  99. /package/{src → packages/components/src}/components/ResponseExample.astro +0 -0
  100. /package/{src → packages/components/src}/components/ResponseField.astro +0 -0
  101. /package/{src → packages/components/src}/components/Searchbar.astro +0 -0
  102. /package/{src → packages/components/src}/components/Step.astro +0 -0
  103. /package/{src → packages/components/src}/components/Steps.astro +0 -0
  104. /package/{src → packages/components/src}/components/Tab.astro +0 -0
  105. /package/{src → packages/components/src}/components/Tabs.astro +0 -0
  106. /package/{src → packages/components/src}/components/Tile.astro +0 -0
  107. /package/{src → packages/components/src}/components/Tip.astro +0 -0
  108. /package/{src → packages/components/src}/components/Tooltip.astro +0 -0
  109. /package/{src → packages/components/src}/components/Tree.astro +0 -0
  110. /package/{src → packages/components/src}/components/TreeFile.astro +0 -0
  111. /package/{src → packages/components/src}/components/TreeFolder.astro +0 -0
  112. /package/{src → packages/components/src}/components/Update.astro +0 -0
  113. /package/{src → packages/components/src}/components/Video.astro +0 -0
  114. /package/{src → packages/components/src}/components/View.astro +0 -0
  115. /package/{src → packages/components/src}/components/Visibility.astro +0 -0
  116. /package/{src → packages/components/src}/components/Warning.astro +0 -0
  117. /package/{src → packages/components/src}/components/class-names.ts +0 -0
  118. /package/{src → packages/components/src}/lib/cli-report.js +0 -0
  119. /package/{src → packages/components/src}/lib/inline-markdown.js +0 -0
  120. /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
@@ -188,7 +188,7 @@ export async function runBuild({ contentDir, packageRoot, verbose = false, draft
188
188
  writeRedirectsFile(siteDir, contentDir, { outDir: distDir, basePath });
189
189
  // Every other host follows Astro's redirect pages - rewritten so the
190
190
  // reader never sees one (rewrite-redirect-pages.js).
191
- rewriteRedirectPages(siteDir, { background: siteConfig.styles?.background?.colors });
191
+ rewriteRedirectPages(siteDir, { background: siteConfig.styles?.background?.colors, appearance: siteConfig.styles?.appearance });
192
192
  // The site's MCP server at /mcp: mcp-index.json is already in dist/ (an
193
193
  // Astro route); this adds the Cloudflare _worker.js that serves it - see
194
194
  // write-mcp-files.js for every host.
@@ -13,6 +13,7 @@
13
13
  // screen. The meta refresh stays for browsers without JavaScript.
14
14
  import fs from 'node:fs';
15
15
  import path from 'node:path';
16
+ import { themeScript, serverTheme } from '../lib/appearance.js';
16
17
 
17
18
  // Any delay: Astro waits 2 seconds on a 302's page (the automatic "/"), none on a 301's.
18
19
  const REFRESH = /<meta http-equiv="refresh" content="\d+;\s*url=([^"]*)"\s*\/?>/i;
@@ -34,15 +35,16 @@ function cssColor(value, fallback) {
34
35
  }
35
36
 
36
37
  /** The page for a redirect to `target`. */
37
- export function redirectPageHtml({ target, canonical = null, background = {} }) {
38
+ export function redirectPageHtml({ target, canonical = null, background = {}, appearance }) {
38
39
  const light = cssColor(background.light, DEFAULT_LIGHT);
39
40
  const dark = cssColor(background.dark, DEFAULT_DARK);
40
41
  // Inside <script>: a JSON string, with "<" escaped so a target can't end the script.
41
42
  const js = JSON.stringify(target).replace(/</g, '\\u003c');
42
43
  const attr = encodeAttr(target);
44
+ const fixed = serverTheme(appearance);
43
45
  return [
44
46
  '<!doctype html>',
45
- '<html lang="en">',
47
+ fixed ? `<html lang="en" data-theme="${fixed}">` : '<html lang="en">',
46
48
  '<head>',
47
49
  '<meta charset="utf-8">',
48
50
  `<script>location.replace(${js} + location.search + location.hash)</script>`,
@@ -51,8 +53,8 @@ export function redirectPageHtml({ target, canonical = null, background = {} })
51
53
  '<meta name="robots" content="noindex">',
52
54
  canonical ? `<link rel="canonical" href="${encodeAttr(canonical)}">` : '',
53
55
  '<title>Redirecting…</title>',
54
- // Same theme choice as every page (BaseLayout.astro): the stored one, else the system's.
55
- "<script>try{var t=localStorage.getItem('wd-theme');if(t!=='light'&&t!=='dark')t=matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light';document.documentElement.dataset.theme=t}catch(e){}</script>",
56
+ // The same theme choice as every page (BaseLayout.astro) - src/lib/appearance.js.
57
+ `<script>${themeScript(appearance)}</script>`,
56
58
  `<style>html{background:${light};color-scheme:light}html[data-theme=dark]{background:${dark};color-scheme:dark}@media (prefers-color-scheme:dark){html:not([data-theme]){background:${dark};color-scheme:dark}}body{margin:0}a{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}</style>`,
57
59
  '</head>',
58
60
  `<body><a href="${attr}">Continue to ${attr}</a></body>`,
@@ -62,7 +64,7 @@ export function redirectPageHtml({ target, canonical = null, background = {} })
62
64
  }
63
65
 
64
66
  /** Rewrites every Astro redirect page under `distDir`. Returns how many. */
65
- export function rewriteRedirectPages(distDir, { background } = {}) {
67
+ export function rewriteRedirectPages(distDir, { background, appearance } = {}) {
66
68
  let count = 0;
67
69
  const walk = (dir) => {
68
70
  for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
@@ -76,7 +78,7 @@ export function rewriteRedirectPages(distDir, { background } = {}) {
76
78
  const refresh = REFRESH.exec(html);
77
79
  if (!refresh || !ASTRO_REDIRECT.test(html)) continue;
78
80
  const canonical = CANONICAL.exec(html);
79
- fs.writeFileSync(full, redirectPageHtml({ target: decodeAttr(refresh[1]), canonical: canonical ? decodeAttr(canonical[1]) : null, background }));
81
+ fs.writeFileSync(full, redirectPageHtml({ target: decodeAttr(refresh[1]), canonical: canonical ? decodeAttr(canonical[1]) : null, background, appearance }));
80
82
  count++;
81
83
  }
82
84
  };
@@ -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
  *
@@ -26,6 +26,7 @@
26
26
  import fs from 'node:fs';
27
27
  import path from 'node:path';
28
28
  import { fileURLToPath } from 'node:url';
29
+ import { readText } from '../lib/config-file.js';
29
30
 
30
31
  const SERVER_SOURCE = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'mcp', 'server.js');
31
32
  const IGNORED_BY_WORKERS = ['_worker.js', '_routes.json'];
@@ -92,7 +93,9 @@ export function writeMcpFiles(distDir, contentDir, version, { siteDir = distDir,
92
93
  fs.writeFileSync(path.join(distDir, '_routes.json'), JSON.stringify({ version: 1, include: [`${basePath}/mcp`, `${basePath}/mcp/`], exclude: [] }, null, 2) + '\n');
93
94
 
94
95
  const ignorePath = path.join(distDir, '.assetsignore');
95
- const existing = fs.existsSync(ignorePath) ? fs.readFileSync(ignorePath, 'utf-8') : '';
96
+ // A project's own public/.assetsignore, without a byte order mark
97
+ // (lib/bom.js).
98
+ const existing = fs.existsSync(ignorePath) ? readText(ignorePath) : '';
96
99
  const lines = existing.split(/\r?\n/).map((l) => l.trim());
97
100
  const missing = IGNORED_BY_WORKERS.filter((name) => !lines.includes(name));
98
101
  if (missing.length) {
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { readConfigText } from '../lib/config-file.js';
3
+ import { readConfigText, readText } from '../lib/config-file.js';
4
4
  import { readMovedApiPages } from '../lib/moved-api-pages.js';
5
5
  import { withBase } from '../lib/base-path.js';
6
6
 
@@ -121,8 +121,9 @@ export function writeRedirectsFile(distDir, contentDir, { outDir = distDir, base
121
121
  const redirectsPath = path.join(outDir, '_redirects');
122
122
  // A hand-written public/_redirects is already copied into dist by Astro
123
123
  // by this point - preserve it (and its priority: first match wins) by
124
- // appending after it rather than overwriting.
125
- const existing = fs.existsSync(redirectsPath) ? fs.readFileSync(redirectsPath, 'utf8').replace(/\s*$/, '\n\n') : '';
124
+ // appending after it rather than overwriting. Without a byte order mark,
125
+ // which would sit in front of its first rule (lib/bom.js).
126
+ const existing = fs.existsSync(redirectsPath) ? readText(redirectsPath).replace(/\s*$/, '\n\n') : '';
126
127
  fs.writeFileSync(redirectsPath, existing + generated);
127
128
  }
128
129
 
@@ -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
 
@@ -8,6 +8,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
8
8
  import { pageFrontmatterSchema, findAllPages } from './lib/config';
9
9
  import { titleFromPath } from './lib/pages.js';
10
10
  import { writedocsTempDir } from './lib/writedocs-temp-dir.js';
11
+ import { staleEntryIds } from './lib/content-store-prune.js';
11
12
 
12
13
  const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
13
14
 
@@ -63,10 +64,16 @@ function skipIfMissing(inner: Loader): Loader {
63
64
  // Left empty: the last spec taken out of writedocs.json while
64
65
  // `writedocs dev` runs (the folder stays then). glob() would only warn
65
66
  // about no files and keep the pages it had.
66
- if (!fs.readdirSync(generatedDocsBase, { recursive: true }).some((file) => /\.mdx?$/i.test(String(file)))) {
67
+ const files = fs
68
+ .readdirSync(generatedDocsBase, { recursive: true })
69
+ .map(String)
70
+ .filter((file) => /\.mdx?$/i.test(file))
71
+ .map((file) => path.join(fileURLToPath(generatedDocsBase), file));
72
+ if (files.length === 0) {
67
73
  for (const id of context.store.keys()) context.store.delete(id);
68
74
  return;
69
75
  }
76
+ forgetMovedFiles(context, files);
70
77
  return inner.load({ ...withTitleFallback(context), watcher: undefined });
71
78
  },
72
79
  };
@@ -92,6 +99,18 @@ const schemaDigest = createHash('sha256')
92
99
  .slice(0, 16);
93
100
 
94
101
  type LoaderContext = Parameters<Loader['load']>[0];
102
+
103
+ // A page's stored entry is kept, old `filePath` and all, while its id and
104
+ // text stay the same - and a page with a `slug` keeps both when it moves to
105
+ // another folder. Entries whose file isn't one of the pages about to be
106
+ // synced are deleted first, so glob() reads those pages again from where
107
+ // they are now. Without this, the build failed on the page's old path, and
108
+ // `writedocs dev` on every page - see lib/content-store-prune.js.
109
+ function forgetMovedFiles(context: LoaderContext, files: string[]) {
110
+ const root = fileURLToPath(context.config.root);
111
+ for (const id of staleEntryIds(context.store.entries(), root, files)) context.store.delete(id);
112
+ }
113
+
95
114
  function withTitleFallback(context: LoaderContext): LoaderContext {
96
115
  return {
97
116
  ...context,
@@ -186,6 +205,7 @@ function livePages(dir: string, base: URL): Loader {
186
205
  for (const id of store.keys()) store.delete(id);
187
206
  return;
188
207
  }
208
+ forgetMovedFiles(context, files.map((file) => path.join(dir, file)));
189
209
  await glob({ pattern: files, base }).load({ ...withTitleFallback(context), watcher: undefined });
190
210
  }
191
211
 
@@ -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.