@writedocs/generator 0.10.20 → 0.11.1

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 (53) hide show
  1. package/astro.config.mjs +32 -8
  2. package/package.json +3 -1
  3. package/src/cli/astro-output.js +44 -11
  4. package/src/cli/base-path-layout.js +44 -0
  5. package/src/cli/build.js +18 -9
  6. package/src/cli/check-built-styles.js +41 -33
  7. package/src/cli/dev.js +21 -4
  8. package/src/cli/run-pagefind.js +154 -148
  9. package/src/cli/write-mcp-files.js +103 -96
  10. package/src/cli/write-redirects-file.js +25 -8
  11. package/src/components/AppIcon.astro +51 -50
  12. package/src/components/Card.astro +193 -192
  13. package/src/components/CopyPageMenu.astro +374 -370
  14. package/src/components/Hint.astro +188 -187
  15. package/src/components/Icon.astro +72 -71
  16. package/src/components/Image.astro +3 -2
  17. package/src/components/Tile.astro +67 -66
  18. package/src/components/Video.astro +137 -136
  19. package/src/layout/BaseLayout.astro +21 -12
  20. package/src/layout/components/AnalyticsScripts.astro +6 -2
  21. package/src/layout/components/Breadcrumbs.astro +98 -97
  22. package/src/layout/components/ConsentBanner.astro +119 -118
  23. package/src/layout/components/MobileMenu.astro +229 -228
  24. package/src/layout/components/NavTree.astro +393 -392
  25. package/src/layout/components/Sidebar.astro +232 -231
  26. package/src/layout/components/SiteFooter.astro +87 -86
  27. package/src/layout/components/TopBar.astro +386 -385
  28. package/src/lib/agent-markdown.js +164 -162
  29. package/src/lib/asset-dimensions.js +89 -89
  30. package/src/lib/base-path.js +90 -0
  31. package/src/lib/config-schema.js +10 -0
  32. package/src/lib/config-schema.ts +17 -0
  33. package/src/lib/config.ts +1314 -1289
  34. package/src/lib/consent.js +108 -102
  35. package/src/lib/json-schema-descriptions.js +1 -0
  36. package/src/lib/link-check.js +7 -2
  37. package/src/lib/llms-index.ts +90 -88
  38. package/src/lib/mcp-dev-integration.js +65 -60
  39. package/src/lib/mcp-index.ts +102 -101
  40. package/src/lib/project-files-integration.js +2 -2
  41. package/src/lib/rehype-base-path.js +62 -0
  42. package/src/lib/robots-txt.js +21 -16
  43. package/src/lib/seo-tags.js +155 -140
  44. package/src/lib/site-base.ts +27 -0
  45. package/src/lib/styles-asset-integration.js +23 -10
  46. package/src/lib/wdignore-cases.json +195 -195
  47. package/src/lib/wdignore.js +177 -177
  48. package/src/pages/404.astro +63 -62
  49. package/src/pages/[...slug].astro +1604 -1597
  50. package/src/pages/[...slug].md.ts +93 -93
  51. package/src/pages/llms-full.txt.ts +88 -86
  52. package/src/scripts/search.ts +245 -237
  53. package/writedocs.schema.json +6 -0
@@ -1,66 +1,67 @@
1
- ---
2
- import { extraClasses } from './class-names';
3
- // Mintlify's <Tile> - a visual preview (the slot, usually an image or a
4
- // light/dark image pair) on a patterned background, with a title and
5
- // description under it. Usually laid out in a <Columns> grid. `title`
6
- // takes inline Markdown (`code`, **bold**, *italic*), like Mintlify's.
7
- import { inlineMarkdown } from '../lib/inline-markdown.js';
8
-
9
- interface Props {
10
- href?: string;
11
- title?: string;
12
- description?: string;
13
- }
14
- const { href, title, description } = Astro.props as Props;
15
- const Tag = href ? 'a' : 'div';
16
- ---
17
- <Tag class:list={["wd-tile", extraClasses(Astro.props)]} href={href}>
18
- <div class="wd-tile-preview"><slot /></div>
19
- {title && <div class="wd-tile-title" set:html={inlineMarkdown(title)} />}
20
- {description && <div class="wd-tile-description">{description}</div>}
21
- </Tag>
22
- <style>
23
- .wd-tile {
24
- display: block;
25
- text-decoration: none;
26
- color: inherit;
27
- }
28
- /* Dotted pattern behind the preview, drawn from the theme's own border
29
- color so it reads in both themes. */
30
- .wd-tile-preview {
31
- display: flex;
32
- align-items: center;
33
- justify-content: center;
34
- height: 10rem;
35
- overflow: hidden;
36
- border: 1px solid var(--wd-border);
37
- border-radius: 0.6rem;
38
- background-color: var(--wd-surface);
39
- background-image: radial-gradient(var(--wd-border) 1px, transparent 1px);
40
- background-size: 14px 14px;
41
- transition: border-color 0.15s ease;
42
- }
43
- a.wd-tile:hover .wd-tile-preview {
44
- border-color: var(--wd-primary);
45
- }
46
- .wd-tile-preview :global(img),
47
- .wd-tile-preview :global(svg) {
48
- max-width: 100%;
49
- max-height: 100%;
50
- object-fit: contain;
51
- margin: 0;
52
- }
53
- .wd-tile-preview :global(p) {
54
- display: contents;
55
- }
56
- .wd-tile-title {
57
- margin-top: 0.6rem;
58
- font-weight: 600;
59
- color: var(--wd-heading);
60
- }
61
- .wd-tile-description {
62
- margin-top: 0.15rem;
63
- font-size: 0.875rem;
64
- color: var(--wd-text);
65
- }
66
- </style>
1
+ ---
2
+ import { extraClasses } from './class-names';
3
+ // Mintlify's <Tile> - a visual preview (the slot, usually an image or a
4
+ // light/dark image pair) on a patterned background, with a title and
5
+ // description under it. Usually laid out in a <Columns> grid. `title`
6
+ // takes inline Markdown (`code`, **bold**, *italic*), like Mintlify's.
7
+ import { inlineMarkdown } from '../lib/inline-markdown.js';
8
+ import { siteHref } from '../lib/site-base';
9
+
10
+ interface Props {
11
+ href?: string;
12
+ title?: string;
13
+ description?: string;
14
+ }
15
+ const { href, title, description } = Astro.props as Props;
16
+ const Tag = href ? 'a' : 'div';
17
+ ---
18
+ <Tag class:list={["wd-tile", extraClasses(Astro.props)]} href={siteHref(href)}>
19
+ <div class="wd-tile-preview"><slot /></div>
20
+ {title && <div class="wd-tile-title" set:html={inlineMarkdown(title)} />}
21
+ {description && <div class="wd-tile-description">{description}</div>}
22
+ </Tag>
23
+ <style>
24
+ .wd-tile {
25
+ display: block;
26
+ text-decoration: none;
27
+ color: inherit;
28
+ }
29
+ /* Dotted pattern behind the preview, drawn from the theme's own border
30
+ color so it reads in both themes. */
31
+ .wd-tile-preview {
32
+ display: flex;
33
+ align-items: center;
34
+ justify-content: center;
35
+ height: 10rem;
36
+ overflow: hidden;
37
+ border: 1px solid var(--wd-border);
38
+ border-radius: 0.6rem;
39
+ background-color: var(--wd-surface);
40
+ background-image: radial-gradient(var(--wd-border) 1px, transparent 1px);
41
+ background-size: 14px 14px;
42
+ transition: border-color 0.15s ease;
43
+ }
44
+ a.wd-tile:hover .wd-tile-preview {
45
+ border-color: var(--wd-primary);
46
+ }
47
+ .wd-tile-preview :global(img),
48
+ .wd-tile-preview :global(svg) {
49
+ max-width: 100%;
50
+ max-height: 100%;
51
+ object-fit: contain;
52
+ margin: 0;
53
+ }
54
+ .wd-tile-preview :global(p) {
55
+ display: contents;
56
+ }
57
+ .wd-tile-title {
58
+ margin-top: 0.6rem;
59
+ font-weight: 600;
60
+ color: var(--wd-heading);
61
+ }
62
+ .wd-tile-description {
63
+ margin-top: 0.15rem;
64
+ font-size: 0.875rem;
65
+ color: var(--wd-text);
66
+ }
67
+ </style>
@@ -1,136 +1,137 @@
1
- ---
2
- import { extraClasses } from './class-names';
3
- // Renders either a native <video> or an <iframe> embed from the same
4
- // `src` prop, auto-detected rather than requiring the author to pick -
5
- // `src="media/clip.mp4"` (a direct video file, local or remote) gets a
6
- // real <video controls>; `src="https://www.youtube.com/embed/..."` (or
7
- // Vimeo, Loom, any other embed URL with no recognizable video file
8
- // extension) gets an <iframe>. Same block-level, own-line, centered
9
- // shape as Image/Frame, and shares their exact card language (border-
10
- // radius, padding, box-shadow) - "same border radius as image and
11
- // frame" was the explicit ask this was built against.
12
- interface Props {
13
- src: string;
14
- // A raw CSS width ("500px", "80%", "40rem", ...) - named `width`
15
- // here (not `size`, Image's own name for the same idea) to match
16
- // this component's own requested API exactly. Same "applied to the
17
- // wrapping figure, not the media element" approach Image.astro's own
18
- // `size` prop uses (see its comment for the real bug that came from
19
- // getting this wrong once already) - the whole component, card
20
- // background included, sizes to `width`, not just the video/iframe
21
- // inside it.
22
- width?: string;
23
- // Only meaningful for the <video> branch - ignored (not rendered as
24
- // an attribute at all) for an <iframe> embed, since a YouTube/Vimeo
25
- // player controls its own playback UI, autoplay policy, and looping
26
- // through its own embed URL query params instead.
27
- controls?: boolean;
28
- autoplay?: boolean;
29
- loop?: boolean;
30
- muted?: boolean;
31
- // Alt text has no real equivalent for video - `title` is the
32
- // accessible-name attribute both <video> (via a wrapping description)
33
- // and <iframe> (a required attribute for a11y tooling to identify
34
- // embedded content) actually use.
35
- title?: string;
36
- caption?: string;
37
- }
38
- const {
39
- src,
40
- width,
41
- controls = true,
42
- autoplay = false,
43
- loop = false,
44
- muted = false,
45
- title,
46
- caption,
47
- } = Astro.props as Props;
48
- const isFile = /\.(mp4|webm|ogg|ogv|mov|m4v)(\?.*)?(#.*)?$/i.test(src);
49
- const sizeStyle = width ? `--wd-video-size:${width}` : undefined;
50
- // Autoplaying video muted is a hard browser requirement, not a style
51
- // choice - every major browser silently blocks (or, worse, plays with
52
- // sound the visitor didn't ask for and then gets auto-paused
53
- // inconsistently) an unmuted autoplay <video>, so an author setting
54
- // autoplay without also remembering muted would get a broken-looking
55
- // embed rather than the "plays immediately" behavior they actually
56
- // asked for. Forcing it here means autoplay just works the one way
57
- // it's actually able to.
58
- const effectiveMuted = muted || autoplay;
59
- ---
60
-
61
- <figure class:list={["wd-video-figure", caption && "wd-video-figure-framed", extraClasses(Astro.props)]} style={sizeStyle}>
62
- {
63
- isFile ? (
64
- <video
65
- class="wd-video"
66
- src={src}
67
- controls={controls}
68
- autoplay={autoplay}
69
- loop={loop}
70
- muted={effectiveMuted}
71
- playsinline
72
- title={title}
73
- />
74
- ) : (
75
- <iframe
76
- class="wd-video wd-video-embed"
77
- src={src}
78
- title={title ?? "Embedded video"}
79
- loading="lazy"
80
- allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
81
- allowfullscreen
82
- />
83
- )
84
- }
85
- {caption && <figcaption class="wd-video-caption">{caption}</figcaption>}
86
- </figure>
87
- <style>
88
- /* Same three rules as Image.astro's own .wd-image-figure/
89
- .wd-image-figure-framed/.wd-image-caption - see that file's own
90
- comments for why width lives on the figure (not the media element),
91
- why padding is what creates the inset-in-a-card look, and why
92
- box-shadow exists alongside the border. Kept in sync on purpose -
93
- both components are explicitly meant to look identical modulo
94
- what's actually inside them. */
95
- .wd-video-figure {
96
- width: var(--wd-video-size, 100%);
97
- max-width: 100%;
98
- margin: 1.25rem auto;
99
- }
100
- .wd-video-figure-framed {
101
- border: 1px solid var(--wd-border);
102
- border-radius: 0.75rem;
103
- background: var(--wd-surface);
104
- padding: 0.5rem;
105
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
106
- }
107
- .wd-video {
108
- display: block;
109
- width: 100%;
110
- height: auto;
111
- border: 0;
112
- border-radius: 0.75rem;
113
- }
114
- /* Unlike <img>/<video> (both read their own intrinsic dimensions once
115
- loaded, so width: 100%; height: auto keeps them proportional on
116
- their own), a bare <iframe> has no intrinsic size at all - without
117
- something constraining its height it either collapses to the UA
118
- default (~150px) or needs an explicit pixel height the embedding
119
- author would have to compute themselves. aspect-ratio: 16 / 9 is
120
- the standard embed shape (YouTube, Vimeo, Loom, ...) and needs no
121
- JS/ResizeObserver trick to stay proportional as width changes -
122
- it's a real, if imperfect, default for embeds that aren't actually
123
- 16:9 (a vertical/Shorts-style video letterboxes instead of filling
124
- the frame), which there's no way to detect automatically from a
125
- bare embed URL.
126
- */
127
- .wd-video-embed {
128
- aspect-ratio: 16 / 9;
129
- }
130
- .wd-video-caption {
131
- margin-top: 0.6rem;
132
- text-align: center;
133
- color: var(--wd-text);
134
- font-size: 0.75rem;
135
- }
136
- </style>
1
+ ---
2
+ import { extraClasses } from './class-names';
3
+ import { siteHref } from '../lib/site-base';
4
+ // Renders either a native <video> or an <iframe> embed from the same
5
+ // `src` prop, auto-detected rather than requiring the author to pick -
6
+ // `src="media/clip.mp4"` (a direct video file, local or remote) gets a
7
+ // real <video controls>; `src="https://www.youtube.com/embed/..."` (or
8
+ // Vimeo, Loom, any other embed URL with no recognizable video file
9
+ // extension) gets an <iframe>. Same block-level, own-line, centered
10
+ // shape as Image/Frame, and shares their exact card language (border-
11
+ // radius, padding, box-shadow) - "same border radius as image and
12
+ // frame" was the explicit ask this was built against.
13
+ interface Props {
14
+ src: string;
15
+ // A raw CSS width ("500px", "80%", "40rem", ...) - named `width`
16
+ // here (not `size`, Image's own name for the same idea) to match
17
+ // this component's own requested API exactly. Same "applied to the
18
+ // wrapping figure, not the media element" approach Image.astro's own
19
+ // `size` prop uses (see its comment for the real bug that came from
20
+ // getting this wrong once already) - the whole component, card
21
+ // background included, sizes to `width`, not just the video/iframe
22
+ // inside it.
23
+ width?: string;
24
+ // Only meaningful for the <video> branch - ignored (not rendered as
25
+ // an attribute at all) for an <iframe> embed, since a YouTube/Vimeo
26
+ // player controls its own playback UI, autoplay policy, and looping
27
+ // through its own embed URL query params instead.
28
+ controls?: boolean;
29
+ autoplay?: boolean;
30
+ loop?: boolean;
31
+ muted?: boolean;
32
+ // Alt text has no real equivalent for video - `title` is the
33
+ // accessible-name attribute both <video> (via a wrapping description)
34
+ // and <iframe> (a required attribute for a11y tooling to identify
35
+ // embedded content) actually use.
36
+ title?: string;
37
+ caption?: string;
38
+ }
39
+ const {
40
+ src,
41
+ width,
42
+ controls = true,
43
+ autoplay = false,
44
+ loop = false,
45
+ muted = false,
46
+ title,
47
+ caption,
48
+ } = Astro.props as Props;
49
+ const isFile = /\.(mp4|webm|ogg|ogv|mov|m4v)(\?.*)?(#.*)?$/i.test(src);
50
+ const sizeStyle = width ? `--wd-video-size:${width}` : undefined;
51
+ // Autoplaying video muted is a hard browser requirement, not a style
52
+ // choice - every major browser silently blocks (or, worse, plays with
53
+ // sound the visitor didn't ask for and then gets auto-paused
54
+ // inconsistently) an unmuted autoplay <video>, so an author setting
55
+ // autoplay without also remembering muted would get a broken-looking
56
+ // embed rather than the "plays immediately" behavior they actually
57
+ // asked for. Forcing it here means autoplay just works the one way
58
+ // it's actually able to.
59
+ const effectiveMuted = muted || autoplay;
60
+ ---
61
+
62
+ <figure class:list={["wd-video-figure", caption && "wd-video-figure-framed", extraClasses(Astro.props)]} style={sizeStyle}>
63
+ {
64
+ isFile ? (
65
+ <video
66
+ class="wd-video"
67
+ src={siteHref(src)}
68
+ controls={controls}
69
+ autoplay={autoplay}
70
+ loop={loop}
71
+ muted={effectiveMuted}
72
+ playsinline
73
+ title={title}
74
+ />
75
+ ) : (
76
+ <iframe
77
+ class="wd-video wd-video-embed"
78
+ src={siteHref(src)}
79
+ title={title ?? "Embedded video"}
80
+ loading="lazy"
81
+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
82
+ allowfullscreen
83
+ />
84
+ )
85
+ }
86
+ {caption && <figcaption class="wd-video-caption">{caption}</figcaption>}
87
+ </figure>
88
+ <style>
89
+ /* Same three rules as Image.astro's own .wd-image-figure/
90
+ .wd-image-figure-framed/.wd-image-caption - see that file's own
91
+ comments for why width lives on the figure (not the media element),
92
+ why padding is what creates the inset-in-a-card look, and why
93
+ box-shadow exists alongside the border. Kept in sync on purpose -
94
+ both components are explicitly meant to look identical modulo
95
+ what's actually inside them. */
96
+ .wd-video-figure {
97
+ width: var(--wd-video-size, 100%);
98
+ max-width: 100%;
99
+ margin: 1.25rem auto;
100
+ }
101
+ .wd-video-figure-framed {
102
+ border: 1px solid var(--wd-border);
103
+ border-radius: 0.75rem;
104
+ background: var(--wd-surface);
105
+ padding: 0.5rem;
106
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
107
+ }
108
+ .wd-video {
109
+ display: block;
110
+ width: 100%;
111
+ height: auto;
112
+ border: 0;
113
+ border-radius: 0.75rem;
114
+ }
115
+ /* Unlike <img>/<video> (both read their own intrinsic dimensions once
116
+ loaded, so width: 100%; height: auto keeps them proportional on
117
+ their own), a bare <iframe> has no intrinsic size at all - without
118
+ something constraining its height it either collapses to the UA
119
+ default (~150px) or needs an explicit pixel height the embedding
120
+ author would have to compute themselves. aspect-ratio: 16 / 9 is
121
+ the standard embed shape (YouTube, Vimeo, Loom, ...) and needs no
122
+ JS/ResizeObserver trick to stay proportional as width changes -
123
+ it's a real, if imperfect, default for embeds that aren't actually
124
+ 16:9 (a vertical/Shorts-style video letterboxes instead of filling
125
+ the frame), which there's no way to detect automatically from a
126
+ bare embed URL.
127
+ */
128
+ .wd-video-embed {
129
+ aspect-ratio: 16 / 9;
130
+ }
131
+ .wd-video-caption {
132
+ margin-top: 0.6rem;
133
+ text-align: center;
134
+ color: var(--wd-text);
135
+ font-size: 0.75rem;
136
+ }
137
+ </style>
@@ -29,6 +29,7 @@ import fs from "node:fs";
29
29
  import nodePath from "node:path";
30
30
  import {
31
31
  resolveSiteUrl,
32
+ resolveSiteRoot,
32
33
  findRootAssets,
33
34
  resolveNavbarColor,
34
35
  contrastTextColor,
@@ -83,6 +84,9 @@ import { contextMenuOptions } from "../lib/config";
83
84
  import { jsonLd, serializeJsonLd } from "../lib/json-ld.js";
84
85
  import { consentOptions } from "../lib/consent.js";
85
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";
86
90
 
87
91
  interface Props {
88
92
  config: DocsConfig;
@@ -91,7 +95,8 @@ interface Props {
91
95
  // see [...slug].astro, which passes entry.data.description straight
92
96
  // through without resolving the fallback itself.
93
97
  description?: string;
94
- // The current page's own path (e.g. "/" or "/guides/foo/"), used to
98
+ // The current page's own path (e.g. "/" or "/guides/foo/" - without the
99
+ // basePath, which siteUrl carries), used to
95
100
  // build the canonical <link> and og:url/twitter:url - [...slug].astro
96
101
  // already computes this via hrefForSlug(currentFileId) for its own
97
102
  // prev/next links, so it's passed through rather than recomputed here.
@@ -170,6 +175,7 @@ const head = seoHead({
170
175
  seo,
171
176
  siteUrl,
172
177
  path,
178
+ base: BASE,
173
179
  });
174
180
  // hreflang: only on a page search engines index, and only with full URLs.
175
181
  const languageLinks = seo.noindex ? [] : hreflangLinks(siteUrl, alternates);
@@ -194,7 +200,7 @@ const structuredData = jsonLd({
194
200
  });
195
201
  // The note that tells an AI agent reading this page where llms.txt is -
196
202
  // see lib/agent-directive.js.
197
- const agentNote = htmlDirective({ siteUrl, markdownPages: contextMenuOptions(config.contextMenu).length > 0 });
203
+ const agentNote = htmlDirective({ siteUrl: resolveSiteRoot(config) || null, markdownPages: contextMenuOptions(config.contextMenu).length > 0 });
198
204
  // Analytics wait for the reader's answer when the consent banner is on -
199
205
  // see lib/consent.js.
200
206
  const consent = consentOptions(config.integrations.consent);
@@ -330,10 +336,10 @@ const darkNavbarHover = darkNavbarConfigured ? `color-mix(in srgb, ${darkNavbarF
330
336
  const lightPageBgColor = lightBackground;
331
337
  const darkPageBgColor = darkBackground;
332
338
  const lightPageBgImage = config.styles.background?.images?.light
333
- ? `url('${config.styles.background.images.light}')`
339
+ ? `url('${siteHref(config.styles.background.images.light)}')`
334
340
  : "none";
335
341
  const darkPageBgImage = config.styles.background?.images?.dark
336
- ? `url('${config.styles.background.images.dark}')`
342
+ ? `url('${siteHref(config.styles.background.images.dark)}')`
337
343
  : "none";
338
344
  // A logo is either one path used for both modes, or a {light, dark,
339
345
  // label} object - normalized to a single light/dark pair here (the one
@@ -451,10 +457,13 @@ const wdFontFamilyBody = resolvedFonts.body ? fontStack(resolvedFonts.body.famil
451
457
  // descriptor, or the Google Fonts URL's `:wght@` axis inside
452
458
  // googleFontsHref() above), not the actual rendered boldness of any
453
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;
454
463
  const fontFaceCss = [
455
- fontFaceRule(resolvedFonts.base),
456
- fontFaceRule(resolvedFonts.heading),
457
- fontFaceRule(resolvedFonts.body),
464
+ fontFaceRule(withSourceBase(resolvedFonts.base)),
465
+ fontFaceRule(withSourceBase(resolvedFonts.heading)),
466
+ fontFaceRule(withSourceBase(resolvedFonts.body)),
458
467
  ]
459
468
  .filter(Boolean)
460
469
  .join("\n");
@@ -506,7 +515,7 @@ const fontExtraCss = [fontFaceCss, fontFallbackCss, fontWeightCss].filter(Boolea
506
515
  ),
507
516
  )
508
517
  }
509
- {config.styles.favicon && <link rel="icon" href={config.styles.favicon} />}
518
+ {config.styles.favicon && <link rel="icon" href={siteHref(config.styles.favicon)} />}
510
519
  {
511
520
  /* styles.fonts - see resolveFonts()/googleFontsHref() in lib/config.ts.
512
521
  Present (non-null) whenever at least one configured font (or the
@@ -726,7 +735,7 @@ const fontExtraCss = [fontFaceCss, fontFallbackCss, fontWeightCss].filter(Boolea
726
735
  {
727
736
  config.scripts.head
728
737
  .filter((s) => !gated(s))
729
- .map((s) => (s.src ? <script is:inline src={s.src} /> : <script is:inline set:html={s.content} />))
738
+ .map((s) => (s.src ? <script is:inline src={siteHref(s.src)} /> : <script is:inline set:html={s.content} />))
730
739
  }
731
740
  {
732
741
  /* Zero-config custom CSS - see findRootAssets() in lib/pages.js and
@@ -747,7 +756,7 @@ const fontExtraCss = [fontFaceCss, fontFallbackCss, fontWeightCss].filter(Boolea
747
756
  pointing at their already-public URL instead of joining
748
757
  rootCssContents above as inlined content. */
749
758
  }
750
- {publicCssHrefs.map((href) => <link rel="stylesheet" href={href} />)}
759
+ {publicCssHrefs.map((href) => <link rel="stylesheet" href={siteHref(href)} />)}
751
760
  </head>
752
761
  <body>
753
762
  {
@@ -861,7 +870,7 @@ const fontExtraCss = [fontFaceCss, fontFallbackCss, fontWeightCss].filter(Boolea
861
870
  {
862
871
  config.scripts.body
863
872
  .filter((s) => !gated(s))
864
- .map((s) => (s.src ? <script is:inline src={s.src} /> : <script is:inline set:html={s.content} />))
873
+ .map((s) => (s.src ? <script is:inline src={siteHref(s.src)} /> : <script is:inline set:html={s.content} />))
865
874
  }
866
875
  {
867
876
  /* Zero-config custom JS - see findRootAssets() in lib/pages.js and
@@ -889,7 +898,7 @@ const fontExtraCss = [fontFaceCss, fontFallbackCss, fontWeightCss].filter(Boolea
889
898
  the more common spot for a plain local script and this hasn't come
890
899
  up in practice). */
891
900
  }
892
- {publicJsHrefs.map((href) => <script is:inline src={href} />)}
901
+ {publicJsHrefs.map((href) => <script is:inline src={siteHref(href)} />)}
893
902
  {
894
903
  /* writedocs.json's `integrations.askAi` - see AskAiWidget.astro. Rendered
895
904
  last of all - it's a floating chat widget, not something anything
@@ -22,6 +22,7 @@
22
22
  // it doesn't wait for consent.
23
23
  import type { DocsConfig } from '../../lib/config';
24
24
  import { analyticsTags, scriptTags, consentLoaderScript } from '../../lib/consent.js';
25
+ import { siteHref } from '../../lib/site-base';
25
26
 
26
27
  interface Props {
27
28
  config: DocsConfig;
@@ -33,8 +34,11 @@ interface Props {
33
34
  }
34
35
  const { config, consent = null, gatedScripts = [] } = Astro.props as Props;
35
36
 
36
- const tags = analyticsTags(config.integrations);
37
- const loader = consent ? consentLoaderScript([...tags, ...scriptTags(gatedScripts)]) : null;
37
+ // A script's `src` can be a file in the site ("/js/stats.js"): it gets the
38
+ // basePath (lib/site-base.ts).
39
+ const withSrcBase = <T extends { src?: string }>(tag: T): T => (tag.src ? { ...tag, src: siteHref(tag.src) } : tag);
40
+ const tags = analyticsTags(config.integrations).map(withSrcBase);
41
+ const loader = consent ? consentLoaderScript([...tags, ...scriptTags(gatedScripts).map(withSrcBase)]) : null;
38
42
  ---
39
43
  {loader ? (
40
44
  <script is:inline set:html={loader} />