@writedocs/generator 0.13.4 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -28
- package/astro.config.mjs +645 -645
- package/bin/writedocs.js +359 -356
- package/package.json +99 -99
- package/src/cli/base-path-layout.js +44 -44
- package/src/cli/build-auth.js +135 -135
- package/src/cli/build.js +223 -203
- package/src/cli/check-built-styles.js +41 -41
- package/src/cli/convert.js +124 -124
- package/src/cli/dev.js +269 -268
- package/src/cli/exit-when-flushed.js +42 -42
- package/src/cli/generate-api-pages.js +509 -507
- package/src/cli/og-image-worker.js +20 -20
- package/src/cli/og-images.js +70 -70
- package/src/cli/page-list-watch.js +71 -69
- package/src/cli/run-astro.js +97 -97
- package/src/cli/run-pagefind.js +154 -154
- package/src/cli/write-mcp-files.js +103 -103
- package/src/cli/write-redirects-file.js +158 -158
- package/src/components/ApiReferencePanel.astro +1792 -1792
- package/src/components/AppIcon.astro +51 -51
- package/src/components/Card.astro +193 -193
- package/src/components/CodeGroup.astro +63 -39
- package/src/components/CopyPageMenu.astro +374 -374
- package/src/components/Hint.astro +188 -188
- package/src/components/Icon.astro +72 -72
- package/src/components/Image.astro +165 -165
- package/src/components/Tile.astro +67 -67
- package/src/components/Video.astro +137 -137
- package/src/content.config.ts +219 -203
- package/src/layout/BaseLayout.astro +908 -908
- package/src/layout/components/AnalyticsScripts.astro +49 -49
- package/src/layout/components/Breadcrumbs.astro +98 -98
- package/src/layout/components/ConsentBanner.astro +119 -119
- package/src/layout/components/MobileMenu.astro +225 -225
- package/src/layout/components/NavTree.astro +422 -408
- package/src/layout/components/Sidebar.astro +232 -232
- package/src/layout/components/SiteFooter.astro +87 -87
- package/src/layout/components/TopBar.astro +386 -386
- package/src/layout/styles/base.css +332 -326
- package/src/layout/styles/mobile-menu.css +285 -285
- package/src/lib/agent-markdown.js +164 -164
- package/src/lib/asset-dimensions.js +89 -89
- package/src/lib/base-path.js +90 -90
- package/src/lib/cli-report.js +22 -22
- package/src/lib/code-line-numbers.js +13 -0
- package/src/lib/config-schema.js +12 -1
- package/src/lib/config-schema.ts +2523 -2509
- package/src/lib/config.ts +1331 -1316
- package/src/lib/consent.js +108 -108
- package/src/lib/content-check.js +4 -1
- package/src/lib/content-store-reload-integration.js +101 -101
- package/src/lib/drafts.js +186 -0
- package/src/lib/icon-data-dev.js +53 -53
- package/src/lib/image-size.js +152 -152
- package/src/lib/json-schema-descriptions.js +228 -228
- package/src/lib/link-check.js +553 -544
- package/src/lib/llms-index.ts +90 -90
- package/src/lib/mcp-dev-integration.js +65 -65
- package/src/lib/mcp-index.ts +102 -102
- package/src/lib/mintlify-convert.js +605 -605
- package/src/lib/moved-api-pages.js +49 -49
- package/src/lib/og-cards.js +33 -33
- package/src/lib/og-image.js +235 -235
- package/src/lib/openapi-dev-status.js +80 -80
- package/src/lib/openapi-reload-integration.js +193 -193
- package/src/lib/pages.js +346 -312
- package/src/lib/project-files-integration.js +116 -116
- package/src/lib/project-files.js +137 -137
- package/src/lib/rehype-base-path.js +62 -62
- package/src/lib/rehype-image-loading.js +71 -71
- package/src/lib/robots-txt.js +21 -21
- package/src/lib/search-scope.js +44 -44
- package/src/lib/selector-placement.js +50 -50
- package/src/lib/seo-tags.js +157 -155
- package/src/lib/shiki-code-block.js +7 -1
- package/src/lib/site-base.ts +27 -27
- package/src/lib/styles-asset-integration.js +291 -291
- package/src/lib/wdignore-cases.json +195 -195
- package/src/lib/wdignore.js +177 -177
- package/src/pages/404.astro +63 -63
- package/src/pages/[...slug].astro +1773 -1608
- package/src/pages/[...slug].md.ts +93 -93
- package/src/pages/llms-full.txt.ts +88 -88
- package/src/pages/og/[...slug].png.ts +63 -63
- package/src/scripts/mobile-menu.ts +80 -80
- package/src/scripts/search.ts +245 -245
- package/src/scripts/sidebar-scroll.ts +61 -61
- package/src/styles/global.css +40 -40
package/src/cli/build.js
CHANGED
|
@@ -1,203 +1,223 @@
|
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// The
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
//
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
//
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
if (
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
+
import { findDraftPages } from '../lib/pages.js';
|
|
21
|
+
import { draftWarnings } from '../lib/drafts.js';
|
|
22
|
+
import { createJsonLocator } from '../lib/config-schema.js';
|
|
23
|
+
|
|
24
|
+
/** `drafts` (`writedocs build --drafts`): draft pages are part of the site -
|
|
25
|
+
* marked, noindex, out of the sitemap, llms.txt and the MCP index, the way
|
|
26
|
+
* `writedocs dev` shows them (lib/drafts.js). Without it they're left out. */
|
|
27
|
+
export async function runBuild({ contentDir, packageRoot, verbose = false, drafts = false }) {
|
|
28
|
+
// One spelling of each folder throughout - see lib/canonical-path.js.
|
|
29
|
+
contentDir = canonicalPath(contentDir);
|
|
30
|
+
packageRoot = canonicalPath(packageRoot);
|
|
31
|
+
const started = Date.now();
|
|
32
|
+
preflightCheck(contentDir);
|
|
33
|
+
writableInstallCheck(packageRoot);
|
|
34
|
+
|
|
35
|
+
// Collected while building, printed together at the end - a warning in
|
|
36
|
+
// the middle of a spinner is easy to miss.
|
|
37
|
+
const warnings = [];
|
|
38
|
+
const notes = [];
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
const addWarning = (where, message) => {
|
|
41
|
+
const key = `${where ?? ''}\n${message}`;
|
|
42
|
+
if (seen.has(key)) return;
|
|
43
|
+
seen.add(key);
|
|
44
|
+
warnings.push({ where, message });
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const api = await generateApiPages({ contentDir, drafts });
|
|
48
|
+
sameDriveCheck(contentDir, packageRoot, { generatedPages: api.groups.length > 0 });
|
|
49
|
+
reportApiPages(api);
|
|
50
|
+
api.warnings.forEach((message) => addWarning(null, message));
|
|
51
|
+
// The draft pages the build leaves out (lib/drafts.js) - and what that
|
|
52
|
+
// took out of the navigation, or leaves a redirect or "/" pointing at.
|
|
53
|
+
// With --drafts, only how many it kept.
|
|
54
|
+
const draftPages = findDraftPages(contentDir);
|
|
55
|
+
if (drafts) {
|
|
56
|
+
if (draftPages.length) notes.push(`${plural(draftPages.length, 'draft page')} built (--drafts): marked, noindex, and out of the sitemap, llms.txt and the MCP index.`);
|
|
57
|
+
} else {
|
|
58
|
+
const configText = readConfigText(contentDir);
|
|
59
|
+
const drafted = draftWarnings({ configText, drafts: draftPages, locate: createJsonLocator(configText) });
|
|
60
|
+
drafted.warnings.forEach(({ where, message }) => addWarning(where, message));
|
|
61
|
+
notes.push(...drafted.notes);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const building = step('Building pages');
|
|
65
|
+
const buildStarted = Date.now();
|
|
66
|
+
let pages = 0;
|
|
67
|
+
let fatal = null;
|
|
68
|
+
const rawTail = [];
|
|
69
|
+
// The link-preview cards: Astro's og route only writes their list here,
|
|
70
|
+
// and this process draws them after Astro, in parallel (og-images.js).
|
|
71
|
+
// Removed first, so a list from an earlier build is never drawn.
|
|
72
|
+
const ogCardsFile = path.join(writedocsTempDir(contentDir), 'og-cards.json');
|
|
73
|
+
fs.mkdirSync(path.dirname(ogCardsFile), { recursive: true });
|
|
74
|
+
fs.rmSync(ogCardsFile, { force: true });
|
|
75
|
+
const { exited } = runAstro('build', {
|
|
76
|
+
packageRoot,
|
|
77
|
+
contentDir,
|
|
78
|
+
// WRITEDOCS_DRAFTS: draftsIncluded() in lib/pages.js - set either way, so
|
|
79
|
+
// one left in the shell's environment can't decide it.
|
|
80
|
+
env: { WRITEDOCS_OG_CARDS_FILE: ogCardsFile, WRITEDOCS_DRAFTS: drafts ? '1' : '' },
|
|
81
|
+
onEvent(event) {
|
|
82
|
+
if (verbose) {
|
|
83
|
+
const line = verboseLine(event);
|
|
84
|
+
if (line !== null) log.line(color.dim(line));
|
|
85
|
+
}
|
|
86
|
+
if (event.type === 'fatal') {
|
|
87
|
+
fatal = event.error;
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (event.type === 'report') {
|
|
91
|
+
if (event.level === 'warn') addWarning(event.where, event.message);
|
|
92
|
+
else if (event.level === 'info' && !notes.includes(event.message)) notes.push(event.message);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (event.type === 'raw') {
|
|
96
|
+
rawTail.push(event.line);
|
|
97
|
+
if (rawTail.length > 40) rawTail.shift();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const route = builtRoute(event);
|
|
101
|
+
if (route) {
|
|
102
|
+
if (route.endsWith('.html')) pages += 1;
|
|
103
|
+
building.update(`Building pages ${color.dim(`(${pages})`)}`);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const warning = authorWarning(event, contentDir, { root: packageRoot });
|
|
107
|
+
if (warning) addWarning(null, warning);
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
const code = await exited;
|
|
111
|
+
|
|
112
|
+
if (fatal || code !== 0) {
|
|
113
|
+
building.fail('Build failed');
|
|
114
|
+
if (fatal) {
|
|
115
|
+
const problem = describeError(fatal, contentDir, { root: packageRoot });
|
|
116
|
+
log.line();
|
|
117
|
+
log.line(formatProblems([{ where: problem.where, message: problem.message }]));
|
|
118
|
+
if (problem.hint) log.line(`\n${color.dim(` Hint: ${problem.hint}`)}`);
|
|
119
|
+
if (verbose && fatal.stack) log.line(`\n${color.dim(fatal.stack)}`);
|
|
120
|
+
} else if (rawTail.length) {
|
|
121
|
+
// No structured error (the worker itself crashed) - show what it printed.
|
|
122
|
+
log.line();
|
|
123
|
+
log.line(color.dim(rawTail.join('\n')));
|
|
124
|
+
}
|
|
125
|
+
log.line();
|
|
126
|
+
log.line(color.dim('Run "writedocs validate" to list every problem in the project at once.'));
|
|
127
|
+
throw new CliExit(1);
|
|
128
|
+
}
|
|
129
|
+
building.succeed(`Built ${plural(pages, 'page')} ${color.dim(`in ${duration(Date.now() - buildStarted)}`)}`);
|
|
130
|
+
|
|
131
|
+
const distDir = path.join(contentDir, 'dist');
|
|
132
|
+
// writedocs.json has been through the build's own validation by now.
|
|
133
|
+
const siteConfig = JSON.parse(readConfigText(contentDir));
|
|
134
|
+
// With a `basePath` ("/docs"), the site goes to dist/docs/ and only the
|
|
135
|
+
// host's own files stay at the root of dist/ - see base-path-layout.js.
|
|
136
|
+
// Without one, siteDir is distDir, and every step below is what it was.
|
|
137
|
+
const basePath = normalizeBasePath(siteConfig.basePath);
|
|
138
|
+
const siteDir = siteDirFor(distDir, basePath);
|
|
139
|
+
// Astro just wrote its actual output to writedocsBuildStagingDir()
|
|
140
|
+
// (astro.config.mjs's own `outDir`), not distDir directly - see that
|
|
141
|
+
// function's own comment (writedocs-temp-dir.js) for why. fs.cpSync
|
|
142
|
+
// (unlike the fs.rename() Astro uses internally to get *into* that
|
|
143
|
+
// staging dir in the first place) copies across filesystem boundaries
|
|
144
|
+
// without issue, so this is the one step that actually needs to bridge
|
|
145
|
+
// packageRoot and contentDir potentially living on different devices.
|
|
146
|
+
// distDir is cleared first so a rebuild doesn't leave a stale file
|
|
147
|
+
// behind from a previous build that the new one no longer produces -
|
|
148
|
+
// the same "the output directory reflects exactly this build, nothing
|
|
149
|
+
// older" expectation `astro build` itself already guarantees when
|
|
150
|
+
// writing directly into outDir.
|
|
151
|
+
const stagingDir = writedocsBuildStagingDir(packageRoot, contentDir);
|
|
152
|
+
// The cards Astro's route listed, into the staging folder's og/ - the
|
|
153
|
+
// same files the route would have made, one thread per CPU (at most 4).
|
|
154
|
+
// Drawn here, before the staging folder replaces dist/: when drawing
|
|
155
|
+
// fails, the build stops with dist/ as it was - no dist/ at all, or the
|
|
156
|
+
// last good build's - the same as when Astro itself fails. Drawn after the
|
|
157
|
+
// copy, a failure left a dist/ with the new pages and none of their cards.
|
|
158
|
+
const drawing = step('Drawing link previews');
|
|
159
|
+
const drawStarted = Date.now();
|
|
160
|
+
try {
|
|
161
|
+
const drawn = await drawOgImages(ogCardsFile, stagingDir);
|
|
162
|
+
if (drawn) drawing.succeed(`Drew ${plural(drawn, 'preview image')} ${color.dim(`in ${duration(Date.now() - drawStarted)}`)}`);
|
|
163
|
+
else drawing.stop();
|
|
164
|
+
} catch (err) {
|
|
165
|
+
drawing.fail('Drawing the link previews failed');
|
|
166
|
+
log.line();
|
|
167
|
+
log.line(color.dim(err.message));
|
|
168
|
+
throw new CliExit(1);
|
|
169
|
+
}
|
|
170
|
+
fs.rmSync(distDir, { recursive: true, force: true });
|
|
171
|
+
fs.cpSync(stagingDir, siteDir, { recursive: true });
|
|
172
|
+
fs.rmSync(stagingDir, { recursive: true, force: true });
|
|
173
|
+
moveRootFiles(siteDir, distDir);
|
|
174
|
+
// Every page writedocs renders links the site's stylesheet. Builds have
|
|
175
|
+
// come out without it on every page while reporting success (the package
|
|
176
|
+
// folder spelled `c:`, fixed in lib/canonical-path.js) - so it's checked
|
|
177
|
+
// here, and a build like that stops instead of being deployed unstyled.
|
|
178
|
+
const unstyled = pagesWithoutStyles(distDir, { basePath });
|
|
179
|
+
if (unstyled.length) {
|
|
180
|
+
log.error(`The build produced ${plural(unstyled.length, 'page')} without the site's styles - for example ${unstyled[0]}.`);
|
|
181
|
+
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.'));
|
|
182
|
+
throw new CliExit(1);
|
|
183
|
+
}
|
|
184
|
+
// Astro's own writedocs.json `redirects` + the automatic "/" redirect only
|
|
185
|
+
// ever produce client-side meta-refresh pages (see write-redirects-file.js)
|
|
186
|
+
// - this turns those into real instant edge redirects on hosts that read
|
|
187
|
+
// a `_redirects` file (Cloudflare Pages, Netlify), purely additively.
|
|
188
|
+
writeRedirectsFile(siteDir, contentDir, { outDir: distDir, basePath });
|
|
189
|
+
// Every other host follows Astro's redirect pages - rewritten so the
|
|
190
|
+
// reader never sees one (rewrite-redirect-pages.js).
|
|
191
|
+
rewriteRedirectPages(siteDir, { background: siteConfig.styles?.background?.colors });
|
|
192
|
+
// The site's MCP server at /mcp: mcp-index.json is already in dist/ (an
|
|
193
|
+
// Astro route); this adds the Cloudflare _worker.js that serves it - see
|
|
194
|
+
// write-mcp-files.js for every host.
|
|
195
|
+
const { version: writedocsVersion } = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf-8'));
|
|
196
|
+
const mcp = writeMcpFiles(distDir, contentDir, writedocsVersion, { siteDir, basePath });
|
|
197
|
+
if (mcp.written.length) notes.push(`MCP server at ${basePath}/mcp - dist/_worker.js runs it on Cloudflare; mcp-index.json holds the pages.`);
|
|
198
|
+
if (mcp.skipped) addWarning(null, `No _worker.js for the MCP server: ${mcp.skipped}.`);
|
|
199
|
+
|
|
200
|
+
const indexing = step('Indexing search');
|
|
201
|
+
try {
|
|
202
|
+
await runPagefind(siteDir, { packageRoot });
|
|
203
|
+
} catch (err) {
|
|
204
|
+
indexing.fail('Search indexing failed');
|
|
205
|
+
log.line();
|
|
206
|
+
log.line(color.dim(err.message));
|
|
207
|
+
throw new CliExit(1);
|
|
208
|
+
}
|
|
209
|
+
indexing.succeed('Indexed search');
|
|
210
|
+
|
|
211
|
+
if (warnings.length) {
|
|
212
|
+
log.line();
|
|
213
|
+
log.warn(plural(warnings.length, 'warning'));
|
|
214
|
+
log.line();
|
|
215
|
+
log.line(formatProblems(warnings));
|
|
216
|
+
}
|
|
217
|
+
if (notes.length) {
|
|
218
|
+
log.line();
|
|
219
|
+
notes.forEach((note) => log.info(note));
|
|
220
|
+
}
|
|
221
|
+
log.line();
|
|
222
|
+
log.success(`Done in ${duration(Date.now() - started)} ${color.dim('-')} site written to ${color.bold(displayPath(distDir))}`);
|
|
223
|
+
}
|
|
@@ -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
|
+
}
|