@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
package/src/cli/build.js CHANGED
@@ -1,203 +1,203 @@
1
- import { canonicalPath } from '../lib/canonical-path.js';
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- import { runAstro } from './run-astro.js';
5
- import { runPagefind } from './run-pagefind.js';
6
- import { preflightCheck, sameDriveCheck, writableInstallCheck } from './preflight.js';
7
- import { generateApiPages } from './generate-api-pages.js';
8
- import { writeRedirectsFile } from './write-redirects-file.js';
9
- import { rewriteRedirectPages } from './rewrite-redirect-pages.js';
10
- import { readConfigText } from '../lib/config-file.js';
11
- import { writeMcpFiles } from './write-mcp-files.js';
12
- import { pagesWithoutStyles } from './check-built-styles.js';
13
- import { writedocsBuildStagingDir, writedocsTempDir } from '../lib/writedocs-temp-dir.js';
14
- import { drawOgImages } from './og-images.js';
15
- import { normalizeBasePath } from '../lib/base-path.js';
16
- import { siteDirFor, moveRootFiles } from './base-path-layout.js';
17
- import { log, step, plural, duration, displayPath, formatProblems, color, CliExit } from './output.js';
18
- import { describeError, builtRoute, authorWarning, verboseLine } from './astro-output.js';
19
- import { reportApiPages } from './api-pages-output.js';
20
-
21
- export async function runBuild({ contentDir, packageRoot, verbose = false }) {
22
- // One spelling of each folder throughout - see lib/canonical-path.js.
23
- contentDir = canonicalPath(contentDir);
24
- packageRoot = canonicalPath(packageRoot);
25
- const started = Date.now();
26
- preflightCheck(contentDir);
27
- writableInstallCheck(packageRoot);
28
-
29
- // Collected while building, printed together at the end - a warning in
30
- // the middle of a spinner is easy to miss.
31
- const warnings = [];
32
- const notes = [];
33
- const seen = new Set();
34
- const addWarning = (where, message) => {
35
- const key = `${where ?? ''}\n${message}`;
36
- if (seen.has(key)) return;
37
- seen.add(key);
38
- warnings.push({ where, message });
39
- };
40
-
41
- const api = await generateApiPages({ contentDir });
42
- sameDriveCheck(contentDir, packageRoot, { generatedPages: api.groups.length > 0 });
43
- reportApiPages(api);
44
- api.warnings.forEach((message) => addWarning(null, message));
45
-
46
- const building = step('Building pages');
47
- const buildStarted = Date.now();
48
- let pages = 0;
49
- let fatal = null;
50
- const rawTail = [];
51
- // The link-preview cards: Astro's og route only writes their list here,
52
- // and this process draws them after Astro, in parallel (og-images.js).
53
- // Removed first, so a list from an earlier build is never drawn.
54
- const ogCardsFile = path.join(writedocsTempDir(contentDir), 'og-cards.json');
55
- fs.mkdirSync(path.dirname(ogCardsFile), { recursive: true });
56
- fs.rmSync(ogCardsFile, { force: true });
57
- const { exited } = runAstro('build', {
58
- packageRoot,
59
- contentDir,
60
- env: { WRITEDOCS_OG_CARDS_FILE: ogCardsFile },
61
- onEvent(event) {
62
- if (verbose) {
63
- const line = verboseLine(event);
64
- if (line !== null) log.line(color.dim(line));
65
- }
66
- if (event.type === 'fatal') {
67
- fatal = event.error;
68
- return;
69
- }
70
- if (event.type === 'report') {
71
- if (event.level === 'warn') addWarning(event.where, event.message);
72
- else if (event.level === 'info' && !notes.includes(event.message)) notes.push(event.message);
73
- return;
74
- }
75
- if (event.type === 'raw') {
76
- rawTail.push(event.line);
77
- if (rawTail.length > 40) rawTail.shift();
78
- return;
79
- }
80
- const route = builtRoute(event);
81
- if (route) {
82
- if (route.endsWith('.html')) pages += 1;
83
- building.update(`Building pages ${color.dim(`(${pages})`)}`);
84
- return;
85
- }
86
- const warning = authorWarning(event, contentDir, { root: packageRoot });
87
- if (warning) addWarning(null, warning);
88
- },
89
- });
90
- const code = await exited;
91
-
92
- if (fatal || code !== 0) {
93
- building.fail('Build failed');
94
- if (fatal) {
95
- const problem = describeError(fatal, contentDir, { root: packageRoot });
96
- log.line();
97
- log.line(formatProblems([{ where: problem.where, message: problem.message }]));
98
- if (problem.hint) log.line(`\n${color.dim(` Hint: ${problem.hint}`)}`);
99
- if (verbose && fatal.stack) log.line(`\n${color.dim(fatal.stack)}`);
100
- } else if (rawTail.length) {
101
- // No structured error (the worker itself crashed) - show what it printed.
102
- log.line();
103
- log.line(color.dim(rawTail.join('\n')));
104
- }
105
- log.line();
106
- log.line(color.dim('Run "writedocs validate" to list every problem in the project at once.'));
107
- throw new CliExit(1);
108
- }
109
- building.succeed(`Built ${plural(pages, 'page')} ${color.dim(`in ${duration(Date.now() - buildStarted)}`)}`);
110
-
111
- const distDir = path.join(contentDir, 'dist');
112
- // writedocs.json has been through the build's own validation by now.
113
- const siteConfig = JSON.parse(readConfigText(contentDir));
114
- // With a `basePath` ("/docs"), the site goes to dist/docs/ and only the
115
- // host's own files stay at the root of dist/ - see base-path-layout.js.
116
- // Without one, siteDir is distDir, and every step below is what it was.
117
- const basePath = normalizeBasePath(siteConfig.basePath);
118
- const siteDir = siteDirFor(distDir, basePath);
119
- // Astro just wrote its actual output to writedocsBuildStagingDir()
120
- // (astro.config.mjs's own `outDir`), not distDir directly - see that
121
- // function's own comment (writedocs-temp-dir.js) for why. fs.cpSync
122
- // (unlike the fs.rename() Astro uses internally to get *into* that
123
- // staging dir in the first place) copies across filesystem boundaries
124
- // without issue, so this is the one step that actually needs to bridge
125
- // packageRoot and contentDir potentially living on different devices.
126
- // distDir is cleared first so a rebuild doesn't leave a stale file
127
- // behind from a previous build that the new one no longer produces -
128
- // the same "the output directory reflects exactly this build, nothing
129
- // older" expectation `astro build` itself already guarantees when
130
- // writing directly into outDir.
131
- const stagingDir = writedocsBuildStagingDir(packageRoot, contentDir);
132
- // The cards Astro's route listed, into the staging folder's og/ - the
133
- // same files the route would have made, one thread per CPU (at most 4).
134
- // Drawn here, before the staging folder replaces dist/: when drawing
135
- // fails, the build stops with dist/ as it was - no dist/ at all, or the
136
- // last good build's - the same as when Astro itself fails. Drawn after the
137
- // copy, a failure left a dist/ with the new pages and none of their cards.
138
- const drawing = step('Drawing link previews');
139
- const drawStarted = Date.now();
140
- try {
141
- const drawn = await drawOgImages(ogCardsFile, stagingDir);
142
- if (drawn) drawing.succeed(`Drew ${plural(drawn, 'preview image')} ${color.dim(`in ${duration(Date.now() - drawStarted)}`)}`);
143
- else drawing.stop();
144
- } catch (err) {
145
- drawing.fail('Drawing the link previews failed');
146
- log.line();
147
- log.line(color.dim(err.message));
148
- throw new CliExit(1);
149
- }
150
- fs.rmSync(distDir, { recursive: true, force: true });
151
- fs.cpSync(stagingDir, siteDir, { recursive: true });
152
- fs.rmSync(stagingDir, { recursive: true, force: true });
153
- moveRootFiles(siteDir, distDir);
154
- // Every page writedocs renders links the site's stylesheet. Builds have
155
- // come out without it on every page while reporting success (the package
156
- // folder spelled `c:`, fixed in lib/canonical-path.js) - so it's checked
157
- // here, and a build like that stops instead of being deployed unstyled.
158
- const unstyled = pagesWithoutStyles(distDir, { basePath });
159
- if (unstyled.length) {
160
- log.error(`The build produced ${plural(unstyled.length, 'page')} without the site's styles - for example ${unstyled[0]}.`);
161
- log.detail(color.dim('This is a fault in the build, not in your pages. Build again; if it happens again, report it with the output of --verbose.'));
162
- throw new CliExit(1);
163
- }
164
- // Astro's own writedocs.json `redirects` + the automatic "/" redirect only
165
- // ever produce client-side meta-refresh pages (see write-redirects-file.js)
166
- // - this turns those into real instant edge redirects on hosts that read
167
- // a `_redirects` file (Cloudflare Pages, Netlify), purely additively.
168
- writeRedirectsFile(siteDir, contentDir, { outDir: distDir, basePath });
169
- // Every other host follows Astro's redirect pages - rewritten so the
170
- // reader never sees one (rewrite-redirect-pages.js).
171
- rewriteRedirectPages(siteDir, { background: siteConfig.styles?.background?.colors });
172
- // The site's MCP server at /mcp: mcp-index.json is already in dist/ (an
173
- // Astro route); this adds the Cloudflare _worker.js that serves it - see
174
- // write-mcp-files.js for every host.
175
- const { version: writedocsVersion } = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf-8'));
176
- const mcp = writeMcpFiles(distDir, contentDir, writedocsVersion, { siteDir, basePath });
177
- if (mcp.written.length) notes.push(`MCP server at ${basePath}/mcp - dist/_worker.js runs it on Cloudflare; mcp-index.json holds the pages.`);
178
- if (mcp.skipped) addWarning(null, `No _worker.js for the MCP server: ${mcp.skipped}.`);
179
-
180
- const indexing = step('Indexing search');
181
- try {
182
- await runPagefind(siteDir, { packageRoot });
183
- } catch (err) {
184
- indexing.fail('Search indexing failed');
185
- log.line();
186
- log.line(color.dim(err.message));
187
- throw new CliExit(1);
188
- }
189
- indexing.succeed('Indexed search');
190
-
191
- if (warnings.length) {
192
- log.line();
193
- log.warn(plural(warnings.length, 'warning'));
194
- log.line();
195
- log.line(formatProblems(warnings));
196
- }
197
- if (notes.length) {
198
- log.line();
199
- notes.forEach((note) => log.info(note));
200
- }
201
- log.line();
202
- log.success(`Done in ${duration(Date.now() - started)} ${color.dim('-')} site written to ${color.bold(displayPath(distDir))}`);
203
- }
1
+ import { canonicalPath } from '../lib/canonical-path.js';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { runAstro } from './run-astro.js';
5
+ import { runPagefind } from './run-pagefind.js';
6
+ import { preflightCheck, sameDriveCheck, writableInstallCheck } from './preflight.js';
7
+ import { generateApiPages } from './generate-api-pages.js';
8
+ import { writeRedirectsFile } from './write-redirects-file.js';
9
+ import { rewriteRedirectPages } from './rewrite-redirect-pages.js';
10
+ import { readConfigText } from '../lib/config-file.js';
11
+ import { writeMcpFiles } from './write-mcp-files.js';
12
+ import { pagesWithoutStyles } from './check-built-styles.js';
13
+ import { writedocsBuildStagingDir, writedocsTempDir } from '../lib/writedocs-temp-dir.js';
14
+ import { drawOgImages } from './og-images.js';
15
+ import { normalizeBasePath } from '../lib/base-path.js';
16
+ import { siteDirFor, moveRootFiles } from './base-path-layout.js';
17
+ import { log, step, plural, duration, displayPath, formatProblems, color, CliExit } from './output.js';
18
+ import { describeError, builtRoute, authorWarning, verboseLine } from './astro-output.js';
19
+ import { reportApiPages } from './api-pages-output.js';
20
+
21
+ export async function runBuild({ contentDir, packageRoot, verbose = false }) {
22
+ // One spelling of each folder throughout - see lib/canonical-path.js.
23
+ contentDir = canonicalPath(contentDir);
24
+ packageRoot = canonicalPath(packageRoot);
25
+ const started = Date.now();
26
+ preflightCheck(contentDir);
27
+ writableInstallCheck(packageRoot);
28
+
29
+ // Collected while building, printed together at the end - a warning in
30
+ // the middle of a spinner is easy to miss.
31
+ const warnings = [];
32
+ const notes = [];
33
+ const seen = new Set();
34
+ const addWarning = (where, message) => {
35
+ const key = `${where ?? ''}\n${message}`;
36
+ if (seen.has(key)) return;
37
+ seen.add(key);
38
+ warnings.push({ where, message });
39
+ };
40
+
41
+ const api = await generateApiPages({ contentDir });
42
+ sameDriveCheck(contentDir, packageRoot, { generatedPages: api.groups.length > 0 });
43
+ reportApiPages(api);
44
+ api.warnings.forEach((message) => addWarning(null, message));
45
+
46
+ const building = step('Building pages');
47
+ const buildStarted = Date.now();
48
+ let pages = 0;
49
+ let fatal = null;
50
+ const rawTail = [];
51
+ // The link-preview cards: Astro's og route only writes their list here,
52
+ // and this process draws them after Astro, in parallel (og-images.js).
53
+ // Removed first, so a list from an earlier build is never drawn.
54
+ const ogCardsFile = path.join(writedocsTempDir(contentDir), 'og-cards.json');
55
+ fs.mkdirSync(path.dirname(ogCardsFile), { recursive: true });
56
+ fs.rmSync(ogCardsFile, { force: true });
57
+ const { exited } = runAstro('build', {
58
+ packageRoot,
59
+ contentDir,
60
+ env: { WRITEDOCS_OG_CARDS_FILE: ogCardsFile },
61
+ onEvent(event) {
62
+ if (verbose) {
63
+ const line = verboseLine(event);
64
+ if (line !== null) log.line(color.dim(line));
65
+ }
66
+ if (event.type === 'fatal') {
67
+ fatal = event.error;
68
+ return;
69
+ }
70
+ if (event.type === 'report') {
71
+ if (event.level === 'warn') addWarning(event.where, event.message);
72
+ else if (event.level === 'info' && !notes.includes(event.message)) notes.push(event.message);
73
+ return;
74
+ }
75
+ if (event.type === 'raw') {
76
+ rawTail.push(event.line);
77
+ if (rawTail.length > 40) rawTail.shift();
78
+ return;
79
+ }
80
+ const route = builtRoute(event);
81
+ if (route) {
82
+ if (route.endsWith('.html')) pages += 1;
83
+ building.update(`Building pages ${color.dim(`(${pages})`)}`);
84
+ return;
85
+ }
86
+ const warning = authorWarning(event, contentDir, { root: packageRoot });
87
+ if (warning) addWarning(null, warning);
88
+ },
89
+ });
90
+ const code = await exited;
91
+
92
+ if (fatal || code !== 0) {
93
+ building.fail('Build failed');
94
+ if (fatal) {
95
+ const problem = describeError(fatal, contentDir, { root: packageRoot });
96
+ log.line();
97
+ log.line(formatProblems([{ where: problem.where, message: problem.message }]));
98
+ if (problem.hint) log.line(`\n${color.dim(` Hint: ${problem.hint}`)}`);
99
+ if (verbose && fatal.stack) log.line(`\n${color.dim(fatal.stack)}`);
100
+ } else if (rawTail.length) {
101
+ // No structured error (the worker itself crashed) - show what it printed.
102
+ log.line();
103
+ log.line(color.dim(rawTail.join('\n')));
104
+ }
105
+ log.line();
106
+ log.line(color.dim('Run "writedocs validate" to list every problem in the project at once.'));
107
+ throw new CliExit(1);
108
+ }
109
+ building.succeed(`Built ${plural(pages, 'page')} ${color.dim(`in ${duration(Date.now() - buildStarted)}`)}`);
110
+
111
+ const distDir = path.join(contentDir, 'dist');
112
+ // writedocs.json has been through the build's own validation by now.
113
+ const siteConfig = JSON.parse(readConfigText(contentDir));
114
+ // With a `basePath` ("/docs"), the site goes to dist/docs/ and only the
115
+ // host's own files stay at the root of dist/ - see base-path-layout.js.
116
+ // Without one, siteDir is distDir, and every step below is what it was.
117
+ const basePath = normalizeBasePath(siteConfig.basePath);
118
+ const siteDir = siteDirFor(distDir, basePath);
119
+ // Astro just wrote its actual output to writedocsBuildStagingDir()
120
+ // (astro.config.mjs's own `outDir`), not distDir directly - see that
121
+ // function's own comment (writedocs-temp-dir.js) for why. fs.cpSync
122
+ // (unlike the fs.rename() Astro uses internally to get *into* that
123
+ // staging dir in the first place) copies across filesystem boundaries
124
+ // without issue, so this is the one step that actually needs to bridge
125
+ // packageRoot and contentDir potentially living on different devices.
126
+ // distDir is cleared first so a rebuild doesn't leave a stale file
127
+ // behind from a previous build that the new one no longer produces -
128
+ // the same "the output directory reflects exactly this build, nothing
129
+ // older" expectation `astro build` itself already guarantees when
130
+ // writing directly into outDir.
131
+ const stagingDir = writedocsBuildStagingDir(packageRoot, contentDir);
132
+ // The cards Astro's route listed, into the staging folder's og/ - the
133
+ // same files the route would have made, one thread per CPU (at most 4).
134
+ // Drawn here, before the staging folder replaces dist/: when drawing
135
+ // fails, the build stops with dist/ as it was - no dist/ at all, or the
136
+ // last good build's - the same as when Astro itself fails. Drawn after the
137
+ // copy, a failure left a dist/ with the new pages and none of their cards.
138
+ const drawing = step('Drawing link previews');
139
+ const drawStarted = Date.now();
140
+ try {
141
+ const drawn = await drawOgImages(ogCardsFile, stagingDir);
142
+ if (drawn) drawing.succeed(`Drew ${plural(drawn, 'preview image')} ${color.dim(`in ${duration(Date.now() - drawStarted)}`)}`);
143
+ else drawing.stop();
144
+ } catch (err) {
145
+ drawing.fail('Drawing the link previews failed');
146
+ log.line();
147
+ log.line(color.dim(err.message));
148
+ throw new CliExit(1);
149
+ }
150
+ fs.rmSync(distDir, { recursive: true, force: true });
151
+ fs.cpSync(stagingDir, siteDir, { recursive: true });
152
+ fs.rmSync(stagingDir, { recursive: true, force: true });
153
+ moveRootFiles(siteDir, distDir);
154
+ // Every page writedocs renders links the site's stylesheet. Builds have
155
+ // come out without it on every page while reporting success (the package
156
+ // folder spelled `c:`, fixed in lib/canonical-path.js) - so it's checked
157
+ // here, and a build like that stops instead of being deployed unstyled.
158
+ const unstyled = pagesWithoutStyles(distDir, { basePath });
159
+ if (unstyled.length) {
160
+ log.error(`The build produced ${plural(unstyled.length, 'page')} without the site's styles - for example ${unstyled[0]}.`);
161
+ log.detail(color.dim('This is a fault in the build, not in your pages. Build again; if it happens again, report it with the output of --verbose.'));
162
+ throw new CliExit(1);
163
+ }
164
+ // Astro's own writedocs.json `redirects` + the automatic "/" redirect only
165
+ // ever produce client-side meta-refresh pages (see write-redirects-file.js)
166
+ // - this turns those into real instant edge redirects on hosts that read
167
+ // a `_redirects` file (Cloudflare Pages, Netlify), purely additively.
168
+ writeRedirectsFile(siteDir, contentDir, { outDir: distDir, basePath });
169
+ // Every other host follows Astro's redirect pages - rewritten so the
170
+ // reader never sees one (rewrite-redirect-pages.js).
171
+ rewriteRedirectPages(siteDir, { background: siteConfig.styles?.background?.colors });
172
+ // The site's MCP server at /mcp: mcp-index.json is already in dist/ (an
173
+ // Astro route); this adds the Cloudflare _worker.js that serves it - see
174
+ // write-mcp-files.js for every host.
175
+ const { version: writedocsVersion } = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf-8'));
176
+ const mcp = writeMcpFiles(distDir, contentDir, writedocsVersion, { siteDir, basePath });
177
+ if (mcp.written.length) notes.push(`MCP server at ${basePath}/mcp - dist/_worker.js runs it on Cloudflare; mcp-index.json holds the pages.`);
178
+ if (mcp.skipped) addWarning(null, `No _worker.js for the MCP server: ${mcp.skipped}.`);
179
+
180
+ const indexing = step('Indexing search');
181
+ try {
182
+ await runPagefind(siteDir, { packageRoot });
183
+ } catch (err) {
184
+ indexing.fail('Search indexing failed');
185
+ log.line();
186
+ log.line(color.dim(err.message));
187
+ throw new CliExit(1);
188
+ }
189
+ indexing.succeed('Indexed search');
190
+
191
+ if (warnings.length) {
192
+ log.line();
193
+ log.warn(plural(warnings.length, 'warning'));
194
+ log.line();
195
+ log.line(formatProblems(warnings));
196
+ }
197
+ if (notes.length) {
198
+ log.line();
199
+ notes.forEach((note) => log.info(note));
200
+ }
201
+ log.line();
202
+ log.success(`Done in ${duration(Date.now() - started)} ${color.dim('-')} site written to ${color.bold(displayPath(distDir))}`);
203
+ }
@@ -1,41 +1,41 @@
1
- // After a build: the pages writedocs rendered that came out without the
2
- // site's styles. Every page BaseLayout.astro renders carries
3
- // <meta name="generator" content="writedocs"> and links its stylesheet
4
- // (/_astro/*.css - /docs/_astro/*.css under a basePath), or inlines it in a
5
- // <style>. Other HTML in dist/ - a redirect page, a file from public/ -
6
- // isn't writedocs' to check.
7
- import fs from 'node:fs';
8
- import path from 'node:path';
9
-
10
- const MARKER = /<meta name="generator" content="writedocs"/;
11
- /** The stylesheet link (or <style>) of a page whose site has `basePath` -
12
- * "" or "/docs", lib/base-path.js: only lowercase letters, digits, "-", "_"
13
- * and "/", nothing to escape in a pattern. */
14
- function stylesPattern(basePath = '') {
15
- const css = `${basePath}/_astro/[^"]+\\.css`;
16
- return new RegExp(`<link[^>]+rel="stylesheet"[^>]+href="${css}"|<link[^>]+href="${css}"[^>]+rel="stylesheet"|<style[\\s>]`);
17
- }
18
-
19
- function htmlFiles(dir) {
20
- const out = [];
21
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
22
- const full = path.join(dir, entry.name);
23
- if (entry.isDirectory()) {
24
- if (entry.name !== '_astro' && entry.name !== 'pagefind') out.push(...htmlFiles(full));
25
- } else if (entry.name.endsWith('.html')) out.push(full);
26
- }
27
- return out;
28
- }
29
-
30
- /** Paths (relative to `distDir`, with forward slashes) of writedocs pages
31
- * with no stylesheet. */
32
- export function pagesWithoutStyles(distDir, { basePath = '' } = {}) {
33
- const STYLES = stylesPattern(basePath);
34
- return htmlFiles(distDir)
35
- .filter((file) => {
36
- const html = fs.readFileSync(file, 'utf8');
37
- return MARKER.test(html) && !STYLES.test(html);
38
- })
39
- .map((file) => path.relative(distDir, file).split(path.sep).join('/'))
40
- .sort();
41
- }
1
+ // After a build: the pages writedocs rendered that came out without the
2
+ // site's styles. Every page BaseLayout.astro renders carries
3
+ // <meta name="generator" content="writedocs"> and links its stylesheet
4
+ // (/_astro/*.css - /docs/_astro/*.css under a basePath), or inlines it in a
5
+ // <style>. Other HTML in dist/ - a redirect page, a file from public/ -
6
+ // isn't writedocs' to check.
7
+ import fs from 'node:fs';
8
+ import path from 'node:path';
9
+
10
+ const MARKER = /<meta name="generator" content="writedocs"/;
11
+ /** The stylesheet link (or <style>) of a page whose site has `basePath` -
12
+ * "" or "/docs", lib/base-path.js: only lowercase letters, digits, "-", "_"
13
+ * and "/", nothing to escape in a pattern. */
14
+ function stylesPattern(basePath = '') {
15
+ const css = `${basePath}/_astro/[^"]+\\.css`;
16
+ return new RegExp(`<link[^>]+rel="stylesheet"[^>]+href="${css}"|<link[^>]+href="${css}"[^>]+rel="stylesheet"|<style[\\s>]`);
17
+ }
18
+
19
+ function htmlFiles(dir) {
20
+ const out = [];
21
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
22
+ const full = path.join(dir, entry.name);
23
+ if (entry.isDirectory()) {
24
+ if (entry.name !== '_astro' && entry.name !== 'pagefind') out.push(...htmlFiles(full));
25
+ } else if (entry.name.endsWith('.html')) out.push(full);
26
+ }
27
+ return out;
28
+ }
29
+
30
+ /** Paths (relative to `distDir`, with forward slashes) of writedocs pages
31
+ * with no stylesheet. */
32
+ export function pagesWithoutStyles(distDir, { basePath = '' } = {}) {
33
+ const STYLES = stylesPattern(basePath);
34
+ return htmlFiles(distDir)
35
+ .filter((file) => {
36
+ const html = fs.readFileSync(file, 'utf8');
37
+ return MARKER.test(html) && !STYLES.test(html);
38
+ })
39
+ .map((file) => path.relative(distDir, file).split(path.sep).join('/'))
40
+ .sort();
41
+ }