@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
|
@@ -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-pagefind.js
CHANGED
|
@@ -1,148 +1,154 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import { spawn } from 'node:child_process';
|
|
4
|
-
import { pathToFileURL } from 'node:url';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Locates the installed pagefind package by walking up node_modules
|
|
8
|
-
* directories from packageRoot - the same lookup algorithm Node itself
|
|
9
|
-
* uses for bare-specifier resolution, just done by hand with fs instead
|
|
10
|
-
* of require.resolve()/import.meta.resolve(). This is necessary (rather
|
|
11
|
-
* than a require.resolve()-based lookup) because pagefind's own
|
|
12
|
-
* package.json declares an "exports" map with only a "." entry scoped to
|
|
13
|
-
* the "import" condition: require.resolve('pagefind/package.json') is
|
|
14
|
-
* blocked outright (exports doesn't list a package.json subpath at all),
|
|
15
|
-
* and require.resolve('pagefind') also fails under CJS require() semantics
|
|
16
|
-
* (no "require"/"default" condition for it to satisfy).
|
|
17
|
-
* import.meta.resolve() would sidestep both, but needs Node 20.6+ -
|
|
18
|
-
* newer than this package's documented minimum (20.3.0, see engines in
|
|
19
|
-
* package.json). Walking node_modules ourselves avoids all of this - we
|
|
20
|
-
* only need pagefind's package.json (for its "bin" field) and the CLI
|
|
21
|
-
* script path, both plain file reads that "exports" doesn't restrict at
|
|
22
|
-
* all (only module *resolution* is subject to it).
|
|
23
|
-
*/
|
|
24
|
-
function findPagefindDir(startDir) {
|
|
25
|
-
let dir = startDir;
|
|
26
|
-
while (true) {
|
|
27
|
-
const candidate = path.join(dir, 'node_modules', 'pagefind');
|
|
28
|
-
if (fs.existsSync(path.join(candidate, 'package.json'))) return candidate;
|
|
29
|
-
const parent = path.dirname(dir);
|
|
30
|
-
if (parent === dir) {
|
|
31
|
-
throw new Error(`Could not find "pagefind" in any node_modules directory above ${startDir}`);
|
|
32
|
-
}
|
|
33
|
-
dir = parent;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function resolvePagefindBin(packageRoot) {
|
|
38
|
-
const dir = findPagefindDir(packageRoot);
|
|
39
|
-
const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
|
|
40
|
-
return path.join(dir, pkg.bin);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Indexes a built static site with Pagefind, writing the search bundle
|
|
45
|
-
* into <siteDir>/pagefind. Run as a postbuild step, after astro build has
|
|
46
|
-
* already produced the final HTML - Pagefind crawls that HTML directly
|
|
47
|
-
* rather than hooking into the Astro/Vite build pipeline, so search stays
|
|
48
|
-
* decoupled from whatever templating produced the pages. Only indexes
|
|
49
|
-
* elements carrying `data-pagefind-body` (see [...slug].astro's
|
|
50
|
-
* `.wd-article`) - without that scoping, Pagefind falls back to indexing
|
|
51
|
-
* every page's entire <body>, polluting every result with sidebar/topbar
|
|
52
|
-
* chrome text repeated on every page.
|
|
53
|
-
*
|
|
54
|
-
* Pagefind's output is captured, not printed: the CLI prints its own step
|
|
55
|
-
* line, and Pagefind's text only when it fails (in the rejected Error).
|
|
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
|
-
const
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
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
|
-
await
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
child.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
child.on('
|
|
147
|
-
|
|
148
|
-
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Locates the installed pagefind package by walking up node_modules
|
|
8
|
+
* directories from packageRoot - the same lookup algorithm Node itself
|
|
9
|
+
* uses for bare-specifier resolution, just done by hand with fs instead
|
|
10
|
+
* of require.resolve()/import.meta.resolve(). This is necessary (rather
|
|
11
|
+
* than a require.resolve()-based lookup) because pagefind's own
|
|
12
|
+
* package.json declares an "exports" map with only a "." entry scoped to
|
|
13
|
+
* the "import" condition: require.resolve('pagefind/package.json') is
|
|
14
|
+
* blocked outright (exports doesn't list a package.json subpath at all),
|
|
15
|
+
* and require.resolve('pagefind') also fails under CJS require() semantics
|
|
16
|
+
* (no "require"/"default" condition for it to satisfy).
|
|
17
|
+
* import.meta.resolve() would sidestep both, but needs Node 20.6+ -
|
|
18
|
+
* newer than this package's documented minimum (20.3.0, see engines in
|
|
19
|
+
* package.json). Walking node_modules ourselves avoids all of this - we
|
|
20
|
+
* only need pagefind's package.json (for its "bin" field) and the CLI
|
|
21
|
+
* script path, both plain file reads that "exports" doesn't restrict at
|
|
22
|
+
* all (only module *resolution* is subject to it).
|
|
23
|
+
*/
|
|
24
|
+
function findPagefindDir(startDir) {
|
|
25
|
+
let dir = startDir;
|
|
26
|
+
while (true) {
|
|
27
|
+
const candidate = path.join(dir, 'node_modules', 'pagefind');
|
|
28
|
+
if (fs.existsSync(path.join(candidate, 'package.json'))) return candidate;
|
|
29
|
+
const parent = path.dirname(dir);
|
|
30
|
+
if (parent === dir) {
|
|
31
|
+
throw new Error(`Could not find "pagefind" in any node_modules directory above ${startDir}`);
|
|
32
|
+
}
|
|
33
|
+
dir = parent;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function resolvePagefindBin(packageRoot) {
|
|
38
|
+
const dir = findPagefindDir(packageRoot);
|
|
39
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
|
|
40
|
+
return path.join(dir, pkg.bin);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Indexes a built static site with Pagefind, writing the search bundle
|
|
45
|
+
* into <siteDir>/pagefind. Run as a postbuild step, after astro build has
|
|
46
|
+
* already produced the final HTML - Pagefind crawls that HTML directly
|
|
47
|
+
* rather than hooking into the Astro/Vite build pipeline, so search stays
|
|
48
|
+
* decoupled from whatever templating produced the pages. Only indexes
|
|
49
|
+
* elements carrying `data-pagefind-body` (see [...slug].astro's
|
|
50
|
+
* `.wd-article`) - without that scoping, Pagefind falls back to indexing
|
|
51
|
+
* every page's entire <body>, polluting every result with sidebar/topbar
|
|
52
|
+
* chrome text repeated on every page.
|
|
53
|
+
*
|
|
54
|
+
* Pagefind's output is captured, not printed: the CLI prints its own step
|
|
55
|
+
* line, and Pagefind's text only when it fails (in the rejected Error).
|
|
56
|
+
*
|
|
57
|
+
* With a `basePath` ("/docs"), `siteDir` is dist/docs/ and nothing here
|
|
58
|
+
* changes: the index keeps each page's address in the site ("/a/"), and
|
|
59
|
+
* Pagefind's script puts the folder its bundle is served from in front of a
|
|
60
|
+
* result (/docs/pagefind/ -> "/docs/a/"). Adding the base here too gave
|
|
61
|
+
* results with it twice.
|
|
62
|
+
*/
|
|
63
|
+
export async function runPagefind(siteDir, { packageRoot }) {
|
|
64
|
+
const groups = searchSpaces(siteDir);
|
|
65
|
+
if (groups) return indexBySpace(siteDir, packageRoot, groups);
|
|
66
|
+
return indexWholeSite(siteDir, packageRoot);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Pages under a hidden navigation item name their search space in their
|
|
70
|
+
// markup ([...slug].astro, lib/hidden-sections.js).
|
|
71
|
+
const SPACE = /data-wd-search-space="([^"]+)"/;
|
|
72
|
+
const SEARCH_PUBLIC = /data-wd-search-public="true"/;
|
|
73
|
+
|
|
74
|
+
/** The site's pages by search space - `{ public, spaces }` - or null when
|
|
75
|
+
* no page is in a hidden space (the whole site is one index, as ever).
|
|
76
|
+
* Only pages Pagefind would index: those with a data-pagefind-body. A
|
|
77
|
+
* page is `{ rel }`, its path in the site with forward slashes.
|
|
78
|
+
* Exported for scripts/search-spaces.test.js. */
|
|
79
|
+
export function searchSpaces(siteDir) {
|
|
80
|
+
const publicPages = [];
|
|
81
|
+
const spaces = new Map();
|
|
82
|
+
const walk = (dir) => {
|
|
83
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
84
|
+
const full = path.join(dir, entry.name);
|
|
85
|
+
if (entry.isDirectory()) {
|
|
86
|
+
if (!['_astro', 'pagefind', 'pagefind-spaces'].includes(entry.name)) walk(full);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (!entry.name.endsWith('.html')) continue;
|
|
90
|
+
const content = fs.readFileSync(full, 'utf8');
|
|
91
|
+
if (!content.includes('data-pagefind-body')) continue;
|
|
92
|
+
// The page's address only, not its HTML: a page is read again when
|
|
93
|
+
// it's added to an index (indexBySpace()). Keeping every page's
|
|
94
|
+
// content here ran the CLI out of memory on a site with 1.7 GiB of
|
|
95
|
+
// HTML - and most sites have no hidden space, so none of it was used.
|
|
96
|
+
const page = { rel: path.relative(siteDir, full).split(path.sep).join('/') };
|
|
97
|
+
const space = SPACE.exec(content)?.[1];
|
|
98
|
+
if (!space) {
|
|
99
|
+
publicPages.push(page);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const group = spaces.get(space) ?? { searchPublic: false, pages: [] };
|
|
103
|
+
group.searchPublic ||= SEARCH_PUBLIC.test(content);
|
|
104
|
+
group.pages.push(page);
|
|
105
|
+
spaces.set(space, group);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
walk(siteDir);
|
|
109
|
+
return spaces.size ? { public: publicPages, spaces } : null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** One index for the public pages (dist/pagefind/) and one per hidden
|
|
113
|
+
* space (dist/pagefind-spaces/<id>/) - so the public search never finds a
|
|
114
|
+
* hidden page, and a hidden space's search finds only its own pages, plus
|
|
115
|
+
* the public ones when it sets `searchPublic`. src/scripts/search.ts loads
|
|
116
|
+
* the index of the page's space. */
|
|
117
|
+
async function indexBySpace(siteDir, packageRoot, groups) {
|
|
118
|
+
const pagefind = await import(pathToFileURL(path.join(findPagefindDir(packageRoot), 'lib', 'index.js')).href);
|
|
119
|
+
const check = (result, what) => {
|
|
120
|
+
if (result.errors?.length) throw new Error(`pagefind (${what}): ${result.errors.join('; ')}`);
|
|
121
|
+
return result;
|
|
122
|
+
};
|
|
123
|
+
const write = async (pages, outputPath, what) => {
|
|
124
|
+
const { index } = check(await pagefind.createIndex({}), what);
|
|
125
|
+
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}`);
|
|
126
|
+
check(await index.writeFiles({ outputPath }), what);
|
|
127
|
+
};
|
|
128
|
+
try {
|
|
129
|
+
await write(groups.public, path.join(siteDir, 'pagefind'), 'public pages');
|
|
130
|
+
for (const [id, space] of groups.spaces) {
|
|
131
|
+
const pages = space.searchPublic ? [...space.pages, ...groups.public] : space.pages;
|
|
132
|
+
await write(pages, path.join(siteDir, 'pagefind-spaces', id), `hidden space ${id}`);
|
|
133
|
+
}
|
|
134
|
+
} finally {
|
|
135
|
+
await pagefind.close();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function indexWholeSite(siteDir, packageRoot) {
|
|
140
|
+
const bin = resolvePagefindBin(packageRoot);
|
|
141
|
+
return new Promise((resolve, reject) => {
|
|
142
|
+
const child = spawn(process.execPath, [bin, '--site', siteDir, '--quiet'], {
|
|
143
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
144
|
+
});
|
|
145
|
+
let output = '';
|
|
146
|
+
child.stdout.on('data', (d) => (output += d));
|
|
147
|
+
child.stderr.on('data', (d) => (output += d));
|
|
148
|
+
child.on('close', (code) => {
|
|
149
|
+
if (code === 0) resolve();
|
|
150
|
+
else reject(new Error(`pagefind exited with code ${code}${output.trim() ? `:\n${output.trim()}` : ''}`));
|
|
151
|
+
});
|
|
152
|
+
child.on('error', reject);
|
|
153
|
+
});
|
|
154
|
+
}
|