@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/astro.config.mjs
CHANGED
|
@@ -39,12 +39,14 @@ import { stylesAssetFallback } from './src/lib/styles-asset-integration.js';
|
|
|
39
39
|
import { mcpDevServer } from './src/lib/mcp-dev-integration.js';
|
|
40
40
|
import { configReload } from './src/lib/config-reload-integration.js';
|
|
41
41
|
import { canonicalPath } from './src/lib/canonical-path.js';
|
|
42
|
+
import { withBase, withoutBase } from './src/lib/base-path.js';
|
|
42
43
|
import { folderAddresses } from './src/lib/folder-redirects.js';
|
|
43
44
|
import { report } from './src/lib/cli-report.js';
|
|
44
45
|
import { publishProjectFiles, generatedRobotsTxt } from './src/lib/project-files-integration.js';
|
|
45
46
|
import { frontmatterNoindex, canonicalIsElsewhere } from './src/lib/seo-tags.js';
|
|
46
47
|
import { readMovedApiPages } from './src/lib/moved-api-pages.js';
|
|
47
48
|
import { rehypeImageLoading } from './src/lib/rehype-image-loading.js';
|
|
49
|
+
import { rehypeBasePath } from './src/lib/rehype-base-path.js';
|
|
48
50
|
import { gitLastModified, newestDate } from './src/lib/last-modified.js';
|
|
49
51
|
import { readSpecPaths } from './src/lib/project-files.js';
|
|
50
52
|
import {
|
|
@@ -52,6 +54,8 @@ import {
|
|
|
52
54
|
resolveCodeblockTheme,
|
|
53
55
|
resolveCodeblockLangAlias,
|
|
54
56
|
resolveSiteUrl,
|
|
57
|
+
resolveSiteOrigin,
|
|
58
|
+
resolveBasePath,
|
|
55
59
|
normalizeEntryId,
|
|
56
60
|
findAllPages,
|
|
57
61
|
} from './src/lib/config.ts';
|
|
@@ -115,6 +119,10 @@ const contentPublicDir = path.join(contentDir, 'public');
|
|
|
115
119
|
// config to be set and would otherwise throw, and a sitemap of
|
|
116
120
|
// document-relative URLs isn't meaningful anyway.
|
|
117
121
|
const siteUrl = resolveSiteUrl(docsConfig);
|
|
122
|
+
// writedocs.json's `basePath` ("" when unset) - see lib/base-path.js. Astro's
|
|
123
|
+
// own `base` gets it (bundled assets, the dev server's address), and so do
|
|
124
|
+
// the page scripts, as __WD_BASE__ (vite.define below).
|
|
125
|
+
const basePath = resolveBasePath(docsConfig);
|
|
118
126
|
if (!siteUrl) {
|
|
119
127
|
report(
|
|
120
128
|
'info',
|
|
@@ -256,7 +264,10 @@ function singleSitemapFile() {
|
|
|
256
264
|
// redirect from the old one the same way; a redirect the site wrote itself
|
|
257
265
|
// for the same address comes later in the list, and wins.
|
|
258
266
|
const movedApiPages = readMovedApiPages(contentDir);
|
|
259
|
-
|
|
267
|
+
// With a basePath, Astro serves a redirect's source under the base itself,
|
|
268
|
+
// but writes its destination as given - so a destination inside the site
|
|
269
|
+
// gets the base here (lib/base-path.js).
|
|
270
|
+
const redirectsConfig = Object.fromEntries([...movedApiPages, ...docsConfig.redirects].map((r) => [r.source, withBase(basePath, r.destination)]));
|
|
260
271
|
|
|
261
272
|
/** Tailwind only scans the Vite root for class names - this package, not
|
|
262
273
|
* the site being built, which is usually somewhere else entirely - so a
|
|
@@ -278,7 +289,10 @@ function contentTailwindSource() {
|
|
|
278
289
|
}
|
|
279
290
|
|
|
280
291
|
export default defineConfig({
|
|
281
|
-
|
|
292
|
+
// The origin alone: Astro adds `base` to it itself (the sitemap's URLs).
|
|
293
|
+
...(siteUrl ? { site: resolveSiteOrigin(docsConfig) } : {}),
|
|
294
|
+
// Only with a basePath: without one the config is exactly what it was.
|
|
295
|
+
...(basePath ? { base: basePath } : {}),
|
|
282
296
|
...(Object.keys(redirectsConfig).length ? { redirects: redirectsConfig } : {}),
|
|
283
297
|
// Astro's own dev-mode toolbar (the floating pill in the bottom center
|
|
284
298
|
// of every page - inspect/audit/settings) is a tool for authoring
|
|
@@ -334,14 +348,16 @@ export default defineConfig({
|
|
|
334
348
|
// @astrojs/sitemap é 45.000). Até aqui, tudo cabe num único
|
|
335
349
|
// sitemap.xml - ver singleSitemapFile() abaixo.
|
|
336
350
|
entryLimit: 50000,
|
|
351
|
+
// The plugin's URLs carry the base ("/docs/guides/a/") - the
|
|
352
|
+
// ids here don't.
|
|
337
353
|
filter: (page) => {
|
|
338
|
-
const pathname = new URL(page).pathname;
|
|
354
|
+
const pathname = withoutBase(basePath, new URL(page).pathname) ?? '/';
|
|
339
355
|
const id = normalizeEntryId(pathname);
|
|
340
356
|
return !noindexIds.has(id);
|
|
341
357
|
},
|
|
342
358
|
// <lastmod>, for the pages git has a date for.
|
|
343
359
|
serialize: (item) => {
|
|
344
|
-
const changed = lastModifiedById.get(normalizeEntryId(new URL(item.url).pathname));
|
|
360
|
+
const changed = lastModifiedById.get(normalizeEntryId(withoutBase(basePath, new URL(item.url).pathname) ?? '/'));
|
|
345
361
|
return changed ? { ...item, lastmod: changed } : item;
|
|
346
362
|
},
|
|
347
363
|
}),
|
|
@@ -351,16 +367,16 @@ export default defineConfig({
|
|
|
351
367
|
]
|
|
352
368
|
: []),
|
|
353
369
|
// After the sitemap: the generated robots.txt names the sitemap file.
|
|
354
|
-
generatedRobotsTxt({ siteUrl, seo: docsConfig.seo }),
|
|
370
|
+
generatedRobotsTxt({ siteUrl, seo: docsConfig.seo, basePath }),
|
|
355
371
|
// Lets styles.favicon/styles.logo/styles.background.images/seo.ogImage/
|
|
356
372
|
// styles.fonts.*.source resolve from anywhere in the project, not just
|
|
357
373
|
// public/ - see collectConfiguredAssetPaths() (lib/config.ts) for the
|
|
358
374
|
// field list and styles-asset-integration.js for how it's actually
|
|
359
375
|
// served/copied.
|
|
360
|
-
stylesAssetFallback(contentDir),
|
|
376
|
+
stylesAssetFallback(contentDir, { basePath }),
|
|
361
377
|
// /mcp in `writedocs dev`, as the build's dist/_worker.js serves it -
|
|
362
378
|
// see src/lib/mcp-dev-integration.js.
|
|
363
|
-
mcpDevServer({ version: JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf-8')).version }),
|
|
379
|
+
mcpDevServer({ version: JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf-8')).version, basePath }),
|
|
364
380
|
// writedocs dev: an edit to writedocs.json reloads the open tab.
|
|
365
381
|
configReload({ configPath: path.join(contentDir, 'writedocs.json') }),
|
|
366
382
|
],
|
|
@@ -482,7 +498,10 @@ export default defineConfig({
|
|
|
482
498
|
// neither plugin's output is visible to the other.
|
|
483
499
|
// rehypeImageLoading: lazy loading and sizes for content images - see
|
|
484
500
|
// lib/rehype-image-loading.js.
|
|
485
|
-
|
|
501
|
+
// rehypeBasePath: the basePath in front of the content's own links and
|
|
502
|
+
// pictures (lib/rehype-base-path.js) - last, since rehypeImageLoading
|
|
503
|
+
// finds an image's file by the address as written.
|
|
504
|
+
rehypePlugins: [rehypeMermaid, rehypeKatex, [rehypeImageLoading, { contentDir }], [rehypeBasePath, { base: basePath }]],
|
|
486
505
|
}),
|
|
487
506
|
shikiConfig: {
|
|
488
507
|
themes: codeblockTheme,
|
|
@@ -526,6 +545,11 @@ export default defineConfig({
|
|
|
526
545
|
// working. See src/styles/global.css for the one @import that wires
|
|
527
546
|
// Tailwind's utilities in.
|
|
528
547
|
vite: {
|
|
548
|
+
// The base for page scripts and components: "" or "/docs". A constant
|
|
549
|
+
// rather than import.meta.env.BASE_URL ("/" with no base, "/docs" or
|
|
550
|
+
// "/docs/" with one), so `__WD_BASE__ + "/pagefind/..."` folds to the
|
|
551
|
+
// same string the bundle had before basePath existed.
|
|
552
|
+
define: { __WD_BASE__: JSON.stringify(basePath) },
|
|
529
553
|
// The dev server only serves files under its workspace root by default.
|
|
530
554
|
// A site's own snippets live in its content directory, and inline React
|
|
531
555
|
// components moved out of pages (lib/mdx-inline-react.js) in writedocs'
|
package/package.json
CHANGED
|
@@ -1,94 +1,97 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@writedocs/generator",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Static site generator for docs — a writedocs.json + MDX folder in, a static site out.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"bin": {
|
|
7
|
-
"writedocs": "./bin/writedocs.js"
|
|
8
|
-
},
|
|
9
|
-
"exports": {
|
|
10
|
-
"./components": "./src/components/index.ts",
|
|
11
|
-
"./config-schema": "./src/lib/config-schema.js",
|
|
12
|
-
"./writedocs.schema.json": "./writedocs.schema.json",
|
|
13
|
-
"./mcp": "./src/mcp/server.js"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"build
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"@
|
|
54
|
-
"@astrojs/
|
|
55
|
-
"@astrojs/
|
|
56
|
-
"@
|
|
57
|
-
"@
|
|
58
|
-
"@iconify-json/
|
|
59
|
-
"@iconify-json/
|
|
60
|
-
"@iconify-json/
|
|
61
|
-
"@iconify-json/
|
|
62
|
-
"@iconify-json/
|
|
63
|
-
"@iconify-json/
|
|
64
|
-
"@iconify-json/
|
|
65
|
-
"@iconify-json/
|
|
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
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@writedocs/generator",
|
|
3
|
+
"version": "0.11.0",
|
|
4
|
+
"description": "Static site generator for docs — a writedocs.json + MDX folder in, a static site out.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"writedocs": "./bin/writedocs.js"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
"./components": "./src/components/index.ts",
|
|
11
|
+
"./config-schema": "./src/lib/config-schema.js",
|
|
12
|
+
"./writedocs.schema.json": "./writedocs.schema.json",
|
|
13
|
+
"./mcp": "./src/mcp/server.js",
|
|
14
|
+
"./wdignore": "./src/lib/wdignore.js",
|
|
15
|
+
"./wdignore-cases.json": "./src/lib/wdignore-cases.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin",
|
|
19
|
+
"src",
|
|
20
|
+
"astro.config.mjs",
|
|
21
|
+
"writedocs.schema.json"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"dev": "node bin/writedocs.js dev",
|
|
25
|
+
"build": "node bin/writedocs.js build",
|
|
26
|
+
"init": "node bin/writedocs.js init",
|
|
27
|
+
"build:schema": "esbuild src/lib/config-schema.ts --format=esm --target=node22 --outfile=src/lib/config-schema.js",
|
|
28
|
+
"prepare": "npm run build:schema && npm run build:json-schema",
|
|
29
|
+
"test": "node --test \"scripts/*.test.js\"",
|
|
30
|
+
"build:json-schema": "node scripts/build-json-schema.mjs"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"docs",
|
|
34
|
+
"documentation",
|
|
35
|
+
"static-site-generator",
|
|
36
|
+
"mdx",
|
|
37
|
+
"astro"
|
|
38
|
+
],
|
|
39
|
+
"homepage": "https://github.com/writedocs/writedocs#readme",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/writedocs/writedocs.git"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/writedocs/writedocs/issues"
|
|
46
|
+
},
|
|
47
|
+
"author": "Gabriel Raeder Gonçalves",
|
|
48
|
+
"license": "ISC",
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@apidevtools/swagger-parser": "12.1.0",
|
|
54
|
+
"@astrojs/markdown-remark": "7.2.4",
|
|
55
|
+
"@astrojs/mdx": "7.0.8",
|
|
56
|
+
"@astrojs/react": "6.0.2",
|
|
57
|
+
"@astrojs/sitemap": "3.7.3",
|
|
58
|
+
"@iconify-json/bi": "1.2.7",
|
|
59
|
+
"@iconify-json/fa6-brands": "1.2.6",
|
|
60
|
+
"@iconify-json/fa6-solid": "1.2.4",
|
|
61
|
+
"@iconify-json/heroicons": "1.2.3",
|
|
62
|
+
"@iconify-json/ion": "1.2.7",
|
|
63
|
+
"@iconify-json/lucide": "1.2.123",
|
|
64
|
+
"@iconify-json/mdi": "1.2.3",
|
|
65
|
+
"@iconify-json/ri": "1.2.10",
|
|
66
|
+
"@iconify-json/simple-icons": "1.2.93",
|
|
67
|
+
"@iconify-json/tabler": "1.2.38",
|
|
68
|
+
"@mdx-js/mdx": "3.1.1",
|
|
69
|
+
"@resvg/resvg-wasm": "2.6.2",
|
|
70
|
+
"@shikijs/transformers": "4.4.3",
|
|
71
|
+
"@tailwindcss/vite": "4.3.3",
|
|
72
|
+
"astro": "7.2.9",
|
|
73
|
+
"astro-icon": "1.1.5",
|
|
74
|
+
"commander": "15.0.0",
|
|
75
|
+
"dotenv": "17.4.2",
|
|
76
|
+
"gray-matter": "4.0.3",
|
|
77
|
+
"ignore": "7.0.5",
|
|
78
|
+
"jsonc-parser": "3.3.1",
|
|
79
|
+
"katex": "0.16.47",
|
|
80
|
+
"mermaid": "11.16.1",
|
|
81
|
+
"pagefind": "1.5.2",
|
|
82
|
+
"react": "19.2.8",
|
|
83
|
+
"react-dom": "19.2.8",
|
|
84
|
+
"rehype-katex": "7.0.1",
|
|
85
|
+
"remark-math": "6.0.0",
|
|
86
|
+
"satori": "0.44.0",
|
|
87
|
+
"shiki": "4.4.3",
|
|
88
|
+
"tailwindcss": "4.3.3",
|
|
89
|
+
"zod": "4.4.3"
|
|
90
|
+
},
|
|
91
|
+
"engines": {
|
|
92
|
+
"node": ">=22.12.0"
|
|
93
|
+
},
|
|
94
|
+
"devDependencies": {
|
|
95
|
+
"esbuild": "0.28.2"
|
|
96
|
+
}
|
|
94
97
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Where a build puts the site in dist/ (build.js). Without a basePath, at
|
|
2
|
+
// dist/ itself, as always. With one ("/docs", writedocs.json - see
|
|
3
|
+
// lib/base-path.js), every file the site serves goes to dist/docs/: a static
|
|
4
|
+
// server that serves dist/ at its root answers /docs/... with no rule of its
|
|
5
|
+
// own, and a proxy that passes /docs/* on with its path unchanged finds every
|
|
6
|
+
// file where its address says.
|
|
7
|
+
//
|
|
8
|
+
// A few files aren't the site's but its host's, and the host reads them at
|
|
9
|
+
// the root of what it serves, so they stay in dist/:
|
|
10
|
+
// 404.html the page a host shows for an address it doesn't have
|
|
11
|
+
// (Cloudflare Pages, the WriteDocs platform look for it there);
|
|
12
|
+
// _redirects the host's redirects - every path in the generated rules
|
|
13
|
+
// carries the base (write-redirects-file.js);
|
|
14
|
+
// _headers the host's response headers, when the project has one;
|
|
15
|
+
// _worker.js, _routes.json, .assetsignore
|
|
16
|
+
// the Cloudflare MCP server (write-mcp-files.js), which
|
|
17
|
+
// Cloudflare only runs from the root.
|
|
18
|
+
import fs from 'node:fs';
|
|
19
|
+
import path from 'node:path';
|
|
20
|
+
|
|
21
|
+
/** The host's files - kept at the root of dist/, outside the basePath. */
|
|
22
|
+
export const ROOT_FILES = ['404.html', '_redirects', '_headers', '_worker.js', '_routes.json', '.assetsignore'];
|
|
23
|
+
|
|
24
|
+
/** The folder the site itself goes to: dist/ without a basePath,
|
|
25
|
+
* dist/docs/ for "/docs", dist/help/docs/ for "/help/docs". */
|
|
26
|
+
export function siteDirFor(distDir, basePath) {
|
|
27
|
+
const segments = (basePath ?? '').split('/').filter(Boolean);
|
|
28
|
+
return segments.length ? path.join(distDir, ...segments) : distDir;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Moves the host's files (ROOT_FILES) a build left in the site's folder up
|
|
32
|
+
* to the root of dist/. Nothing to do without a basePath. Returns the names
|
|
33
|
+
* moved. */
|
|
34
|
+
export function moveRootFiles(siteDir, distDir) {
|
|
35
|
+
if (path.resolve(siteDir) === path.resolve(distDir)) return [];
|
|
36
|
+
const moved = [];
|
|
37
|
+
for (const name of ROOT_FILES) {
|
|
38
|
+
const from = path.join(siteDir, name);
|
|
39
|
+
if (!fs.existsSync(from)) continue;
|
|
40
|
+
fs.renameSync(from, path.join(distDir, name));
|
|
41
|
+
moved.push(name);
|
|
42
|
+
}
|
|
43
|
+
return moved;
|
|
44
|
+
}
|