@writedocs/generator 0.13.3 → 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 (87) hide show
  1. package/README.md +28 -28
  2. package/astro.config.mjs +645 -645
  3. package/bin/writedocs.js +43 -12
  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 +1 -1
  10. package/src/cli/dev.js +268 -268
  11. package/src/cli/exit-when-flushed.js +4 -0
  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.js +414 -75
  48. package/src/lib/config-schema.ts +2509 -1905
  49. package/src/lib/config.ts +1316 -1314
  50. package/src/lib/consent.js +108 -108
  51. package/src/lib/content-store-reload-integration.js +101 -101
  52. package/src/lib/icon-data-dev.js +53 -53
  53. package/src/lib/image-size.js +152 -152
  54. package/src/lib/json-schema-descriptions.js +228 -228
  55. package/src/lib/link-check.js +544 -544
  56. package/src/lib/llms-index.ts +90 -90
  57. package/src/lib/mcp-dev-integration.js +65 -65
  58. package/src/lib/mcp-index.ts +102 -102
  59. package/src/lib/mintlify-convert.js +605 -605
  60. package/src/lib/moved-api-pages.js +49 -49
  61. package/src/lib/og-cards.js +33 -33
  62. package/src/lib/og-image.js +235 -235
  63. package/src/lib/openapi-dev-status.js +80 -80
  64. package/src/lib/openapi-reload-integration.js +193 -193
  65. package/src/lib/pages.js +312 -312
  66. package/src/lib/project-files-integration.js +116 -116
  67. package/src/lib/project-files.js +137 -137
  68. package/src/lib/rehype-base-path.js +62 -62
  69. package/src/lib/rehype-image-loading.js +71 -71
  70. package/src/lib/robots-txt.js +21 -21
  71. package/src/lib/search-scope.js +44 -44
  72. package/src/lib/selector-placement.js +50 -50
  73. package/src/lib/seo-tags.js +155 -155
  74. package/src/lib/shiki-code-block.js +7 -1
  75. package/src/lib/site-base.ts +27 -27
  76. package/src/lib/styles-asset-integration.js +291 -291
  77. package/src/lib/wdignore-cases.json +195 -195
  78. package/src/lib/wdignore.js +177 -177
  79. package/src/pages/404.astro +63 -63
  80. package/src/pages/[...slug].astro +1762 -1608
  81. package/src/pages/[...slug].md.ts +93 -93
  82. package/src/pages/llms-full.txt.ts +88 -88
  83. package/src/pages/og/[...slug].png.ts +63 -63
  84. package/src/scripts/mobile-menu.ts +80 -80
  85. package/src/scripts/search.ts +245 -245
  86. package/src/scripts/sidebar-scroll.ts +61 -61
  87. package/src/styles/global.css +40 -40
@@ -1,158 +1,158 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { readConfigText } from '../lib/config-file.js';
4
- import { readMovedApiPages } from '../lib/moved-api-pages.js';
5
- import { withBase } from '../lib/base-path.js';
6
-
7
- // Astro's own `output: 'static'` redirects (both writedocs.json's `redirects`
8
- // feature and the automatic "/" -> first-nav-page redirect in
9
- // [...slug].astro) are never real server/edge redirects - with no adapter
10
- // installed, Astro can only ever emit a client-side
11
- // `<meta http-equiv="refresh">` page (see redirectSchema's own comment in
12
- // lib/config.ts for why `permanent`/status-code isn't even offered as a
13
- // config option). That page is a real, working redirect, but it's a flash
14
- // of unstyled content before the browser honors the meta-refresh - visibly
15
- // bad on a deployed site, and exactly what a reader lands on for a second
16
- // or more depending on network/host latency.
17
- //
18
- // Cloudflare Pages and Netlify both read a `_redirects` file at the root
19
- // of the deployed output and turn each line into a real edge-level
20
- // redirect - no page ever renders, no flash. This step generates that file
21
- // as a purely additive improvement: hosts that honor `_redirects` get an
22
- // instant real redirect, and every other static host (S3, GitHub Pages,
23
- // etc.) falls back to the meta-refresh page Astro already generates, which
24
- // keeps working exactly as before. Neither this file nor its absence ever
25
- // changes what Astro itself builds.
26
- // `contentDir` rather than a pre-loaded config object: this runs from
27
- // build.js, invoked by plain `node`, not through Astro/Vite's TS
28
- // transform - loadDocsConfig() (lib/config.ts) can't be imported here the
29
- // way astro.config.mjs and every .astro file import it. writedocs.json has
30
- // already been through preflightCheck() (valid JSON) and Astro's own
31
- // loadDocsConfig() call inside astro.config.mjs (schema-valid, or the
32
- // build above would already have failed) by the time this runs, so a
33
- // second, un-validated JSON.parse() here is safe - this only ever reads
34
- // the one `redirects` array back out, nothing that needs zod's defaults
35
- // or transforms.
36
- //
37
- // `distDir` is the site's own folder - dist/, or dist/docs/ with a
38
- // `basePath` (base-path-layout.js) - where the built pages are read from.
39
- // `outDir` is where `_redirects` goes: the root of dist/, always, since the
40
- // host reads it there. `basePath` ("/docs") goes in front of every address
41
- // the rules name, source and destination - the host matches the full path
42
- // it was asked for - and adds `/ -> /docs/` for whoever opens the root of
43
- // the address directly.
44
- export function writeRedirectsFile(distDir, contentDir, { outDir = distDir, basePath = '' } = {}) {
45
- const writedocsJson = JSON.parse(readConfigText(contentDir));
46
- const redirects = writedocsJson.redirects ?? [];
47
- const lines = [];
48
- const at = (address) => withBase(basePath, address);
49
-
50
- // writedocs.json's own `redirects` array - one line per entry, always 301
51
- // (there's nowhere else in this project to source a status code from;
52
- // see redirectSchema's comment in lib/config.ts on why the schema itself
53
- // has no field for one - a redirect a site author deliberately
54
- // configured is safe to treat as permanent).
55
- // Each address in both forms, with and without the trailing slash:
56
- // `_redirects` matches the path as it was requested, and a rule for
57
- // "/old" alone left "/old/" to the fallback page - a 200, not a 301.
58
- // An address the site lists itself keeps its own destination.
59
- const listed = new Set(redirects.map((r) => r.source));
60
- for (const { source, destination } of redirects) {
61
- lines.push(`${at(source)} ${at(destination)} 301`);
62
- const other = otherSlashForm(source);
63
- if (other && !listed.has(other)) lines.push(`${at(other)} ${at(destination)} 301`);
64
- }
65
- // Generated API pages that changed address (lib/moved-api-pages.js) -
66
- // after the site's own, which win for the same address (first match).
67
- // With and without the trailing slash: `_redirects` matches the path
68
- // as requested.
69
- for (const { source, destination } of readMovedApiPages(contentDir)) {
70
- if (redirects.some((r) => r.source.replace(/\/+$/, '') === source)) continue;
71
- lines.push(`${at(source)} ${at(destination)} 301`, `${at(source)}/ ${at(destination)} 301`);
72
- }
73
-
74
- // The automatic root "/" redirect (see the `rootRedirect` block in
75
- // [...slug].astro's getStaticPaths()) isn't reachable from here without
76
- // re-deriving the same first-nav-page resolution Astro already did -
77
- // instead, read it straight back out of the meta-refresh tag in the
78
- // already-built dist/index.html. If writedocs.json already defines its own
79
- // `/` redirect above, that one wins (first match wins in `_redirects`,
80
- // and it's already listed first) - skip the automatic one entirely
81
- // rather than emit a second, unreachable rule for the same path.
82
- const hasExplicitRootRedirect = redirects.some((r) => r.source === '/');
83
- const indexHtmlPath = path.join(distDir, 'index.html');
84
- if (!hasExplicitRootRedirect && fs.existsSync(indexHtmlPath)) {
85
- const html = fs.readFileSync(indexHtmlPath, 'utf8');
86
- const match = html.match(/<meta http-equiv="refresh" content="\d+;\s*url=([^"]+)"/i);
87
- // 302, not 301: see [...slug].astro - a browser keeps a 301 for good,
88
- // and "/" stops redirecting once the site gets a home page. The page's
89
- // target already carries the base ([...slug].astro writes it so); the
90
- // site's root under a base answers with and without the slash.
91
- if (match) lines.push(basePath ? `${basePath}/ ${match[1]} 302` : `/ ${match[1]} 302`);
92
- if (match && basePath) lines.push(`${basePath} ${match[1]} 302`);
93
- }
94
-
95
- // Folder addresses redirecting to the first page under them
96
- // (lib/folder-redirects.js). Read back from the built pages like "/"
97
- // above: Astro writes a temporary (302) redirect's page with a 2-second
98
- // refresh and a permanent one's with 0 - writedocs.json's own redirects
99
- // and `url` pages are permanent, so the 2-second ones are exactly the
100
- // automatic folder redirects. (Read before rewrite-redirect-pages.js makes
101
- // every redirect page go at once.)
102
- for (const { url, target } of temporaryRedirectPages(distDir)) {
103
- lines.push(`${at(url)} ${target} 302`, `${at(url).replace(/\/$/, '')} ${target} 302`);
104
- }
105
-
106
- // The root of the address, opened directly (empresa.com/ on a host that
107
- // serves only this site): to the site, under its base. Temporary, like "/".
108
- if (basePath) lines.push(`/ ${basePath}/ 302`);
109
-
110
- if (lines.length === 0) return;
111
-
112
- const generated = [
113
- '# Generated by writedocs (see src/cli/write-redirects-file.js).',
114
- '# Gives Cloudflare Pages / Netlify a real edge redirect for the same',
115
- "# paths Astro's own static-mode <meta http-equiv=\"refresh\"> pages",
116
- '# already cover - other static hosts keep using those pages as-is.',
117
- ...lines,
118
- '',
119
- ].join('\n');
120
-
121
- const redirectsPath = path.join(outDir, '_redirects');
122
- // A hand-written public/_redirects is already copied into dist by Astro
123
- // by this point - preserve it (and its priority: first match wins) by
124
- // appending after it rather than overwriting.
125
- const existing = fs.existsSync(redirectsPath) ? fs.readFileSync(redirectsPath, 'utf8').replace(/\s*$/, '\n\n') : '';
126
- fs.writeFileSync(redirectsPath, existing + generated);
127
- }
128
-
129
- /** "/old" for "/old/" and the reverse - null for the root, and for an
130
- * address that names a file ("/feed.xml"), which has one form only. */
131
- export function otherSlashForm(source) {
132
- if (typeof source !== 'string' || source === '/' || !source.startsWith('/')) return null;
133
- if (source.endsWith('/')) return source.slice(0, -1) || null;
134
- if (/\.[a-z0-9]+$/i.test(source.split('/').pop())) return null;
135
- return `${source}/`;
136
- }
137
-
138
- /** Astro's pages for temporary redirects below the site's root, as
139
- * `{ url: "/docs/creator/", target }`. */
140
- function temporaryRedirectPages(distDir) {
141
- const found = [];
142
- const walk = (dir) => {
143
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
144
- const full = path.join(dir, entry.name);
145
- if (entry.isDirectory()) {
146
- if (!['_astro', 'pagefind', 'pagefind-spaces'].includes(entry.name)) walk(full);
147
- continue;
148
- }
149
- if (entry.name !== 'index.html' || dir === distDir) continue;
150
- const html = fs.readFileSync(full, 'utf8');
151
- if (!html.includes('<title>Redirecting to:')) continue;
152
- const match = html.match(/<meta http-equiv="refresh" content="2;\s*url=([^"]+)"/i);
153
- if (match) found.push({ url: `/${path.relative(distDir, dir).split(path.sep).join('/')}/`, target: match[1] });
154
- }
155
- };
156
- walk(distDir);
157
- return found.sort((a, b) => a.url.localeCompare(b.url));
158
- }
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { readConfigText } from '../lib/config-file.js';
4
+ import { readMovedApiPages } from '../lib/moved-api-pages.js';
5
+ import { withBase } from '../lib/base-path.js';
6
+
7
+ // Astro's own `output: 'static'` redirects (both writedocs.json's `redirects`
8
+ // feature and the automatic "/" -> first-nav-page redirect in
9
+ // [...slug].astro) are never real server/edge redirects - with no adapter
10
+ // installed, Astro can only ever emit a client-side
11
+ // `<meta http-equiv="refresh">` page (see redirectSchema's own comment in
12
+ // lib/config.ts for why `permanent`/status-code isn't even offered as a
13
+ // config option). That page is a real, working redirect, but it's a flash
14
+ // of unstyled content before the browser honors the meta-refresh - visibly
15
+ // bad on a deployed site, and exactly what a reader lands on for a second
16
+ // or more depending on network/host latency.
17
+ //
18
+ // Cloudflare Pages and Netlify both read a `_redirects` file at the root
19
+ // of the deployed output and turn each line into a real edge-level
20
+ // redirect - no page ever renders, no flash. This step generates that file
21
+ // as a purely additive improvement: hosts that honor `_redirects` get an
22
+ // instant real redirect, and every other static host (S3, GitHub Pages,
23
+ // etc.) falls back to the meta-refresh page Astro already generates, which
24
+ // keeps working exactly as before. Neither this file nor its absence ever
25
+ // changes what Astro itself builds.
26
+ // `contentDir` rather than a pre-loaded config object: this runs from
27
+ // build.js, invoked by plain `node`, not through Astro/Vite's TS
28
+ // transform - loadDocsConfig() (lib/config.ts) can't be imported here the
29
+ // way astro.config.mjs and every .astro file import it. writedocs.json has
30
+ // already been through preflightCheck() (valid JSON) and Astro's own
31
+ // loadDocsConfig() call inside astro.config.mjs (schema-valid, or the
32
+ // build above would already have failed) by the time this runs, so a
33
+ // second, un-validated JSON.parse() here is safe - this only ever reads
34
+ // the one `redirects` array back out, nothing that needs zod's defaults
35
+ // or transforms.
36
+ //
37
+ // `distDir` is the site's own folder - dist/, or dist/docs/ with a
38
+ // `basePath` (base-path-layout.js) - where the built pages are read from.
39
+ // `outDir` is where `_redirects` goes: the root of dist/, always, since the
40
+ // host reads it there. `basePath` ("/docs") goes in front of every address
41
+ // the rules name, source and destination - the host matches the full path
42
+ // it was asked for - and adds `/ -> /docs/` for whoever opens the root of
43
+ // the address directly.
44
+ export function writeRedirectsFile(distDir, contentDir, { outDir = distDir, basePath = '' } = {}) {
45
+ const writedocsJson = JSON.parse(readConfigText(contentDir));
46
+ const redirects = writedocsJson.redirects ?? [];
47
+ const lines = [];
48
+ const at = (address) => withBase(basePath, address);
49
+
50
+ // writedocs.json's own `redirects` array - one line per entry, always 301
51
+ // (there's nowhere else in this project to source a status code from;
52
+ // see redirectSchema's comment in lib/config.ts on why the schema itself
53
+ // has no field for one - a redirect a site author deliberately
54
+ // configured is safe to treat as permanent).
55
+ // Each address in both forms, with and without the trailing slash:
56
+ // `_redirects` matches the path as it was requested, and a rule for
57
+ // "/old" alone left "/old/" to the fallback page - a 200, not a 301.
58
+ // An address the site lists itself keeps its own destination.
59
+ const listed = new Set(redirects.map((r) => r.source));
60
+ for (const { source, destination } of redirects) {
61
+ lines.push(`${at(source)} ${at(destination)} 301`);
62
+ const other = otherSlashForm(source);
63
+ if (other && !listed.has(other)) lines.push(`${at(other)} ${at(destination)} 301`);
64
+ }
65
+ // Generated API pages that changed address (lib/moved-api-pages.js) -
66
+ // after the site's own, which win for the same address (first match).
67
+ // With and without the trailing slash: `_redirects` matches the path
68
+ // as requested.
69
+ for (const { source, destination } of readMovedApiPages(contentDir)) {
70
+ if (redirects.some((r) => r.source.replace(/\/+$/, '') === source)) continue;
71
+ lines.push(`${at(source)} ${at(destination)} 301`, `${at(source)}/ ${at(destination)} 301`);
72
+ }
73
+
74
+ // The automatic root "/" redirect (see the `rootRedirect` block in
75
+ // [...slug].astro's getStaticPaths()) isn't reachable from here without
76
+ // re-deriving the same first-nav-page resolution Astro already did -
77
+ // instead, read it straight back out of the meta-refresh tag in the
78
+ // already-built dist/index.html. If writedocs.json already defines its own
79
+ // `/` redirect above, that one wins (first match wins in `_redirects`,
80
+ // and it's already listed first) - skip the automatic one entirely
81
+ // rather than emit a second, unreachable rule for the same path.
82
+ const hasExplicitRootRedirect = redirects.some((r) => r.source === '/');
83
+ const indexHtmlPath = path.join(distDir, 'index.html');
84
+ if (!hasExplicitRootRedirect && fs.existsSync(indexHtmlPath)) {
85
+ const html = fs.readFileSync(indexHtmlPath, 'utf8');
86
+ const match = html.match(/<meta http-equiv="refresh" content="\d+;\s*url=([^"]+)"/i);
87
+ // 302, not 301: see [...slug].astro - a browser keeps a 301 for good,
88
+ // and "/" stops redirecting once the site gets a home page. The page's
89
+ // target already carries the base ([...slug].astro writes it so); the
90
+ // site's root under a base answers with and without the slash.
91
+ if (match) lines.push(basePath ? `${basePath}/ ${match[1]} 302` : `/ ${match[1]} 302`);
92
+ if (match && basePath) lines.push(`${basePath} ${match[1]} 302`);
93
+ }
94
+
95
+ // Folder addresses redirecting to the first page under them
96
+ // (lib/folder-redirects.js). Read back from the built pages like "/"
97
+ // above: Astro writes a temporary (302) redirect's page with a 2-second
98
+ // refresh and a permanent one's with 0 - writedocs.json's own redirects
99
+ // and `url` pages are permanent, so the 2-second ones are exactly the
100
+ // automatic folder redirects. (Read before rewrite-redirect-pages.js makes
101
+ // every redirect page go at once.)
102
+ for (const { url, target } of temporaryRedirectPages(distDir)) {
103
+ lines.push(`${at(url)} ${target} 302`, `${at(url).replace(/\/$/, '')} ${target} 302`);
104
+ }
105
+
106
+ // The root of the address, opened directly (empresa.com/ on a host that
107
+ // serves only this site): to the site, under its base. Temporary, like "/".
108
+ if (basePath) lines.push(`/ ${basePath}/ 302`);
109
+
110
+ if (lines.length === 0) return;
111
+
112
+ const generated = [
113
+ '# Generated by writedocs (see src/cli/write-redirects-file.js).',
114
+ '# Gives Cloudflare Pages / Netlify a real edge redirect for the same',
115
+ "# paths Astro's own static-mode <meta http-equiv=\"refresh\"> pages",
116
+ '# already cover - other static hosts keep using those pages as-is.',
117
+ ...lines,
118
+ '',
119
+ ].join('\n');
120
+
121
+ const redirectsPath = path.join(outDir, '_redirects');
122
+ // A hand-written public/_redirects is already copied into dist by Astro
123
+ // by this point - preserve it (and its priority: first match wins) by
124
+ // appending after it rather than overwriting.
125
+ const existing = fs.existsSync(redirectsPath) ? fs.readFileSync(redirectsPath, 'utf8').replace(/\s*$/, '\n\n') : '';
126
+ fs.writeFileSync(redirectsPath, existing + generated);
127
+ }
128
+
129
+ /** "/old" for "/old/" and the reverse - null for the root, and for an
130
+ * address that names a file ("/feed.xml"), which has one form only. */
131
+ export function otherSlashForm(source) {
132
+ if (typeof source !== 'string' || source === '/' || !source.startsWith('/')) return null;
133
+ if (source.endsWith('/')) return source.slice(0, -1) || null;
134
+ if (/\.[a-z0-9]+$/i.test(source.split('/').pop())) return null;
135
+ return `${source}/`;
136
+ }
137
+
138
+ /** Astro's pages for temporary redirects below the site's root, as
139
+ * `{ url: "/docs/creator/", target }`. */
140
+ function temporaryRedirectPages(distDir) {
141
+ const found = [];
142
+ const walk = (dir) => {
143
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
144
+ const full = path.join(dir, entry.name);
145
+ if (entry.isDirectory()) {
146
+ if (!['_astro', 'pagefind', 'pagefind-spaces'].includes(entry.name)) walk(full);
147
+ continue;
148
+ }
149
+ if (entry.name !== 'index.html' || dir === distDir) continue;
150
+ const html = fs.readFileSync(full, 'utf8');
151
+ if (!html.includes('<title>Redirecting to:')) continue;
152
+ const match = html.match(/<meta http-equiv="refresh" content="2;\s*url=([^"]+)"/i);
153
+ if (match) found.push({ url: `/${path.relative(distDir, dir).split(path.sep).join('/')}/`, target: match[1] });
154
+ }
155
+ };
156
+ walk(distDir);
157
+ return found.sort((a, b) => a.url.localeCompare(b.url));
158
+ }