@writedocs/generator 0.11.0 → 0.12.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/package.json +3 -1
- package/src/cli/astro-output.js +44 -11
- package/src/cli/build.js +28 -2
- package/src/cli/dev.js +261 -261
- package/src/cli/og-image-worker.js +20 -0
- package/src/cli/og-images.js +70 -0
- package/src/cli/run-astro.js +97 -93
- package/src/components/ApiReferencePanel.astro +1792 -1792
- package/src/layout/BaseLayout.astro +1 -3
- package/src/layout/components/MobileMenu.astro +9 -13
- package/src/layout/components/NavTree.astro +21 -6
- package/src/layout/components/Sidebar.astro +4 -4
- package/src/layout/styles/base.css +326 -327
- package/src/layout/styles/mobile-menu.css +285 -285
- package/src/lib/og-cards.js +33 -0
- package/src/lib/og-image.js +235 -168
- package/src/pages/og/[...slug].png.ts +63 -64
- package/src/scripts/mobile-menu.ts +80 -55
- package/src/scripts/search.ts +9 -5
- package/src/scripts/sidebar-scroll.ts +61 -65
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@writedocs/generator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Static site generator for docs — a writedocs.json + MDX folder in, a static site out.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -83,9 +83,11 @@
|
|
|
83
83
|
"react-dom": "19.2.8",
|
|
84
84
|
"rehype-katex": "7.0.1",
|
|
85
85
|
"remark-math": "6.0.0",
|
|
86
|
+
"rolldown": "1.2.4",
|
|
86
87
|
"satori": "0.44.0",
|
|
87
88
|
"shiki": "4.4.3",
|
|
88
89
|
"tailwindcss": "4.3.3",
|
|
90
|
+
"vite": "8.2.1",
|
|
89
91
|
"zod": "4.4.3"
|
|
90
92
|
},
|
|
91
93
|
"engines": {
|
package/src/cli/astro-output.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// author should see or noise to hide.
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import path from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
8
9
|
|
|
9
10
|
const ANSI = /\x1b\[[0-9;]*m/g;
|
|
10
11
|
export const stripAnsi = (text) => String(text ?? '').replace(ANSI, '');
|
|
@@ -14,7 +15,10 @@ export const stripAnsi = (text) => String(text ?? '').replace(ANSI, '');
|
|
|
14
15
|
const SECTION = /\n\s*(Stack trace|Hint|Error reference|Location|Caused by):/;
|
|
15
16
|
|
|
16
17
|
function absolutePath(file, root) {
|
|
17
|
-
const clean = file.replace(
|
|
18
|
+
const clean = file.replace(/[?#].*$/, '');
|
|
19
|
+
if (clean.startsWith('file:')) {
|
|
20
|
+
try { return fileURLToPath(clean); } catch {}
|
|
21
|
+
}
|
|
18
22
|
return path.resolve(root ?? process.cwd(), clean);
|
|
19
23
|
}
|
|
20
24
|
|
|
@@ -146,19 +150,48 @@ export function requestLog(event) {
|
|
|
146
150
|
return match ? { status: Number(match[1]), url: match[2] } : null;
|
|
147
151
|
}
|
|
148
152
|
|
|
153
|
+
// Warnings that name the author's page but are about code writedocs and
|
|
154
|
+
// Astro generate, so there's nothing for the author to do: newer rolldown
|
|
155
|
+
// versions flag the "use astro:head-inject" directive Astro writes into the
|
|
156
|
+
// wrapper module of every .mdx page (astro/dist/content/
|
|
157
|
+
// vite-plugin-content-assets.js) - one warning per page, on every build.
|
|
158
|
+
const GENERATED_CODE_WARNINGS = [/\[MODULE_LEVEL_DIRECTIVE\][^\n]*"use astro:head-inject"/];
|
|
159
|
+
|
|
160
|
+
const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
161
|
+
|
|
149
162
|
/** An Astro/Vite warning worth showing the author: one about their own
|
|
150
|
-
* files (it names a path inside the project),
|
|
151
|
-
*
|
|
152
|
-
* internals - is about writedocs itself, and stays
|
|
153
|
-
* it).
|
|
154
|
-
|
|
163
|
+
* files (it names a path inside the project), with those paths rewritten
|
|
164
|
+
* relative to the project. Everything else - bundle sizes, dependency
|
|
165
|
+
* optimization, route internals - is about writedocs itself, and stays
|
|
166
|
+
* hidden (--verbose shows it).
|
|
167
|
+
*
|
|
168
|
+
* A path counts only as a whole path that resolves inside contentDir:
|
|
169
|
+
* absolute, or relative to `root` (Astro's working folder, the package
|
|
170
|
+
* root - rolldown names modules that way). Matching contentDir as a bare
|
|
171
|
+
* substring once let a project at /build claim every warning naming
|
|
172
|
+
* ".../build/..." and turned "creator-review/build.mdx" into
|
|
173
|
+
* "creator-review..mdx". */
|
|
174
|
+
export function authorWarning(event, contentDir, { root } = {}) {
|
|
155
175
|
if (event.type !== 'astro-log' || event.level !== 'warn') return null;
|
|
156
176
|
const text = stripAnsi(event.message);
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
177
|
+
if (GENERATED_CODE_WARNINGS.some((pattern) => pattern.test(text))) return null;
|
|
178
|
+
|
|
179
|
+
// A path starts after a space, a quote or a bracket, as contentDir itself
|
|
180
|
+
// (which may hold spaces) or as ./ or ../, and runs to the next of those.
|
|
181
|
+
const variants = [...new Set([contentDir, contentDir.split(path.sep).join('/'), contentDir.split('/').join('\\')])];
|
|
182
|
+
const starts = [...variants.map(escapeRegExp), '\\.\\.?[\\\\/]'].join('|');
|
|
183
|
+
const pathToken = new RegExp(`(?<![^\\s"'\`(\\[<=])(?:file:///?)?(?:${starts})[^\\s"'\`()\\[\\]<>,]*`, 'g');
|
|
184
|
+
|
|
185
|
+
let named = false;
|
|
186
|
+
const out = text.replace(pathToken, (token) => {
|
|
187
|
+
const at = token.match(/(?::\d+){1,2}$/)?.[0] ?? '';
|
|
188
|
+
const file = token.slice(0, token.length - at.length);
|
|
189
|
+
const rel = relativeTo(contentDir, file, root);
|
|
190
|
+
if (rel === null) return token;
|
|
191
|
+
named = true;
|
|
192
|
+
return `${rel || '.'}${at}`;
|
|
193
|
+
});
|
|
194
|
+
return named ? out.trim() : null;
|
|
162
195
|
}
|
|
163
196
|
|
|
164
197
|
/** One event as a plain line, for --verbose. */
|
package/src/cli/build.js
CHANGED
|
@@ -10,7 +10,8 @@ import { rewriteRedirectPages } from './rewrite-redirect-pages.js';
|
|
|
10
10
|
import { readConfigText } from '../lib/config-file.js';
|
|
11
11
|
import { writeMcpFiles } from './write-mcp-files.js';
|
|
12
12
|
import { pagesWithoutStyles } from './check-built-styles.js';
|
|
13
|
-
import { writedocsBuildStagingDir } from '../lib/writedocs-temp-dir.js';
|
|
13
|
+
import { writedocsBuildStagingDir, writedocsTempDir } from '../lib/writedocs-temp-dir.js';
|
|
14
|
+
import { drawOgImages } from './og-images.js';
|
|
14
15
|
import { normalizeBasePath } from '../lib/base-path.js';
|
|
15
16
|
import { siteDirFor, moveRootFiles } from './base-path-layout.js';
|
|
16
17
|
import { log, step, plural, duration, displayPath, formatProblems, color, CliExit } from './output.js';
|
|
@@ -47,9 +48,16 @@ export async function runBuild({ contentDir, packageRoot, verbose = false }) {
|
|
|
47
48
|
let pages = 0;
|
|
48
49
|
let fatal = null;
|
|
49
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 });
|
|
50
57
|
const { exited } = runAstro('build', {
|
|
51
58
|
packageRoot,
|
|
52
59
|
contentDir,
|
|
60
|
+
env: { WRITEDOCS_OG_CARDS_FILE: ogCardsFile },
|
|
53
61
|
onEvent(event) {
|
|
54
62
|
if (verbose) {
|
|
55
63
|
const line = verboseLine(event);
|
|
@@ -75,7 +83,7 @@ export async function runBuild({ contentDir, packageRoot, verbose = false }) {
|
|
|
75
83
|
building.update(`Building pages ${color.dim(`(${pages})`)}`);
|
|
76
84
|
return;
|
|
77
85
|
}
|
|
78
|
-
const warning = authorWarning(event, contentDir);
|
|
86
|
+
const warning = authorWarning(event, contentDir, { root: packageRoot });
|
|
79
87
|
if (warning) addWarning(null, warning);
|
|
80
88
|
},
|
|
81
89
|
});
|
|
@@ -121,6 +129,24 @@ export async function runBuild({ contentDir, packageRoot, verbose = false }) {
|
|
|
121
129
|
// older" expectation `astro build` itself already guarantees when
|
|
122
130
|
// writing directly into outDir.
|
|
123
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
|
+
}
|
|
124
150
|
fs.rmSync(distDir, { recursive: true, force: true });
|
|
125
151
|
fs.cpSync(stagingDir, siteDir, { recursive: true });
|
|
126
152
|
fs.rmSync(stagingDir, { recursive: true, force: true });
|