@writedocs/generator 0.10.19 → 0.11.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/astro.config.mjs +32 -8
- package/package.json +96 -93
- package/src/cli/base-path-layout.js +44 -0
- package/src/cli/build.js +177 -168
- package/src/cli/check-built-styles.js +41 -33
- package/src/cli/dev.js +261 -244
- package/src/cli/generate-api-pages.js +9 -5
- package/src/cli/page-list-watch.js +69 -66
- package/src/cli/run-pagefind.js +154 -148
- package/src/cli/write-mcp-files.js +103 -96
- package/src/cli/write-redirects-file.js +25 -8
- package/src/components/AppIcon.astro +51 -50
- package/src/components/Card.astro +193 -192
- package/src/components/CopyPageMenu.astro +374 -370
- package/src/components/Hint.astro +188 -187
- package/src/components/Icon.astro +72 -71
- package/src/components/Image.astro +165 -164
- package/src/components/Tile.astro +67 -66
- package/src/components/Video.astro +137 -136
- package/src/layout/BaseLayout.astro +21 -12
- package/src/layout/components/AnalyticsScripts.astro +6 -2
- package/src/layout/components/Breadcrumbs.astro +98 -97
- package/src/layout/components/ConsentBanner.astro +119 -118
- package/src/layout/components/MobileMenu.astro +229 -228
- package/src/layout/components/NavTree.astro +393 -392
- package/src/layout/components/Sidebar.astro +232 -231
- package/src/layout/components/SiteFooter.astro +87 -86
- package/src/layout/components/TopBar.astro +386 -385
- package/src/lib/agent-markdown.js +164 -162
- package/src/lib/asset-dimensions.js +89 -0
- package/src/lib/base-path.js +90 -0
- package/src/lib/config-schema.js +10 -0
- package/src/lib/config-schema.ts +17 -0
- package/src/lib/config.ts +1314 -1289
- package/src/lib/consent.js +108 -102
- package/src/lib/image-size.js +152 -140
- package/src/lib/json-schema-descriptions.js +1 -0
- package/src/lib/link-check.js +42 -4
- package/src/lib/llms-index.ts +90 -88
- package/src/lib/mcp-dev-integration.js +65 -60
- package/src/lib/mcp-index.ts +102 -101
- package/src/lib/pages.js +312 -304
- package/src/lib/project-files-integration.js +116 -61
- package/src/lib/project-files.js +137 -126
- package/src/lib/project-ignore.js +46 -0
- package/src/lib/rehype-base-path.js +62 -0
- package/src/lib/rehype-image-loading.js +71 -71
- package/src/lib/robots-txt.js +21 -16
- package/src/lib/seo-tags.js +155 -140
- package/src/lib/site-base.ts +27 -0
- package/src/lib/styles-asset-integration.js +58 -12
- package/src/lib/wdignore-cases.json +195 -0
- package/src/lib/wdignore.js +177 -0
- package/src/pages/404.astro +63 -62
- package/src/pages/[...slug].astro +1604 -1597
- package/src/pages/[...slug].md.ts +93 -93
- package/src/pages/llms-full.txt.ts +88 -86
- package/src/scripts/search.ts +241 -237
- package/writedocs.schema.json +6 -0
package/src/cli/build.js
CHANGED
|
@@ -1,168 +1,177 @@
|
|
|
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 } from '../lib/writedocs-temp-dir.js';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
api.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
// a
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
// Astro
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
indexing
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
log.line();
|
|
160
|
-
log.line(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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 } from '../lib/writedocs-temp-dir.js';
|
|
14
|
+
import { normalizeBasePath } from '../lib/base-path.js';
|
|
15
|
+
import { siteDirFor, moveRootFiles } from './base-path-layout.js';
|
|
16
|
+
import { log, step, plural, duration, displayPath, formatProblems, color, CliExit } from './output.js';
|
|
17
|
+
import { describeError, builtRoute, authorWarning, verboseLine } from './astro-output.js';
|
|
18
|
+
import { reportApiPages } from './api-pages-output.js';
|
|
19
|
+
|
|
20
|
+
export async function runBuild({ contentDir, packageRoot, verbose = false }) {
|
|
21
|
+
// One spelling of each folder throughout - see lib/canonical-path.js.
|
|
22
|
+
contentDir = canonicalPath(contentDir);
|
|
23
|
+
packageRoot = canonicalPath(packageRoot);
|
|
24
|
+
const started = Date.now();
|
|
25
|
+
preflightCheck(contentDir);
|
|
26
|
+
writableInstallCheck(packageRoot);
|
|
27
|
+
|
|
28
|
+
// Collected while building, printed together at the end - a warning in
|
|
29
|
+
// the middle of a spinner is easy to miss.
|
|
30
|
+
const warnings = [];
|
|
31
|
+
const notes = [];
|
|
32
|
+
const seen = new Set();
|
|
33
|
+
const addWarning = (where, message) => {
|
|
34
|
+
const key = `${where ?? ''}\n${message}`;
|
|
35
|
+
if (seen.has(key)) return;
|
|
36
|
+
seen.add(key);
|
|
37
|
+
warnings.push({ where, message });
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const api = await generateApiPages({ contentDir });
|
|
41
|
+
sameDriveCheck(contentDir, packageRoot, { generatedPages: api.groups.length > 0 });
|
|
42
|
+
reportApiPages(api);
|
|
43
|
+
api.warnings.forEach((message) => addWarning(null, message));
|
|
44
|
+
|
|
45
|
+
const building = step('Building pages');
|
|
46
|
+
const buildStarted = Date.now();
|
|
47
|
+
let pages = 0;
|
|
48
|
+
let fatal = null;
|
|
49
|
+
const rawTail = [];
|
|
50
|
+
const { exited } = runAstro('build', {
|
|
51
|
+
packageRoot,
|
|
52
|
+
contentDir,
|
|
53
|
+
onEvent(event) {
|
|
54
|
+
if (verbose) {
|
|
55
|
+
const line = verboseLine(event);
|
|
56
|
+
if (line !== null) log.line(color.dim(line));
|
|
57
|
+
}
|
|
58
|
+
if (event.type === 'fatal') {
|
|
59
|
+
fatal = event.error;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (event.type === 'report') {
|
|
63
|
+
if (event.level === 'warn') addWarning(event.where, event.message);
|
|
64
|
+
else if (event.level === 'info' && !notes.includes(event.message)) notes.push(event.message);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (event.type === 'raw') {
|
|
68
|
+
rawTail.push(event.line);
|
|
69
|
+
if (rawTail.length > 40) rawTail.shift();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const route = builtRoute(event);
|
|
73
|
+
if (route) {
|
|
74
|
+
if (route.endsWith('.html')) pages += 1;
|
|
75
|
+
building.update(`Building pages ${color.dim(`(${pages})`)}`);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const warning = authorWarning(event, contentDir);
|
|
79
|
+
if (warning) addWarning(null, warning);
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
const code = await exited;
|
|
83
|
+
|
|
84
|
+
if (fatal || code !== 0) {
|
|
85
|
+
building.fail('Build failed');
|
|
86
|
+
if (fatal) {
|
|
87
|
+
const problem = describeError(fatal, contentDir, { root: packageRoot });
|
|
88
|
+
log.line();
|
|
89
|
+
log.line(formatProblems([{ where: problem.where, message: problem.message }]));
|
|
90
|
+
if (problem.hint) log.line(`\n${color.dim(` Hint: ${problem.hint}`)}`);
|
|
91
|
+
if (verbose && fatal.stack) log.line(`\n${color.dim(fatal.stack)}`);
|
|
92
|
+
} else if (rawTail.length) {
|
|
93
|
+
// No structured error (the worker itself crashed) - show what it printed.
|
|
94
|
+
log.line();
|
|
95
|
+
log.line(color.dim(rawTail.join('\n')));
|
|
96
|
+
}
|
|
97
|
+
log.line();
|
|
98
|
+
log.line(color.dim('Run "writedocs validate" to list every problem in the project at once.'));
|
|
99
|
+
throw new CliExit(1);
|
|
100
|
+
}
|
|
101
|
+
building.succeed(`Built ${plural(pages, 'page')} ${color.dim(`in ${duration(Date.now() - buildStarted)}`)}`);
|
|
102
|
+
|
|
103
|
+
const distDir = path.join(contentDir, 'dist');
|
|
104
|
+
// writedocs.json has been through the build's own validation by now.
|
|
105
|
+
const siteConfig = JSON.parse(readConfigText(contentDir));
|
|
106
|
+
// With a `basePath` ("/docs"), the site goes to dist/docs/ and only the
|
|
107
|
+
// host's own files stay at the root of dist/ - see base-path-layout.js.
|
|
108
|
+
// Without one, siteDir is distDir, and every step below is what it was.
|
|
109
|
+
const basePath = normalizeBasePath(siteConfig.basePath);
|
|
110
|
+
const siteDir = siteDirFor(distDir, basePath);
|
|
111
|
+
// Astro just wrote its actual output to writedocsBuildStagingDir()
|
|
112
|
+
// (astro.config.mjs's own `outDir`), not distDir directly - see that
|
|
113
|
+
// function's own comment (writedocs-temp-dir.js) for why. fs.cpSync
|
|
114
|
+
// (unlike the fs.rename() Astro uses internally to get *into* that
|
|
115
|
+
// staging dir in the first place) copies across filesystem boundaries
|
|
116
|
+
// without issue, so this is the one step that actually needs to bridge
|
|
117
|
+
// packageRoot and contentDir potentially living on different devices.
|
|
118
|
+
// distDir is cleared first so a rebuild doesn't leave a stale file
|
|
119
|
+
// behind from a previous build that the new one no longer produces -
|
|
120
|
+
// the same "the output directory reflects exactly this build, nothing
|
|
121
|
+
// older" expectation `astro build` itself already guarantees when
|
|
122
|
+
// writing directly into outDir.
|
|
123
|
+
const stagingDir = writedocsBuildStagingDir(packageRoot, contentDir);
|
|
124
|
+
fs.rmSync(distDir, { recursive: true, force: true });
|
|
125
|
+
fs.cpSync(stagingDir, siteDir, { recursive: true });
|
|
126
|
+
fs.rmSync(stagingDir, { recursive: true, force: true });
|
|
127
|
+
moveRootFiles(siteDir, distDir);
|
|
128
|
+
// Every page writedocs renders links the site's stylesheet. Builds have
|
|
129
|
+
// come out without it on every page while reporting success (the package
|
|
130
|
+
// folder spelled `c:`, fixed in lib/canonical-path.js) - so it's checked
|
|
131
|
+
// here, and a build like that stops instead of being deployed unstyled.
|
|
132
|
+
const unstyled = pagesWithoutStyles(distDir, { basePath });
|
|
133
|
+
if (unstyled.length) {
|
|
134
|
+
log.error(`The build produced ${plural(unstyled.length, 'page')} without the site's styles - for example ${unstyled[0]}.`);
|
|
135
|
+
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.'));
|
|
136
|
+
throw new CliExit(1);
|
|
137
|
+
}
|
|
138
|
+
// Astro's own writedocs.json `redirects` + the automatic "/" redirect only
|
|
139
|
+
// ever produce client-side meta-refresh pages (see write-redirects-file.js)
|
|
140
|
+
// - this turns those into real instant edge redirects on hosts that read
|
|
141
|
+
// a `_redirects` file (Cloudflare Pages, Netlify), purely additively.
|
|
142
|
+
writeRedirectsFile(siteDir, contentDir, { outDir: distDir, basePath });
|
|
143
|
+
// Every other host follows Astro's redirect pages - rewritten so the
|
|
144
|
+
// reader never sees one (rewrite-redirect-pages.js).
|
|
145
|
+
rewriteRedirectPages(siteDir, { background: siteConfig.styles?.background?.colors });
|
|
146
|
+
// The site's MCP server at /mcp: mcp-index.json is already in dist/ (an
|
|
147
|
+
// Astro route); this adds the Cloudflare _worker.js that serves it - see
|
|
148
|
+
// write-mcp-files.js for every host.
|
|
149
|
+
const { version: writedocsVersion } = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf-8'));
|
|
150
|
+
const mcp = writeMcpFiles(distDir, contentDir, writedocsVersion, { siteDir, basePath });
|
|
151
|
+
if (mcp.written.length) notes.push(`MCP server at ${basePath}/mcp - dist/_worker.js runs it on Cloudflare; mcp-index.json holds the pages.`);
|
|
152
|
+
if (mcp.skipped) addWarning(null, `No _worker.js for the MCP server: ${mcp.skipped}.`);
|
|
153
|
+
|
|
154
|
+
const indexing = step('Indexing search');
|
|
155
|
+
try {
|
|
156
|
+
await runPagefind(siteDir, { packageRoot });
|
|
157
|
+
} catch (err) {
|
|
158
|
+
indexing.fail('Search indexing failed');
|
|
159
|
+
log.line();
|
|
160
|
+
log.line(color.dim(err.message));
|
|
161
|
+
throw new CliExit(1);
|
|
162
|
+
}
|
|
163
|
+
indexing.succeed('Indexed search');
|
|
164
|
+
|
|
165
|
+
if (warnings.length) {
|
|
166
|
+
log.line();
|
|
167
|
+
log.warn(plural(warnings.length, 'warning'));
|
|
168
|
+
log.line();
|
|
169
|
+
log.line(formatProblems(warnings));
|
|
170
|
+
}
|
|
171
|
+
if (notes.length) {
|
|
172
|
+
log.line();
|
|
173
|
+
notes.forEach((note) => log.info(note));
|
|
174
|
+
}
|
|
175
|
+
log.line();
|
|
176
|
+
log.success(`Done in ${duration(Date.now() - started)} ${color.dim('-')} site written to ${color.bold(displayPath(distDir))}`);
|
|
177
|
+
}
|
|
@@ -1,33 +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), or inlines it in a
|
|
5
|
-
// redirect page, a file from public/ -
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
+
}
|