@vite-hub/docs 0.3.1 → 0.4.1
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/README.md +15 -13
- package/dist/{agent-copy-BJp_Yf5d.js → agent-copy-xPaWye_g.js} +1 -1
- package/dist/assistant-pages-BN7hNsSZ.js +37 -0
- package/dist/{assistant-shared-Dll_F_yy.d.ts → assistant-shared-CWIKRtBv.d.ts} +3 -2
- package/dist/{assistant-shared-CdtXowot.js → assistant-shared-WzButktj.js} +23 -7
- package/dist/assistant-worker.d.ts +1 -1
- package/dist/assistant-worker.js +1 -1
- package/dist/assistant.d.ts +1 -1
- package/dist/assistant.js +1 -1
- package/dist/{content-9CINWiRf.js → content-CPZGnn3S.js} +3 -33
- package/dist/{draft-DUBx--r9.js → draft-BjWmaiLn.js} +1 -1
- package/dist/error-diagnostics-B_ZOy7kF.js +93 -0
- package/dist/files-UY4h1_36.js +38 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/link-checker-redirects.js +1 -1
- package/dist/{manifest-Dzp5-_AJ.d.ts → manifest-CMoxcwPm.d.ts} +8 -2
- package/dist/{manifest-D66AEF8F.js → manifest-ZdxLrcvt.js} +47 -33
- package/dist/{markdown-Cn9-4oVG.js → markdown-DUWnEMPp.js} +1 -1
- package/dist/navigation.d.ts +1 -2
- package/dist/navigation.js +1 -2
- package/dist/{nuxt-B5LrERKc.d.ts → nuxt-CAGpKl_-.d.ts} +5 -4
- package/dist/nuxt.d.ts +1 -1
- package/dist/nuxt.js +465 -82
- package/dist/{page-BbmSfZO8.js → page-GPt09oex.js} +2 -1
- package/dist/primitive-rail.d.ts +1 -1
- package/dist/primitive-rail.js +7 -2
- package/dist/{raw-C03EUJKw.js → raw-BChwipz_.js} +6 -0
- package/dist/{redirects-BrbWFSzW.js → redirects-CmR1yu5A.js} +18 -6
- package/dist/runtime/app/components/content/McpClient.vue +170 -0
- package/dist/runtime/app/components/content/McpInstall.vue +238 -0
- package/dist/runtime/server/llms.js +1 -1
- package/dist/runtime/server/markdown.js +1 -1
- package/dist/runtime/server/mcp.js +1 -1
- package/dist/runtime/server/page.js +3 -3
- package/dist/runtime/server/raw.js +1 -1
- package/dist/runtime/server/search.js +2 -2
- package/dist/runtime/server/sitemap.js +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +4 -4
- package/package.json +11 -11
- package/dist/error-diagnostics-BoOsP6Y4.js +0 -53
package/dist/nuxt.js
CHANGED
|
@@ -1,26 +1,171 @@
|
|
|
1
1
|
import { docsAppPath, docsIndexedPages, docsManifestPages, docsPageIcon, docsPageIndexed, docsRailIcon, docsRawPath, docsSectionIcon, isDocsPath, normalizeDocsBase, normalizeDocsPath } from "./navigation.js";
|
|
2
|
-
import { a as replacesDocsPage, t as docsMount } from "./page-
|
|
3
|
-
import { t as docsErrorDiagnostics } from "./error-diagnostics-
|
|
4
|
-
import { n as docsRedirectProblems, r as docsRedirects, t as docsRedirectError } from "./redirects-
|
|
5
|
-
import { a as
|
|
6
|
-
import { r as docsContentSource } from "./agent-copy-
|
|
2
|
+
import { a as replacesDocsPage, o as routePaths, t as docsMount } from "./page-GPt09oex.js";
|
|
3
|
+
import { t as docsErrorDiagnostics } from "./error-diagnostics-B_ZOy7kF.js";
|
|
4
|
+
import { i as docsServerRoutes, n as docsRedirectProblems, r as docsRedirects, t as docsRedirectError } from "./redirects-CmR1yu5A.js";
|
|
5
|
+
import { a as docsAppManifestSource, c as resolveDocsSources, d as docsLinkExclusion, f as docsOutputFile, i as docsAppManifest, l as checkDocsLinks, n as createDocsContent, o as docsAppPanelSource, s as readDocsContent, t as contentName, u as docsLinkError } from "./manifest-ZdxLrcvt.js";
|
|
6
|
+
import { r as docsContentSource } from "./agent-copy-xPaWye_g.js";
|
|
7
7
|
import { i as docsThemeScope, n as docsThemeAdditions, r as docsUi, t as docsAppConfigUi } from "./theme-DzC8LtMH.js";
|
|
8
8
|
import { createRequire } from "node:module";
|
|
9
9
|
import { addComponent, addComponentsDir, addImportsDir, addPlugin, addRouteMiddleware, addServerHandler, addTemplate, addTypeTemplate, createResolver, defineNuxtModule, extendPages, updateTemplates, useLogger } from "@nuxt/kit";
|
|
10
|
-
import {
|
|
10
|
+
import { addRoute, createRouter, findAllRoutes, routeToRegExp } from "rou3";
|
|
11
|
+
import { defineDiagnostics, formatDiagnostic } from "nostics";
|
|
11
12
|
import { createHash } from "node:crypto";
|
|
12
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, watch, writeFileSync } from "node:fs";
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
|
|
13
14
|
import { readFile, readdir } from "node:fs/promises";
|
|
14
|
-
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
15
|
+
import { basename, dirname, join, parse, posix, relative, resolve, sep } from "node:path";
|
|
15
16
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
17
|
+
import { tmpdir } from "node:os";
|
|
16
18
|
import { findContentEntry } from "@vite-hub/source/vite";
|
|
17
19
|
import { vitehubTheme } from "@vite-hub/ui/theme";
|
|
18
20
|
import { sizeOf } from "comark-zoom/size";
|
|
19
21
|
import { defu } from "defu";
|
|
20
|
-
import {
|
|
21
|
-
import { ELEMENT_NODE, parse, walkSync } from "ultrahtml";
|
|
22
|
+
import { ELEMENT_NODE, parse as parse$1, walkSync } from "ultrahtml";
|
|
22
23
|
import { gzipSync } from "node:zlib";
|
|
23
24
|
import postcss from "postcss";
|
|
25
|
+
//#region ../internal/dist/build/vite.js
|
|
26
|
+
const projectRootDirectoryMarkers = [
|
|
27
|
+
["server", "agents"],
|
|
28
|
+
["server", "channels"],
|
|
29
|
+
["server", "connections"],
|
|
30
|
+
["server", "browsers"],
|
|
31
|
+
["server", "emails"],
|
|
32
|
+
["server", "schedules"],
|
|
33
|
+
["server", "workspaces"]
|
|
34
|
+
];
|
|
35
|
+
const projectRootFileMarkers = [
|
|
36
|
+
["package.json"],
|
|
37
|
+
["nuxt.config.ts"],
|
|
38
|
+
["nuxt.config.mts"],
|
|
39
|
+
["nuxt.config.js"],
|
|
40
|
+
["nuxt.config.mjs"]
|
|
41
|
+
];
|
|
42
|
+
const VITEHUB_PROJECT_ROOT = "__vitehubProjectRoot";
|
|
43
|
+
function resolveViteHubProjectRoot(root, options = {}) {
|
|
44
|
+
const resolvedRoot = resolve(root);
|
|
45
|
+
const temporaryRoot = resolve(tmpdir());
|
|
46
|
+
const sharedTemporaryRoot = dirname(temporaryRoot) === parse(temporaryRoot).root ? temporaryRoot : void 0;
|
|
47
|
+
if (options.projectRoot) return resolve(resolvedRoot, options.projectRoot);
|
|
48
|
+
if (basename(resolvedRoot) === "app") {
|
|
49
|
+
const parent = dirname(resolvedRoot);
|
|
50
|
+
if (parent !== sharedTemporaryRoot && (hasProjectRootDirectoryMarker(parent) || hasProjectRootFileMarker(parent, [
|
|
51
|
+
"nuxt.config.ts",
|
|
52
|
+
"nuxt.config.mts",
|
|
53
|
+
"nuxt.config.js",
|
|
54
|
+
"nuxt.config.mjs"
|
|
55
|
+
]))) return parent;
|
|
56
|
+
}
|
|
57
|
+
let current = resolvedRoot;
|
|
58
|
+
while (true) {
|
|
59
|
+
if (current === sharedTemporaryRoot && resolvedRoot !== current) return resolvedRoot;
|
|
60
|
+
if (hasProjectRootMarker(current)) return current;
|
|
61
|
+
const parent = dirname(current);
|
|
62
|
+
if (parent === current) return resolvedRoot;
|
|
63
|
+
current = parent;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function hasProjectRootDirectoryMarker(root) {
|
|
67
|
+
for (const marker of projectRootDirectoryMarkers) try {
|
|
68
|
+
if (statSync(resolve(root, ...marker)).isDirectory()) return true;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error.code !== "ENOENT") throw error;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
function hasProjectRootMarker(root) {
|
|
75
|
+
if (hasProjectRootDirectoryMarker(root)) return true;
|
|
76
|
+
return hasProjectRootFileMarker(root, projectRootFileMarkers.flat());
|
|
77
|
+
}
|
|
78
|
+
function hasProjectRootFileMarker(root, markers) {
|
|
79
|
+
for (const marker of markers) {
|
|
80
|
+
const path = Array.isArray(marker) ? marker : [marker];
|
|
81
|
+
try {
|
|
82
|
+
if (statSync(resolve(root, ...path)).isFile()) return true;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error.code !== "ENOENT") throw error;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region ../internal/dist/hints.js
|
|
91
|
+
/**
|
|
92
|
+
* The file that lists the hints of the last build or dev server, relative to the project root. A hint is a warning
|
|
93
|
+
* about something that works now and fails later, such as counts that stay in one server's memory. Agents and CI read
|
|
94
|
+
* the file instead of the terminal.
|
|
95
|
+
*/
|
|
96
|
+
const viteHubHintsFile = ".vitehub/hints.json";
|
|
97
|
+
const VITEHUB_NUXT_HINTS = "__vitehubNuxtHints";
|
|
98
|
+
const runsKey = Symbol.for("vitehub.hints.runs");
|
|
99
|
+
const shared = globalThis;
|
|
100
|
+
const runs = shared[runsKey] ??= /* @__PURE__ */ new Map();
|
|
101
|
+
const startedKey = Symbol.for("vitehub.hints.started");
|
|
102
|
+
const startedShared = globalThis;
|
|
103
|
+
const started = startedShared[startedKey] ??= /* @__PURE__ */ new WeakSet();
|
|
104
|
+
/**
|
|
105
|
+
* The report of the ViteHub project root, where the other generated files go. A Nuxt app with `srcDir: "app"` has its
|
|
106
|
+
* Vite root in `app/`, one folder below.
|
|
107
|
+
*/
|
|
108
|
+
function hintsFile(config) {
|
|
109
|
+
const projectRoot = Reflect.get(config, VITEHUB_PROJECT_ROOT);
|
|
110
|
+
return resolve(typeof projectRoot === "string" ? projectRoot : resolveViteHubProjectRoot(config.root), viteHubHintsFile);
|
|
111
|
+
}
|
|
112
|
+
function startRun(config) {
|
|
113
|
+
const file = hintsFile(config);
|
|
114
|
+
const run = {
|
|
115
|
+
file,
|
|
116
|
+
report: {
|
|
117
|
+
version: 1,
|
|
118
|
+
command: config.command,
|
|
119
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
120
|
+
hints: []
|
|
121
|
+
},
|
|
122
|
+
keys: /* @__PURE__ */ new Set()
|
|
123
|
+
};
|
|
124
|
+
runs.set(file, run);
|
|
125
|
+
return run;
|
|
126
|
+
}
|
|
127
|
+
function write(run) {
|
|
128
|
+
mkdirSync(dirname(run.file), { recursive: true });
|
|
129
|
+
writeFileSync(run.file, `${JSON.stringify(run.report, null, 2)}\n`);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Reports a hint from a Vite plugin hook, or from a Nitro or Nuxt hook of the same build: prints it once with its fix and docs link, and adds it to
|
|
133
|
+
* {@link viteHubHintsFile}. Build the diagnostic from the package's nostics catalog, so its code has a docs page.
|
|
134
|
+
*/
|
|
135
|
+
function reportViteHubHint(config, diagnostic) {
|
|
136
|
+
if (skipHints(config)) return;
|
|
137
|
+
const nuxt = config[VITEHUB_NUXT_HINTS];
|
|
138
|
+
if (typeof nuxt === "function") return nuxt(diagnostic);
|
|
139
|
+
const run = runs.get(hintsFile(config)) ?? startRun(config);
|
|
140
|
+
const hint = {
|
|
141
|
+
code: diagnostic.code,
|
|
142
|
+
why: diagnostic.why,
|
|
143
|
+
...diagnostic.fix ? { fix: diagnostic.fix } : {},
|
|
144
|
+
...diagnostic.docs ? { docs: diagnostic.docs } : {},
|
|
145
|
+
...diagnostic.sources?.length ? { sources: diagnostic.sources } : {}
|
|
146
|
+
};
|
|
147
|
+
const key = JSON.stringify([hint.code, hint.sources ?? []]);
|
|
148
|
+
if (run.keys.has(key)) return;
|
|
149
|
+
run.keys.add(key);
|
|
150
|
+
run.report.hints.push(hint);
|
|
151
|
+
write(run);
|
|
152
|
+
(config.logger ?? console).warn(formatDiagnostic(diagnostic));
|
|
153
|
+
}
|
|
154
|
+
function skipHints(config) {
|
|
155
|
+
return !config.command || Reflect.get(config, "__vitehubPrepare") === true || Reflect.get(config, "vitehubCliDiscovery") === true;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Starts the hints of a build or dev server: writes an empty {@link viteHubHintsFile}, so a run without hints does not
|
|
159
|
+
* leave the hints of an earlier run in place. Every plugin that reports hints calls it from `configResolved`, so a
|
|
160
|
+
* package used without `vitehub()` starts its own run. Nuxt uses the app instance as owner so its Vite builds and
|
|
161
|
+
* separate Nitro build share one report; replay, prepare and discovery never reset it.
|
|
162
|
+
*/
|
|
163
|
+
function startViteHubHints(config, owner = config) {
|
|
164
|
+
if (skipHints(config) || config["__vitehubNuxtHints"] || started.has(owner)) return;
|
|
165
|
+
started.add(owner);
|
|
166
|
+
write(startRun(config));
|
|
167
|
+
}
|
|
168
|
+
//#endregion
|
|
24
169
|
//#region ../internal/dist/invariant.js
|
|
25
170
|
const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
26
171
|
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
@@ -168,6 +313,63 @@ async function docsCommentsDependencies(nuxt, comments) {
|
|
|
168
313
|
} };
|
|
169
314
|
}
|
|
170
315
|
//#endregion
|
|
316
|
+
//#region src/content-check.ts
|
|
317
|
+
/**
|
|
318
|
+
* `content.check()` over the docs pages, as `vitehub content check` runs it: links to missing pages, and the title and
|
|
319
|
+
* description rules of `seoAudit`, from the Markdown and without built HTML. Each page has its URL from the manifest.
|
|
320
|
+
*/
|
|
321
|
+
async function checkDocsContent(options, manifest, appBase, check) {
|
|
322
|
+
const sources = options.sources ? resolveDocsSources(options.sources, options.rootDir) : [{ dir: options.dir }];
|
|
323
|
+
const byFile = new Map(docsManifestPages(manifest).map((page) => [`${page.source ? Number(page.source.slice(5)) : 0}:${page.file}`, page.path]));
|
|
324
|
+
const byId = /* @__PURE__ */ new Map();
|
|
325
|
+
const content = createDocsContent(sources, options.rootDir, {
|
|
326
|
+
check,
|
|
327
|
+
url: (index, id) => byId.get(`${index}:${id}`) ?? null
|
|
328
|
+
});
|
|
329
|
+
try {
|
|
330
|
+
for (const index of sources.keys()) {
|
|
331
|
+
const name = contentName(index);
|
|
332
|
+
for (const file of await content.list(name)) {
|
|
333
|
+
const path = byFile.get(`${index}:${file.meta.key.slice(name.length + 1)}`);
|
|
334
|
+
if (path) byId.set(`${index}:${file.path.replace(/^\/+/, "")}`, docsAppPath(path, appBase));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return await content.check();
|
|
338
|
+
} finally {
|
|
339
|
+
await content.dispose();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/** The findings of a check that the link checker reports: errors, such as a link to a missing page. */
|
|
343
|
+
function docsContentLinkProblems(result) {
|
|
344
|
+
return result.findings.filter((finding) => finding.severity === "error").map(problem);
|
|
345
|
+
}
|
|
346
|
+
/** Add a source location only when Content and the rendered audit found the same problem. */
|
|
347
|
+
function docsContentSeoLocation(result, pages, appBase) {
|
|
348
|
+
const byMessage = new Map(result.findings.filter((finding) => finding.line !== null && (finding.rule === "title" || finding.rule === "description")).map((finding) => [finding.message, finding]));
|
|
349
|
+
return (page, field, message) => {
|
|
350
|
+
const source = pages.get(page.path);
|
|
351
|
+
if (!source) return message;
|
|
352
|
+
if (field === "description" && (source.seo?.description ?? source.description) !== page.description) return message;
|
|
353
|
+
const finding = byMessage.get(`${docsAppPath(page.path, appBase)}${message.slice(page.path.length)}`);
|
|
354
|
+
return finding ? problem({
|
|
355
|
+
...finding,
|
|
356
|
+
message
|
|
357
|
+
}) : message;
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
/** `docs/guide.md:12: <message> (CONTENT_R0062)`. */
|
|
361
|
+
function problem(finding) {
|
|
362
|
+
return `${finding.line === null ? finding.path : `${finding.path}:${finding.line}`}: ${finding.message} (${finding.code})`;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* The app's own pages as link patterns for `check.ignoreLinks`: `/pricing`, and `/blog/*` for `/blog/:id`. Content knows
|
|
366
|
+
* only the docs pages, and these pages answer too. A catch-all page, such as `/:slug(.*)*`, would cover every link, so
|
|
367
|
+
* it is left out.
|
|
368
|
+
*/
|
|
369
|
+
function docsAppPageLinks(routes) {
|
|
370
|
+
return [...new Set(routePaths(routes).filter((path) => !/\(\.\*\)\*?|\*$/.test(path)).map((path) => path.replace(/:\w+(?:\([^)]*\))?\??/g, "*") || "/"))];
|
|
371
|
+
}
|
|
372
|
+
//#endregion
|
|
171
373
|
//#region src/files.ts
|
|
172
374
|
/** The Markdown files of a folder, without dot files or dot folders, as Nitro's server assets list them. */
|
|
173
375
|
function markdownFiles(dir) {
|
|
@@ -218,10 +420,11 @@ function packDocsFiles(stores, order = []) {
|
|
|
218
420
|
function docsDevFilesModule(stores) {
|
|
219
421
|
return [
|
|
220
422
|
`const files = {\n${stores.map((store) => ` ${JSON.stringify(store.name)}: {\n${markdownFiles(store.dir).map((file) => ` ${JSON.stringify(file)}: () => import(${JSON.stringify(`${join(store.dir, file).split(sep).join("/")}?raw`)}),`).join("\n")}\n },`).join("\n")}\n}`,
|
|
423
|
+
"const has = (store, file) => Object.hasOwn(files, store) && Object.hasOwn(files[store], file)",
|
|
221
424
|
"export default {",
|
|
425
|
+
" has,",
|
|
222
426
|
" async read(store, file) {",
|
|
223
|
-
"
|
|
224
|
-
" return load ? (await load()).default : null",
|
|
427
|
+
" return has(store, file) ? (await files[store][file]()).default : null",
|
|
225
428
|
" },",
|
|
226
429
|
"}",
|
|
227
430
|
""
|
|
@@ -279,7 +482,7 @@ function readDocsSeoPage(path, html, origin) {
|
|
|
279
482
|
if (property && attribute(tag, "content")?.trim()) openGraph.add(property.toLowerCase());
|
|
280
483
|
}
|
|
281
484
|
const levels = [];
|
|
282
|
-
walkSync(parse(body), (node, parent) => {
|
|
485
|
+
walkSync(parse$1(body), (node, parent) => {
|
|
283
486
|
if (node.type !== ELEMENT_NODE || !/^h[1-6]$/i.test(node.name)) return;
|
|
284
487
|
for (let ancestor = parent; ancestor; ancestor = ancestor.parent) if (ancestor.type === ELEMENT_NODE && ancestor.attributes.class?.split(/\s+/).includes("docs-example-preview")) return;
|
|
285
488
|
levels.push(Number(node.name[1]));
|
|
@@ -316,13 +519,17 @@ function docsSitemapPaths(xml, origin) {
|
|
|
316
519
|
* search engines index needs its own title and description within the limits, one `h1`, headings in order, enough
|
|
317
520
|
* text, complete Open Graph tags, and a link from another page. A page that is a copy, through `noindex` or a canonical
|
|
318
521
|
* link to another page, is left out of those checks. Every page must stay below the size limit and must not link to a
|
|
319
|
-
* redirect or to an endpoint.
|
|
522
|
+
* redirect or to an endpoint.
|
|
320
523
|
*/
|
|
321
524
|
function docsSeoProblems(pages, sitemap, options = {}) {
|
|
322
525
|
const problems = [];
|
|
526
|
+
const add = (code, message) => problems.push({
|
|
527
|
+
code,
|
|
528
|
+
message
|
|
529
|
+
});
|
|
323
530
|
const byPath = new Map(pages.map((page) => [page.path, page]));
|
|
324
531
|
const megabytes = (bytes) => `${(bytes / 1e6).toFixed(1)} MB`;
|
|
325
|
-
for (const page of pages) if (page.bytes > docsSeoLimits.bytes)
|
|
532
|
+
for (const page of pages) if (page.bytes > docsSeoLimits.bytes) add("DOCS_SEO_HTML_TOO_LARGE", `${page.path} has ${megabytes(page.bytes)} of HTML, and Googlebot reads only the first ${megabytes(docsSeoLimits.bytes)}. Split the page, or show long lists with a component that renders less markup than a Markdown table.`);
|
|
326
533
|
const redirects = new Set(pages.filter((page) => page.redirect).map((page) => page.path));
|
|
327
534
|
const endpoints = new Set(options.endpoints);
|
|
328
535
|
const linkedFrom = /* @__PURE__ */ new Map();
|
|
@@ -332,41 +539,48 @@ function docsSeoProblems(pages, sitemap, options = {}) {
|
|
|
332
539
|
}
|
|
333
540
|
for (const [link, from] of linkedFrom) {
|
|
334
541
|
const where = from.length > 3 ? `${from.slice(0, 3).join(", ")} and ${from.length - 3} more pages` : from.join(", ");
|
|
335
|
-
|
|
542
|
+
add("DOCS_SEO_LINK_NOT_PAGE", redirects.has(link) ? `${where} link to ${link}, which redirects. Link to the page that it redirects to.` : `${where} link to ${link}, an endpoint that answers a browser with an error. Write the URL as code, or link to the page that explains it.`);
|
|
336
543
|
}
|
|
337
544
|
for (const path of sitemap) {
|
|
338
545
|
const page = byPath.get(path);
|
|
339
|
-
if (!page)
|
|
340
|
-
else if (page.redirect)
|
|
546
|
+
if (!page) add("DOCS_SEO_SITEMAP_NOT_PAGE", `${path} is in the sitemap, but the build did not prerender it as a page. Remove it from the sitemap, or make it a page.`);
|
|
547
|
+
else if (page.redirect) add("DOCS_SEO_SITEMAP_NOT_PAGE", `${path} is in the sitemap, but it redirects. List the page that it redirects to instead.`);
|
|
341
548
|
}
|
|
342
549
|
const indexed = pages.filter((page) => !page.redirect && !page.noindex && (page.canonical === null || page.canonical === page.path));
|
|
343
550
|
const { title, description, words } = docsSeoLimits;
|
|
551
|
+
const withSourceLocation = options.withSourceLocation ?? ((_page, _field, message) => message);
|
|
344
552
|
for (const page of indexed) {
|
|
345
553
|
const at = page.path;
|
|
346
|
-
if (!page.title)
|
|
347
|
-
else if (page.title.length < title.min || page.title.length > title.max)
|
|
348
|
-
if (!page.description)
|
|
349
|
-
else if (page.description.length < description.min || page.description.length > description.max)
|
|
350
|
-
if (page.h1 !== 1)
|
|
351
|
-
if (page.headingSkip)
|
|
352
|
-
if (page.words < words)
|
|
554
|
+
if (!page.title) add("DOCS_SEO_TITLE_INVALID", `${at} has no title. Set \`title\` in its frontmatter.`);
|
|
555
|
+
else if (page.title.length < title.min || page.title.length > title.max) add("DOCS_SEO_TITLE_INVALID", withSourceLocation(page, "title", `${at} has a title of ${page.title.length} characters, "${page.title}". Keep it between ${title.min} and ${title.max}, with \`seo.title\` when the heading must stay.`));
|
|
556
|
+
if (!page.description) add("DOCS_SEO_DESCRIPTION_INVALID", `${at} has no description. Set \`description\` in its frontmatter.`);
|
|
557
|
+
else if (page.description.length < description.min || page.description.length > description.max) add("DOCS_SEO_DESCRIPTION_INVALID", withSourceLocation(page, "description", `${at} has a description of ${page.description.length} characters. Keep it between ${description.min} and ${description.max}.`));
|
|
558
|
+
if (page.h1 !== 1) add("DOCS_SEO_HEADINGS_INVALID", `${at} has ${page.h1} h1 headings. Give it one.`);
|
|
559
|
+
if (page.headingSkip) add("DOCS_SEO_HEADINGS_INVALID", `${at} skips a heading level, ${page.headingSkip}. Go down one level at a time.`);
|
|
560
|
+
if (page.words < words) add("DOCS_SEO_PAGE_THIN", `${at} has ${page.words} words. Write at least ${words}, or merge it into another page.`);
|
|
353
561
|
const missing = page.openGraphMissing.filter((tag) => !(tag === "og:image" && page.twitterCard === "summary") && !(tag === "og:url" && options.siteUrl === false));
|
|
354
|
-
if (missing.length)
|
|
562
|
+
if (missing.length) add("DOCS_SEO_OPEN_GRAPH_INCOMPLETE", `${at} has no ${missing.join(", ")} tag, so share previews and site audits call its Open Graph tags incomplete. Pages from \`useDocsSeo()\` set them; an app page that writes its own head needs them too.`);
|
|
355
563
|
}
|
|
356
|
-
for (const [field,
|
|
564
|
+
for (const [field, code] of [["title", "DOCS_SEO_TITLE_INVALID"], ["description", "DOCS_SEO_DESCRIPTION_INVALID"]]) {
|
|
357
565
|
const groups = /* @__PURE__ */ new Map();
|
|
358
566
|
for (const page of indexed) if (page[field]) groups.set(page[field], [...groups.get(page[field]) ?? [], page.path]);
|
|
359
|
-
for (const [value, paths] of groups) if (paths.length > 1)
|
|
567
|
+
for (const [value, paths] of groups) if (paths.length > 1) add(code, `${paths.join(", ")} share the ${field} "${value}". Give each page its own.`);
|
|
360
568
|
}
|
|
361
569
|
const linked = /* @__PURE__ */ new Set();
|
|
362
570
|
for (const page of pages) for (const link of page.links) if (link !== page.path) linked.add(link);
|
|
363
|
-
for (const page of indexed) if (page.path !== "/" && !linked.has(page.path))
|
|
571
|
+
for (const page of indexed) if (page.path !== "/" && !linked.has(page.path)) add("DOCS_SEO_PAGE_UNLINKED", `No page links to ${page.path}. Link it from the navigation, the footer, or a related page.`);
|
|
364
572
|
return problems;
|
|
365
573
|
}
|
|
366
|
-
/**
|
|
367
|
-
/** `DOCS_SEO_FAILED`, with the list of problems in `problems`. */
|
|
574
|
+
/** `DOCS_SEO_FAILED`, which stops the build, with the list of problems in `problems`. */
|
|
368
575
|
function docsSeoError(problems) {
|
|
369
|
-
|
|
576
|
+
const messages = problems.map((problem) => problem.message);
|
|
577
|
+
return Object.assign(docsErrorDiagnostics.DOCS_SEO_FAILED({ problems: messages }), { problems: messages });
|
|
578
|
+
}
|
|
579
|
+
/** One hint for each code of the problems, with the problems of that code, for `seoAudit: "warn"`. */
|
|
580
|
+
function docsSeoHints(problems) {
|
|
581
|
+
const byCode = /* @__PURE__ */ new Map();
|
|
582
|
+
for (const problem of problems) byCode.set(problem.code, [...byCode.get(problem.code) ?? [], problem.message]);
|
|
583
|
+
return [...byCode].map(([code, messages]) => docsErrorDiagnostics[code]({ problems: messages }));
|
|
370
584
|
}
|
|
371
585
|
function attribute(tag, name) {
|
|
372
586
|
if (!tag) return void 0;
|
|
@@ -501,6 +715,10 @@ const docsNuxtModule = defineNuxtModule({
|
|
|
501
715
|
enabled: docs.ogImage !== false,
|
|
502
716
|
zeroRuntime: true,
|
|
503
717
|
runtimeCacheStorage: false,
|
|
718
|
+
compatibility: {
|
|
719
|
+
dev: { takumi: "node" },
|
|
720
|
+
prerender: { takumi: "node" }
|
|
721
|
+
},
|
|
504
722
|
defaults: {
|
|
505
723
|
width: 1200,
|
|
506
724
|
height: 630
|
|
@@ -533,7 +751,8 @@ const docsNuxtModule = defineNuxtModule({
|
|
|
533
751
|
const sourceDirs = sources?.map((source, index) => source.dir ?? join(sourcesDir, `docs-${index}`));
|
|
534
752
|
const contentDirsToWatch = sources ? sources.flatMap((source) => source.dir ?? []) : [contentDir];
|
|
535
753
|
const agentDir = join(nuxt.options.buildDir, "docs/agent");
|
|
536
|
-
const
|
|
754
|
+
const resolveBase = () => normalizeDocsBase(options.base ?? (sources || existsSync(join(contentDir, "docs")) ? "/docs" : "/"));
|
|
755
|
+
const base = resolveBase();
|
|
537
756
|
const manifestOptions = {
|
|
538
757
|
dir: contentDir,
|
|
539
758
|
base,
|
|
@@ -592,6 +811,22 @@ const docsNuxtModule = defineNuxtModule({
|
|
|
592
811
|
const moduleOptions = nuxt.options;
|
|
593
812
|
let read = await readDocsContent(manifestOptions);
|
|
594
813
|
let manifest = read.manifest;
|
|
814
|
+
/**
|
|
815
|
+
* Resolves when development has read the content after a change. Nuxt generates the app again when a file is added
|
|
816
|
+
* or removed, and the manifest templates wait for this read, so that run does not write the old pages.
|
|
817
|
+
*/
|
|
818
|
+
let contentRead = Promise.resolve();
|
|
819
|
+
let contentReadDone;
|
|
820
|
+
const startContentRead = () => {
|
|
821
|
+
if (!contentReadDone) contentRead = new Promise((done) => {
|
|
822
|
+
contentReadDone = done;
|
|
823
|
+
});
|
|
824
|
+
};
|
|
825
|
+
const endContentRead = () => {
|
|
826
|
+
contentReadDone?.();
|
|
827
|
+
contentReadDone = void 0;
|
|
828
|
+
};
|
|
829
|
+
const afterContentRead = (source) => contentReadDone ? contentRead.then(source) : source();
|
|
595
830
|
/** Copies the pages of each Content Source into the build, where the server and the agent copies read them. */
|
|
596
831
|
function writeSources(files) {
|
|
597
832
|
rmSync(sourcesDir, {
|
|
@@ -606,7 +841,8 @@ const docsNuxtModule = defineNuxtModule({
|
|
|
606
841
|
}
|
|
607
842
|
writeSources(read.files);
|
|
608
843
|
/** The Markdown of a page, from the content folder or from the copy of its Content Source. */
|
|
609
|
-
const
|
|
844
|
+
const pageFile = (page) => join(page.source ? sourceDirs[Number(page.source.slice(5))] : contentDir, page.file);
|
|
845
|
+
const readPage = (page) => readFileSync(pageFile(page), "utf8");
|
|
610
846
|
/**
|
|
611
847
|
* Content renders the agent copy of each page on request. `rawMarkdown` is a function of the app's build, so it runs
|
|
612
848
|
* here, and the server reads each page that it changed from `docs/agent/<source>/<file>`. `nuxi build` empties the
|
|
@@ -637,15 +873,18 @@ const docsNuxtModule = defineNuxtModule({
|
|
|
637
873
|
nuxt.hook("build:before", async () => {
|
|
638
874
|
agentCopies = await writeAgentSources();
|
|
639
875
|
});
|
|
640
|
-
const indexedPagePaths =
|
|
876
|
+
const indexedPagePaths = docsManifestPages(manifest).filter(docsPageIndexed).map((page) => docsAppPath(page.path, config.appBase));
|
|
877
|
+
const indexedPageExclusions = new Set(indexedPagePaths);
|
|
878
|
+
if (indexedPagePaths.length) indexedPageExclusions.add(new RegExp(`^(?:${indexedPagePaths.map((path) => RegExp.escape(path)).join("|")})[?#]`));
|
|
641
879
|
if (options.linkChecker !== false) {
|
|
642
880
|
const linkChecker = moduleOptions.linkChecker ??= {};
|
|
643
881
|
linkChecker.excludeLinks = [
|
|
644
882
|
...linkChecker.excludeLinks ?? [],
|
|
645
883
|
...options.linkChecker?.excludeLinks ?? [],
|
|
884
|
+
...config.mcp ? [/^(?:cursor:\/\/anysphere\.cursor-deeplink\/mcp\/install|vscode:mcp\/install)\?/] : [],
|
|
646
885
|
...docsManifestPages(manifest).map((page) => docsAppPath(docsRawPath(page.path), config.appBase)),
|
|
647
886
|
...docsManifestPages(manifest).filter((page) => !docsPageIndexed(page)).map((page) => docsAppPath(page.path, config.appBase)),
|
|
648
|
-
...
|
|
887
|
+
...indexedPageExclusions
|
|
649
888
|
];
|
|
650
889
|
}
|
|
651
890
|
moduleOptions.runtimeConfig.public.mdc ??= { headings: { anchorLinks: {
|
|
@@ -731,19 +970,27 @@ const docsNuxtModule = defineNuxtModule({
|
|
|
731
970
|
};
|
|
732
971
|
const agentDiscoveryOptions = defu(moduleOptions.agentDiscovery, discovery);
|
|
733
972
|
if (agentDiscoveryOptions.errors !== false) nuxt.options.experimental.inlineErrorRendering = false;
|
|
734
|
-
|
|
735
|
-
const standalone =
|
|
736
|
-
|
|
737
|
-
...
|
|
973
|
+
const discoveryRoutes = (pages) => {
|
|
974
|
+
const standalone = pages.pages.map((page) => page.path).filter((path) => path !== "/");
|
|
975
|
+
return config.appBase === "/" ? [.../* @__PURE__ */ new Set([
|
|
976
|
+
...pages.root?.path === "/" || pages.pages.some((page) => page.path === "/") ? ["/"] : [],
|
|
738
977
|
config.base,
|
|
739
978
|
`${config.base.replace(/\/+$/, "")}/**`,
|
|
740
979
|
...standalone
|
|
741
|
-
])] : docsManifestPages(
|
|
980
|
+
])] : docsManifestPages(pages).flatMap((page) => [.../* @__PURE__ */ new Set([page.path, docsAppPath(page.path, config.appBase).replace(/(.)\/$/, "$1")])].map((path) => ({
|
|
742
981
|
path,
|
|
743
982
|
raw: docsAppPath(docsRawPath(page.path), config.appBase)
|
|
744
983
|
})));
|
|
745
|
-
}
|
|
984
|
+
};
|
|
985
|
+
const ownDiscoveryRoutes = Boolean(agentDiscoveryOptions.routes?.length);
|
|
986
|
+
if (!ownDiscoveryRoutes) agentDiscoveryOptions.routes = discoveryRoutes(manifest);
|
|
746
987
|
moduleOptions.agentDiscovery = agentDiscoveryOptions;
|
|
988
|
+
/**
|
|
989
|
+
* What the module reads from the manifest only when Nuxt starts: the mount of the docs page route, and the routes
|
|
990
|
+
* that negotiate Markdown. A content change that moves them needs a restart. Any other change reloads the pages.
|
|
991
|
+
* `<base>/**` already covers a new page below the base.
|
|
992
|
+
*/
|
|
993
|
+
const startupShape = (pages) => JSON.stringify([docsMount(pages), ownDiscoveryRoutes ? null : discoveryRoutes(pages).filter((route) => typeof route !== "string" || route.endsWith("/**") || !isDocsPath(route, config.base))]);
|
|
747
994
|
const agentFile = addTemplate({
|
|
748
995
|
filename: "docs/agent.mjs",
|
|
749
996
|
write: true,
|
|
@@ -755,7 +1002,7 @@ const docsNuxtModule = defineNuxtModule({
|
|
|
755
1002
|
const manifestSource = () => `export default JSON.parse(${JSON.stringify(JSON.stringify(manifest))})\n`;
|
|
756
1003
|
const manifestFile = addTemplate({
|
|
757
1004
|
filename: "docs/manifest.mjs",
|
|
758
|
-
getContents: manifestSource,
|
|
1005
|
+
getContents: () => afterContentRead(manifestSource),
|
|
759
1006
|
write: true
|
|
760
1007
|
}).dst;
|
|
761
1008
|
addTemplate({
|
|
@@ -766,7 +1013,7 @@ const docsNuxtModule = defineNuxtModule({
|
|
|
766
1013
|
const app = () => docsAppManifest(manifest, { panels: !nuxt.options.dev });
|
|
767
1014
|
nuxt.options.alias["#docs/manifest"] = addTemplate({
|
|
768
1015
|
filename: "docs/app-manifest.mjs",
|
|
769
|
-
getContents: () => docsAppManifestSource(app().manifest),
|
|
1016
|
+
getContents: () => afterContentRead(() => docsAppManifestSource(app().manifest)),
|
|
770
1017
|
write: true
|
|
771
1018
|
}).dst;
|
|
772
1019
|
const panelFiles = app().panels.map((panel, index) => ({
|
|
@@ -879,13 +1126,105 @@ const docsNuxtModule = defineNuxtModule({
|
|
|
879
1126
|
if (nuxt.options.dev) {
|
|
880
1127
|
nuxt.options.watch = [.../* @__PURE__ */ new Set([...nuxt.options.watch ?? [], examplesDir])];
|
|
881
1128
|
let timer;
|
|
1129
|
+
let reading = Promise.resolve();
|
|
882
1130
|
let regeneration = Promise.resolve();
|
|
883
1131
|
let closed = false;
|
|
884
1132
|
let viteServer;
|
|
885
1133
|
nuxt.hook("vite:serverCreated", (server) => {
|
|
886
1134
|
viteServer = server;
|
|
887
1135
|
});
|
|
1136
|
+
const shape = startupShape(manifest);
|
|
1137
|
+
const isContentFile = (file) => /(\.md|\.navigation\.yml)$/.test(file) && contentDirsToWatch.some((dir) => resolve(file).startsWith(`${dir}${sep}`));
|
|
1138
|
+
nuxt.hook("vite:extend", ({ config }) => {
|
|
1139
|
+
(config.plugins ??= []).push({
|
|
1140
|
+
name: "vite-hub:docs-content",
|
|
1141
|
+
applyToEnvironment: (environment) => environment.name === "nitro",
|
|
1142
|
+
hotUpdate: {
|
|
1143
|
+
order: "pre",
|
|
1144
|
+
handler: ({ file }) => isContentFile(file) ? [] : void 0
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1147
|
+
});
|
|
1148
|
+
/**
|
|
1149
|
+
* Shows a content change without a restart. Content reads each page on request, so only the generated modules
|
|
1150
|
+
* change: the manifest of the app and the server, `#docs/files`, which lists the files, and the changed files.
|
|
1151
|
+
* Returns false when Nitro does not run in Vite, where the server must restart to see a new manifest.
|
|
1152
|
+
*/
|
|
1153
|
+
async function reloadPages(change) {
|
|
1154
|
+
const nitro = viteServer?.environments?.nitro;
|
|
1155
|
+
if (!viteServer || !nitro) return false;
|
|
1156
|
+
if (change.manifest) {
|
|
1157
|
+
await updateTemplates({ filter: (template) => template.filename === "docs/manifest.mjs" || template.filename === "docs/app-manifest.mjs" });
|
|
1158
|
+
const source = manifestSource();
|
|
1159
|
+
if (!existsSync(manifestFile) || readFileSync(manifestFile, "utf8") !== source) writeFileSync(manifestFile, source);
|
|
1160
|
+
}
|
|
1161
|
+
const modules = [...change.files.flatMap((file) => [...nitro.moduleGraph.getModulesByFile(file) ?? []]), ...change.list ? [nitro.moduleGraph.getModuleById("#docs/files")] : []];
|
|
1162
|
+
for (const module of modules) if (module) nitro.moduleGraph.invalidateModule(module);
|
|
1163
|
+
if (change.manifest || modules.length) viteServer.watcher.emit("change", manifestFile);
|
|
1164
|
+
return true;
|
|
1165
|
+
}
|
|
888
1166
|
const logError = (error) => useLogger("@vite-hub/docs").error(error);
|
|
1167
|
+
const restart = () => {
|
|
1168
|
+
Promise.resolve(nuxt.callHook("restart")).catch(logError);
|
|
1169
|
+
};
|
|
1170
|
+
/** The changed files since the last run, or null when a watcher did not name one. */
|
|
1171
|
+
let changed = /* @__PURE__ */ new Set();
|
|
1172
|
+
let contentVersion = 0;
|
|
1173
|
+
/** Reads the content again after a change of `file`, or of any file when the watcher did not name one. */
|
|
1174
|
+
function schedule(file) {
|
|
1175
|
+
if (file) changed?.add(file);
|
|
1176
|
+
else changed = null;
|
|
1177
|
+
const version = ++contentVersion;
|
|
1178
|
+
startContentRead();
|
|
1179
|
+
clearTimeout(timer);
|
|
1180
|
+
timer = setTimeout(() => {
|
|
1181
|
+
const files = changed;
|
|
1182
|
+
changed = /* @__PURE__ */ new Set();
|
|
1183
|
+
const result = reading.then(async () => {
|
|
1184
|
+
if (closed) return;
|
|
1185
|
+
try {
|
|
1186
|
+
if (resolveBase() !== base) return "restart";
|
|
1187
|
+
const next = await readDocsContent(manifestOptions);
|
|
1188
|
+
const previous = JSON.stringify(manifest);
|
|
1189
|
+
const copies = await writeAgentSources(next);
|
|
1190
|
+
const copiesChanged = copies.join("\n") !== agentCopies.join("\n");
|
|
1191
|
+
agentCopies = copies;
|
|
1192
|
+
read = next;
|
|
1193
|
+
manifest = next.manifest;
|
|
1194
|
+
const manifestChanged = JSON.stringify(manifest) !== previous;
|
|
1195
|
+
return {
|
|
1196
|
+
files: [...files ?? docsManifestPages(manifest).map(pageFile), ...copies],
|
|
1197
|
+
copies,
|
|
1198
|
+
copiesChanged,
|
|
1199
|
+
manifestChanged,
|
|
1200
|
+
shapeChanged: manifestChanged && startupShape(manifest) !== shape,
|
|
1201
|
+
listChanged: manifestChanged || copiesChanged || files === null
|
|
1202
|
+
};
|
|
1203
|
+
} catch (error) {
|
|
1204
|
+
logError(error);
|
|
1205
|
+
} finally {
|
|
1206
|
+
if (version === contentVersion) endContentRead();
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
reading = result.then(() => {});
|
|
1210
|
+
regeneration = regeneration.then(async () => {
|
|
1211
|
+
const change = await result;
|
|
1212
|
+
if (closed || !change) return;
|
|
1213
|
+
if (change === "restart") return restart();
|
|
1214
|
+
if (!change.shapeChanged && await reloadPages({
|
|
1215
|
+
files: change.files,
|
|
1216
|
+
manifest: change.manifestChanged,
|
|
1217
|
+
list: change.listChanged
|
|
1218
|
+
})) return;
|
|
1219
|
+
for (const file of change.copies) viteServer?.watcher.emit("change", file);
|
|
1220
|
+
if (change.manifestChanged || change.copiesChanged) restart();
|
|
1221
|
+
}).catch(logError);
|
|
1222
|
+
}, 100);
|
|
1223
|
+
}
|
|
1224
|
+
nuxt.hook("builder:watch", (_event, path) => {
|
|
1225
|
+
const file = resolve(nuxt.options.srcDir, path);
|
|
1226
|
+
if (isContentFile(file)) schedule(file);
|
|
1227
|
+
});
|
|
889
1228
|
const watchers = contentDirsToWatch.map((contentDir) => {
|
|
890
1229
|
let watchDir = contentDir;
|
|
891
1230
|
while (!existsSync(watchDir) && dirname(watchDir) !== watchDir) watchDir = dirname(watchDir);
|
|
@@ -894,32 +1233,15 @@ const docsNuxtModule = defineNuxtModule({
|
|
|
894
1233
|
const changedPath = resolve(watchDir, file);
|
|
895
1234
|
if (changedPath !== contentDir && !changedPath.startsWith(`${contentDir}${sep}`) && !contentDir.startsWith(`${changedPath}${sep}`)) return;
|
|
896
1235
|
if (event === "change" && !/(\.md|\.navigation\.yml)$/.test(file)) return;
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
timer = setTimeout(() => {
|
|
900
|
-
regeneration = regeneration.then(async () => {
|
|
901
|
-
if (closed) return;
|
|
902
|
-
try {
|
|
903
|
-
const next = await readDocsContent(manifestOptions);
|
|
904
|
-
const changed = JSON.stringify(next.manifest) !== JSON.stringify(manifest);
|
|
905
|
-
const copies = await writeAgentSources(next);
|
|
906
|
-
const copiesChanged = copies.join("\n") !== agentCopies.join("\n");
|
|
907
|
-
agentCopies = copies;
|
|
908
|
-
for (const file of copies) viteServer?.watcher.emit("change", file);
|
|
909
|
-
read = next;
|
|
910
|
-
manifest = next.manifest;
|
|
911
|
-
if ((changed || copiesChanged) && !closed) Promise.resolve(nuxt.callHook("restart")).catch(logError);
|
|
912
|
-
} catch (error) {
|
|
913
|
-
logError(error);
|
|
914
|
-
}
|
|
915
|
-
});
|
|
916
|
-
}, 100);
|
|
1236
|
+
schedule(changedPath);
|
|
1237
|
+
} else schedule(null);
|
|
917
1238
|
});
|
|
918
1239
|
});
|
|
919
1240
|
nuxt.hook("close", async () => {
|
|
920
1241
|
closed = true;
|
|
921
1242
|
clearTimeout(timer);
|
|
922
1243
|
for (const watcher of watchers) watcher.close();
|
|
1244
|
+
endContentRead();
|
|
923
1245
|
await regeneration;
|
|
924
1246
|
});
|
|
925
1247
|
}
|
|
@@ -1042,9 +1364,14 @@ const docsNuxtModule = defineNuxtModule({
|
|
|
1042
1364
|
path: join(runtime, "app/middleware/docs-layout.ts"),
|
|
1043
1365
|
global: true
|
|
1044
1366
|
});
|
|
1367
|
+
/** Link patterns of the app's own pages, which the Content check of the docs links accepts. */
|
|
1368
|
+
let appPageLinks = [];
|
|
1369
|
+
let appReplacesDocs = false;
|
|
1045
1370
|
extendPages((pages) => {
|
|
1371
|
+
appPageLinks = docsAppPageLinks(pages);
|
|
1046
1372
|
const mount = docsMount(manifest);
|
|
1047
|
-
|
|
1373
|
+
appReplacesDocs = replacesDocsPage(pages, mount);
|
|
1374
|
+
if (appReplacesDocs) return;
|
|
1048
1375
|
pages.push({
|
|
1049
1376
|
name: "docs-page",
|
|
1050
1377
|
path: `${mount === "/" ? "" : mount}/:slug(.*)*`,
|
|
@@ -1110,32 +1437,73 @@ const docsNuxtModule = defineNuxtModule({
|
|
|
1110
1437
|
"/llms-full.txt"
|
|
1111
1438
|
];
|
|
1112
1439
|
}
|
|
1440
|
+
const buildingHints = () => !nuxt.options.dev && !Reflect.get(nuxt.options, "_prepare") && !Reflect.get(nuxt.options, "vitehubCliDiscovery");
|
|
1441
|
+
const hintsConfig = () => ({
|
|
1442
|
+
root: nuxt.options.rootDir,
|
|
1443
|
+
command: "build",
|
|
1444
|
+
logger: useLogger("@vite-hub/docs")
|
|
1445
|
+
});
|
|
1446
|
+
const startHints = () => {
|
|
1447
|
+
if (buildingHints()) startViteHubHints(hintsConfig(), nuxt);
|
|
1448
|
+
};
|
|
1449
|
+
nuxt.hook("build:before", startHints);
|
|
1450
|
+
Reflect.apply(nuxt.hook, nuxt, ["nitro:build:before", startHints]);
|
|
1451
|
+
let checkSourceLinks;
|
|
1113
1452
|
Reflect.apply(nuxt.hook, nuxt, ["nitro:init", (nitro) => {
|
|
1114
1453
|
const building = !nuxt.options.dev && !Reflect.get(nuxt.options, "_prepare");
|
|
1454
|
+
const seoAudit = options.seoAudit ?? "warn";
|
|
1455
|
+
const redirects = docsRedirects(nitro.options.routeRules ?? {});
|
|
1456
|
+
const settings = options.linkChecker || {};
|
|
1457
|
+
const runtimePath = () => docsRuntimePath(nitro.options, config.appBase, docsMount(manifest));
|
|
1458
|
+
const excludeLinks = [
|
|
1459
|
+
...(moduleOptions.linkChecker?.excludeLinks ?? []).filter((link) => !indexedPageExclusions.has(link)),
|
|
1460
|
+
...settings.excludeLinks ?? [],
|
|
1461
|
+
...redirects.map((redirect) => docsAppPath(redirect.from, config.appBase)),
|
|
1462
|
+
...config.mcp ? [docsAppPath("/mcp", config.appBase)] : []
|
|
1463
|
+
];
|
|
1464
|
+
const excluded = docsLinkExclusion(excludeLinks);
|
|
1465
|
+
const outputFile = nitro.options.output && docsOutputFile(nitro.options.output.publicDir, config.appBase);
|
|
1466
|
+
const appPage = (path) => appPageLinks.some((pattern) => posix.matchesGlob(path, pattern));
|
|
1467
|
+
const base = config.appBase.replace(/\/+$/, "");
|
|
1468
|
+
let contentCheck;
|
|
1469
|
+
const checkContent = () => contentCheck ??= (async () => {
|
|
1470
|
+
const isRuntimePath = runtimePath();
|
|
1471
|
+
return checkDocsContent(manifestOptions, manifest, config.appBase, {
|
|
1472
|
+
isLinkTarget: (url, href) => {
|
|
1473
|
+
const path = url.pathname;
|
|
1474
|
+
if (base && path !== base && !path.startsWith(`${base}/`)) return true;
|
|
1475
|
+
return excluded(url, href) || appPage(path.slice(base.length) || "/") || isRuntimePath(path) || Boolean(outputFile?.(path));
|
|
1476
|
+
},
|
|
1477
|
+
...config.site.url ? { site: config.site.url } : {},
|
|
1478
|
+
titleTemplate: `%s · ${config.site.name}`
|
|
1479
|
+
});
|
|
1480
|
+
})();
|
|
1115
1481
|
if (options.linkChecker !== false && building) {
|
|
1116
|
-
const
|
|
1482
|
+
const serverRoutes = docsServerRoutes(nitro.routing?.routes.routes ?? [], resolver.resolve("./runtime"));
|
|
1483
|
+
const problems = docsRedirectProblems(manifest, redirects, serverRoutes);
|
|
1117
1484
|
if (problems.length) throw docsRedirectError(problems);
|
|
1118
|
-
|
|
1485
|
+
let sourceLinks;
|
|
1486
|
+
const checkLinks = () => sourceLinks ??= (async () => {
|
|
1487
|
+
const checked = await checkContent();
|
|
1488
|
+
const broken = docsContentLinkProblems(checked);
|
|
1489
|
+
if (broken.length) throw docsLinkError(broken);
|
|
1490
|
+
useLogger("@vite-hub/docs").info?.(`Checked the links of ${checked.sources.reduce((pages, source) => pages + source.pages, 0)} Markdown pages with \`vitehub content check\``);
|
|
1491
|
+
})();
|
|
1492
|
+
checkSourceLinks = checkLinks;
|
|
1493
|
+
nitro.hooks?.hook("compiled", async () => {
|
|
1119
1494
|
if (!nitro.options.output) return;
|
|
1120
|
-
|
|
1121
|
-
const settings = options.linkChecker || {};
|
|
1495
|
+
await checkLinks();
|
|
1122
1496
|
const result = checkDocsLinks({
|
|
1123
1497
|
dir: nitro.options.output.publicDir,
|
|
1124
1498
|
siteUrl: config.site.url || "https://docs.local",
|
|
1125
1499
|
appBase: config.appBase,
|
|
1126
1500
|
...settings,
|
|
1127
|
-
isRuntimePath:
|
|
1128
|
-
excludeLinks
|
|
1129
|
-
...(moduleOptions.linkChecker?.excludeLinks ?? []).filter((link) => typeof link !== "string" || !indexedPagePaths.has(link)),
|
|
1130
|
-
...settings.excludeLinks ?? [],
|
|
1131
|
-
...redirects.map((redirect) => docsAppPath(redirect.from, config.appBase)),
|
|
1132
|
-
...config.mcp ? [docsAppPath("/mcp", config.appBase)] : []
|
|
1133
|
-
]
|
|
1501
|
+
isRuntimePath: runtimePath(),
|
|
1502
|
+
excludeLinks
|
|
1134
1503
|
});
|
|
1135
1504
|
useLogger("@vite-hub/docs").info?.(`Checked links and fragments of ${result.pages} pages`);
|
|
1136
1505
|
});
|
|
1137
1506
|
}
|
|
1138
|
-
const seoAudit = options.seoAudit ?? "warn";
|
|
1139
1507
|
if (seoAudit && building) {
|
|
1140
1508
|
const origin = `${config.site.url || "http://docs.invalid"}${config.appBase.replace(/\/+$/, "")}`;
|
|
1141
1509
|
const pages = [];
|
|
@@ -1145,19 +1513,32 @@ const docsNuxtModule = defineNuxtModule({
|
|
|
1145
1513
|
if (route.route === "/sitemap.xml") sitemap = docsSitemapPaths(route.contents, origin);
|
|
1146
1514
|
else if (route.fileName?.endsWith(".html") && route.contentType?.includes("text/html")) pages.push(readDocsSeoPage(route.route, route.contents, origin));
|
|
1147
1515
|
});
|
|
1148
|
-
|
|
1516
|
+
const adapted = new Set((sources ?? []).flatMap((source, index) => source.frontmatter ? [`docs-${index}`] : []));
|
|
1517
|
+
nitro.hooks?.hook("prerender:done", async () => {
|
|
1518
|
+
const rendered = new Set(pages.map((page) => page.path));
|
|
1519
|
+
const candidates = appReplacesDocs ? [] : docsManifestPages(manifest).filter((page) => rendered.has(page.path) && !appPage(page.path) && !(page.source && adapted.has(page.source)));
|
|
1149
1520
|
const problems = docsSeoProblems(pages, sitemap, {
|
|
1150
1521
|
endpoints: config.mcp ? ["/mcp"] : [],
|
|
1151
|
-
siteUrl: Boolean(config.site.url)
|
|
1522
|
+
siteUrl: Boolean(config.site.url),
|
|
1523
|
+
withSourceLocation: candidates.length ? docsContentSeoLocation(await checkContent(), new Map(candidates.map((page) => [page.path, page])), config.appBase) : void 0
|
|
1152
1524
|
});
|
|
1153
1525
|
if (!problems.length) return;
|
|
1154
|
-
|
|
1155
|
-
if (
|
|
1156
|
-
useLogger("@vite-hub/docs").warn(`${error.message}\nSet \`docs.seoAudit\` to "error" to stop the build on these, or to false to turn the check off.`);
|
|
1526
|
+
if (seoAudit === "error" || seoAudit === true) throw docsSeoError(problems);
|
|
1527
|
+
if (buildingHints()) for (const hint of docsSeoHints(problems)) reportViteHubHint(hintsConfig(), hint);
|
|
1157
1528
|
});
|
|
1158
1529
|
}
|
|
1159
1530
|
}]);
|
|
1160
1531
|
Reflect.apply(nuxt.hook, nuxt, ["nitro:config", (nitro) => {
|
|
1532
|
+
if (options.linkChecker !== false && !nuxt.options.dev && !Reflect.get(nuxt.options, "_prepare")) {
|
|
1533
|
+
const prerenderDone = nitro.hooks?.["prerender:done"];
|
|
1534
|
+
nitro.hooks = {
|
|
1535
|
+
...nitro.hooks,
|
|
1536
|
+
"prerender:done": async (result) => {
|
|
1537
|
+
await checkSourceLinks?.();
|
|
1538
|
+
await prerenderDone?.(result);
|
|
1539
|
+
}
|
|
1540
|
+
};
|
|
1541
|
+
}
|
|
1161
1542
|
if (config.appBase !== "/") {
|
|
1162
1543
|
for (const link of [...nitro.runtimeConfig?.agentDiscovery?.links ?? [], ...nitro.runtimeConfig?.public?.agentDiscovery?.resources ?? []]) {
|
|
1163
1544
|
link.href = docsAppPath(link.href, config.appBase);
|
|
@@ -1251,7 +1632,9 @@ const shellIcons = [
|
|
|
1251
1632
|
"i-lucide-search",
|
|
1252
1633
|
"i-lucide-x",
|
|
1253
1634
|
"i-simple-icons-anthropic",
|
|
1635
|
+
"i-simple-icons-claude",
|
|
1254
1636
|
"i-simple-icons-cursor",
|
|
1637
|
+
"i-simple-icons-windsurf",
|
|
1255
1638
|
"i-simple-icons-github",
|
|
1256
1639
|
"i-simple-icons-markdown",
|
|
1257
1640
|
"i-simple-icons-openai",
|