@writedocs/generator 0.10.18 → 0.10.20
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 +96 -93
- package/src/cli/generate-api-pages.js +9 -5
- package/src/cli/page-list-watch.js +69 -66
- package/src/cli/run-astro.js +2 -0
- package/src/cli/run-pagefind.js +10 -4
- package/src/components/Image.astro +164 -164
- package/src/layout/BaseLayout.astro +11 -8
- package/src/lib/asset-dimensions.js +89 -0
- package/src/lib/build-memo.js +22 -0
- package/src/lib/config-schema.js +5 -0
- package/src/lib/config-schema.ts +5 -0
- package/src/lib/config.ts +8 -0
- package/src/lib/image-size.js +152 -140
- package/src/lib/json-schema-descriptions.js +1 -0
- package/src/lib/link-check.js +35 -2
- package/src/lib/og-image.js +13 -3
- package/src/lib/pages.js +312 -291
- 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-image-loading.js +71 -71
- package/src/lib/styles-asset-integration.js +35 -2
- package/src/lib/wdignore-cases.json +195 -0
- package/src/lib/wdignore.js +177 -0
- package/src/pages/[...slug].astro +15 -4
- package/src/pages/og/[...slug].png.ts +3 -2
- package/writedocs.schema.json +5 -0
package/package.json
CHANGED
|
@@ -1,94 +1,97 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@writedocs/generator",
|
|
3
|
-
"version": "0.10.
|
|
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.10.20",
|
|
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
|
}
|
|
@@ -5,6 +5,7 @@ import matter from 'gray-matter';
|
|
|
5
5
|
import { writedocsTempDir } from '../lib/writedocs-temp-dir.js';
|
|
6
6
|
import { parseOpenApiRef, openApiOperationKey, specDirName } from '../lib/openapi-ref.js';
|
|
7
7
|
import { findAllPages } from '../lib/pages.js';
|
|
8
|
+
import { projectIgnore } from '../lib/project-ignore.js';
|
|
8
9
|
import { readConfigText } from '../lib/config-file.js';
|
|
9
10
|
import { HTTP_METHODS, collectOpenApiGroups } from '../lib/openapi-spec.js';
|
|
10
11
|
import { operationMetaDescription } from '../lib/meta-description.js';
|
|
@@ -93,8 +94,10 @@ const OVERRIDE_SCAN_EXCLUDED_DIRS = new Set(['node_modules', 'dist', '.astro', '
|
|
|
93
94
|
* id ("docs/webhooks/index") the rest of the routing pipeline would
|
|
94
95
|
* never actually resolve, since the page's real id is "docs/webhooks") -
|
|
95
96
|
* into `overrides`, skipping OVERRIDE_SCAN_EXCLUDED_DIRS at the content
|
|
96
|
-
* root's own top level
|
|
97
|
-
|
|
97
|
+
* root's own top level and whatever `rules` - the project's ignore rules,
|
|
98
|
+
* lib/wdignore.js - leave out: such a file isn't a page (findAllPages()
|
|
99
|
+
* skips it too), so it can't stand in for a generated one. */
|
|
100
|
+
function scanDirForOverrides(dir, relBase, overrides, rules) {
|
|
98
101
|
let entries;
|
|
99
102
|
try {
|
|
100
103
|
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
@@ -106,10 +109,11 @@ function scanDirForOverrides(dir, relBase, overrides) {
|
|
|
106
109
|
const rel = relBase ? `${relBase}/${entry.name}` : entry.name;
|
|
107
110
|
if (entry.isDirectory()) {
|
|
108
111
|
if (relBase === '' && OVERRIDE_SCAN_EXCLUDED_DIRS.has(entry.name)) continue;
|
|
109
|
-
|
|
112
|
+
if (rules.ignores(rel, true)) continue;
|
|
113
|
+
scanDirForOverrides(full, rel, overrides, rules);
|
|
110
114
|
continue;
|
|
111
115
|
}
|
|
112
|
-
if (!/\.mdx?$/i.test(entry.name)) continue;
|
|
116
|
+
if (!/\.mdx?$/i.test(entry.name) || rules.ignores(rel)) continue;
|
|
113
117
|
const raw = fs.readFileSync(full, 'utf-8');
|
|
114
118
|
let data;
|
|
115
119
|
try {
|
|
@@ -140,7 +144,7 @@ function scanDirForOverrides(dir, relBase, overrides) {
|
|
|
140
144
|
* lives. */
|
|
141
145
|
function findHandWrittenOverrides(contentDir) {
|
|
142
146
|
const overrides = new Map(); // operationKey -> file id
|
|
143
|
-
scanDirForOverrides(contentDir, '', overrides);
|
|
147
|
+
scanDirForOverrides(contentDir, '', overrides, projectIgnore(contentDir));
|
|
144
148
|
return overrides;
|
|
145
149
|
}
|
|
146
150
|
|
|
@@ -1,66 +1,69 @@
|
|
|
1
|
-
// `writedocs dev`: noticing pages added or removed. The preview's list of page
|
|
2
|
-
// files is read once, when it starts (content.config.ts hands findAllPages()'s
|
|
3
|
-
// list to Astro) - an edit to a page shows up at once, but a new page stays
|
|
4
|
-
// "not found" and a deleted one keeps being served. So this watches the
|
|
5
|
-
// content folder, and when the list findAllPages() gives changes, calls
|
|
6
|
-
// `onChange` - cli/dev.js restarts the preview then.
|
|
7
|
-
//
|
|
8
|
-
// It compares the list itself, not file events: a Markdown file that isn't
|
|
9
|
-
// a page (no frontmatter, not in the navigation), an edit to a page, or a
|
|
10
|
-
// save that writes a file twice doesn't restart anything.
|
|
11
|
-
import fs from 'node:fs';
|
|
12
|
-
import { findAllPages, EXCLUDED_TOP_LEVEL_DIRS } from '../lib/pages.js';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (
|
|
25
|
-
const
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
close() {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
1
|
+
// `writedocs dev`: noticing pages added or removed. The preview's list of page
|
|
2
|
+
// files is read once, when it starts (content.config.ts hands findAllPages()'s
|
|
3
|
+
// list to Astro) - an edit to a page shows up at once, but a new page stays
|
|
4
|
+
// "not found" and a deleted one keeps being served. So this watches the
|
|
5
|
+
// content folder, and when the list findAllPages() gives changes, calls
|
|
6
|
+
// `onChange` - cli/dev.js restarts the preview then.
|
|
7
|
+
//
|
|
8
|
+
// It compares the list itself, not file events: a Markdown file that isn't
|
|
9
|
+
// a page (no frontmatter, not in the navigation), an edit to a page, or a
|
|
10
|
+
// save that writes a file twice doesn't restart anything.
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import { findAllPages, EXCLUDED_TOP_LEVEL_DIRS } from '../lib/pages.js';
|
|
13
|
+
import { WDIGNORE_FILE } from '../lib/wdignore.js';
|
|
14
|
+
|
|
15
|
+
/** Wait this long after the last file event before checking - a rename, a
|
|
16
|
+
* copy of several files or an editor's save arrive as a burst of events. */
|
|
17
|
+
export const SETTLE_MS = 400;
|
|
18
|
+
|
|
19
|
+
/** Whether a changed file can change the page list: a .md/.mdx file, or
|
|
20
|
+
* writedocs.json (it lists pages that have no frontmatter), outside the
|
|
21
|
+
* folders findAllPages() never looks in - or the project's `.wdignore`,
|
|
22
|
+
* which says which files aren't pages. */
|
|
23
|
+
export function mayChangePages(relative) {
|
|
24
|
+
if (!relative) return true;
|
|
25
|
+
const parts = String(relative).split(/[\\/]/);
|
|
26
|
+
if (parts.length === 1 && parts[0] === WDIGNORE_FILE) return true;
|
|
27
|
+
if (EXCLUDED_TOP_LEVEL_DIRS.has(parts[0]) || parts.some((part) => part.startsWith('.'))) return false;
|
|
28
|
+
const name = parts[parts.length - 1];
|
|
29
|
+
return /\.mdx?$/i.test(name) || name === 'writedocs.json';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Starts watching; returns `{ close }`. `onChange({ added, removed })` gets
|
|
33
|
+
* the page files (relative paths) that came and went. */
|
|
34
|
+
export function watchPageList(contentDir, onChange, { settleMs = SETTLE_MS } = {}) {
|
|
35
|
+
let current = new Set(findAllPages(contentDir));
|
|
36
|
+
let timer = null;
|
|
37
|
+
const check = () => {
|
|
38
|
+
let next;
|
|
39
|
+
try {
|
|
40
|
+
next = new Set(findAllPages(contentDir));
|
|
41
|
+
} catch {
|
|
42
|
+
return; // mid-save, or a folder being moved - the next event checks again
|
|
43
|
+
}
|
|
44
|
+
const added = [...next].filter((file) => !current.has(file));
|
|
45
|
+
const removed = [...current].filter((file) => !next.has(file));
|
|
46
|
+
if (!added.length && !removed.length) return;
|
|
47
|
+
current = next;
|
|
48
|
+
onChange({ added, removed });
|
|
49
|
+
};
|
|
50
|
+
let watcher;
|
|
51
|
+
try {
|
|
52
|
+
watcher = fs.watch(contentDir, { recursive: true }, (_event, filename) => {
|
|
53
|
+
if (!mayChangePages(filename)) return;
|
|
54
|
+
clearTimeout(timer);
|
|
55
|
+
timer = setTimeout(check, settleMs);
|
|
56
|
+
});
|
|
57
|
+
watcher.on('error', () => {});
|
|
58
|
+
} catch {
|
|
59
|
+
// A file system without recursive watching: pages added while `dev`
|
|
60
|
+
// runs need a restart, as before.
|
|
61
|
+
return { close() {} };
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
close() {
|
|
65
|
+
clearTimeout(timer);
|
|
66
|
+
watcher.close();
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
package/src/cli/run-astro.js
CHANGED
|
@@ -54,6 +54,8 @@ export function runAstro(command, { packageRoot, contentDir, port, onEvent }) {
|
|
|
54
54
|
// fileIdForEntry() can resolve it back into a docs/-relative file id
|
|
55
55
|
// - see that function for why.
|
|
56
56
|
WRITEDOCS_PACKAGE_ROOT: packageRoot,
|
|
57
|
+
// 'dev' or 'build' - lib/build-memo.js keeps per-build results only in a build.
|
|
58
|
+
WRITEDOCS_COMMAND: command,
|
|
57
59
|
...(port ? { WRITEDOCS_PORT: String(port) } : {}),
|
|
58
60
|
},
|
|
59
61
|
});
|
package/src/cli/run-pagefind.js
CHANGED
|
@@ -67,8 +67,10 @@ const SEARCH_PUBLIC = /data-wd-search-public="true"/;
|
|
|
67
67
|
|
|
68
68
|
/** The site's pages by search space - `{ public, spaces }` - or null when
|
|
69
69
|
* no page is in a hidden space (the whole site is one index, as ever).
|
|
70
|
-
* Only pages Pagefind would index: those with a data-pagefind-body.
|
|
71
|
-
|
|
70
|
+
* Only pages Pagefind would index: those with a data-pagefind-body. A
|
|
71
|
+
* page is `{ rel }`, its path in the site with forward slashes.
|
|
72
|
+
* Exported for scripts/search-spaces.test.js. */
|
|
73
|
+
export function searchSpaces(siteDir) {
|
|
72
74
|
const publicPages = [];
|
|
73
75
|
const spaces = new Map();
|
|
74
76
|
const walk = (dir) => {
|
|
@@ -81,7 +83,11 @@ function searchSpaces(siteDir) {
|
|
|
81
83
|
if (!entry.name.endsWith('.html')) continue;
|
|
82
84
|
const content = fs.readFileSync(full, 'utf8');
|
|
83
85
|
if (!content.includes('data-pagefind-body')) continue;
|
|
84
|
-
|
|
86
|
+
// The page's address only, not its HTML: a page is read again when
|
|
87
|
+
// it's added to an index (indexBySpace()). Keeping every page's
|
|
88
|
+
// content here ran the CLI out of memory on a site with 1.7 GiB of
|
|
89
|
+
// HTML - and most sites have no hidden space, so none of it was used.
|
|
90
|
+
const page = { rel: path.relative(siteDir, full).split(path.sep).join('/') };
|
|
85
91
|
const space = SPACE.exec(content)?.[1];
|
|
86
92
|
if (!space) {
|
|
87
93
|
publicPages.push(page);
|
|
@@ -110,7 +116,7 @@ async function indexBySpace(siteDir, packageRoot, groups) {
|
|
|
110
116
|
};
|
|
111
117
|
const write = async (pages, outputPath, what) => {
|
|
112
118
|
const { index } = check(await pagefind.createIndex({}), what);
|
|
113
|
-
for (const page of pages) check(await index.addHTMLFile({ sourcePath: page.rel, content: page.
|
|
119
|
+
for (const page of pages) check(await index.addHTMLFile({ sourcePath: page.rel, content: fs.readFileSync(path.join(siteDir, ...page.rel.split('/')), 'utf8') }), `${what}: ${page.rel}`);
|
|
114
120
|
check(await index.writeFiles({ outputPath }), what);
|
|
115
121
|
};
|
|
116
122
|
try {
|