@writedocs/generator 0.13.4 → 0.13.5

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 (86) hide show
  1. package/README.md +28 -28
  2. package/astro.config.mjs +645 -645
  3. package/bin/writedocs.js +356 -356
  4. package/package.json +99 -99
  5. package/src/cli/base-path-layout.js +44 -44
  6. package/src/cli/build-auth.js +135 -135
  7. package/src/cli/build.js +203 -203
  8. package/src/cli/check-built-styles.js +41 -41
  9. package/src/cli/convert.js +124 -124
  10. package/src/cli/dev.js +268 -268
  11. package/src/cli/exit-when-flushed.js +42 -42
  12. package/src/cli/generate-api-pages.js +507 -507
  13. package/src/cli/og-image-worker.js +20 -20
  14. package/src/cli/og-images.js +70 -70
  15. package/src/cli/page-list-watch.js +69 -69
  16. package/src/cli/run-astro.js +97 -97
  17. package/src/cli/run-pagefind.js +154 -154
  18. package/src/cli/write-mcp-files.js +103 -103
  19. package/src/cli/write-redirects-file.js +158 -158
  20. package/src/components/ApiReferencePanel.astro +1792 -1792
  21. package/src/components/AppIcon.astro +51 -51
  22. package/src/components/Card.astro +193 -193
  23. package/src/components/CodeGroup.astro +63 -39
  24. package/src/components/CopyPageMenu.astro +374 -374
  25. package/src/components/Hint.astro +188 -188
  26. package/src/components/Icon.astro +72 -72
  27. package/src/components/Image.astro +165 -165
  28. package/src/components/Tile.astro +67 -67
  29. package/src/components/Video.astro +137 -137
  30. package/src/content.config.ts +203 -203
  31. package/src/layout/BaseLayout.astro +908 -908
  32. package/src/layout/components/AnalyticsScripts.astro +49 -49
  33. package/src/layout/components/Breadcrumbs.astro +98 -98
  34. package/src/layout/components/ConsentBanner.astro +119 -119
  35. package/src/layout/components/MobileMenu.astro +225 -225
  36. package/src/layout/components/NavTree.astro +408 -408
  37. package/src/layout/components/Sidebar.astro +232 -232
  38. package/src/layout/components/SiteFooter.astro +87 -87
  39. package/src/layout/components/TopBar.astro +386 -386
  40. package/src/layout/styles/base.css +332 -326
  41. package/src/layout/styles/mobile-menu.css +285 -285
  42. package/src/lib/agent-markdown.js +164 -164
  43. package/src/lib/asset-dimensions.js +89 -89
  44. package/src/lib/base-path.js +90 -90
  45. package/src/lib/cli-report.js +22 -22
  46. package/src/lib/code-line-numbers.js +13 -0
  47. package/src/lib/config-schema.ts +2509 -2509
  48. package/src/lib/config.ts +1316 -1316
  49. package/src/lib/consent.js +108 -108
  50. package/src/lib/content-store-reload-integration.js +101 -101
  51. package/src/lib/icon-data-dev.js +53 -53
  52. package/src/lib/image-size.js +152 -152
  53. package/src/lib/json-schema-descriptions.js +228 -228
  54. package/src/lib/link-check.js +544 -544
  55. package/src/lib/llms-index.ts +90 -90
  56. package/src/lib/mcp-dev-integration.js +65 -65
  57. package/src/lib/mcp-index.ts +102 -102
  58. package/src/lib/mintlify-convert.js +605 -605
  59. package/src/lib/moved-api-pages.js +49 -49
  60. package/src/lib/og-cards.js +33 -33
  61. package/src/lib/og-image.js +235 -235
  62. package/src/lib/openapi-dev-status.js +80 -80
  63. package/src/lib/openapi-reload-integration.js +193 -193
  64. package/src/lib/pages.js +312 -312
  65. package/src/lib/project-files-integration.js +116 -116
  66. package/src/lib/project-files.js +137 -137
  67. package/src/lib/rehype-base-path.js +62 -62
  68. package/src/lib/rehype-image-loading.js +71 -71
  69. package/src/lib/robots-txt.js +21 -21
  70. package/src/lib/search-scope.js +44 -44
  71. package/src/lib/selector-placement.js +50 -50
  72. package/src/lib/seo-tags.js +155 -155
  73. package/src/lib/shiki-code-block.js +7 -1
  74. package/src/lib/site-base.ts +27 -27
  75. package/src/lib/styles-asset-integration.js +291 -291
  76. package/src/lib/wdignore-cases.json +195 -195
  77. package/src/lib/wdignore.js +177 -177
  78. package/src/pages/404.astro +63 -63
  79. package/src/pages/[...slug].astro +1762 -1608
  80. package/src/pages/[...slug].md.ts +93 -93
  81. package/src/pages/llms-full.txt.ts +88 -88
  82. package/src/pages/og/[...slug].png.ts +63 -63
  83. package/src/scripts/mobile-menu.ts +80 -80
  84. package/src/scripts/search.ts +245 -245
  85. package/src/scripts/sidebar-scroll.ts +61 -61
  86. package/src/styles/global.css +40 -40
@@ -1,908 +1,908 @@
1
- ---
2
- // The site's root HTML shell: <head> meta/SEO tags, the writedocs.json
3
- // `integrations`/`scripts` passthrough, the color-theme flash-
4
- // prevention script, the dismissible `banner`, and the three-column
5
- // .wd-shell (sidebar/main/toc) that every page's own content lands in.
6
- // Everything else that used to live directly in this file - the topbar,
7
- // the mobile hamburger drawer, the search modal, the footer, and the
8
- // analytics/AI-chat integration scripts - is now its own component,
9
- // composed below. This file had grown to ~2200 lines covering all of
10
- // those unrelated concerns in one place before that split; each piece is
11
- // small enough on its own now to read start-to-finish without losing the
12
- // thread, and a change to (say) the mobile menu no longer means scrolling
13
- // past a thousand lines of unrelated topbar/search/footer code to find
14
- // the right spot. This file is the only .astro file that stays directly
15
- // in src/layout/ - every other component lives in src/layout/components/,
16
- // and every plain .css file (base.css, banner.css, and the rest each
17
- // component below imports for itself) lives in src/layout/styles/ - this
18
- // file is the layout's single entry point/orchestrator, everything else
19
- // is a piece it composes.
20
- import fs from "node:fs";
21
- // Named `nodePath`, not the more natural `path` - this component already
22
- // destructures a prop called `path` (the current page's own URL path,
23
- // see Props below) from Astro.props, which would otherwise shadow a
24
- // module-level `path` import inside this component's own scope, silently
25
- // turning every `path.join(...)` call into a TypeError at render time
26
- // ("path.join is not a function") rather than a compile-time error, since
27
- // both are just plain identifiers to the bundler. Hit and fixed while
28
- // wiring up findRootAssets() below - real bug, not a hypothetical.
29
- import nodePath from "node:path";
30
- import {
31
- resolveSiteUrl,
32
- resolveSiteRoot,
33
- findRootAssets,
34
- resolveNavbarColor,
35
- contrastTextColor,
36
- resolveFonts,
37
- googleFontsHref,
38
- fontFaceRule,
39
- type DocsConfig,
40
- type Selector,
41
- type GlobalDropdownView,
42
- type SeoFields,
43
- } from "../lib/config";
44
- import "../styles/global.css";
45
- // rehypeKatex (astro.config.mjs) renders every $inline$/$$block$$ math
46
- // span into real KaTeX markup at build time - this is the one runtime
47
- // dependency that output needs: layout/glyph CSS for the .katex class
48
- // tree, self-hosted (bundled by Vite, fonts included via its own url()
49
- // asset resolution) rather than a KaTeX CDN link. Loaded site-wide, same
50
- // as global.css above - a page with no math in it pays for one small,
51
- // cached stylesheet and nothing else (no fonts are actually fetched
52
- // unless a page's rendered KaTeX markup uses their glyphs). KaTeX's own
53
- // output deliberately sets no explicit text color, inheriting `color`
54
- // from whatever wraps it - so it already follows this site's light/dark
55
- // theme with no extra CSS needed here.
56
- import "katex/dist/katex.min.css";
57
- import "./styles/base.css";
58
- import "./styles/banner.css";
59
- // Astro's client-side router - swaps <body> content between same-origin
60
- // navigations via the native View Transition API instead of a hard
61
- // browser reload, so the topbar/sidebar/footer don't visibly flash/
62
- // "twitch" on every click the way a full document reload does. Every
63
- // interactive component's own <script> (TopBar's dropdowns, search,
64
- // TableOfContents, Mermaid, the copy-page menu, ...) already calls its
65
- // init function once directly *and* re-registers it on the
66
- // `astro:page-load` event (see e.g. TableOfContents.astro's own
67
- // `initToc(document); document.addEventListener('astro:page-load', ...)`
68
- // pair) - that event only ever fires when this router is active, so this
69
- // was already the intended architecture, just missing this one piece
70
- // that actually turns it on.
71
- import { ClientRouter } from "astro:transitions";
72
- import TopBar from "./components/TopBar.astro";
73
- import MobileMenu from "./components/MobileMenu.astro";
74
- import SearchModal from "./components/SearchModal.astro";
75
- import ImageZoom from "./components/ImageZoom.astro";
76
- import SiteFooter from "./components/SiteFooter.astro";
77
- import AnalyticsScripts from "./components/AnalyticsScripts.astro";
78
- import AskAiWidget from "./components/AskAiWidget.astro";
79
- import ConsentBanner from "./components/ConsentBanner.astro";
80
- import { seoHead, hreflangLinks } from "../lib/seo-tags.js";
81
- import { fontStack, fallbackFontFaces } from "../lib/font-fallback.js";
82
- import { htmlDirective } from "../lib/agent-directive.js";
83
- import { contextMenuOptions } from "../lib/config";
84
- import { jsonLd, serializeJsonLd } from "../lib/json-ld.js";
85
- import { consentOptions } from "../lib/consent.js";
86
- import { oncePerBuild } from "../lib/build-memo.js";
87
- // 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";
90
-
91
- interface Props {
92
- config: DocsConfig;
93
- title: string;
94
- // Falls back to config.description when a page has none of its own -
95
- // see [...slug].astro, which passes entry.data.description straight
96
- // through without resolving the fallback itself.
97
- description?: string;
98
- // The current page's own path (e.g. "/" or "/guides/foo/" - without the
99
- // basePath, which siteUrl carries), used to
100
- // build the canonical <link> and og:url/twitter:url - [...slug].astro
101
- // already computes this via hrefForSlug(currentFileId) for its own
102
- // prev/next links, so it's passed through rather than recomputed here.
103
- path: string;
104
- // Site-wide seo (writedocs.json) merged with this page's own frontmatter
105
- // seo override - see mergeSeo() in lib/config.ts. [...slug].astro does
106
- // the merging; this component just renders the result.
107
- seo?: SeoFields;
108
- // One Selector per level of the active page's navigation path (tabs,
109
- // versions, languages, products, or a dropdown used as a nested level)
110
- // - see resolveSections()/buildSelectors() in lib/config.ts for how
111
- // this is computed from however the site's writedocs.json nests things.
112
- // Passed straight through to TopBar.astro and MobileMenu.astro, which
113
- // each derive their own view of it (TopBar's switcherSelectors/
114
- // tabSelectors vs. MobileMenu's per-level accordion rows).
115
- selectors?: Selector[];
116
- // The always-visible topbar dropdown list from navigation.global.dropdowns
117
- // - independent of the active selectors, shown on every page. Also
118
- // passed straight through to TopBar.astro and MobileMenu.astro.
119
- globalDropdowns?: GlobalDropdownView[];
120
- // Per-page frontmatter `mode` (content.config.ts) - controls how much
121
- // site chrome wraps this page. 'blank' drops the topbar and the whole
122
- // .wd-shell (sidebar/toc columns) entirely, rendering only <slot />
123
- // directly in <body> - see the template below. Every other mode
124
- // (including 'custom') still gets the topbar; [...slug].astro is what
125
- // decides whether to actually pass sidebar/toc slot content for
126
- // 'wide'/'frame'/'custom' (BaseLayout has no sidebar/toc content of its
127
- // own to conditionally omit - an unfilled named slot in Astro already
128
- // renders nothing, so this component only needs to know whether to
129
- // render the *column wrapper divs* at all).
130
- mode?: "default" | "wide" | "frame" | "custom" | "blank";
131
- // The page's language, for <html lang> - the `language` of the
132
- // navigation level it belongs to (see [...slug].astro), or 'en'.
133
- lang?: string;
134
- // This page in each language - `{ lang, href }`, its own included - for
135
- // the hreflang links (languageAlternates() in lib/item-pages.js). Empty for
136
- // a page with no counterpart in another language.
137
- alternates?: { lang: string; href: string }[];
138
- // Home, the linked groups above the page, the page - for the page's
139
- // structured data (lib/json-ld.js).
140
- breadcrumbs?: { name: string; href: string }[];
141
- // An OpenAPI page: its structured data says APIReference.
142
- isApi?: boolean;
143
- }
144
- const {
145
- config,
146
- title,
147
- description,
148
- path,
149
- seo = {},
150
- selectors = [],
151
- globalDropdowns = [],
152
- mode = "default",
153
- lang = "en",
154
- alternates = [],
155
- breadcrumbs = [],
156
- isApi = false,
157
- } = Astro.props as Props;
158
- const showSidebarCol = mode === "default" || mode === "wide";
159
- const showTocCol = mode === "default";
160
- // Meta tag resolution - all derived once here rather than inline in the
161
- // template below, so the JSX stays a straight list of conditional <meta>
162
- // tags instead of repeating this logic at each call site.
163
- // seoHead() (lib/seo-tags.js) decides every tag - the <title>, the canonical
164
- // link, and the description, robots, Open Graph and Twitter metas, with
165
- // `seo.metatags` replacing or adding to them.
166
- const siteUrl = resolveSiteUrl(config);
167
- // The site's logo - the light one, or the dark one when that's all there is -
168
- // for the organization in the structured data.
169
- const siteLogo = typeof config.styles.logo === "string" ? config.styles.logo : (config.styles.logo?.light ?? config.styles.logo?.dark);
170
- const head = seoHead({
171
- title,
172
- siteName: config.name,
173
- description,
174
- siteDescription: config.description,
175
- seo,
176
- siteUrl,
177
- path,
178
- base: BASE,
179
- });
180
- // hreflang: only on a page search engines index, and only with full URLs.
181
- const languageLinks = seo.noindex ? [] : hreflangLinks(siteUrl, alternates);
182
- // Structured data - see lib/json-ld.js for what a page gets.
183
- const structuredData = jsonLd({
184
- siteUrl,
185
- siteName: config.name,
186
- siteDescription: config.description,
187
- title,
188
- description: seo.description ?? description ?? config.description,
189
- path,
190
- canonical: head.canonical,
191
- lang,
192
- mode,
193
- isApi,
194
- noindex: Boolean(seo.noindex),
195
- breadcrumbs,
196
- organization: config.seo.organization,
197
- logo: siteLogo,
198
- socials: config.socials,
199
- custom: seo.jsonLd,
200
- });
201
- // The note that tells an AI agent reading this page where llms.txt is -
202
- // see lib/agent-directive.js.
203
- const agentNote = htmlDirective({ siteUrl: resolveSiteRoot(config) || null, markdownPages: contextMenuOptions(config.contextMenu).length > 0 });
204
- // Analytics wait for the reader's answer when the consent banner is on -
205
- // see lib/consent.js.
206
- const consent = consentOptions(config.integrations.consent);
207
- const gated = (s: { consent?: boolean }) => Boolean(consent && s.consent);
208
- // Light-mode values come straight from styles.colors/styles.background
209
- // (with defaults); dark-mode values fall back to their light counterpart
210
- // when the site's own dark override doesn't set them, so a site only has
211
- // to specify what actually changes for dark mode. Both sets are always
212
- // computed and handed to the CSS below (light-mode ones as sensible
213
- // starting defaults, but the .wd-* class hides/shows appropriately) - see
214
- // the `[data-theme="dark"]` override rule below, which is what actually
215
- // switches which set is live. Unlike every other bit of CSS this file
216
- // used to own directly, this specific pair of rules can't move into a
217
- // plain external .css file the way base.css/banner.css did - `define:vars`
218
- // (right below) is what lets these raw hex/URL values get interpolated
219
- // into custom-property assignments at all, and that directive only works
220
- // on a <style> tag physically inside an .astro file's own template.
221
- const lightPrimary = config.styles.colors.primary;
222
- const lightText = config.styles.colors.text ?? "#404045";
223
- const darkPrimary = config.styles.colors.dark?.primary ?? lightPrimary;
224
- // Body text - also the sidebar's and table of contents' links. Headings,
225
- // bold text and group titles use the stronger --wd-heading (below).
226
- const darkText = config.styles.colors.dark?.text ?? "#a0a0a5";
227
- // Text drawn on the primary color (step numbers, the info banner, the API
228
- // playground's buttons) - white, or black on a clearly light primary
229
- // (contrastTextColor(), lib/config.ts). It used to be white everywhere,
230
- // unreadable on a light primary - and a light dark-mode primary is exactly
231
- // what dark-mode links need.
232
- const lightOnPrimary = contrastTextColor(lightPrimary);
233
- const darkOnPrimary = contrastTextColor(darkPrimary);
234
- // styles.background.colors is now the single source for any background
235
- // color - both the flat --wd-background surface (dropdowns/modals/kbd
236
- // chips/footer/topbar-fallback/etc., every other `var(--wd-background)`
237
- // call site) and the <body> canvas paint below. There used to be a
238
- // separate styles.colors.background/colors.dark.background pair driving
239
- // just the --wd-background half, independent of this - see config.ts's
240
- // own comment on why that split was removed; `lightBackground`/
241
- // `darkBackground` here is what used to read that other field.
242
- const lightBackground = config.styles.background?.colors?.light ?? "#ffffff";
243
- const darkBackground = config.styles.background?.colors?.dark ?? "#0b1120";
244
- // The topbar/mobile-menu-panel background - falls back to the page's own
245
- // background (above) when a site doesn't set it, so an unconfigured navbar
246
- // keeps blending into the page exactly as it always has; only sites that
247
- // explicitly set `styles.navbar.light`/`.dark` get a topbar that looks
248
- // different from the page behind it. resolveNavbarColor() (lib/config.ts)
249
- // is what splits the string-or-{background,accent} union `navbar.light`/
250
- // `.dark` can now be into its two parts - see its own comment.
251
- const navLight = resolveNavbarColor(config.styles.navbar?.light, lightBackground);
252
- const navDark = resolveNavbarColor(config.styles.navbar?.dark, darkBackground);
253
- const lightNavbarBg = navLight.background;
254
- const darkNavbarBg = navDark.background;
255
- // Whether this side of `styles.navbar` was configured at all - string or
256
- // object form, doesn't matter, just "is there a writedocs.json value here" -
257
- // not merely "does lightNavbarBg differ from the page background", since
258
- // a site could deliberately set navbar to the *same* color as the page
259
- // background and this should still count as configured. What this gates:
260
- // once true, the navbar's own text/icon color stops assuming it's sitting
261
- // on something close to the page background (--wd-text's own tuning
262
- // target) and switches to being computed fresh against whatever
263
- // `background` actually resolved to.
264
- const lightNavbarConfigured = config.styles.navbar?.light !== undefined;
265
- const darkNavbarConfigured = config.styles.navbar?.dark !== undefined;
266
- // --wd-navbar-foreground/-muted: the topbar's own text/icon color, plain
267
- // (resting) state. Never a writedocs.json value, even indirectly - always
268
- // contrastTextColor(lightNavbarBg) (lib/config.ts, picks black or white by
269
- // luminance) the moment this side of `navbar` is configured at all, or the
270
- // literal --wd-text/--wd-text-muted var references when it isn't, so an
271
- // unconfigured navbar renders pixel-identical to before this feature
272
- // existed. An earlier version of this let an object-form field double as
273
- // both "the navbar's accent color" and "the navbar's text color" - real
274
- // bug, caught immediately: a site picking a light accent (to stay legible
275
- // against a dark/saturated background, the whole point of setting it) got
276
- // that same light color as its *text*, which is exactly backwards. Text
277
- // legibility isn't a design choice worth exposing at all here - it's
278
- // always computed, correctly, every time. The muted variant mixes that
279
- // same resolved color toward transparent (not toward lightNavbarBg, which
280
- // would drag it back toward the background's own hue and undo the
281
- // contrast fix) - a plain opacity reduction, so it stays legible
282
- // regardless of what hue the navbar itself happens to be.
283
- const lightNavbarFg = lightNavbarConfigured ? contrastTextColor(lightNavbarBg) : "var(--wd-text)";
284
- const darkNavbarFg = darkNavbarConfigured ? contrastTextColor(darkNavbarBg) : "var(--wd-text)";
285
- // The current tab (and a hovered one) stands out: the heading color on the
286
- // page's own background, or the same computed black/white on a configured
287
- // navbar - which is already the strongest color there.
288
- const lightNavbarFgStrong = lightNavbarConfigured ? lightNavbarFg : "var(--wd-heading)";
289
- const darkNavbarFgStrong = darkNavbarConfigured ? darkNavbarFg : "var(--wd-heading)";
290
- const lightNavbarFgMuted = lightNavbarConfigured
291
- ? `color-mix(in srgb, ${lightNavbarFg} 70%, transparent)`
292
- : "var(--wd-text-muted)";
293
- const darkNavbarFgMuted = darkNavbarConfigured
294
- ? `color-mix(in srgb, ${darkNavbarFg} 70%, transparent)`
295
- : "var(--wd-text-muted)";
296
- // --wd-navbar-accent: the tab-hover-underline/active-tab-fill color inside
297
- // the topbar specifically - `accent` on the object form (a real, legitimate
298
- // design choice, unlike text color above), falling back to the sitewide
299
- // --wd-primary (today's exact behavior) when unset - a site that sets a
300
- // navbar background but no accent keeps its ordinary brand-colored
301
- // active-tab underline.
302
- const lightNavbarAccent = navLight.accent ?? lightPrimary;
303
- const darkNavbarAccent = navDark.accent ?? darkPrimary;
304
- // --wd-navbar-border: the switcher pills' (version/language/product) own
305
- // border. Never the flat --wd-border (a fixed neutral gray/slate tuned for
306
- // sitting on the page background) once navbar is configured - that reads
307
- // as a harsh, near-white outline against a saturated/colored navbar
308
- // background, since it's not picked with that background in mind at all.
309
- // Same mix-toward-transparent technique as the muted foreground above: a
310
- // low-opacity tint of the already-contrast-correct navbarFg, so it stays
311
- // soft and legible against any navbar hue instead of a flat, unrelated
312
- // gray. Unconfigured navbar keeps the literal var(--wd-border) reference,
313
- // pixel-identical to before this existed.
314
- const lightNavbarBorder = lightNavbarConfigured
315
- ? `color-mix(in srgb, ${lightNavbarFg} 25%, transparent)`
316
- : "var(--wd-border)";
317
- const darkNavbarBorder = darkNavbarConfigured
318
- ? `color-mix(in srgb, ${darkNavbarFg} 25%, transparent)`
319
- : "var(--wd-border)";
320
- // --wd-navbar-hover: a topbar tab's background on hover. On a navbar with
321
- // the page's own background, the sidebar's hover tint (NavTree.astro) -
322
- // the same 6% of --wd-primary. A configured navbar can *be* the primary
323
- // color, where that tint would vanish, so there it's a light tint of the
324
- // navbar's own contrast-correct text color instead, like --wd-navbar-border.
325
- const sidebarHover = "color-mix(in srgb, var(--wd-primary) 6%, transparent)";
326
- const lightNavbarHover = lightNavbarConfigured ? `color-mix(in srgb, ${lightNavbarFg} 12%, transparent)` : sidebarHover;
327
- const darkNavbarHover = darkNavbarConfigured ? `color-mix(in srgb, ${darkNavbarFg} 12%, transparent)` : sidebarHover;
328
- // The <body> canvas's own paint - same color as --wd-background above
329
- // (there's only one background color to configure now), plus an optional
330
- // image layered on top. `images.light`/`.dark` are plain public/-relative
331
- // paths (same convention as styles.logo/favicon) - wrapped in url(...) here
332
- // (or 'none' when unset) since CSS custom properties can't have url()
333
- // applied to them after the fact (`url(var(--x))` isn't valid CSS - the
334
- // value itself has to already be a full `url(...)` token, which is what
335
- // these two variables hold).
336
- const lightPageBgColor = lightBackground;
337
- const darkPageBgColor = darkBackground;
338
- const lightPageBgImage = config.styles.background?.images?.light
339
- ? `url('${siteHref(config.styles.background.images.light)}')`
340
- : "none";
341
- const darkPageBgImage = config.styles.background?.images?.dark
342
- ? `url('${siteHref(config.styles.background.images.dark)}')`
343
- : "none";
344
- // A logo is either one path used for both modes, or a {light, dark,
345
- // label} object - normalized to a single light/dark pair here (the one
346
- // place that needs to know which form writedocs.json used) so TopBar.astro,
347
- // MobileMenu.astro, and SiteFooter.astro - each of which render their own
348
- // copy of the brand link - never need to branch on it themselves. The
349
- // brand link shows the image(s) alone by default - no site name text next
350
- // to it, since a real logo asset is usually already a wordmark. `label`
351
- // (only settable on the object form - see config.ts) opts back into
352
- // showing text next to the image - or, since `light`/`dark` are
353
- // themselves optional on that form, stands entirely on its own:
354
- // `styles.logo: { label: "..." }` with no images at all overrides just the
355
- // brand text without adding any logo image. A site with neither a logo
356
- // image nor a label falls back to plain config.name text, so the brand
357
- // link is never left empty.
358
- const logo = config.styles.logo;
359
- const logoLight = typeof logo === "string" ? logo : logo?.light;
360
- const logoDark = typeof logo === "string" ? logo : logo?.dark;
361
- const logoLabel = typeof logo === "string" ? undefined : logo?.label;
362
- const hasLogoImage = Boolean(logoLight || logoDark);
363
- const brandLabel = logoLabel ?? (hasLogoImage ? undefined : config.name);
364
-
365
- // writedocs.json's `footer.logo` (same {light, dark, label} shape as
366
- // `styles.logo` above, via config.ts's shared logoSchema) - unset by
367
- // default, in which case SiteFooter.astro just gets the same
368
- // logoLight/logoDark/logoLabel as the topbar/mobile menu above. Set, it
369
- // replaces those entirely (not just fills in whichever side is missing)
370
- // before ever reaching SiteFooter - a footer wanting a different mark
371
- // than the topbar (or none at all - `styles.logo` set, `footer.logo`
372
- // deliberately absent-of-images-but-present, e.g. `{ label: "" }`, isn't
373
- // a real use case worth solving here) shouldn't still show the sitewide
374
- // one alongside or underneath it.
375
- const footerLogoConfig = config.footer.logo;
376
- const footerLogoLight = footerLogoConfig
377
- ? typeof footerLogoConfig === "string"
378
- ? footerLogoConfig
379
- : footerLogoConfig.light
380
- : logoLight;
381
- const footerLogoDark = footerLogoConfig
382
- ? typeof footerLogoConfig === "string"
383
- ? footerLogoConfig
384
- : footerLogoConfig.dark
385
- : logoDark;
386
-
387
- // Zero-config custom CSS/JS - any `.css`/`.js` file anywhere in the
388
- // project (root, `docs/`, `snippets/`, `public/`, any subfolder -
389
- // `dist/`/`node_modules/`/etc. excluded, see findRootAssets() in
390
- // lib/pages.js) is auto-loaded on every page, no writedocs.json entry
391
- // needed. In `writedocs dev` they're read fresh on every render, so an
392
- // edit to one of these files shows up on the next page load without a
393
- // server restart - same freshness `loadDocsConfig(contentDir)` itself
394
- // already gives writedocs.json edits in [...slug].astro/404.astro. In a
395
- // build, where they can't change, the list and the files are read once
396
- // for all pages (oncePerBuild(), lib/build-memo.js).
397
- // Rendered in addition to, not instead of, writedocs.json's own explicit
398
- // `scripts` field - that still exists for external/CDN script URLs
399
- // (`src`) and inline content that should only load under deliberate
400
- // config, and renders before these so a file living in the project (the
401
- // more locally-owned override) wins over a URL possibly pointing at
402
- // someone else's asset.
403
- const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
404
- const rootAssets = findRootAssets(contentDir);
405
- // `name` is a POSIX-separated path relative to contentDir (e.g.
406
- // "docs/theme.css") - split and rejoin with nodePath.join rather than
407
- // handing the raw string straight to it, so a nested asset resolves
408
- // correctly on every OS this might run on, not just POSIX ones.
409
- const rootCssContents = oncePerBuild("root-css-contents", () => rootAssets.css.map((name) =>
410
- fs.readFileSync(nodePath.join(contentDir, ...name.split("/")), "utf-8"),
411
- ));
412
- const rootJsContents = oncePerBuild("root-js-contents", () => rootAssets.js.map((name) =>
413
- fs.readFileSync(nodePath.join(contentDir, ...name.split("/")), "utf-8"),
414
- ));
415
- // public/*.css and public/*.js auto-load too, but as <link>/<script src>
416
- // pointing at their already-public URL (see findRootAssets()'s own
417
- // comment for why - no point inlining a file that's also independently
418
- // fetchable at that exact URL). publicJsHrefs is filtered against
419
- // writedocs.json's own `scripts.head` so a site that hasn't yet removed an
420
- // explicit `src` entry for the same public/ file doesn't get that href
421
- // rendered twice - the explicit entry still works, it's just redundant
422
- // with this now. publicCssHrefs has no equivalent filter to apply -
423
- // there's no explicit stylesheet-URL config field anymore.
424
- const explicitScriptSrcs = new Set(config.scripts.head.map((s) => s.src).filter((src): src is string => Boolean(src)));
425
- const publicCssHrefs = rootAssets.publicCss;
426
- const publicJsHrefs = rootAssets.publicJs.filter((href) => !explicitScriptSrcs.has(href));
427
-
428
- // styles.fonts (see fontsSchema/resolveFonts() in lib/config.ts) - resolves
429
- // to plain Inter, genuinely loaded via Google Fonts (not just named in a
430
- // fallback stack the way base.css used to), when a site sets no `fonts`
431
- // field at all. `fontStack()` quotes the family name (safe even for a
432
- // single-word name, and required for one with spaces like "Playfair
433
- // Display") and appends the same system-font fallback chain base.css
434
- // always used, so a reader who somehow loads the page before the web font
435
- // finishes fetching still sees a reasonable font rather than the browser
436
- // default serif. `heading`/`body` are left `null` (not defaulted to the
437
- // same value as `base`) whenever a site hasn't overridden them - base.css
438
- // falls back to `--wd-font-family` itself via CSS var(), so a `null` here
439
- // deliberately never gets its own CSS var written into the style block
440
- // below.
441
- const resolvedFonts = resolveFonts(config);
442
- const fontsGoogleHref = googleFontsHref(resolvedFonts);
443
- // fontStack() and the stand-in font that keeps text from moving when the
444
- // web font arrives are in lib/font-fallback.js.
445
- // heading/body already fall back to `resolvedFonts.base` right here (not
446
- // left as a CSS var() fallback chain for :root below to resolve) - same
447
- // "fully resolve in JS, plain values into define:vars" approach every
448
- // other themeable value in this file already uses (see lightPrimary/
449
- // darkPrimary etc. above), rather than introducing a different pattern
450
- // just for fonts.
451
- const wdFontFamily = fontStack(resolvedFonts.base.family);
452
- const wdFontFamilyHeading = resolvedFonts.heading ? fontStack(resolvedFonts.heading.family) : wdFontFamily;
453
- const wdFontFamilyBody = resolvedFonts.body ? fontStack(resolvedFonts.body.family) : wdFontFamily;
454
- // One @font-face rule per source-based font actually configured (Google
455
- // Fonts, covered by fontsGoogleHref above instead, never reach here) - this
456
- // only ever gets the right *file* loaded (the @font-face `font-weight`
457
- // descriptor, or the Google Fonts URL's `:wght@` axis inside
458
- // googleFontsHref() above), not the actual rendered boldness of any
459
- // element - see wdFontWeightCss right below for that other half.
460
- // A `source` in the project is a site address: it gets the basePath.
461
- const withSourceBase = <T extends { source?: string } | null>(font: T): T =>
462
- font?.source ? { ...font, source: siteHref(font.source) } : font;
463
- const fontFaceCss = [
464
- fontFaceRule(withSourceBase(resolvedFonts.base)),
465
- fontFaceRule(withSourceBase(resolvedFonts.heading)),
466
- fontFaceRule(withSourceBase(resolvedFonts.body)),
467
- ]
468
- .filter(Boolean)
469
- .join("\n");
470
- // Without this, a configured `weight` only ever changed which font *file*
471
- // loaded - h1-h6 still rendered at the browser's own default `font-weight:
472
- // bold` (a user-agent-stylesheet rule, present regardless of which file
473
- // actually loaded), so a heading weight of e.g. 400 was silently faux-
474
- // bolded back to looking bold anyway, with no visible effect from
475
- // changing the config at all. `resolvedFonts.heading?.weight ?? base.weight`
476
- // falls back the same way family already does (an override with no
477
- // weight of its own still inherits the top-level one); `undefined` when
478
- // nothing at any level configured a weight, which deliberately renders no
479
- // rule at all here - an unconfigured site keeps today's plain browser-
480
- // default bold headings/normal body text exactly as before this feature
481
- // existed, not a forced 400/700 nobody asked for.
482
- const wdFontWeightHeading = resolvedFonts.heading?.weight ?? resolvedFonts.base.weight;
483
- const wdFontWeightBody = resolvedFonts.body?.weight ?? resolvedFonts.base.weight;
484
- const fontWeightCss = [
485
- wdFontWeightHeading !== undefined ? `h1, h2, h3, h4, h5, h6 { font-weight: ${wdFontWeightHeading}; }` : "",
486
- wdFontWeightBody !== undefined ? `body { font-weight: ${wdFontWeightBody}; }` : "",
487
- ]
488
- .filter(Boolean)
489
- .join("\n");
490
- // The stand-in for each font that has one (lib/font-fallback.js) - the
491
- // stacks above already name it, right after the font itself.
492
- const fontFallbackCss = fallbackFontFaces(
493
- [resolvedFonts.base, resolvedFonts.heading, resolvedFonts.body].filter(Boolean).map((font) => font!.family),
494
- );
495
- const fontExtraCss = [fontFaceCss, fontFallbackCss, fontWeightCss].filter(Boolean).join("\n");
496
- ---
497
-
498
- <!doctype html>
499
- <html lang={lang}>
500
- <head>
501
- <meta charset="UTF-8" />
502
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
503
- {/* Marks the pages writedocs renders - the build checks each has the site's styles (cli/check-built-styles.js). */}
504
- <meta name="generator" content="writedocs" />
505
- <title>{head.title}</title>
506
- <ClientRouter />
507
- {head.canonical && <link rel="canonical" href={head.canonical} />}
508
- {languageLinks.map((link) => <link rel="alternate" hreflang={link.hreflang} href={link.href} />)}
509
- {
510
- head.metas.map((meta) =>
511
- meta.attr === "property" ? (
512
- <meta property={meta.key} content={meta.content} />
513
- ) : (
514
- <meta name={meta.key} content={meta.content} />
515
- ),
516
- )
517
- }
518
- {config.styles.favicon && <link rel="icon" href={siteHref(config.styles.favicon)} />}
519
- {
520
- /* styles.fonts - see resolveFonts()/googleFontsHref() in lib/config.ts.
521
- Present (non-null) whenever at least one configured font (or the
522
- Inter default, when styles.fonts is unset entirely) has no `source`
523
- - i.e. is a Google Font, auto-loaded by family name. The two
524
- preconnect hints warm up the connections googleapis.com's own CSS
525
- response will immediately need (its @font-face rules point at
526
- gstatic.com for the actual font files) before the browser has even
527
- parsed that response - Google's own recommended pattern for using
528
- their fonts. Rendered this early in <head> (right after favicon,
529
- before Open Graph/Twitter meta) so the font starts loading as soon
530
- as possible rather than competing with less render-critical tags
531
- for bandwidth/priority. */
532
- }
533
- {
534
- fontsGoogleHref && (
535
- <>
536
- <link rel="preconnect" href="https://fonts.googleapis.com" />
537
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
538
- <link rel="stylesheet" href={fontsGoogleHref} />
539
- </>
540
- )
541
- }
542
- {
543
- /* writedocs.json's `integrations` (the six analytics providers) - see
544
- AnalyticsScripts.astro. Rendered as early in <head> as reasonably
545
- possible (right after the meta tags, before even the theme-
546
- detection script below) - the usual placement every one of these
547
- providers' own install instructions ask for, so pageview timing is
548
- captured as close to actual page load as it can be. */
549
- }
550
- {structuredData.map((block) => <script is:inline type="application/ld+json" set:html={serializeJsonLd(block)} />)}
551
- <AnalyticsScripts
552
- config={config}
553
- consent={consent}
554
- gatedScripts={[...config.scripts.head, ...config.scripts.body].filter(gated)}
555
- />
556
- <script is:inline>
557
- // Sets [data-theme] and [data-banner-dismissed] on <html> before
558
- // first paint, so the page never flashes the wrong mode or an
559
- // already-dismissed banner. Preference order for theme: an explicit
560
- // prior choice (localStorage), then the OS-level preference,
561
- // defaulting to light. The click handlers that update both live in
562
- // src/scripts/theme-toggle.ts and src/scripts/banner.ts.
563
- //
564
- // Also re-run on `astro:after-swap` (ClientRouter, see BaseLayout's
565
- // own import of it below), not just the initial load - Astro's
566
- // client-side navigation swaps <html>'s attributes wholesale to
567
- // match the newly-fetched page's raw server-rendered markup (see
568
- // swapRootAttributes() in astro/dist/transitions/swap-functions.js),
569
- // which has neither of these dataset attributes baked in since
570
- // they're pure client-side runtime state, not something the server
571
- // ever renders. Without re-running this after every swap, a
572
- // dismissed banner (or a chosen dark theme) would silently come
573
- // back on the very next navigation - both attributes get wiped, not
574
- // just reset to their default, so this has to unconditionally
575
- // reapply them from localStorage every time, exactly as it does on
576
- // first load. `astro:after-swap` fires synchronously right after
577
- // that swap and before the browser's next paint, so this still
578
- // prevents any visible flash on client-side navigations too.
579
- function wdApplyStoredPreferences() {
580
- try {
581
- var stored = localStorage.getItem("wd-theme");
582
- var theme =
583
- stored === "light" || stored === "dark"
584
- ? stored
585
- : window.matchMedia("(prefers-color-scheme: dark)").matches
586
- ? "dark"
587
- : "light";
588
- document.documentElement.dataset.theme = theme;
589
- } catch (e) {
590
- document.documentElement.dataset.theme = "light";
591
- }
592
- try {
593
- document.documentElement.dataset.bannerDismissed =
594
- localStorage.getItem("wd-banner-dismissed") === "true" ? "true" : "false";
595
- } catch (e) {
596
- document.documentElement.dataset.bannerDismissed = "false";
597
- }
598
- }
599
- wdApplyStoredPreferences();
600
- document.addEventListener("astro:after-swap", wdApplyStoredPreferences);
601
- </script>
602
- <script>
603
- // Preserves the sidebar's own scroll position across a ClientRouter
604
- // navigation - see src/scripts/sidebar-scroll.ts for why this is
605
- // needed at all (the sidebar is re-rendered fresh, server-side, on
606
- // every page, so it's a brand-new DOM node each time, reset to
607
- // scrollTop 0 like a real page reload would be). Same before-swap/
608
- // after-swap pairing as wdApplyStoredPreferences above, and for the
609
- // same reason: after-swap fires before the next paint, so there's no
610
- // visible flash of the sidebar sitting at the top before jumping
611
- // back to where the reader had it scrolled.
612
- import { saveSidebarScroll, restoreSidebarScroll } from "../scripts/sidebar-scroll";
613
-
614
- document.addEventListener("astro:before-swap", saveSidebarScroll);
615
- document.addEventListener("astro:after-swap", restoreSidebarScroll);
616
- </script>
617
- <style
618
- define:vars={{
619
- wdPrimaryLight: lightPrimary,
620
- wdOnPrimaryLight: lightOnPrimary,
621
- wdBackgroundLight: lightBackground,
622
- wdTextLight: lightText,
623
- wdNavbarLight: lightNavbarBg,
624
- wdNavbarFgLight: lightNavbarFg,
625
- wdNavbarFgStrongLight: lightNavbarFgStrong,
626
- wdNavbarFgMutedLight: lightNavbarFgMuted,
627
- wdNavbarAccentLight: lightNavbarAccent,
628
- wdNavbarBorderLight: lightNavbarBorder,
629
- wdNavbarHoverLight: lightNavbarHover,
630
- wdPageBgColorLight: lightPageBgColor,
631
- wdPageBgImageLight: lightPageBgImage,
632
- wdFontFamily,
633
- wdFontFamilyHeading,
634
- wdFontFamilyBody,
635
- wdPrimaryDark: darkPrimary,
636
- wdOnPrimaryDark: darkOnPrimary,
637
- wdBackgroundDark: darkBackground,
638
- wdTextDark: darkText,
639
- wdNavbarDark: darkNavbarBg,
640
- wdNavbarFgDark: darkNavbarFg,
641
- wdNavbarFgStrongDark: darkNavbarFgStrong,
642
- wdNavbarFgMutedDark: darkNavbarFgMuted,
643
- wdNavbarAccentDark: darkNavbarAccent,
644
- wdNavbarBorderDark: darkNavbarBorder,
645
- wdNavbarHoverDark: darkNavbarHover,
646
- wdPageBgColorDark: darkPageBgColor,
647
- wdPageBgImageDark: darkPageBgImage,
648
- }}
649
- >
650
- :root {
651
- --wd-primary: var(--wdPrimaryLight);
652
- --wd-on-primary: var(--wdOnPrimaryLight);
653
- --wd-background: var(--wdBackgroundLight);
654
- --wd-text: var(--wdTextLight);
655
- --wd-navbar-background: var(--wdNavbarLight);
656
- --wd-navbar-foreground: var(--wdNavbarFgLight);
657
- --wd-navbar-foreground-strong: var(--wdNavbarFgStrongLight);
658
- --wd-navbar-foreground-muted: var(--wdNavbarFgMutedLight);
659
- --wd-navbar-accent: var(--wdNavbarAccentLight);
660
- --wd-navbar-border: var(--wdNavbarBorderLight);
661
- --wd-navbar-hover: var(--wdNavbarHoverLight);
662
- --wd-page-bg-color: var(--wdPageBgColorLight);
663
- --wd-page-bg-image: var(--wdPageBgImageLight);
664
- --wd-text-muted: #64748b;
665
- /* Headings, bold text, card titles, and the sidebar's group titles -
666
- a stronger color than body text (--wd-text), which the sidebar's
667
- and table of contents' links use (--wd-nav-text). */
668
- --wd-heading: #18191d;
669
- --wd-nav-title: var(--wd-heading);
670
- --wd-nav-text: var(--wd-text);
671
- --wd-border: #e2e8f0;
672
- --wd-surface: #f8fafc;
673
- /* The browser's own controls - the page's scrollbar, a code block's -
674
- drawn for the theme on screen. Without it they stayed light in dark
675
- mode. */
676
- color-scheme: light;
677
- /* Not mode-dependent (a site's chosen font doesn't change between
678
- light/dark) - set once here rather than duplicated in the
679
- :root[data-theme='dark'] block below. */
680
- --wd-font-family: var(--wdFontFamily);
681
- --wd-font-family-heading: var(--wdFontFamilyHeading);
682
- --wd-font-family-body: var(--wdFontFamilyBody);
683
- }
684
- /* Higher specificity than the plain :root rule above (an attribute
685
- selector on :root beats an unqualified one), so this wins
686
- regardless of source order once data-theme is set to "dark" by
687
- the inline script above or the toggle button's click handler
688
- (src/scripts/theme-toggle.ts). */
689
- :root[data-theme="dark"] {
690
- --wd-primary: var(--wdPrimaryDark);
691
- --wd-on-primary: var(--wdOnPrimaryDark);
692
- --wd-background: var(--wdBackgroundDark);
693
- --wd-text: var(--wdTextDark);
694
- --wd-navbar-background: var(--wdNavbarDark);
695
- --wd-navbar-foreground: var(--wdNavbarFgDark);
696
- --wd-navbar-foreground-strong: var(--wdNavbarFgStrongDark);
697
- --wd-navbar-foreground-muted: var(--wdNavbarFgMutedDark);
698
- --wd-navbar-accent: var(--wdNavbarAccentDark);
699
- --wd-navbar-border: var(--wdNavbarBorderDark);
700
- --wd-navbar-hover: var(--wdNavbarHoverDark);
701
- --wd-page-bg-color: var(--wdPageBgColorDark);
702
- --wd-page-bg-image: var(--wdPageBgImageDark);
703
- --wd-text-muted: #94a3b8;
704
- --wd-heading: #e0e0e5;
705
- --wd-border: #1e293b;
706
- --wd-surface: #131a2b;
707
- color-scheme: dark;
708
- }
709
- </style>
710
- {
711
- /* styles.fonts: local/externally-hosted font(s) (fontFaceRule() in
712
- lib/config.ts - a local `source` path resolves the same way
713
- styles.favicon/styles.logo/styles.background.images already do, see
714
- collectConfiguredAssetPaths() + styles-asset-integration.js, no
715
- extra wiring needed here beyond listing it there), plus a
716
- font-weight override for h1-h6/body whenever `weight` was actually
717
- configured somewhere (fontWeightCss above) - both concatenated
718
- into one block since both need the same raw-CSS-text treatment.
719
- set:html (not a plain <style>{fontExtraCss}</style>) because this
720
- needs to render already-built CSS text as-is, not have Astro's own
721
- CSS parser/scoper attempt to process an `@font-face` block or a
722
- bare `h1, h2, ...` selector list assembled as a runtime string -
723
- empty string renders nothing when neither piece has anything to
724
- contribute (every configured font is a Google Font, and no
725
- `weight` was set anywhere in `styles.fonts`). */
726
- }
727
- {fontExtraCss && <style set:html={fontExtraCss} />}
728
- {
729
- /* writedocs.json's `scripts.head` - see scriptEntrySchema in lib/config.ts.
730
- Each entry is exactly one of an external/local `src` or inline
731
- `content` (enforced by the schema's own .refine()), rendered right
732
- before </head> so it runs before body content paints - the usual
733
- spot a third-party script's own install instructions ask for. */
734
- }
735
- {
736
- config.scripts.head
737
- .filter((s) => !gated(s))
738
- .map((s) => (s.src ? <script is:inline src={siteHref(s.src)} /> : <script is:inline set:html={s.content} />))
739
- }
740
- {
741
- /* Zero-config custom CSS - see findRootAssets() in lib/pages.js and
742
- rootCssContents above. Rendered last in <head>, so a project-owned
743
- file - anywhere in the project, not just the root - wins over
744
- everything else writedocs generates itself. Inlined as raw <style>
745
- content rather than a <link> - these files aren't necessarily under
746
- `public/`, so there's no guaranteed build-time copy step making them
747
- independently fetchable as a URL; inlining sidesteps needing one.
748
- One <style> tag per file (not concatenated) so each is independently
749
- visible/attributable
750
- in devtools. */
751
- }
752
- {rootCssContents.map((content) => <style is:inline set:html={content} />)}
753
- {
754
- /* Zero-config custom CSS living in public/ - see findRootAssets()'s
755
- own comment in lib/pages.js for why these render as <link> tags
756
- pointing at their already-public URL instead of joining
757
- rootCssContents above as inlined content. */
758
- }
759
- {publicCssHrefs.map((href) => <link rel="stylesheet" href={siteHref(href)} />)}
760
- </head>
761
- <body>
762
- {
763
- /* For AI agents, first thing in the page: where the documentation index
764
- is (lib/agent-directive.js). Not for people - hidden from sight
765
- (.wd-agent-note, base.css) and from screen readers, its link out of
766
- the tab order, and kept out of search snippets and the site's search. */
767
- }
768
- <div class="wd-agent-note" aria-hidden="true" data-nosnippet data-pagefind-ignore>
769
- {agentNote.before}<a href={agentNote.href} tabindex="-1">{agentNote.link}</a>{agentNote.after}
770
- </div>
771
- {
772
- mode === "blank" ? (
773
- // No site chrome at all - no topbar, no sidebar/toc columns, not
774
- // even the .wd-shell wrapper's own max-width - the page's own
775
- // MDX/components control 100% of the layout, including whether
776
- // there's any nav/branding at all. SearchModal.astro's own overlay
777
- // markup and its ⌘K listener still work even with no visible
778
- // trigger button to click (it's rendered unconditionally below,
779
- // outside this mode === 'blank' branch), so that's left in rather
780
- // than also gated on mode.
781
- <slot />
782
- ) : (
783
- <Fragment>
784
- {/* Everything above the footer, in one wrapper - see .wd-page/body in
785
- base.css: body is a flex column, this is its flex: 1 0 auto item,
786
- and the footer (a plain sibling below, not inside this wrapper) is
787
- what that pushes down to the viewport's bottom edge on a page
788
- short enough not to need scrolling - the "sticky footer" pattern,
789
- not position: sticky/fixed (either of which would cover page
790
- content instead of just trailing it once actually reached). */}
791
- <div class="wd-page">
792
- {config.banner && (
793
- <div class={`wd-banner wd-banner-${config.banner.type}`} id="wd-banner">
794
- <div class="wd-banner-inner">
795
- <span class="wd-banner-content">{config.banner.content}</span>
796
- {config.banner.dismissible && (
797
- <button type="button" class="wd-banner-dismiss" aria-label="Dismiss banner" data-banner-dismiss>
798
- &times;
799
- </button>
800
- )}
801
- </div>
802
- </div>
803
- )}
804
- <TopBar
805
- config={config}
806
- selectors={selectors}
807
- globalDropdowns={globalDropdowns}
808
- showSidebarCol={showSidebarCol}
809
- logoLight={logoLight}
810
- logoDark={logoDark}
811
- brandLabel={brandLabel}
812
- />
813
- <MobileMenu
814
- config={config}
815
- selectors={selectors}
816
- globalDropdowns={globalDropdowns}
817
- showSidebarCol={showSidebarCol}
818
- logoLight={logoLight}
819
- logoDark={logoDark}
820
- brandLabel={brandLabel}
821
- />
822
- <div class="wd-shell">
823
- {showSidebarCol && (
824
- <div class="wd-sidebar-col">
825
- <slot name="sidebar" />
826
- </div>
827
- )}
828
- <div class="wd-main-col">
829
- <slot />
830
- </div>
831
- {showTocCol && (
832
- <div class="wd-toc-col">
833
- <slot name="toc" />
834
- </div>
835
- )}
836
- </div>
837
- </div>
838
- <SiteFooter config={config} logoLight={footerLogoLight} logoDark={footerLogoDark} />
839
- </Fragment>
840
- )
841
- }
842
-
843
- <SearchModal />
844
- <ImageZoom />
845
- {consent && <ConsentBanner consent={consent} />}
846
-
847
- <script>
848
- import { initBanner } from "../scripts/banner";
849
- import { initTopbarOffset } from "../scripts/topbar-offset";
850
-
851
- initBanner(document);
852
- document.addEventListener("astro:page-load", () => initBanner(document));
853
-
854
- // No ordering dependency on initBanner above - see topbar-offset.ts
855
- // for why it measures only the topbar itself (not the banner) and
856
- // why that's live-measured rather than a fixed CSS value.
857
- initTopbarOffset();
858
- document.addEventListener("astro:page-load", () => initTopbarOffset());
859
- </script>
860
- {
861
- /* writedocs.json's `scripts.body` - see scriptEntrySchema in lib/config.ts.
862
- Rendered after everything above (including every component's own
863
- <script> tags, which Astro/Vite already bundles to run in document
864
- order) so it runs after every other script on the page has already
865
- loaded/hydrated - matching where a third-party script's own install
866
- instructions usually ask for a "body end" placement. */
867
- }
868
- {
869
- config.scripts.body
870
- .filter((s) => !gated(s))
871
- .map((s) => (s.src ? <script is:inline src={siteHref(s.src)} /> : <script is:inline set:html={s.content} />))
872
- }
873
- {
874
- /* Zero-config custom JS - see findRootAssets() in lib/pages.js and
875
- rootJsContents above. Rendered last, after writedocs.json's own
876
- `scripts.body`, same "most locally-owned override runs last"
877
- reasoning as the root CSS above. `is:inline` here isn't optional -
878
- without it, Astro tries to process/bundle the tag as a module and
879
- the build fails outright ("Cannot find the built path for ...
880
- type=script&index=N") the same way a dynamic-`src` script did
881
- while this file's own writedocs.json `scripts` support was first being
882
- built - see that feature's own commit for the full story. */
883
- }
884
- {rootJsContents.map((content) => <script is:inline set:html={content} />)}
885
- {
886
- /* Zero-config custom JS living in public/ - see this file's own CSS
887
- equivalent above and findRootAssets()'s comment in lib/pages.js.
888
- `<script src>`, not `is:inline set:html` - the file's already a
889
- fetchable URL, no reason to inline its content. Filtered against
890
- config.scripts.head's own `src` entries (publicJsHrefs) for the
891
- same duplicate-tag reason as the CSS <link>s above - note this
892
- only dedupes against `scripts.head`, not `scripts.body` (a public/
893
- file explicitly listed there instead would still also render here
894
- as a second tag; `scripts.head` vs `scripts.body` placement is a
895
- deliberate choice this can't second-guess, but `head` is by far
896
- the more common spot for a plain local script and this hasn't come
897
- up in practice). */
898
- }
899
- {publicJsHrefs.map((href) => <script is:inline src={siteHref(href)} />)}
900
- {
901
- /* writedocs.json's `integrations.askAi` - see AskAiWidget.astro. Rendered
902
- last of all - it's a floating chat widget, not something anything
903
- else on the page depends on running before, so there's no reason
904
- to load it any earlier than absolutely last. */
905
- }
906
- <AskAiWidget config={config} />
907
- </body>
908
- </html>
1
+ ---
2
+ // The site's root HTML shell: <head> meta/SEO tags, the writedocs.json
3
+ // `integrations`/`scripts` passthrough, the color-theme flash-
4
+ // prevention script, the dismissible `banner`, and the three-column
5
+ // .wd-shell (sidebar/main/toc) that every page's own content lands in.
6
+ // Everything else that used to live directly in this file - the topbar,
7
+ // the mobile hamburger drawer, the search modal, the footer, and the
8
+ // analytics/AI-chat integration scripts - is now its own component,
9
+ // composed below. This file had grown to ~2200 lines covering all of
10
+ // those unrelated concerns in one place before that split; each piece is
11
+ // small enough on its own now to read start-to-finish without losing the
12
+ // thread, and a change to (say) the mobile menu no longer means scrolling
13
+ // past a thousand lines of unrelated topbar/search/footer code to find
14
+ // the right spot. This file is the only .astro file that stays directly
15
+ // in src/layout/ - every other component lives in src/layout/components/,
16
+ // and every plain .css file (base.css, banner.css, and the rest each
17
+ // component below imports for itself) lives in src/layout/styles/ - this
18
+ // file is the layout's single entry point/orchestrator, everything else
19
+ // is a piece it composes.
20
+ import fs from "node:fs";
21
+ // Named `nodePath`, not the more natural `path` - this component already
22
+ // destructures a prop called `path` (the current page's own URL path,
23
+ // see Props below) from Astro.props, which would otherwise shadow a
24
+ // module-level `path` import inside this component's own scope, silently
25
+ // turning every `path.join(...)` call into a TypeError at render time
26
+ // ("path.join is not a function") rather than a compile-time error, since
27
+ // both are just plain identifiers to the bundler. Hit and fixed while
28
+ // wiring up findRootAssets() below - real bug, not a hypothetical.
29
+ import nodePath from "node:path";
30
+ import {
31
+ resolveSiteUrl,
32
+ resolveSiteRoot,
33
+ findRootAssets,
34
+ resolveNavbarColor,
35
+ contrastTextColor,
36
+ resolveFonts,
37
+ googleFontsHref,
38
+ fontFaceRule,
39
+ type DocsConfig,
40
+ type Selector,
41
+ type GlobalDropdownView,
42
+ type SeoFields,
43
+ } from "../lib/config";
44
+ import "../styles/global.css";
45
+ // rehypeKatex (astro.config.mjs) renders every $inline$/$$block$$ math
46
+ // span into real KaTeX markup at build time - this is the one runtime
47
+ // dependency that output needs: layout/glyph CSS for the .katex class
48
+ // tree, self-hosted (bundled by Vite, fonts included via its own url()
49
+ // asset resolution) rather than a KaTeX CDN link. Loaded site-wide, same
50
+ // as global.css above - a page with no math in it pays for one small,
51
+ // cached stylesheet and nothing else (no fonts are actually fetched
52
+ // unless a page's rendered KaTeX markup uses their glyphs). KaTeX's own
53
+ // output deliberately sets no explicit text color, inheriting `color`
54
+ // from whatever wraps it - so it already follows this site's light/dark
55
+ // theme with no extra CSS needed here.
56
+ import "katex/dist/katex.min.css";
57
+ import "./styles/base.css";
58
+ import "./styles/banner.css";
59
+ // Astro's client-side router - swaps <body> content between same-origin
60
+ // navigations via the native View Transition API instead of a hard
61
+ // browser reload, so the topbar/sidebar/footer don't visibly flash/
62
+ // "twitch" on every click the way a full document reload does. Every
63
+ // interactive component's own <script> (TopBar's dropdowns, search,
64
+ // TableOfContents, Mermaid, the copy-page menu, ...) already calls its
65
+ // init function once directly *and* re-registers it on the
66
+ // `astro:page-load` event (see e.g. TableOfContents.astro's own
67
+ // `initToc(document); document.addEventListener('astro:page-load', ...)`
68
+ // pair) - that event only ever fires when this router is active, so this
69
+ // was already the intended architecture, just missing this one piece
70
+ // that actually turns it on.
71
+ import { ClientRouter } from "astro:transitions";
72
+ import TopBar from "./components/TopBar.astro";
73
+ import MobileMenu from "./components/MobileMenu.astro";
74
+ import SearchModal from "./components/SearchModal.astro";
75
+ import ImageZoom from "./components/ImageZoom.astro";
76
+ import SiteFooter from "./components/SiteFooter.astro";
77
+ import AnalyticsScripts from "./components/AnalyticsScripts.astro";
78
+ import AskAiWidget from "./components/AskAiWidget.astro";
79
+ import ConsentBanner from "./components/ConsentBanner.astro";
80
+ import { seoHead, hreflangLinks } from "../lib/seo-tags.js";
81
+ import { fontStack, fallbackFontFaces } from "../lib/font-fallback.js";
82
+ import { htmlDirective } from "../lib/agent-directive.js";
83
+ import { contextMenuOptions } from "../lib/config";
84
+ import { jsonLd, serializeJsonLd } from "../lib/json-ld.js";
85
+ import { consentOptions } from "../lib/consent.js";
86
+ import { oncePerBuild } from "../lib/build-memo.js";
87
+ // 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";
90
+
91
+ interface Props {
92
+ config: DocsConfig;
93
+ title: string;
94
+ // Falls back to config.description when a page has none of its own -
95
+ // see [...slug].astro, which passes entry.data.description straight
96
+ // through without resolving the fallback itself.
97
+ description?: string;
98
+ // The current page's own path (e.g. "/" or "/guides/foo/" - without the
99
+ // basePath, which siteUrl carries), used to
100
+ // build the canonical <link> and og:url/twitter:url - [...slug].astro
101
+ // already computes this via hrefForSlug(currentFileId) for its own
102
+ // prev/next links, so it's passed through rather than recomputed here.
103
+ path: string;
104
+ // Site-wide seo (writedocs.json) merged with this page's own frontmatter
105
+ // seo override - see mergeSeo() in lib/config.ts. [...slug].astro does
106
+ // the merging; this component just renders the result.
107
+ seo?: SeoFields;
108
+ // One Selector per level of the active page's navigation path (tabs,
109
+ // versions, languages, products, or a dropdown used as a nested level)
110
+ // - see resolveSections()/buildSelectors() in lib/config.ts for how
111
+ // this is computed from however the site's writedocs.json nests things.
112
+ // Passed straight through to TopBar.astro and MobileMenu.astro, which
113
+ // each derive their own view of it (TopBar's switcherSelectors/
114
+ // tabSelectors vs. MobileMenu's per-level accordion rows).
115
+ selectors?: Selector[];
116
+ // The always-visible topbar dropdown list from navigation.global.dropdowns
117
+ // - independent of the active selectors, shown on every page. Also
118
+ // passed straight through to TopBar.astro and MobileMenu.astro.
119
+ globalDropdowns?: GlobalDropdownView[];
120
+ // Per-page frontmatter `mode` (content.config.ts) - controls how much
121
+ // site chrome wraps this page. 'blank' drops the topbar and the whole
122
+ // .wd-shell (sidebar/toc columns) entirely, rendering only <slot />
123
+ // directly in <body> - see the template below. Every other mode
124
+ // (including 'custom') still gets the topbar; [...slug].astro is what
125
+ // decides whether to actually pass sidebar/toc slot content for
126
+ // 'wide'/'frame'/'custom' (BaseLayout has no sidebar/toc content of its
127
+ // own to conditionally omit - an unfilled named slot in Astro already
128
+ // renders nothing, so this component only needs to know whether to
129
+ // render the *column wrapper divs* at all).
130
+ mode?: "default" | "wide" | "frame" | "custom" | "blank";
131
+ // The page's language, for <html lang> - the `language` of the
132
+ // navigation level it belongs to (see [...slug].astro), or 'en'.
133
+ lang?: string;
134
+ // This page in each language - `{ lang, href }`, its own included - for
135
+ // the hreflang links (languageAlternates() in lib/item-pages.js). Empty for
136
+ // a page with no counterpart in another language.
137
+ alternates?: { lang: string; href: string }[];
138
+ // Home, the linked groups above the page, the page - for the page's
139
+ // structured data (lib/json-ld.js).
140
+ breadcrumbs?: { name: string; href: string }[];
141
+ // An OpenAPI page: its structured data says APIReference.
142
+ isApi?: boolean;
143
+ }
144
+ const {
145
+ config,
146
+ title,
147
+ description,
148
+ path,
149
+ seo = {},
150
+ selectors = [],
151
+ globalDropdowns = [],
152
+ mode = "default",
153
+ lang = "en",
154
+ alternates = [],
155
+ breadcrumbs = [],
156
+ isApi = false,
157
+ } = Astro.props as Props;
158
+ const showSidebarCol = mode === "default" || mode === "wide";
159
+ const showTocCol = mode === "default";
160
+ // Meta tag resolution - all derived once here rather than inline in the
161
+ // template below, so the JSX stays a straight list of conditional <meta>
162
+ // tags instead of repeating this logic at each call site.
163
+ // seoHead() (lib/seo-tags.js) decides every tag - the <title>, the canonical
164
+ // link, and the description, robots, Open Graph and Twitter metas, with
165
+ // `seo.metatags` replacing or adding to them.
166
+ const siteUrl = resolveSiteUrl(config);
167
+ // The site's logo - the light one, or the dark one when that's all there is -
168
+ // for the organization in the structured data.
169
+ const siteLogo = typeof config.styles.logo === "string" ? config.styles.logo : (config.styles.logo?.light ?? config.styles.logo?.dark);
170
+ const head = seoHead({
171
+ title,
172
+ siteName: config.name,
173
+ description,
174
+ siteDescription: config.description,
175
+ seo,
176
+ siteUrl,
177
+ path,
178
+ base: BASE,
179
+ });
180
+ // hreflang: only on a page search engines index, and only with full URLs.
181
+ const languageLinks = seo.noindex ? [] : hreflangLinks(siteUrl, alternates);
182
+ // Structured data - see lib/json-ld.js for what a page gets.
183
+ const structuredData = jsonLd({
184
+ siteUrl,
185
+ siteName: config.name,
186
+ siteDescription: config.description,
187
+ title,
188
+ description: seo.description ?? description ?? config.description,
189
+ path,
190
+ canonical: head.canonical,
191
+ lang,
192
+ mode,
193
+ isApi,
194
+ noindex: Boolean(seo.noindex),
195
+ breadcrumbs,
196
+ organization: config.seo.organization,
197
+ logo: siteLogo,
198
+ socials: config.socials,
199
+ custom: seo.jsonLd,
200
+ });
201
+ // The note that tells an AI agent reading this page where llms.txt is -
202
+ // see lib/agent-directive.js.
203
+ const agentNote = htmlDirective({ siteUrl: resolveSiteRoot(config) || null, markdownPages: contextMenuOptions(config.contextMenu).length > 0 });
204
+ // Analytics wait for the reader's answer when the consent banner is on -
205
+ // see lib/consent.js.
206
+ const consent = consentOptions(config.integrations.consent);
207
+ const gated = (s: { consent?: boolean }) => Boolean(consent && s.consent);
208
+ // Light-mode values come straight from styles.colors/styles.background
209
+ // (with defaults); dark-mode values fall back to their light counterpart
210
+ // when the site's own dark override doesn't set them, so a site only has
211
+ // to specify what actually changes for dark mode. Both sets are always
212
+ // computed and handed to the CSS below (light-mode ones as sensible
213
+ // starting defaults, but the .wd-* class hides/shows appropriately) - see
214
+ // the `[data-theme="dark"]` override rule below, which is what actually
215
+ // switches which set is live. Unlike every other bit of CSS this file
216
+ // used to own directly, this specific pair of rules can't move into a
217
+ // plain external .css file the way base.css/banner.css did - `define:vars`
218
+ // (right below) is what lets these raw hex/URL values get interpolated
219
+ // into custom-property assignments at all, and that directive only works
220
+ // on a <style> tag physically inside an .astro file's own template.
221
+ const lightPrimary = config.styles.colors.primary;
222
+ const lightText = config.styles.colors.text ?? "#404045";
223
+ const darkPrimary = config.styles.colors.dark?.primary ?? lightPrimary;
224
+ // Body text - also the sidebar's and table of contents' links. Headings,
225
+ // bold text and group titles use the stronger --wd-heading (below).
226
+ const darkText = config.styles.colors.dark?.text ?? "#a0a0a5";
227
+ // Text drawn on the primary color (step numbers, the info banner, the API
228
+ // playground's buttons) - white, or black on a clearly light primary
229
+ // (contrastTextColor(), lib/config.ts). It used to be white everywhere,
230
+ // unreadable on a light primary - and a light dark-mode primary is exactly
231
+ // what dark-mode links need.
232
+ const lightOnPrimary = contrastTextColor(lightPrimary);
233
+ const darkOnPrimary = contrastTextColor(darkPrimary);
234
+ // styles.background.colors is now the single source for any background
235
+ // color - both the flat --wd-background surface (dropdowns/modals/kbd
236
+ // chips/footer/topbar-fallback/etc., every other `var(--wd-background)`
237
+ // call site) and the <body> canvas paint below. There used to be a
238
+ // separate styles.colors.background/colors.dark.background pair driving
239
+ // just the --wd-background half, independent of this - see config.ts's
240
+ // own comment on why that split was removed; `lightBackground`/
241
+ // `darkBackground` here is what used to read that other field.
242
+ const lightBackground = config.styles.background?.colors?.light ?? "#ffffff";
243
+ const darkBackground = config.styles.background?.colors?.dark ?? "#0b1120";
244
+ // The topbar/mobile-menu-panel background - falls back to the page's own
245
+ // background (above) when a site doesn't set it, so an unconfigured navbar
246
+ // keeps blending into the page exactly as it always has; only sites that
247
+ // explicitly set `styles.navbar.light`/`.dark` get a topbar that looks
248
+ // different from the page behind it. resolveNavbarColor() (lib/config.ts)
249
+ // is what splits the string-or-{background,accent} union `navbar.light`/
250
+ // `.dark` can now be into its two parts - see its own comment.
251
+ const navLight = resolveNavbarColor(config.styles.navbar?.light, lightBackground);
252
+ const navDark = resolveNavbarColor(config.styles.navbar?.dark, darkBackground);
253
+ const lightNavbarBg = navLight.background;
254
+ const darkNavbarBg = navDark.background;
255
+ // Whether this side of `styles.navbar` was configured at all - string or
256
+ // object form, doesn't matter, just "is there a writedocs.json value here" -
257
+ // not merely "does lightNavbarBg differ from the page background", since
258
+ // a site could deliberately set navbar to the *same* color as the page
259
+ // background and this should still count as configured. What this gates:
260
+ // once true, the navbar's own text/icon color stops assuming it's sitting
261
+ // on something close to the page background (--wd-text's own tuning
262
+ // target) and switches to being computed fresh against whatever
263
+ // `background` actually resolved to.
264
+ const lightNavbarConfigured = config.styles.navbar?.light !== undefined;
265
+ const darkNavbarConfigured = config.styles.navbar?.dark !== undefined;
266
+ // --wd-navbar-foreground/-muted: the topbar's own text/icon color, plain
267
+ // (resting) state. Never a writedocs.json value, even indirectly - always
268
+ // contrastTextColor(lightNavbarBg) (lib/config.ts, picks black or white by
269
+ // luminance) the moment this side of `navbar` is configured at all, or the
270
+ // literal --wd-text/--wd-text-muted var references when it isn't, so an
271
+ // unconfigured navbar renders pixel-identical to before this feature
272
+ // existed. An earlier version of this let an object-form field double as
273
+ // both "the navbar's accent color" and "the navbar's text color" - real
274
+ // bug, caught immediately: a site picking a light accent (to stay legible
275
+ // against a dark/saturated background, the whole point of setting it) got
276
+ // that same light color as its *text*, which is exactly backwards. Text
277
+ // legibility isn't a design choice worth exposing at all here - it's
278
+ // always computed, correctly, every time. The muted variant mixes that
279
+ // same resolved color toward transparent (not toward lightNavbarBg, which
280
+ // would drag it back toward the background's own hue and undo the
281
+ // contrast fix) - a plain opacity reduction, so it stays legible
282
+ // regardless of what hue the navbar itself happens to be.
283
+ const lightNavbarFg = lightNavbarConfigured ? contrastTextColor(lightNavbarBg) : "var(--wd-text)";
284
+ const darkNavbarFg = darkNavbarConfigured ? contrastTextColor(darkNavbarBg) : "var(--wd-text)";
285
+ // The current tab (and a hovered one) stands out: the heading color on the
286
+ // page's own background, or the same computed black/white on a configured
287
+ // navbar - which is already the strongest color there.
288
+ const lightNavbarFgStrong = lightNavbarConfigured ? lightNavbarFg : "var(--wd-heading)";
289
+ const darkNavbarFgStrong = darkNavbarConfigured ? darkNavbarFg : "var(--wd-heading)";
290
+ const lightNavbarFgMuted = lightNavbarConfigured
291
+ ? `color-mix(in srgb, ${lightNavbarFg} 70%, transparent)`
292
+ : "var(--wd-text-muted)";
293
+ const darkNavbarFgMuted = darkNavbarConfigured
294
+ ? `color-mix(in srgb, ${darkNavbarFg} 70%, transparent)`
295
+ : "var(--wd-text-muted)";
296
+ // --wd-navbar-accent: the tab-hover-underline/active-tab-fill color inside
297
+ // the topbar specifically - `accent` on the object form (a real, legitimate
298
+ // design choice, unlike text color above), falling back to the sitewide
299
+ // --wd-primary (today's exact behavior) when unset - a site that sets a
300
+ // navbar background but no accent keeps its ordinary brand-colored
301
+ // active-tab underline.
302
+ const lightNavbarAccent = navLight.accent ?? lightPrimary;
303
+ const darkNavbarAccent = navDark.accent ?? darkPrimary;
304
+ // --wd-navbar-border: the switcher pills' (version/language/product) own
305
+ // border. Never the flat --wd-border (a fixed neutral gray/slate tuned for
306
+ // sitting on the page background) once navbar is configured - that reads
307
+ // as a harsh, near-white outline against a saturated/colored navbar
308
+ // background, since it's not picked with that background in mind at all.
309
+ // Same mix-toward-transparent technique as the muted foreground above: a
310
+ // low-opacity tint of the already-contrast-correct navbarFg, so it stays
311
+ // soft and legible against any navbar hue instead of a flat, unrelated
312
+ // gray. Unconfigured navbar keeps the literal var(--wd-border) reference,
313
+ // pixel-identical to before this existed.
314
+ const lightNavbarBorder = lightNavbarConfigured
315
+ ? `color-mix(in srgb, ${lightNavbarFg} 25%, transparent)`
316
+ : "var(--wd-border)";
317
+ const darkNavbarBorder = darkNavbarConfigured
318
+ ? `color-mix(in srgb, ${darkNavbarFg} 25%, transparent)`
319
+ : "var(--wd-border)";
320
+ // --wd-navbar-hover: a topbar tab's background on hover. On a navbar with
321
+ // the page's own background, the sidebar's hover tint (NavTree.astro) -
322
+ // the same 6% of --wd-primary. A configured navbar can *be* the primary
323
+ // color, where that tint would vanish, so there it's a light tint of the
324
+ // navbar's own contrast-correct text color instead, like --wd-navbar-border.
325
+ const sidebarHover = "color-mix(in srgb, var(--wd-primary) 6%, transparent)";
326
+ const lightNavbarHover = lightNavbarConfigured ? `color-mix(in srgb, ${lightNavbarFg} 12%, transparent)` : sidebarHover;
327
+ const darkNavbarHover = darkNavbarConfigured ? `color-mix(in srgb, ${darkNavbarFg} 12%, transparent)` : sidebarHover;
328
+ // The <body> canvas's own paint - same color as --wd-background above
329
+ // (there's only one background color to configure now), plus an optional
330
+ // image layered on top. `images.light`/`.dark` are plain public/-relative
331
+ // paths (same convention as styles.logo/favicon) - wrapped in url(...) here
332
+ // (or 'none' when unset) since CSS custom properties can't have url()
333
+ // applied to them after the fact (`url(var(--x))` isn't valid CSS - the
334
+ // value itself has to already be a full `url(...)` token, which is what
335
+ // these two variables hold).
336
+ const lightPageBgColor = lightBackground;
337
+ const darkPageBgColor = darkBackground;
338
+ const lightPageBgImage = config.styles.background?.images?.light
339
+ ? `url('${siteHref(config.styles.background.images.light)}')`
340
+ : "none";
341
+ const darkPageBgImage = config.styles.background?.images?.dark
342
+ ? `url('${siteHref(config.styles.background.images.dark)}')`
343
+ : "none";
344
+ // A logo is either one path used for both modes, or a {light, dark,
345
+ // label} object - normalized to a single light/dark pair here (the one
346
+ // place that needs to know which form writedocs.json used) so TopBar.astro,
347
+ // MobileMenu.astro, and SiteFooter.astro - each of which render their own
348
+ // copy of the brand link - never need to branch on it themselves. The
349
+ // brand link shows the image(s) alone by default - no site name text next
350
+ // to it, since a real logo asset is usually already a wordmark. `label`
351
+ // (only settable on the object form - see config.ts) opts back into
352
+ // showing text next to the image - or, since `light`/`dark` are
353
+ // themselves optional on that form, stands entirely on its own:
354
+ // `styles.logo: { label: "..." }` with no images at all overrides just the
355
+ // brand text without adding any logo image. A site with neither a logo
356
+ // image nor a label falls back to plain config.name text, so the brand
357
+ // link is never left empty.
358
+ const logo = config.styles.logo;
359
+ const logoLight = typeof logo === "string" ? logo : logo?.light;
360
+ const logoDark = typeof logo === "string" ? logo : logo?.dark;
361
+ const logoLabel = typeof logo === "string" ? undefined : logo?.label;
362
+ const hasLogoImage = Boolean(logoLight || logoDark);
363
+ const brandLabel = logoLabel ?? (hasLogoImage ? undefined : config.name);
364
+
365
+ // writedocs.json's `footer.logo` (same {light, dark, label} shape as
366
+ // `styles.logo` above, via config.ts's shared logoSchema) - unset by
367
+ // default, in which case SiteFooter.astro just gets the same
368
+ // logoLight/logoDark/logoLabel as the topbar/mobile menu above. Set, it
369
+ // replaces those entirely (not just fills in whichever side is missing)
370
+ // before ever reaching SiteFooter - a footer wanting a different mark
371
+ // than the topbar (or none at all - `styles.logo` set, `footer.logo`
372
+ // deliberately absent-of-images-but-present, e.g. `{ label: "" }`, isn't
373
+ // a real use case worth solving here) shouldn't still show the sitewide
374
+ // one alongside or underneath it.
375
+ const footerLogoConfig = config.footer.logo;
376
+ const footerLogoLight = footerLogoConfig
377
+ ? typeof footerLogoConfig === "string"
378
+ ? footerLogoConfig
379
+ : footerLogoConfig.light
380
+ : logoLight;
381
+ const footerLogoDark = footerLogoConfig
382
+ ? typeof footerLogoConfig === "string"
383
+ ? footerLogoConfig
384
+ : footerLogoConfig.dark
385
+ : logoDark;
386
+
387
+ // Zero-config custom CSS/JS - any `.css`/`.js` file anywhere in the
388
+ // project (root, `docs/`, `snippets/`, `public/`, any subfolder -
389
+ // `dist/`/`node_modules/`/etc. excluded, see findRootAssets() in
390
+ // lib/pages.js) is auto-loaded on every page, no writedocs.json entry
391
+ // needed. In `writedocs dev` they're read fresh on every render, so an
392
+ // edit to one of these files shows up on the next page load without a
393
+ // server restart - same freshness `loadDocsConfig(contentDir)` itself
394
+ // already gives writedocs.json edits in [...slug].astro/404.astro. In a
395
+ // build, where they can't change, the list and the files are read once
396
+ // for all pages (oncePerBuild(), lib/build-memo.js).
397
+ // Rendered in addition to, not instead of, writedocs.json's own explicit
398
+ // `scripts` field - that still exists for external/CDN script URLs
399
+ // (`src`) and inline content that should only load under deliberate
400
+ // config, and renders before these so a file living in the project (the
401
+ // more locally-owned override) wins over a URL possibly pointing at
402
+ // someone else's asset.
403
+ const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
404
+ const rootAssets = findRootAssets(contentDir);
405
+ // `name` is a POSIX-separated path relative to contentDir (e.g.
406
+ // "docs/theme.css") - split and rejoin with nodePath.join rather than
407
+ // handing the raw string straight to it, so a nested asset resolves
408
+ // correctly on every OS this might run on, not just POSIX ones.
409
+ const rootCssContents = oncePerBuild("root-css-contents", () => rootAssets.css.map((name) =>
410
+ fs.readFileSync(nodePath.join(contentDir, ...name.split("/")), "utf-8"),
411
+ ));
412
+ const rootJsContents = oncePerBuild("root-js-contents", () => rootAssets.js.map((name) =>
413
+ fs.readFileSync(nodePath.join(contentDir, ...name.split("/")), "utf-8"),
414
+ ));
415
+ // public/*.css and public/*.js auto-load too, but as <link>/<script src>
416
+ // pointing at their already-public URL (see findRootAssets()'s own
417
+ // comment for why - no point inlining a file that's also independently
418
+ // fetchable at that exact URL). publicJsHrefs is filtered against
419
+ // writedocs.json's own `scripts.head` so a site that hasn't yet removed an
420
+ // explicit `src` entry for the same public/ file doesn't get that href
421
+ // rendered twice - the explicit entry still works, it's just redundant
422
+ // with this now. publicCssHrefs has no equivalent filter to apply -
423
+ // there's no explicit stylesheet-URL config field anymore.
424
+ const explicitScriptSrcs = new Set(config.scripts.head.map((s) => s.src).filter((src): src is string => Boolean(src)));
425
+ const publicCssHrefs = rootAssets.publicCss;
426
+ const publicJsHrefs = rootAssets.publicJs.filter((href) => !explicitScriptSrcs.has(href));
427
+
428
+ // styles.fonts (see fontsSchema/resolveFonts() in lib/config.ts) - resolves
429
+ // to plain Inter, genuinely loaded via Google Fonts (not just named in a
430
+ // fallback stack the way base.css used to), when a site sets no `fonts`
431
+ // field at all. `fontStack()` quotes the family name (safe even for a
432
+ // single-word name, and required for one with spaces like "Playfair
433
+ // Display") and appends the same system-font fallback chain base.css
434
+ // always used, so a reader who somehow loads the page before the web font
435
+ // finishes fetching still sees a reasonable font rather than the browser
436
+ // default serif. `heading`/`body` are left `null` (not defaulted to the
437
+ // same value as `base`) whenever a site hasn't overridden them - base.css
438
+ // falls back to `--wd-font-family` itself via CSS var(), so a `null` here
439
+ // deliberately never gets its own CSS var written into the style block
440
+ // below.
441
+ const resolvedFonts = resolveFonts(config);
442
+ const fontsGoogleHref = googleFontsHref(resolvedFonts);
443
+ // fontStack() and the stand-in font that keeps text from moving when the
444
+ // web font arrives are in lib/font-fallback.js.
445
+ // heading/body already fall back to `resolvedFonts.base` right here (not
446
+ // left as a CSS var() fallback chain for :root below to resolve) - same
447
+ // "fully resolve in JS, plain values into define:vars" approach every
448
+ // other themeable value in this file already uses (see lightPrimary/
449
+ // darkPrimary etc. above), rather than introducing a different pattern
450
+ // just for fonts.
451
+ const wdFontFamily = fontStack(resolvedFonts.base.family);
452
+ const wdFontFamilyHeading = resolvedFonts.heading ? fontStack(resolvedFonts.heading.family) : wdFontFamily;
453
+ const wdFontFamilyBody = resolvedFonts.body ? fontStack(resolvedFonts.body.family) : wdFontFamily;
454
+ // One @font-face rule per source-based font actually configured (Google
455
+ // Fonts, covered by fontsGoogleHref above instead, never reach here) - this
456
+ // only ever gets the right *file* loaded (the @font-face `font-weight`
457
+ // descriptor, or the Google Fonts URL's `:wght@` axis inside
458
+ // googleFontsHref() above), not the actual rendered boldness of any
459
+ // element - see wdFontWeightCss right below for that other half.
460
+ // A `source` in the project is a site address: it gets the basePath.
461
+ const withSourceBase = <T extends { source?: string } | null>(font: T): T =>
462
+ font?.source ? { ...font, source: siteHref(font.source) } : font;
463
+ const fontFaceCss = [
464
+ fontFaceRule(withSourceBase(resolvedFonts.base)),
465
+ fontFaceRule(withSourceBase(resolvedFonts.heading)),
466
+ fontFaceRule(withSourceBase(resolvedFonts.body)),
467
+ ]
468
+ .filter(Boolean)
469
+ .join("\n");
470
+ // Without this, a configured `weight` only ever changed which font *file*
471
+ // loaded - h1-h6 still rendered at the browser's own default `font-weight:
472
+ // bold` (a user-agent-stylesheet rule, present regardless of which file
473
+ // actually loaded), so a heading weight of e.g. 400 was silently faux-
474
+ // bolded back to looking bold anyway, with no visible effect from
475
+ // changing the config at all. `resolvedFonts.heading?.weight ?? base.weight`
476
+ // falls back the same way family already does (an override with no
477
+ // weight of its own still inherits the top-level one); `undefined` when
478
+ // nothing at any level configured a weight, which deliberately renders no
479
+ // rule at all here - an unconfigured site keeps today's plain browser-
480
+ // default bold headings/normal body text exactly as before this feature
481
+ // existed, not a forced 400/700 nobody asked for.
482
+ const wdFontWeightHeading = resolvedFonts.heading?.weight ?? resolvedFonts.base.weight;
483
+ const wdFontWeightBody = resolvedFonts.body?.weight ?? resolvedFonts.base.weight;
484
+ const fontWeightCss = [
485
+ wdFontWeightHeading !== undefined ? `h1, h2, h3, h4, h5, h6 { font-weight: ${wdFontWeightHeading}; }` : "",
486
+ wdFontWeightBody !== undefined ? `body { font-weight: ${wdFontWeightBody}; }` : "",
487
+ ]
488
+ .filter(Boolean)
489
+ .join("\n");
490
+ // The stand-in for each font that has one (lib/font-fallback.js) - the
491
+ // stacks above already name it, right after the font itself.
492
+ const fontFallbackCss = fallbackFontFaces(
493
+ [resolvedFonts.base, resolvedFonts.heading, resolvedFonts.body].filter(Boolean).map((font) => font!.family),
494
+ );
495
+ const fontExtraCss = [fontFaceCss, fontFallbackCss, fontWeightCss].filter(Boolean).join("\n");
496
+ ---
497
+
498
+ <!doctype html>
499
+ <html lang={lang}>
500
+ <head>
501
+ <meta charset="UTF-8" />
502
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
503
+ {/* Marks the pages writedocs renders - the build checks each has the site's styles (cli/check-built-styles.js). */}
504
+ <meta name="generator" content="writedocs" />
505
+ <title>{head.title}</title>
506
+ <ClientRouter />
507
+ {head.canonical && <link rel="canonical" href={head.canonical} />}
508
+ {languageLinks.map((link) => <link rel="alternate" hreflang={link.hreflang} href={link.href} />)}
509
+ {
510
+ head.metas.map((meta) =>
511
+ meta.attr === "property" ? (
512
+ <meta property={meta.key} content={meta.content} />
513
+ ) : (
514
+ <meta name={meta.key} content={meta.content} />
515
+ ),
516
+ )
517
+ }
518
+ {config.styles.favicon && <link rel="icon" href={siteHref(config.styles.favicon)} />}
519
+ {
520
+ /* styles.fonts - see resolveFonts()/googleFontsHref() in lib/config.ts.
521
+ Present (non-null) whenever at least one configured font (or the
522
+ Inter default, when styles.fonts is unset entirely) has no `source`
523
+ - i.e. is a Google Font, auto-loaded by family name. The two
524
+ preconnect hints warm up the connections googleapis.com's own CSS
525
+ response will immediately need (its @font-face rules point at
526
+ gstatic.com for the actual font files) before the browser has even
527
+ parsed that response - Google's own recommended pattern for using
528
+ their fonts. Rendered this early in <head> (right after favicon,
529
+ before Open Graph/Twitter meta) so the font starts loading as soon
530
+ as possible rather than competing with less render-critical tags
531
+ for bandwidth/priority. */
532
+ }
533
+ {
534
+ fontsGoogleHref && (
535
+ <>
536
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
537
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
538
+ <link rel="stylesheet" href={fontsGoogleHref} />
539
+ </>
540
+ )
541
+ }
542
+ {
543
+ /* writedocs.json's `integrations` (the six analytics providers) - see
544
+ AnalyticsScripts.astro. Rendered as early in <head> as reasonably
545
+ possible (right after the meta tags, before even the theme-
546
+ detection script below) - the usual placement every one of these
547
+ providers' own install instructions ask for, so pageview timing is
548
+ captured as close to actual page load as it can be. */
549
+ }
550
+ {structuredData.map((block) => <script is:inline type="application/ld+json" set:html={serializeJsonLd(block)} />)}
551
+ <AnalyticsScripts
552
+ config={config}
553
+ consent={consent}
554
+ gatedScripts={[...config.scripts.head, ...config.scripts.body].filter(gated)}
555
+ />
556
+ <script is:inline>
557
+ // Sets [data-theme] and [data-banner-dismissed] on <html> before
558
+ // first paint, so the page never flashes the wrong mode or an
559
+ // already-dismissed banner. Preference order for theme: an explicit
560
+ // prior choice (localStorage), then the OS-level preference,
561
+ // defaulting to light. The click handlers that update both live in
562
+ // src/scripts/theme-toggle.ts and src/scripts/banner.ts.
563
+ //
564
+ // Also re-run on `astro:after-swap` (ClientRouter, see BaseLayout's
565
+ // own import of it below), not just the initial load - Astro's
566
+ // client-side navigation swaps <html>'s attributes wholesale to
567
+ // match the newly-fetched page's raw server-rendered markup (see
568
+ // swapRootAttributes() in astro/dist/transitions/swap-functions.js),
569
+ // which has neither of these dataset attributes baked in since
570
+ // they're pure client-side runtime state, not something the server
571
+ // ever renders. Without re-running this after every swap, a
572
+ // dismissed banner (or a chosen dark theme) would silently come
573
+ // back on the very next navigation - both attributes get wiped, not
574
+ // just reset to their default, so this has to unconditionally
575
+ // reapply them from localStorage every time, exactly as it does on
576
+ // first load. `astro:after-swap` fires synchronously right after
577
+ // that swap and before the browser's next paint, so this still
578
+ // prevents any visible flash on client-side navigations too.
579
+ function wdApplyStoredPreferences() {
580
+ try {
581
+ var stored = localStorage.getItem("wd-theme");
582
+ var theme =
583
+ stored === "light" || stored === "dark"
584
+ ? stored
585
+ : window.matchMedia("(prefers-color-scheme: dark)").matches
586
+ ? "dark"
587
+ : "light";
588
+ document.documentElement.dataset.theme = theme;
589
+ } catch (e) {
590
+ document.documentElement.dataset.theme = "light";
591
+ }
592
+ try {
593
+ document.documentElement.dataset.bannerDismissed =
594
+ localStorage.getItem("wd-banner-dismissed") === "true" ? "true" : "false";
595
+ } catch (e) {
596
+ document.documentElement.dataset.bannerDismissed = "false";
597
+ }
598
+ }
599
+ wdApplyStoredPreferences();
600
+ document.addEventListener("astro:after-swap", wdApplyStoredPreferences);
601
+ </script>
602
+ <script>
603
+ // Preserves the sidebar's own scroll position across a ClientRouter
604
+ // navigation - see src/scripts/sidebar-scroll.ts for why this is
605
+ // needed at all (the sidebar is re-rendered fresh, server-side, on
606
+ // every page, so it's a brand-new DOM node each time, reset to
607
+ // scrollTop 0 like a real page reload would be). Same before-swap/
608
+ // after-swap pairing as wdApplyStoredPreferences above, and for the
609
+ // same reason: after-swap fires before the next paint, so there's no
610
+ // visible flash of the sidebar sitting at the top before jumping
611
+ // back to where the reader had it scrolled.
612
+ import { saveSidebarScroll, restoreSidebarScroll } from "../scripts/sidebar-scroll";
613
+
614
+ document.addEventListener("astro:before-swap", saveSidebarScroll);
615
+ document.addEventListener("astro:after-swap", restoreSidebarScroll);
616
+ </script>
617
+ <style
618
+ define:vars={{
619
+ wdPrimaryLight: lightPrimary,
620
+ wdOnPrimaryLight: lightOnPrimary,
621
+ wdBackgroundLight: lightBackground,
622
+ wdTextLight: lightText,
623
+ wdNavbarLight: lightNavbarBg,
624
+ wdNavbarFgLight: lightNavbarFg,
625
+ wdNavbarFgStrongLight: lightNavbarFgStrong,
626
+ wdNavbarFgMutedLight: lightNavbarFgMuted,
627
+ wdNavbarAccentLight: lightNavbarAccent,
628
+ wdNavbarBorderLight: lightNavbarBorder,
629
+ wdNavbarHoverLight: lightNavbarHover,
630
+ wdPageBgColorLight: lightPageBgColor,
631
+ wdPageBgImageLight: lightPageBgImage,
632
+ wdFontFamily,
633
+ wdFontFamilyHeading,
634
+ wdFontFamilyBody,
635
+ wdPrimaryDark: darkPrimary,
636
+ wdOnPrimaryDark: darkOnPrimary,
637
+ wdBackgroundDark: darkBackground,
638
+ wdTextDark: darkText,
639
+ wdNavbarDark: darkNavbarBg,
640
+ wdNavbarFgDark: darkNavbarFg,
641
+ wdNavbarFgStrongDark: darkNavbarFgStrong,
642
+ wdNavbarFgMutedDark: darkNavbarFgMuted,
643
+ wdNavbarAccentDark: darkNavbarAccent,
644
+ wdNavbarBorderDark: darkNavbarBorder,
645
+ wdNavbarHoverDark: darkNavbarHover,
646
+ wdPageBgColorDark: darkPageBgColor,
647
+ wdPageBgImageDark: darkPageBgImage,
648
+ }}
649
+ >
650
+ :root {
651
+ --wd-primary: var(--wdPrimaryLight);
652
+ --wd-on-primary: var(--wdOnPrimaryLight);
653
+ --wd-background: var(--wdBackgroundLight);
654
+ --wd-text: var(--wdTextLight);
655
+ --wd-navbar-background: var(--wdNavbarLight);
656
+ --wd-navbar-foreground: var(--wdNavbarFgLight);
657
+ --wd-navbar-foreground-strong: var(--wdNavbarFgStrongLight);
658
+ --wd-navbar-foreground-muted: var(--wdNavbarFgMutedLight);
659
+ --wd-navbar-accent: var(--wdNavbarAccentLight);
660
+ --wd-navbar-border: var(--wdNavbarBorderLight);
661
+ --wd-navbar-hover: var(--wdNavbarHoverLight);
662
+ --wd-page-bg-color: var(--wdPageBgColorLight);
663
+ --wd-page-bg-image: var(--wdPageBgImageLight);
664
+ --wd-text-muted: #64748b;
665
+ /* Headings, bold text, card titles, and the sidebar's group titles -
666
+ a stronger color than body text (--wd-text), which the sidebar's
667
+ and table of contents' links use (--wd-nav-text). */
668
+ --wd-heading: #18191d;
669
+ --wd-nav-title: var(--wd-heading);
670
+ --wd-nav-text: var(--wd-text);
671
+ --wd-border: #e2e8f0;
672
+ --wd-surface: #f8fafc;
673
+ /* The browser's own controls - the page's scrollbar, a code block's -
674
+ drawn for the theme on screen. Without it they stayed light in dark
675
+ mode. */
676
+ color-scheme: light;
677
+ /* Not mode-dependent (a site's chosen font doesn't change between
678
+ light/dark) - set once here rather than duplicated in the
679
+ :root[data-theme='dark'] block below. */
680
+ --wd-font-family: var(--wdFontFamily);
681
+ --wd-font-family-heading: var(--wdFontFamilyHeading);
682
+ --wd-font-family-body: var(--wdFontFamilyBody);
683
+ }
684
+ /* Higher specificity than the plain :root rule above (an attribute
685
+ selector on :root beats an unqualified one), so this wins
686
+ regardless of source order once data-theme is set to "dark" by
687
+ the inline script above or the toggle button's click handler
688
+ (src/scripts/theme-toggle.ts). */
689
+ :root[data-theme="dark"] {
690
+ --wd-primary: var(--wdPrimaryDark);
691
+ --wd-on-primary: var(--wdOnPrimaryDark);
692
+ --wd-background: var(--wdBackgroundDark);
693
+ --wd-text: var(--wdTextDark);
694
+ --wd-navbar-background: var(--wdNavbarDark);
695
+ --wd-navbar-foreground: var(--wdNavbarFgDark);
696
+ --wd-navbar-foreground-strong: var(--wdNavbarFgStrongDark);
697
+ --wd-navbar-foreground-muted: var(--wdNavbarFgMutedDark);
698
+ --wd-navbar-accent: var(--wdNavbarAccentDark);
699
+ --wd-navbar-border: var(--wdNavbarBorderDark);
700
+ --wd-navbar-hover: var(--wdNavbarHoverDark);
701
+ --wd-page-bg-color: var(--wdPageBgColorDark);
702
+ --wd-page-bg-image: var(--wdPageBgImageDark);
703
+ --wd-text-muted: #94a3b8;
704
+ --wd-heading: #e0e0e5;
705
+ --wd-border: #1e293b;
706
+ --wd-surface: #131a2b;
707
+ color-scheme: dark;
708
+ }
709
+ </style>
710
+ {
711
+ /* styles.fonts: local/externally-hosted font(s) (fontFaceRule() in
712
+ lib/config.ts - a local `source` path resolves the same way
713
+ styles.favicon/styles.logo/styles.background.images already do, see
714
+ collectConfiguredAssetPaths() + styles-asset-integration.js, no
715
+ extra wiring needed here beyond listing it there), plus a
716
+ font-weight override for h1-h6/body whenever `weight` was actually
717
+ configured somewhere (fontWeightCss above) - both concatenated
718
+ into one block since both need the same raw-CSS-text treatment.
719
+ set:html (not a plain <style>{fontExtraCss}</style>) because this
720
+ needs to render already-built CSS text as-is, not have Astro's own
721
+ CSS parser/scoper attempt to process an `@font-face` block or a
722
+ bare `h1, h2, ...` selector list assembled as a runtime string -
723
+ empty string renders nothing when neither piece has anything to
724
+ contribute (every configured font is a Google Font, and no
725
+ `weight` was set anywhere in `styles.fonts`). */
726
+ }
727
+ {fontExtraCss && <style set:html={fontExtraCss} />}
728
+ {
729
+ /* writedocs.json's `scripts.head` - see scriptEntrySchema in lib/config.ts.
730
+ Each entry is exactly one of an external/local `src` or inline
731
+ `content` (enforced by the schema's own .refine()), rendered right
732
+ before </head> so it runs before body content paints - the usual
733
+ spot a third-party script's own install instructions ask for. */
734
+ }
735
+ {
736
+ config.scripts.head
737
+ .filter((s) => !gated(s))
738
+ .map((s) => (s.src ? <script is:inline src={siteHref(s.src)} /> : <script is:inline set:html={s.content} />))
739
+ }
740
+ {
741
+ /* Zero-config custom CSS - see findRootAssets() in lib/pages.js and
742
+ rootCssContents above. Rendered last in <head>, so a project-owned
743
+ file - anywhere in the project, not just the root - wins over
744
+ everything else writedocs generates itself. Inlined as raw <style>
745
+ content rather than a <link> - these files aren't necessarily under
746
+ `public/`, so there's no guaranteed build-time copy step making them
747
+ independently fetchable as a URL; inlining sidesteps needing one.
748
+ One <style> tag per file (not concatenated) so each is independently
749
+ visible/attributable
750
+ in devtools. */
751
+ }
752
+ {rootCssContents.map((content) => <style is:inline set:html={content} />)}
753
+ {
754
+ /* Zero-config custom CSS living in public/ - see findRootAssets()'s
755
+ own comment in lib/pages.js for why these render as <link> tags
756
+ pointing at their already-public URL instead of joining
757
+ rootCssContents above as inlined content. */
758
+ }
759
+ {publicCssHrefs.map((href) => <link rel="stylesheet" href={siteHref(href)} />)}
760
+ </head>
761
+ <body>
762
+ {
763
+ /* For AI agents, first thing in the page: where the documentation index
764
+ is (lib/agent-directive.js). Not for people - hidden from sight
765
+ (.wd-agent-note, base.css) and from screen readers, its link out of
766
+ the tab order, and kept out of search snippets and the site's search. */
767
+ }
768
+ <div class="wd-agent-note" aria-hidden="true" data-nosnippet data-pagefind-ignore>
769
+ {agentNote.before}<a href={agentNote.href} tabindex="-1">{agentNote.link}</a>{agentNote.after}
770
+ </div>
771
+ {
772
+ mode === "blank" ? (
773
+ // No site chrome at all - no topbar, no sidebar/toc columns, not
774
+ // even the .wd-shell wrapper's own max-width - the page's own
775
+ // MDX/components control 100% of the layout, including whether
776
+ // there's any nav/branding at all. SearchModal.astro's own overlay
777
+ // markup and its ⌘K listener still work even with no visible
778
+ // trigger button to click (it's rendered unconditionally below,
779
+ // outside this mode === 'blank' branch), so that's left in rather
780
+ // than also gated on mode.
781
+ <slot />
782
+ ) : (
783
+ <Fragment>
784
+ {/* Everything above the footer, in one wrapper - see .wd-page/body in
785
+ base.css: body is a flex column, this is its flex: 1 0 auto item,
786
+ and the footer (a plain sibling below, not inside this wrapper) is
787
+ what that pushes down to the viewport's bottom edge on a page
788
+ short enough not to need scrolling - the "sticky footer" pattern,
789
+ not position: sticky/fixed (either of which would cover page
790
+ content instead of just trailing it once actually reached). */}
791
+ <div class="wd-page">
792
+ {config.banner && (
793
+ <div class={`wd-banner wd-banner-${config.banner.type}`} id="wd-banner">
794
+ <div class="wd-banner-inner">
795
+ <span class="wd-banner-content">{config.banner.content}</span>
796
+ {config.banner.dismissible && (
797
+ <button type="button" class="wd-banner-dismiss" aria-label="Dismiss banner" data-banner-dismiss>
798
+ &times;
799
+ </button>
800
+ )}
801
+ </div>
802
+ </div>
803
+ )}
804
+ <TopBar
805
+ config={config}
806
+ selectors={selectors}
807
+ globalDropdowns={globalDropdowns}
808
+ showSidebarCol={showSidebarCol}
809
+ logoLight={logoLight}
810
+ logoDark={logoDark}
811
+ brandLabel={brandLabel}
812
+ />
813
+ <MobileMenu
814
+ config={config}
815
+ selectors={selectors}
816
+ globalDropdowns={globalDropdowns}
817
+ showSidebarCol={showSidebarCol}
818
+ logoLight={logoLight}
819
+ logoDark={logoDark}
820
+ brandLabel={brandLabel}
821
+ />
822
+ <div class="wd-shell">
823
+ {showSidebarCol && (
824
+ <div class="wd-sidebar-col">
825
+ <slot name="sidebar" />
826
+ </div>
827
+ )}
828
+ <div class="wd-main-col">
829
+ <slot />
830
+ </div>
831
+ {showTocCol && (
832
+ <div class="wd-toc-col">
833
+ <slot name="toc" />
834
+ </div>
835
+ )}
836
+ </div>
837
+ </div>
838
+ <SiteFooter config={config} logoLight={footerLogoLight} logoDark={footerLogoDark} />
839
+ </Fragment>
840
+ )
841
+ }
842
+
843
+ <SearchModal />
844
+ <ImageZoom />
845
+ {consent && <ConsentBanner consent={consent} />}
846
+
847
+ <script>
848
+ import { initBanner } from "../scripts/banner";
849
+ import { initTopbarOffset } from "../scripts/topbar-offset";
850
+
851
+ initBanner(document);
852
+ document.addEventListener("astro:page-load", () => initBanner(document));
853
+
854
+ // No ordering dependency on initBanner above - see topbar-offset.ts
855
+ // for why it measures only the topbar itself (not the banner) and
856
+ // why that's live-measured rather than a fixed CSS value.
857
+ initTopbarOffset();
858
+ document.addEventListener("astro:page-load", () => initTopbarOffset());
859
+ </script>
860
+ {
861
+ /* writedocs.json's `scripts.body` - see scriptEntrySchema in lib/config.ts.
862
+ Rendered after everything above (including every component's own
863
+ <script> tags, which Astro/Vite already bundles to run in document
864
+ order) so it runs after every other script on the page has already
865
+ loaded/hydrated - matching where a third-party script's own install
866
+ instructions usually ask for a "body end" placement. */
867
+ }
868
+ {
869
+ config.scripts.body
870
+ .filter((s) => !gated(s))
871
+ .map((s) => (s.src ? <script is:inline src={siteHref(s.src)} /> : <script is:inline set:html={s.content} />))
872
+ }
873
+ {
874
+ /* Zero-config custom JS - see findRootAssets() in lib/pages.js and
875
+ rootJsContents above. Rendered last, after writedocs.json's own
876
+ `scripts.body`, same "most locally-owned override runs last"
877
+ reasoning as the root CSS above. `is:inline` here isn't optional -
878
+ without it, Astro tries to process/bundle the tag as a module and
879
+ the build fails outright ("Cannot find the built path for ...
880
+ type=script&index=N") the same way a dynamic-`src` script did
881
+ while this file's own writedocs.json `scripts` support was first being
882
+ built - see that feature's own commit for the full story. */
883
+ }
884
+ {rootJsContents.map((content) => <script is:inline set:html={content} />)}
885
+ {
886
+ /* Zero-config custom JS living in public/ - see this file's own CSS
887
+ equivalent above and findRootAssets()'s comment in lib/pages.js.
888
+ `<script src>`, not `is:inline set:html` - the file's already a
889
+ fetchable URL, no reason to inline its content. Filtered against
890
+ config.scripts.head's own `src` entries (publicJsHrefs) for the
891
+ same duplicate-tag reason as the CSS <link>s above - note this
892
+ only dedupes against `scripts.head`, not `scripts.body` (a public/
893
+ file explicitly listed there instead would still also render here
894
+ as a second tag; `scripts.head` vs `scripts.body` placement is a
895
+ deliberate choice this can't second-guess, but `head` is by far
896
+ the more common spot for a plain local script and this hasn't come
897
+ up in practice). */
898
+ }
899
+ {publicJsHrefs.map((href) => <script is:inline src={siteHref(href)} />)}
900
+ {
901
+ /* writedocs.json's `integrations.askAi` - see AskAiWidget.astro. Rendered
902
+ last of all - it's a floating chat widget, not something anything
903
+ else on the page depends on running before, so there's no reason
904
+ to load it any earlier than absolutely last. */
905
+ }
906
+ <AskAiWidget config={config} />
907
+ </body>
908
+ </html>