@vite-hub/docs 0.0.0-stage → 0.3.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/LICENSE +201 -0
- package/README.md +453 -2
- package/dist/agent-copy-BJp_Yf5d.js +33 -0
- package/dist/assistant-shared-CdtXowot.js +97 -0
- package/dist/assistant-shared-Dll_F_yy.d.ts +27 -0
- package/dist/assistant-worker.d.ts +11 -0
- package/dist/assistant-worker.js +16 -0
- package/dist/assistant.d.ts +14 -0
- package/dist/assistant.js +19 -0
- package/dist/content-9CINWiRf.js +171 -0
- package/dist/draft-DUBx--r9.js +45 -0
- package/dist/error-diagnostics-BoOsP6Y4.js +53 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +27 -0
- package/dist/link-checker-redirects.d.ts +13 -0
- package/dist/link-checker-redirects.js +25 -0
- package/dist/manifest-D66AEF8F.js +420 -0
- package/dist/manifest-Dzp5-_AJ.d.ts +74 -0
- package/dist/markdown-Cn9-4oVG.js +378 -0
- package/dist/navigation.d.ts +284 -0
- package/dist/navigation.js +520 -0
- package/dist/nuxt-B5LrERKc.d.ts +240 -0
- package/dist/nuxt.d.ts +3 -0
- package/dist/nuxt.js +1485 -0
- package/dist/page-BbmSfZO8.js +81 -0
- package/dist/page-Dx2JD3y1.d.ts +74 -0
- package/dist/primitive-rail.d.ts +110 -0
- package/dist/primitive-rail.js +284 -0
- package/dist/raw-C03EUJKw.js +851 -0
- package/dist/redirects-BrbWFSzW.js +62 -0
- package/dist/runtime/app/app.vue +11 -0
- package/dist/runtime/app/assistant/DocsAssistant.vue +81 -0
- package/dist/runtime/app/assistant/DocsAssistantOff.vue +8 -0
- package/dist/runtime/app/assistant/DocsAssistantPanel.vue +322 -0
- package/dist/runtime/app/components/AppHeader.vue +368 -0
- package/dist/runtime/app/components/AppSearch.vue +68 -0
- package/dist/runtime/app/components/DocsAppShell.vue +62 -0
- package/dist/runtime/app/components/DocsArticle.vue +184 -0
- package/dist/runtime/app/components/DocsAsideFooter.vue +94 -0
- package/dist/runtime/app/components/DocsAsideLeftBody.vue +584 -0
- package/dist/runtime/app/components/DocsAsideLeftTop.vue +132 -0
- package/dist/runtime/app/components/DocsBrandMark.vue +52 -0
- package/dist/runtime/app/components/DocsCatalogFooter.vue +129 -0
- package/dist/runtime/app/components/DocsCodePanel.vue +388 -0
- package/dist/runtime/app/components/DocsCodePre.vue +120 -0
- package/dist/runtime/app/components/DocsHeaderActions.vue +4 -0
- package/dist/runtime/app/components/DocsLanding.vue +83 -0
- package/dist/runtime/app/components/DocsMarkdown.vue +64 -0
- package/dist/runtime/app/components/DocsPage.vue +149 -0
- package/dist/runtime/app/components/DocsPageCredits.vue +41 -0
- package/dist/runtime/app/components/DocsPageHeaderLinks.vue +120 -0
- package/dist/runtime/app/components/DocsRail.vue +239 -0
- package/dist/runtime/app/components/DocsSidebarStrip.vue +81 -0
- package/dist/runtime/app/components/DocsSidebars.vue +63 -0
- package/dist/runtime/app/components/OgImage/DocsPage.takumi.vue +33 -0
- package/dist/runtime/app/components/content/AgentOnly.vue +9 -0
- package/dist/runtime/app/components/content/CodeTree.vue +203 -0
- package/dist/runtime/app/components/content/ComarkHtml.vue +31 -0
- package/dist/runtime/app/components/content/Correct.vue +17 -0
- package/dist/runtime/app/components/content/Example.vue +260 -0
- package/dist/runtime/app/components/content/ExamplePreview.vue +6 -0
- package/dist/runtime/app/components/content/Examples.vue +71 -0
- package/dist/runtime/app/components/content/Incorrect.vue +17 -0
- package/dist/runtime/app/components/content/PageList.vue +206 -0
- package/dist/runtime/app/components/content/ProductFeatureItem.vue +43 -0
- package/dist/runtime/app/components/content/ProductFeatures.vue +17 -0
- package/dist/runtime/app/components/content/TutorialStep.vue +39 -0
- package/dist/runtime/app/composables/docs-assistant-problem.ts +59 -0
- package/dist/runtime/app/composables/docs-theme.ts +15 -0
- package/dist/runtime/app/composables/docs.ts +83 -0
- package/dist/runtime/app/composables/headerActions.ts +6 -0
- package/dist/runtime/app/composables/icons.ts +14 -0
- package/dist/runtime/app/composables/seo.ts +64 -0
- package/dist/runtime/app/composables/tutorial.ts +40 -0
- package/dist/runtime/app/composables/useDocsAssistant.ts +17 -0
- package/dist/runtime/app/error.vue +88 -0
- package/dist/runtime/app/layouts/default.vue +7 -0
- package/dist/runtime/app/layouts/docs.vue +104 -0
- package/dist/runtime/app/middleware/docs-layout.ts +23 -0
- package/dist/runtime/app/pages/docs-page.vue +3 -0
- package/dist/runtime/app/plugins/comark-css.ts +14 -0
- package/dist/runtime/app/plugins/icon-stroke.ts +12 -0
- package/dist/runtime/app/plugins/theme-color.ts +18 -0
- package/dist/runtime/app/utils/docs-theme.ts +43 -0
- package/dist/runtime/app/utils/file-tree.ts +40 -0
- package/dist/runtime/server/llms.d.ts +6 -0
- package/dist/runtime/server/llms.js +7 -0
- package/dist/runtime/server/markdown.d.ts +10 -0
- package/dist/runtime/server/markdown.js +11 -0
- package/dist/runtime/server/mcp.d.ts +6 -0
- package/dist/runtime/server/mcp.js +7 -0
- package/dist/runtime/server/page.d.ts +7 -0
- package/dist/runtime/server/page.js +27 -0
- package/dist/runtime/server/raw.d.ts +10 -0
- package/dist/runtime/server/raw.js +23 -0
- package/dist/runtime/server/search.d.ts +6 -0
- package/dist/runtime/server/search.js +32 -0
- package/dist/runtime/server/sitemap.d.ts +6 -0
- package/dist/runtime/server/sitemap.js +52 -0
- package/dist/runtime/server/trailing-slash.d.ts +10 -0
- package/dist/runtime/server/trailing-slash.js +28 -0
- package/dist/runtime/theme/design.css +464 -0
- package/dist/schema-DwpXW0VZ.js +98 -0
- package/dist/server.d.ts +15 -0
- package/dist/server.js +5 -0
- package/dist/theme-BXyu4uFL.d.ts +32 -0
- package/dist/theme-DzC8LtMH.js +237 -0
- package/dist/theme.d.ts +2 -0
- package/dist/theme.js +2 -0
- package/dist/types-BhG6vGfG.d.ts +212 -0
- package/package.json +141 -3
package/dist/nuxt.js
ADDED
|
@@ -0,0 +1,1485 @@
|
|
|
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-BbmSfZO8.js";
|
|
3
|
+
import { t as docsErrorDiagnostics } from "./error-diagnostics-BoOsP6Y4.js";
|
|
4
|
+
import { n as docsRedirectProblems, r as docsRedirects, t as docsRedirectError } from "./redirects-BrbWFSzW.js";
|
|
5
|
+
import { a as docsAppPanelSource, c as checkDocsLinks, i as docsAppManifestSource, o as readDocsContent, r as docsAppManifest, s as resolveDocsSources } from "./manifest-D66AEF8F.js";
|
|
6
|
+
import { r as docsContentSource } from "./agent-copy-BJp_Yf5d.js";
|
|
7
|
+
import { i as docsThemeScope, n as docsThemeAdditions, r as docsUi, t as docsAppConfigUi } from "./theme-DzC8LtMH.js";
|
|
8
|
+
import { createRequire } from "node:module";
|
|
9
|
+
import { addComponent, addComponentsDir, addImportsDir, addPlugin, addRouteMiddleware, addServerHandler, addTemplate, addTypeTemplate, createResolver, defineNuxtModule, extendPages, updateTemplates, useLogger } from "@nuxt/kit";
|
|
10
|
+
import { defineDiagnostics } from "nostics";
|
|
11
|
+
import { createHash } from "node:crypto";
|
|
12
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, watch, writeFileSync } from "node:fs";
|
|
13
|
+
import { readFile, readdir } from "node:fs/promises";
|
|
14
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
15
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
16
|
+
import { findContentEntry } from "@vite-hub/source/vite";
|
|
17
|
+
import { vitehubTheme } from "@vite-hub/ui/theme";
|
|
18
|
+
import { sizeOf } from "comark-zoom/size";
|
|
19
|
+
import { defu } from "defu";
|
|
20
|
+
import { addRoute, createRouter, findAllRoutes, routeToRegExp } from "rou3";
|
|
21
|
+
import { ELEMENT_NODE, parse, walkSync } from "ultrahtml";
|
|
22
|
+
import { gzipSync } from "node:zlib";
|
|
23
|
+
import postcss from "postcss";
|
|
24
|
+
//#region ../internal/dist/invariant.js
|
|
25
|
+
const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
26
|
+
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
27
|
+
codes: { INTERNAL_INVARIANT_FAILED: {
|
|
28
|
+
why: ({ what }) => `ViteHub reached a state that it does not expect: ${what}`,
|
|
29
|
+
fix: "This is a ViteHub bug. Open an issue at https://github.com/vite-hub/vitehub/issues with this error message and its stack trace."
|
|
30
|
+
} }
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* The error for a state that only a ViteHub bug can reach, such as an impossible branch. `what` says which rule broke.
|
|
34
|
+
* Use a code from the package catalog when a developer can cause the error or fix it.
|
|
35
|
+
*/
|
|
36
|
+
function invariantError(what) {
|
|
37
|
+
return invariantDiagnostics.INTERNAL_INVARIANT_FAILED({ what });
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/module-options.ts
|
|
41
|
+
/** The module name: a string entry, or the `getMeta()` name of an imported module function. */
|
|
42
|
+
async function moduleName(module) {
|
|
43
|
+
if (typeof module !== "function") return module;
|
|
44
|
+
const getMeta = Reflect.get(module, "getMeta");
|
|
45
|
+
if (typeof getMeta !== "function") return;
|
|
46
|
+
const meta = await Reflect.apply(getMeta, module, []);
|
|
47
|
+
return meta && typeof meta === "object" ? Reflect.get(meta, "name") : void 0;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The options of a Nuxt module: its config key, then the inline options of its `modules` entries, which win. Undefined
|
|
51
|
+
* when neither is there, or when `requireInstalled` is set and no module entry matches. `names` are the entry names
|
|
52
|
+
* and the `getMeta()` name of the module.
|
|
53
|
+
*/
|
|
54
|
+
async function readModuleOptions(nuxt, names, configKey, requireInstalled = false) {
|
|
55
|
+
let installed = false;
|
|
56
|
+
let inline = {};
|
|
57
|
+
for (const entry of nuxt.options.modules) {
|
|
58
|
+
const [module, options] = Array.isArray(entry) ? entry : [entry, void 0];
|
|
59
|
+
const name = await moduleName(module);
|
|
60
|
+
if (typeof name !== "string" || !names.includes(name)) continue;
|
|
61
|
+
installed = true;
|
|
62
|
+
if (options && typeof options === "object") inline = {
|
|
63
|
+
...inline,
|
|
64
|
+
...options
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const configured = Reflect.get(nuxt.options, configKey);
|
|
68
|
+
if (!installed && (requireInstalled || !configured)) return;
|
|
69
|
+
return {
|
|
70
|
+
...configured && typeof configured === "object" ? configured : {},
|
|
71
|
+
...inline
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Inline and `vitehub` key options of `vite-hub/nuxt`, or `undefined` when the module is not installed. */
|
|
75
|
+
async function viteHubModuleOptions(nuxt) {
|
|
76
|
+
return await readModuleOptions(nuxt, ["vite-hub/nuxt"], "vitehub", true);
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/assistant-nuxt.ts
|
|
80
|
+
/**
|
|
81
|
+
* Checks what the docs assistant needs, when `docs.assistant` is on. The docs module calls it from its setup.
|
|
82
|
+
*
|
|
83
|
+
* The assistant's Agent and its ChatGPT Connection are application files (`server/agents/<agent>.ts` and
|
|
84
|
+
* `server/connections/chatgpt.ts`), because Agents and Connections are discovered from files. `DocsAssistant`, the panel
|
|
85
|
+
* component, is registered only when this option is on.
|
|
86
|
+
*
|
|
87
|
+
* Any Nitro preset works. `docsAssistant` runs Codex on Node.js and a model-backed Driver in a Worker build. An Agent
|
|
88
|
+
* that sets a provider Driver itself fails a Worker build with `AGENT_B0019` from `@vite-hub/agent`.
|
|
89
|
+
*/
|
|
90
|
+
function setupDocsAssistant(nuxt, config) {
|
|
91
|
+
const assistant = config.assistant;
|
|
92
|
+
if (!assistant) return;
|
|
93
|
+
nuxt.hook("modules:done", async () => {
|
|
94
|
+
if (!(await viteHubModuleOptions(nuxt))?.agent) throw docsErrorDiagnostics.DOCS_ASSISTANT_AGENTS_MISSING({ agent: assistant.agent });
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/comark-blocks.ts
|
|
99
|
+
/**
|
|
100
|
+
* The source of a module whose default export is comark-ui's block components by tag, each one loaded on first use.
|
|
101
|
+
* `comark-ui/vue` imports every block package, so a page that rendered with it downloaded all of them. Each tag imports
|
|
102
|
+
* the package that defines its component. The tags that comark-ui defines itself, such as the Mermaid wrapper, import
|
|
103
|
+
* `comark-ui/vue`. comark-ui 0.12.2 has `comark-ui/vue/lazy` (https://github.com/onmax/comark-ui/pull/434), but its block
|
|
104
|
+
* packages change the spacing of callouts, so the switch waits for that decision.
|
|
105
|
+
*/
|
|
106
|
+
async function comarkBlocksSource() {
|
|
107
|
+
let ui;
|
|
108
|
+
try {
|
|
109
|
+
ui = createRequire(import.meta.url).resolve("comark-ui/package.json");
|
|
110
|
+
} catch {
|
|
111
|
+
return "export default {}\n";
|
|
112
|
+
}
|
|
113
|
+
const fromUi = createRequire(ui);
|
|
114
|
+
const uiVue = fromUi.resolve("comark-ui/vue");
|
|
115
|
+
const uiModule = await import(pathToFileURL(uiVue).href);
|
|
116
|
+
const components = uiModule.components ?? uiModule.default().components;
|
|
117
|
+
const files = /* @__PURE__ */ new Map();
|
|
118
|
+
const dependencies = Object.keys(JSON.parse(readFileSync(ui, "utf8")).dependencies ?? {});
|
|
119
|
+
for (const name of dependencies.filter((name) => name.startsWith("comark-"))) {
|
|
120
|
+
let file;
|
|
121
|
+
try {
|
|
122
|
+
file = fromUi.resolve(`${name}/vue`);
|
|
123
|
+
} catch {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const plugin = await import(pathToFileURL(file).href);
|
|
127
|
+
for (const component of Object.values(plugin.components ?? {})) files.set(component, file);
|
|
128
|
+
}
|
|
129
|
+
return `import { defineAsyncComponent } from "vue"\nexport default {\n${Object.entries(components).map(([tag, component]) => {
|
|
130
|
+
const owner = files.get(component);
|
|
131
|
+
const file = JSON.stringify(owner ?? uiVue);
|
|
132
|
+
const map = owner ? "module.components" : "(module.components ?? module.default().components)";
|
|
133
|
+
return ` ${JSON.stringify(tag)}: defineAsyncComponent(() => import(${file}).then(module => ${map}[${JSON.stringify(tag)}])),`;
|
|
134
|
+
}).join("\n")}\n}\n`;
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/comments-nuxt.ts
|
|
138
|
+
/** Whether the app can import `name`, as `vite-hub` resolves its optional peers. */
|
|
139
|
+
function installed(name, rootDir) {
|
|
140
|
+
try {
|
|
141
|
+
createRequire(join(rootDir, "package.json")).resolve(`${name}/package.json`);
|
|
142
|
+
return true;
|
|
143
|
+
} catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The module dependency that turns Comments on in `vite-hub/nuxt`. Comments keeps threads in a ViteHub Database, so a
|
|
149
|
+
* site without `vite-hub/nuxt` has none unless it asks for them, which fails the build. `false` sets `comments: false`.
|
|
150
|
+
* The dependency only sets defaults: the app's own `vitehub.comments` wins.
|
|
151
|
+
*/
|
|
152
|
+
async function docsCommentsDependencies(nuxt, comments) {
|
|
153
|
+
const vitehub = await viteHubModuleOptions(nuxt);
|
|
154
|
+
if (comments === false) return vitehub ? { "vite-hub/nuxt": {
|
|
155
|
+
optional: true,
|
|
156
|
+
defaults: { comments: false }
|
|
157
|
+
} } : {};
|
|
158
|
+
if (!vitehub) {
|
|
159
|
+
if (comments === void 0) return {};
|
|
160
|
+
throw docsErrorDiagnostics.DOCS_COMMENTS_VITEHUB_MISSING();
|
|
161
|
+
}
|
|
162
|
+
if (vitehub.comments === false) return {};
|
|
163
|
+
if (!installed("@vite-hub/comments", nuxt.options.rootDir)) throw docsErrorDiagnostics.DOCS_COMMENTS_PACKAGE_MISSING();
|
|
164
|
+
if (Reflect.get(vitehub, "database") === false) throw docsErrorDiagnostics.DOCS_COMMENTS_DATABASE_OFF();
|
|
165
|
+
return { "vite-hub/nuxt": {
|
|
166
|
+
optional: true,
|
|
167
|
+
defaults: { comments: comments === void 0 || comments === true ? true : comments }
|
|
168
|
+
} };
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/files.ts
|
|
172
|
+
/** The Markdown files of a folder, without dot files or dot folders, as Nitro's server assets list them. */
|
|
173
|
+
function markdownFiles(dir) {
|
|
174
|
+
if (!existsSync(dir)) return [];
|
|
175
|
+
return readdirSync(dir, {
|
|
176
|
+
recursive: true,
|
|
177
|
+
withFileTypes: true
|
|
178
|
+
}).filter((entry) => entry.isFile() && entry.name.endsWith(".md")).map((entry) => relative(dir, join(entry.parentPath, entry.name)).split(sep).join("/")).filter((file) => !file.split("/").some((part) => part.startsWith("."))).sort();
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Packs the Markdown files of every store into one gzip stream. `order` lists `[store, file]` pairs to put first. Gzip
|
|
182
|
+
* finds repeats only in the last 32 KB, so a page next to its raw copy packs a third smaller than the two folders apart.
|
|
183
|
+
*/
|
|
184
|
+
function packDocsFiles(stores, order = []) {
|
|
185
|
+
const files = new Map(stores.map((store) => [store.name, new Map(markdownFiles(store.dir).map((file) => [file, join(store.dir, file)]))]));
|
|
186
|
+
const sequence = [];
|
|
187
|
+
const added = /* @__PURE__ */ new Set();
|
|
188
|
+
const add = (store, file) => {
|
|
189
|
+
const path = files.get(store)?.get(file);
|
|
190
|
+
if (!path || added.has(`${store}\0${file}`)) return;
|
|
191
|
+
added.add(`${store}\0${file}`);
|
|
192
|
+
sequence.push([
|
|
193
|
+
store,
|
|
194
|
+
file,
|
|
195
|
+
path
|
|
196
|
+
]);
|
|
197
|
+
};
|
|
198
|
+
for (const [store, file] of order) add(store, file);
|
|
199
|
+
for (const [store, paths] of files) for (const file of paths.keys()) add(store, file);
|
|
200
|
+
const index = Object.fromEntries(stores.map((store) => [store.name, {}]));
|
|
201
|
+
const chunks = [];
|
|
202
|
+
let offset = 0;
|
|
203
|
+
for (const [store, file, path] of sequence) {
|
|
204
|
+
const bytes = readFileSync(path);
|
|
205
|
+
index[store][file] = [offset, offset + bytes.length];
|
|
206
|
+
chunks.push(bytes);
|
|
207
|
+
offset += bytes.length;
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
index,
|
|
211
|
+
packed: gzipSync(Buffer.concat(chunks), { level: 9 }).toString("base64")
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The source of `#docs/files` in development. Each file is a `?raw` import, so Vite watches it, and an edit shows on the
|
|
216
|
+
* next read. The server can run in workerd, which cannot read the folders from disk.
|
|
217
|
+
*/
|
|
218
|
+
function docsDevFilesModule(stores) {
|
|
219
|
+
return [
|
|
220
|
+
`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}`,
|
|
221
|
+
"export default {",
|
|
222
|
+
" async read(store, file) {",
|
|
223
|
+
" const load = Object.hasOwn(files, store) && Object.hasOwn(files[store], file) ? files[store][file] : undefined",
|
|
224
|
+
" return load ? (await load()).default : null",
|
|
225
|
+
" },",
|
|
226
|
+
"}",
|
|
227
|
+
""
|
|
228
|
+
].join("\n");
|
|
229
|
+
}
|
|
230
|
+
/** The source of `#docs/files` for a production build. */
|
|
231
|
+
function docsFilesModule(stores, order) {
|
|
232
|
+
const { index, packed } = packDocsFiles(stores, order);
|
|
233
|
+
return `export default { index: JSON.parse(${JSON.stringify(JSON.stringify(index))}), packed: ${JSON.stringify(packed)} }\n`;
|
|
234
|
+
}
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/seo-audit.ts
|
|
237
|
+
/**
|
|
238
|
+
* The search checks that every prerendered page must pass. The limits are those of common site audits, such as OpenSEO
|
|
239
|
+
* and Ahrefs: a title of 10 to 60 characters, a description of 70 to 160, one `h1`, headings that go down one level at
|
|
240
|
+
* a time, at least 150 words of text, and at most 2 MB (2,000,000 bytes) of HTML, because Googlebot reads only the first
|
|
241
|
+
* 2 MB of a page.
|
|
242
|
+
*/
|
|
243
|
+
const docsSeoLimits = {
|
|
244
|
+
title: {
|
|
245
|
+
min: 10,
|
|
246
|
+
max: 60
|
|
247
|
+
},
|
|
248
|
+
description: {
|
|
249
|
+
min: 70,
|
|
250
|
+
max: 160
|
|
251
|
+
},
|
|
252
|
+
words: 150,
|
|
253
|
+
bytes: 2e6
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* The Open Graph tags that a share preview needs. Without one, site audits call the tags incomplete. A page without a
|
|
257
|
+
* share image says so with `twitter:card` set to `summary`, and a site without `site.url` has no URL to give.
|
|
258
|
+
*/
|
|
259
|
+
const docsOpenGraphTags = [
|
|
260
|
+
"og:title",
|
|
261
|
+
"og:type",
|
|
262
|
+
"og:image",
|
|
263
|
+
"og:url"
|
|
264
|
+
];
|
|
265
|
+
const hiddenElements = /<(script|style|noscript|svg|template)\b[^>]*>[\s\S]*?<\/\1>/gi;
|
|
266
|
+
const blockTags = /<\/?(?:address|article|aside|blockquote|br|caption|dd|details|dialog|div|dl|dt|fieldset|figcaption|figure|footer|form|h[1-6]|header|hgroup|hr|li|main|nav|ol|p|pre|section|summary|table|td|th|tr|ul)\b[^>]*>/gi;
|
|
267
|
+
/**
|
|
268
|
+
* Reads one prerendered HTML page at an app path. `origin` is the site URL with the app base, such as
|
|
269
|
+
* `https://acme.dev/help`, so links and the canonical link turn into app paths too.
|
|
270
|
+
*/
|
|
271
|
+
function readDocsSeoPage(path, html, origin) {
|
|
272
|
+
const head = html.match(/<head\b[^>]*>([\s\S]*?)<\/head>/i)?.[1] ?? "";
|
|
273
|
+
const body = (html.match(/<body\b[^>]*>([\s\S]*)<\/body>/i)?.[1] ?? html).replace(hiddenElements, " ");
|
|
274
|
+
const meta = (name) => attribute(head.match(new RegExp(`<meta\\b[^>]*\\b(?:name|http-equiv)=["']${name}["'][^>]*>`, "i"))?.[0], "content");
|
|
275
|
+
const canonical = attribute(head.match(/<link\b[^>]*\brel=["']canonical["'][^>]*>/i)?.[0], "href");
|
|
276
|
+
const openGraph = /* @__PURE__ */ new Set();
|
|
277
|
+
for (const [tag] of head.matchAll(/<meta\b[^>]*>/gi)) {
|
|
278
|
+
const property = attribute(tag, "property");
|
|
279
|
+
if (property && attribute(tag, "content")?.trim()) openGraph.add(property.toLowerCase());
|
|
280
|
+
}
|
|
281
|
+
const levels = [];
|
|
282
|
+
walkSync(parse(body), (node, parent) => {
|
|
283
|
+
if (node.type !== ELEMENT_NODE || !/^h[1-6]$/i.test(node.name)) return;
|
|
284
|
+
for (let ancestor = parent; ancestor; ancestor = ancestor.parent) if (ancestor.type === ELEMENT_NODE && ancestor.attributes.class?.split(/\s+/).includes("docs-example-preview")) return;
|
|
285
|
+
levels.push(Number(node.name[1]));
|
|
286
|
+
});
|
|
287
|
+
const skip = levels.findIndex((level, index) => index > 0 && level > levels[index - 1] + 1);
|
|
288
|
+
const text = decode(body.replace(blockTags, " ").replace(/<[^>]+>/g, ""));
|
|
289
|
+
const links = /* @__PURE__ */ new Set();
|
|
290
|
+
for (const match of body.matchAll(/<a\b[^>]*>/gi)) {
|
|
291
|
+
const link = appPath(attribute(match[0], "href"), path, origin);
|
|
292
|
+
if (link) links.add(link);
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
path,
|
|
296
|
+
title: decode(head.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i)?.[1] ?? "").trim(),
|
|
297
|
+
description: (meta("description") ?? "").trim(),
|
|
298
|
+
canonical: canonical === void 0 ? null : appPath(canonical, path, origin) ?? canonical,
|
|
299
|
+
noindex: /\bnoindex\b/i.test(meta("robots") ?? ""),
|
|
300
|
+
redirect: meta("refresh") !== void 0,
|
|
301
|
+
bytes: new TextEncoder().encode(html).byteLength,
|
|
302
|
+
openGraphMissing: docsOpenGraphTags.filter((tag) => !openGraph.has(tag)),
|
|
303
|
+
twitterCard: meta("twitter:card")?.trim() || null,
|
|
304
|
+
h1: levels.filter((level) => level === 1).length,
|
|
305
|
+
headingSkip: skip > 0 ? `h${levels[skip - 1]} → h${levels[skip]}` : null,
|
|
306
|
+
words: text.split(/\s+/).filter(Boolean).length,
|
|
307
|
+
links: [...links]
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/** The app paths of a sitemap. `origin` is the site URL with the app base, as for {@link readDocsSeoPage}. */
|
|
311
|
+
function docsSitemapPaths(xml, origin) {
|
|
312
|
+
return [...xml.matchAll(/<loc>\s*([^<\s]+)\s*<\/loc>/g)].map((match) => appPath(decode(match[1]), "/", origin) ?? match[1]);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* The problems of a site: each page in the sitemap must be a prerendered page and not a redirect, and each page that
|
|
316
|
+
* search engines index needs its own title and description within the limits, one `h1`, headings in order, enough
|
|
317
|
+
* text, complete Open Graph tags, and a link from another page. A page that is a copy, through `noindex` or a canonical
|
|
318
|
+
* 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. Each problem is one sentence that names the fix.
|
|
320
|
+
*/
|
|
321
|
+
function docsSeoProblems(pages, sitemap, options = {}) {
|
|
322
|
+
const problems = [];
|
|
323
|
+
const byPath = new Map(pages.map((page) => [page.path, page]));
|
|
324
|
+
const megabytes = (bytes) => `${(bytes / 1e6).toFixed(1)} MB`;
|
|
325
|
+
for (const page of pages) if (page.bytes > docsSeoLimits.bytes) problems.push(`${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
|
+
const redirects = new Set(pages.filter((page) => page.redirect).map((page) => page.path));
|
|
327
|
+
const endpoints = new Set(options.endpoints);
|
|
328
|
+
const linkedFrom = /* @__PURE__ */ new Map();
|
|
329
|
+
for (const page of pages) {
|
|
330
|
+
if (page.redirect) continue;
|
|
331
|
+
for (const link of page.links) if (redirects.has(link) || endpoints.has(link)) linkedFrom.set(link, [...linkedFrom.get(link) ?? [], page.path]);
|
|
332
|
+
}
|
|
333
|
+
for (const [link, from] of linkedFrom) {
|
|
334
|
+
const where = from.length > 3 ? `${from.slice(0, 3).join(", ")} and ${from.length - 3} more pages` : from.join(", ");
|
|
335
|
+
problems.push(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
|
+
}
|
|
337
|
+
for (const path of sitemap) {
|
|
338
|
+
const page = byPath.get(path);
|
|
339
|
+
if (!page) problems.push(`${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.`);
|
|
340
|
+
else if (page.redirect) problems.push(`${path} is in the sitemap, but it redirects. List the page that it redirects to instead.`);
|
|
341
|
+
}
|
|
342
|
+
const indexed = pages.filter((page) => !page.redirect && !page.noindex && (page.canonical === null || page.canonical === page.path));
|
|
343
|
+
const { title, description, words } = docsSeoLimits;
|
|
344
|
+
for (const page of indexed) {
|
|
345
|
+
const at = page.path;
|
|
346
|
+
if (!page.title) problems.push(`${at} has no title. Set \`title\` in its frontmatter.`);
|
|
347
|
+
else if (page.title.length < title.min || page.title.length > title.max) problems.push(`${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.`);
|
|
348
|
+
if (!page.description) problems.push(`${at} has no description. Set \`description\` in its frontmatter.`);
|
|
349
|
+
else if (page.description.length < description.min || page.description.length > description.max) problems.push(`${at} has a description of ${page.description.length} characters. Keep it between ${description.min} and ${description.max}.`);
|
|
350
|
+
if (page.h1 !== 1) problems.push(`${at} has ${page.h1} h1 headings. Give it one.`);
|
|
351
|
+
if (page.headingSkip) problems.push(`${at} skips a heading level, ${page.headingSkip}. Go down one level at a time.`);
|
|
352
|
+
if (page.words < words) problems.push(`${at} has ${page.words} words. Write at least ${words}, or merge it into another page.`);
|
|
353
|
+
const missing = page.openGraphMissing.filter((tag) => !(tag === "og:image" && page.twitterCard === "summary") && !(tag === "og:url" && options.siteUrl === false));
|
|
354
|
+
if (missing.length) problems.push(`${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
|
+
}
|
|
356
|
+
for (const [field, label] of [["title", "title"], ["description", "description"]]) {
|
|
357
|
+
const groups = /* @__PURE__ */ new Map();
|
|
358
|
+
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) problems.push(`${paths.join(", ")} share the ${label} "${value}". Give each page its own.`);
|
|
360
|
+
}
|
|
361
|
+
const linked = /* @__PURE__ */ new Set();
|
|
362
|
+
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)) problems.push(`No page links to ${page.path}. Link it from the navigation, the footer, or a related page.`);
|
|
364
|
+
return problems;
|
|
365
|
+
}
|
|
366
|
+
/** Pages that search engines would flag. The build stops on them while the check is on. */
|
|
367
|
+
/** `DOCS_SEO_FAILED`, with the list of problems in `problems`. */
|
|
368
|
+
function docsSeoError(problems) {
|
|
369
|
+
return Object.assign(docsErrorDiagnostics.DOCS_SEO_FAILED({ problems }), { problems });
|
|
370
|
+
}
|
|
371
|
+
function attribute(tag, name) {
|
|
372
|
+
if (!tag) return void 0;
|
|
373
|
+
const value = tag.match(new RegExp(`\\s${name}=(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i"));
|
|
374
|
+
return value ? decode(value[1] ?? value[2] ?? value[3] ?? "") : void 0;
|
|
375
|
+
}
|
|
376
|
+
/** The app path of a link, without the app base, or `null` for a link that leaves the site. */
|
|
377
|
+
function appPath(href, from, origin) {
|
|
378
|
+
if (!href || /^(?:[a-z][a-z\d+.-]*:(?!\/\/)|#)/i.test(href)) return null;
|
|
379
|
+
const site = new URL(origin || "http://docs.invalid");
|
|
380
|
+
const base = site.pathname.replace(/\/+$/, "");
|
|
381
|
+
let url;
|
|
382
|
+
try {
|
|
383
|
+
url = new URL(href, `${site.origin}${base}${from}`);
|
|
384
|
+
} catch {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
if (url.origin !== site.origin || base && url.pathname !== base && !url.pathname.startsWith(`${base}/`)) return null;
|
|
388
|
+
const path = url.pathname.slice(base.length) || "/";
|
|
389
|
+
return path.length > 1 ? path.replace(/\/+$/, "") : path;
|
|
390
|
+
}
|
|
391
|
+
const entities = {
|
|
392
|
+
amp: "&",
|
|
393
|
+
lt: "<",
|
|
394
|
+
gt: ">",
|
|
395
|
+
quot: "\"",
|
|
396
|
+
apos: "'",
|
|
397
|
+
nbsp: " "
|
|
398
|
+
};
|
|
399
|
+
function decode(value) {
|
|
400
|
+
return value.replace(/&(#x[\da-f]+|#\d+|[a-z]+);/gi, (match, entity) => {
|
|
401
|
+
if (entity[0] !== "#") return entities[entity.toLowerCase()] ?? match;
|
|
402
|
+
const code = entity[1] === "x" || entity[1] === "X" ? Number.parseInt(entity.slice(2), 16) : Number(entity.slice(1));
|
|
403
|
+
return Number.isNaN(code) ? match : String.fromCodePoint(code);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
//#endregion
|
|
407
|
+
//#region src/theme-css.ts
|
|
408
|
+
function readTheme(file) {
|
|
409
|
+
const css = postcss.parse(readFileSync(file, "utf8"), { from: file });
|
|
410
|
+
css.walkAtRules("import", (rule) => {
|
|
411
|
+
const path = rule.params.match(/^["'](\.[^"']+)["']$/)?.[1];
|
|
412
|
+
if (path) rule.replaceWith(readTheme(resolve(dirname(file), path)).nodes);
|
|
413
|
+
});
|
|
414
|
+
css.walkAtRules("source", (rule) => {
|
|
415
|
+
const path = rule.params.match(/^["'](\.[^"']+)["']$/)?.[1];
|
|
416
|
+
if (path) rule.params = JSON.stringify(resolve(dirname(file), path));
|
|
417
|
+
});
|
|
418
|
+
return css;
|
|
419
|
+
}
|
|
420
|
+
const shadcnTokens = /* @__PURE__ */ new Set([
|
|
421
|
+
"--background",
|
|
422
|
+
"--foreground",
|
|
423
|
+
"--muted",
|
|
424
|
+
"--muted-foreground",
|
|
425
|
+
"--border",
|
|
426
|
+
"--primary",
|
|
427
|
+
"--popover",
|
|
428
|
+
"--ring",
|
|
429
|
+
"--radius",
|
|
430
|
+
"--primary-foreground",
|
|
431
|
+
"--input",
|
|
432
|
+
"--destructive",
|
|
433
|
+
"--overlay",
|
|
434
|
+
"--popover-foreground",
|
|
435
|
+
"--shadow-popover",
|
|
436
|
+
"--shadow-dialog"
|
|
437
|
+
]);
|
|
438
|
+
/** The shared design system on docs pages inside an app, without changing the app's Tailwind font theme or primary. */
|
|
439
|
+
function docsThemeCss(file) {
|
|
440
|
+
const css = readTheme(file);
|
|
441
|
+
css.walkRules((rule) => {
|
|
442
|
+
const values = /* @__PURE__ */ new Map();
|
|
443
|
+
rule.each((node) => {
|
|
444
|
+
if (node.type === "decl" && shadcnTokens.has(node.prop)) {
|
|
445
|
+
values.set(node.prop, node.value);
|
|
446
|
+
node.remove();
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
rule.each((node) => {
|
|
450
|
+
if (node.type === "decl") node.value = node.value.replace(/var\((--[\w-]+)\)/g, (match, name) => values.get(name) ?? match);
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
css.walkAtRules("theme", (rule) => {
|
|
454
|
+
rule.replaceWith(postcss.rule({
|
|
455
|
+
selector: ":root",
|
|
456
|
+
nodes: rule.nodes
|
|
457
|
+
}));
|
|
458
|
+
});
|
|
459
|
+
css.walkRules((rule) => {
|
|
460
|
+
rule.selectors = rule.selectors.map((selector) => /^(?:html|:root)\b/.test(selector) ? selector.replace(/^(html|:root)/, "$1:where(.vh-docs)") : `:where(.vh-docs) ${selector}`);
|
|
461
|
+
});
|
|
462
|
+
css.walkDecls("--ui-primary", (declaration) => {
|
|
463
|
+
declaration.remove();
|
|
464
|
+
});
|
|
465
|
+
return css.toString();
|
|
466
|
+
}
|
|
467
|
+
//#endregion
|
|
468
|
+
//#region src/nuxt.ts
|
|
469
|
+
const docsNuxtModule = defineNuxtModule({
|
|
470
|
+
meta: {
|
|
471
|
+
configKey: "docs",
|
|
472
|
+
name: "@vite-hub/docs"
|
|
473
|
+
},
|
|
474
|
+
defaults: {},
|
|
475
|
+
moduleDependencies: async (nuxt) => {
|
|
476
|
+
const docs = await readModuleOptions(nuxt, [
|
|
477
|
+
"@vite-hub/docs",
|
|
478
|
+
"@vite-hub/docs/nuxt",
|
|
479
|
+
"vite-hub/docs/nuxt"
|
|
480
|
+
], "docs") ?? {};
|
|
481
|
+
const fontsPath = dependency("@nuxt/fonts");
|
|
482
|
+
const uiFontsPath = createRequire(dependency("@nuxt/ui")).resolve("@nuxt/fonts");
|
|
483
|
+
nuxt.options.alias["@nuxt/fonts"] = fontsPath;
|
|
484
|
+
nuxt.options.alias[uiFontsPath] = fontsPath;
|
|
485
|
+
return {
|
|
486
|
+
...await docsCommentsDependencies(nuxt, docs.comments),
|
|
487
|
+
"@nuxt/fonts": {},
|
|
488
|
+
"@nuxt/ui": { defaults: {
|
|
489
|
+
prose: true,
|
|
490
|
+
content: true
|
|
491
|
+
} },
|
|
492
|
+
[dependency("@vite-hub/ui/nuxt")]: {},
|
|
493
|
+
[dependency("nuxt-agent-discovery")]: {},
|
|
494
|
+
[dependency("nuxt-site-config")]: { defaults: {
|
|
495
|
+
name: docs.site?.name ?? "Docs",
|
|
496
|
+
url: docs.site?.url,
|
|
497
|
+
description: docs.site?.description,
|
|
498
|
+
defaultLocale: "en"
|
|
499
|
+
} },
|
|
500
|
+
[dependency("nuxt-og-image")]: { defaults: {
|
|
501
|
+
enabled: docs.ogImage !== false,
|
|
502
|
+
zeroRuntime: true,
|
|
503
|
+
runtimeCacheStorage: false,
|
|
504
|
+
defaults: {
|
|
505
|
+
width: 1200,
|
|
506
|
+
height: 630
|
|
507
|
+
}
|
|
508
|
+
} },
|
|
509
|
+
[dependency("nuxt-schema-org")]: {},
|
|
510
|
+
...docs.linkChecker === false ? {} : {
|
|
511
|
+
[fileURLToPath(new URL("./link-checker-redirects.js", import.meta.url))]: {},
|
|
512
|
+
[dependency("nuxt-link-checker")]: { defaults: {
|
|
513
|
+
failOnError: true,
|
|
514
|
+
fetchRemoteUrls: false,
|
|
515
|
+
showLiveInspections: false
|
|
516
|
+
} }
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
},
|
|
520
|
+
async setup(options, nuxt) {
|
|
521
|
+
const resolver = createResolver(import.meta.url);
|
|
522
|
+
const runtime = resolver.resolve("./runtime");
|
|
523
|
+
const packageRoot = resolver.resolve("..");
|
|
524
|
+
nuxt.options.build.transpile.push(packageRoot);
|
|
525
|
+
nuxt.options.build.transpile.push(/^(?:@comark\/|comark(?:-[\w-]+)?(?:\/|$))/, "@vueuse/core");
|
|
526
|
+
const transform = nuxt.options.imports.transform ??= {};
|
|
527
|
+
transform.include ??= [];
|
|
528
|
+
transform.include.push(new RegExp(`^${packageRoot.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/`));
|
|
529
|
+
const contentDir = resolve(nuxt.options.rootDir, options.dir ?? "content");
|
|
530
|
+
const sources = options.sources && resolveDocsSources(options.sources, nuxt.options.rootDir);
|
|
531
|
+
const sourcesDir = join(nuxt.options.buildDir, "docs/sources");
|
|
532
|
+
/** The folder that the server reads each source's pages from, by page `source` name. */
|
|
533
|
+
const sourceDirs = sources?.map((source, index) => source.dir ?? join(sourcesDir, `docs-${index}`));
|
|
534
|
+
const contentDirsToWatch = sources ? sources.flatMap((source) => source.dir ?? []) : [contentDir];
|
|
535
|
+
const agentDir = join(nuxt.options.buildDir, "docs/agent");
|
|
536
|
+
const base = normalizeDocsBase(options.base ?? (sources || existsSync(join(contentDir, "docs")) ? "/docs" : "/"));
|
|
537
|
+
const manifestOptions = {
|
|
538
|
+
dir: contentDir,
|
|
539
|
+
base,
|
|
540
|
+
sources: options.sources,
|
|
541
|
+
rootDir: nuxt.options.rootDir,
|
|
542
|
+
sections: options.sections
|
|
543
|
+
};
|
|
544
|
+
const config = publicConfig(options, base, nuxt.options.app.baseURL);
|
|
545
|
+
const ownsApp = !hasAppComponent(nuxt.options._layers.map((layer) => layer.config.srcDir), nuxt.options.extensions);
|
|
546
|
+
nuxt.hook("prepare:types", ({ tsConfig, sharedTsConfig, serverTsConfig }) => {
|
|
547
|
+
const templates = new Set(nuxt.options.build.templates.map((template) => template.dst));
|
|
548
|
+
for (const paths of [
|
|
549
|
+
tsConfig,
|
|
550
|
+
sharedTsConfig,
|
|
551
|
+
serverTsConfig
|
|
552
|
+
].map((config) => config?.compilerOptions?.paths)) for (const [alias, target] of Object.entries(nuxt.options.alias)) {
|
|
553
|
+
const declaration = target.replace(/\.mjs$/, ".d.mts");
|
|
554
|
+
if (paths?.[alias] && alias.startsWith("#docs/") && templates.has(declaration)) paths[alias] = [declaration];
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
const articleLayout = ownsApp ? "default" : "docs-article";
|
|
558
|
+
nuxt.options.alias["#docs/shell"] = addTemplate({
|
|
559
|
+
filename: "docs/shell.mjs",
|
|
560
|
+
write: true,
|
|
561
|
+
getContents: () => `export const ownsApp = ${ownsApp}\nexport const articleLayout = ${JSON.stringify(articleLayout)}\n`
|
|
562
|
+
}).dst;
|
|
563
|
+
addTemplate({
|
|
564
|
+
filename: "docs/shell.d.mts",
|
|
565
|
+
write: true,
|
|
566
|
+
getContents: () => `export declare const ownsApp: boolean\nexport declare const articleLayout: ${JSON.stringify(articleLayout)}\n`
|
|
567
|
+
});
|
|
568
|
+
const stylesDir = join(nuxt.options.buildDir, "docs/styles");
|
|
569
|
+
const { css: comarkCss, names: comarkCssNames } = comarkStylesheet();
|
|
570
|
+
const comarkCssFile = `comark-${createHash("sha256").update(comarkCss).digest("hex").slice(0, 10)}.css`;
|
|
571
|
+
function writeComarkCss() {
|
|
572
|
+
mkdirSync(stylesDir, { recursive: true });
|
|
573
|
+
writeFileSync(join(stylesDir, comarkCssFile), comarkCss);
|
|
574
|
+
}
|
|
575
|
+
writeComarkCss();
|
|
576
|
+
nuxt.hook("build:before", writeComarkCss);
|
|
577
|
+
if (config.github && !nuxt.options.dev) config.github.stars = await githubStars(config.github.repo);
|
|
578
|
+
nuxt.options.runtimeConfig.public.docs = config;
|
|
579
|
+
addTypeTemplate({
|
|
580
|
+
filename: "types/vite-hub-docs.d.ts",
|
|
581
|
+
getContents: () => docsRuntimeConfigTypes
|
|
582
|
+
});
|
|
583
|
+
setupDocsAssistant(nuxt, config);
|
|
584
|
+
addComponent({
|
|
585
|
+
name: "DocsAssistant",
|
|
586
|
+
filePath: join(runtime, config.assistant ? "app/assistant/DocsAssistant.vue" : "app/assistant/DocsAssistantOff.vue")
|
|
587
|
+
});
|
|
588
|
+
if (config.assistant) addComponent({
|
|
589
|
+
name: "DocsAssistantPanel",
|
|
590
|
+
filePath: join(runtime, "app/assistant/DocsAssistantPanel.vue")
|
|
591
|
+
});
|
|
592
|
+
const moduleOptions = nuxt.options;
|
|
593
|
+
let read = await readDocsContent(manifestOptions);
|
|
594
|
+
let manifest = read.manifest;
|
|
595
|
+
/** Copies the pages of each Content Source into the build, where the server and the agent copies read them. */
|
|
596
|
+
function writeSources(files) {
|
|
597
|
+
rmSync(sourcesDir, {
|
|
598
|
+
force: true,
|
|
599
|
+
recursive: true
|
|
600
|
+
});
|
|
601
|
+
for (const file of files) {
|
|
602
|
+
const target = join(sourcesDir, file.source, file.file);
|
|
603
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
604
|
+
writeFileSync(target, file.markdown);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
writeSources(read.files);
|
|
608
|
+
/** The Markdown of a page, from the content folder or from the copy of its Content Source. */
|
|
609
|
+
const readPage = (page) => readFileSync(join(page.source ? sourceDirs[Number(page.source.slice(5))] : contentDir, page.file), "utf8");
|
|
610
|
+
/**
|
|
611
|
+
* Content renders the agent copy of each page on request. `rawMarkdown` is a function of the app's build, so it runs
|
|
612
|
+
* here, and the server reads each page that it changed from `docs/agent/<source>/<file>`. `nuxi build` empties the
|
|
613
|
+
* build folder after the modules load, so it runs before the build. It returns the paths of the copies.
|
|
614
|
+
*/
|
|
615
|
+
async function writeAgentSources(snapshot = read) {
|
|
616
|
+
writeSources(snapshot.files);
|
|
617
|
+
rmSync(agentDir, {
|
|
618
|
+
force: true,
|
|
619
|
+
recursive: true
|
|
620
|
+
});
|
|
621
|
+
mkdirSync(agentDir, { recursive: true });
|
|
622
|
+
const rawMarkdown = options.rawMarkdown;
|
|
623
|
+
if (!rawMarkdown) return [];
|
|
624
|
+
const written = [];
|
|
625
|
+
for (const page of docsManifestPages(snapshot.manifest)) {
|
|
626
|
+
const source = readPage(page);
|
|
627
|
+
const rewritten = await rawMarkdown(source, page);
|
|
628
|
+
if (rewritten === source) continue;
|
|
629
|
+
const target = join(agentDir, docsContentSource(page), page.file);
|
|
630
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
631
|
+
writeFileSync(target, rewritten);
|
|
632
|
+
written.push(target);
|
|
633
|
+
}
|
|
634
|
+
return written;
|
|
635
|
+
}
|
|
636
|
+
let agentCopies = [];
|
|
637
|
+
nuxt.hook("build:before", async () => {
|
|
638
|
+
agentCopies = await writeAgentSources();
|
|
639
|
+
});
|
|
640
|
+
const indexedPagePaths = new Set(docsManifestPages(manifest).filter((page) => docsPageIndexed(page)).map((page) => docsAppPath(page.path, config.appBase)));
|
|
641
|
+
if (options.linkChecker !== false) {
|
|
642
|
+
const linkChecker = moduleOptions.linkChecker ??= {};
|
|
643
|
+
linkChecker.excludeLinks = [
|
|
644
|
+
...linkChecker.excludeLinks ?? [],
|
|
645
|
+
...options.linkChecker?.excludeLinks ?? [],
|
|
646
|
+
...docsManifestPages(manifest).map((page) => docsAppPath(docsRawPath(page.path), config.appBase)),
|
|
647
|
+
...docsManifestPages(manifest).filter((page) => !docsPageIndexed(page)).map((page) => docsAppPath(page.path, config.appBase)),
|
|
648
|
+
...indexedPagePaths
|
|
649
|
+
];
|
|
650
|
+
}
|
|
651
|
+
moduleOptions.runtimeConfig.public.mdc ??= { headings: { anchorLinks: {
|
|
652
|
+
h1: false,
|
|
653
|
+
h2: true,
|
|
654
|
+
h3: true,
|
|
655
|
+
h4: true,
|
|
656
|
+
h5: false,
|
|
657
|
+
h6: false
|
|
658
|
+
} } };
|
|
659
|
+
const design = docsUi(config.site.name);
|
|
660
|
+
moduleOptions.appConfig.ui = docsAppConfigUi(ownsApp ? design : docsThemeAdditions(design), moduleOptions.appConfig.ui, moduleOptions._layers.map((layer) => layer.config.appConfig?.ui));
|
|
661
|
+
nuxt.options.alias["#docs/theme"] = addTemplate({
|
|
662
|
+
filename: "docs/theme.mjs",
|
|
663
|
+
write: true,
|
|
664
|
+
getContents: () => `export default ${JSON.stringify(ownsApp ? {
|
|
665
|
+
ui: {},
|
|
666
|
+
props: {}
|
|
667
|
+
} : docsThemeScope(design))}\n`
|
|
668
|
+
}).dst;
|
|
669
|
+
addTemplate({
|
|
670
|
+
filename: "docs/theme.d.mts",
|
|
671
|
+
write: true,
|
|
672
|
+
getContents: () => `import type { DocsThemeScope } from "@vite-hub/docs/nuxt"\ndeclare const theme: DocsThemeScope\nexport default theme\n`
|
|
673
|
+
});
|
|
674
|
+
const fonts = moduleOptions.fonts ??= {};
|
|
675
|
+
const families = fonts.families ??= [];
|
|
676
|
+
for (const name of ["Geist", "Geist Mono"]) if (!families.some((family) => family.name === name)) families.push({
|
|
677
|
+
name,
|
|
678
|
+
global: true
|
|
679
|
+
});
|
|
680
|
+
if (ownsApp) setDocsHead(nuxt.options.app.head, config.site.name);
|
|
681
|
+
const discovery = {
|
|
682
|
+
source: false,
|
|
683
|
+
siteName: config.site.name,
|
|
684
|
+
siteUrl: config.site.url,
|
|
685
|
+
discovery: {
|
|
686
|
+
links: [
|
|
687
|
+
{
|
|
688
|
+
href: "/sitemap.md",
|
|
689
|
+
rel: "sitemap",
|
|
690
|
+
type: "text/markdown",
|
|
691
|
+
title: "Sitemap (Markdown): every page on the site"
|
|
692
|
+
},
|
|
693
|
+
{
|
|
694
|
+
href: "/llms.txt",
|
|
695
|
+
rel: "describedby",
|
|
696
|
+
type: "text/plain",
|
|
697
|
+
title: "llms.txt: index of the documentation for LLMs"
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
href: "/llms.txt",
|
|
701
|
+
rel: "service-desc",
|
|
702
|
+
type: "text/plain",
|
|
703
|
+
anchor: "/",
|
|
704
|
+
header: false
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
href: "/llms-full.txt",
|
|
708
|
+
rel: "describedby",
|
|
709
|
+
type: "text/plain",
|
|
710
|
+
title: "llms-full.txt: the full documentation as a single file"
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
href: "/llms-full.txt",
|
|
714
|
+
rel: "service-desc",
|
|
715
|
+
type: "text/plain",
|
|
716
|
+
anchor: "/",
|
|
717
|
+
header: false
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
href: config.appBase === "/" ? "/sitemap.xml" : `${config.site.url}${docsAppPath("/sitemap.xml", config.appBase)}`,
|
|
721
|
+
rel: "sitemap",
|
|
722
|
+
type: "application/xml",
|
|
723
|
+
title: "Sitemap (XML)"
|
|
724
|
+
}
|
|
725
|
+
],
|
|
726
|
+
mcpServerCard: config.mcp ? {
|
|
727
|
+
endpoint: `${config.site.url}${docsAppPath("/mcp", config.appBase)}`,
|
|
728
|
+
name: config.mcp.name
|
|
729
|
+
} : false
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
const agentDiscoveryOptions = defu(moduleOptions.agentDiscovery, discovery);
|
|
733
|
+
if (agentDiscoveryOptions.errors !== false) nuxt.options.experimental.inlineErrorRendering = false;
|
|
734
|
+
if (!agentDiscoveryOptions.routes?.length) {
|
|
735
|
+
const standalone = manifest.pages.map((page) => page.path).filter((path) => path !== "/");
|
|
736
|
+
agentDiscoveryOptions.routes = config.appBase === "/" ? [.../* @__PURE__ */ new Set([
|
|
737
|
+
...manifest.root?.path === "/" || manifest.pages.some((page) => page.path === "/") ? ["/"] : [],
|
|
738
|
+
config.base,
|
|
739
|
+
`${config.base.replace(/\/+$/, "")}/**`,
|
|
740
|
+
...standalone
|
|
741
|
+
])] : docsManifestPages(manifest).flatMap((page) => [.../* @__PURE__ */ new Set([page.path, docsAppPath(page.path, config.appBase).replace(/(.)\/$/, "$1")])].map((path) => ({
|
|
742
|
+
path,
|
|
743
|
+
raw: docsAppPath(docsRawPath(page.path), config.appBase)
|
|
744
|
+
})));
|
|
745
|
+
}
|
|
746
|
+
moduleOptions.agentDiscovery = agentDiscoveryOptions;
|
|
747
|
+
const agentFile = addTemplate({
|
|
748
|
+
filename: "docs/agent.mjs",
|
|
749
|
+
write: true,
|
|
750
|
+
getContents: () => `export default ${JSON.stringify({ llms: {
|
|
751
|
+
...options.llms?.details ? { details: options.llms.details } : {},
|
|
752
|
+
...options.llms?.sections ? { sections: options.llms.sections } : {}
|
|
753
|
+
} })}\n`
|
|
754
|
+
}).dst;
|
|
755
|
+
const manifestSource = () => `export default JSON.parse(${JSON.stringify(JSON.stringify(manifest))})\n`;
|
|
756
|
+
const manifestFile = addTemplate({
|
|
757
|
+
filename: "docs/manifest.mjs",
|
|
758
|
+
getContents: manifestSource,
|
|
759
|
+
write: true
|
|
760
|
+
}).dst;
|
|
761
|
+
addTemplate({
|
|
762
|
+
filename: "docs/manifest.d.ts",
|
|
763
|
+
getContents: () => `import type { DocsManifest } from "@vite-hub/docs"\ndeclare const manifest: DocsManifest\nexport default manifest\n`,
|
|
764
|
+
write: true
|
|
765
|
+
});
|
|
766
|
+
const app = () => docsAppManifest(manifest, { panels: !nuxt.options.dev });
|
|
767
|
+
nuxt.options.alias["#docs/manifest"] = addTemplate({
|
|
768
|
+
filename: "docs/app-manifest.mjs",
|
|
769
|
+
getContents: () => docsAppManifestSource(app().manifest),
|
|
770
|
+
write: true
|
|
771
|
+
}).dst;
|
|
772
|
+
const panelFiles = app().panels.map((panel, index) => ({
|
|
773
|
+
path: panel.path,
|
|
774
|
+
file: addTemplate({
|
|
775
|
+
filename: `docs/panels/${index}.mjs`,
|
|
776
|
+
getContents: () => docsAppPanelSource(app().panels.find((candidate) => candidate.path === panel.path) ?? {
|
|
777
|
+
...panel,
|
|
778
|
+
pages: []
|
|
779
|
+
}),
|
|
780
|
+
write: true
|
|
781
|
+
}).dst
|
|
782
|
+
}));
|
|
783
|
+
nuxt.options.alias["#docs/panels"] = addTemplate({
|
|
784
|
+
filename: "docs/panels.mjs",
|
|
785
|
+
write: true,
|
|
786
|
+
getContents: () => `export default {\n${panelFiles.map(({ path, file }) => ` ${JSON.stringify(path)}: () => import(${JSON.stringify(file)}),\n`).join("")}}\n`
|
|
787
|
+
}).dst;
|
|
788
|
+
nuxt.hook("build:manifest", (chunks) => {
|
|
789
|
+
for (const [key, chunk] of Object.entries(chunks)) if (/docs[/\\]panels[/\\]\d+\.mjs$/.test(decodeURIComponent(key))) chunk.prefetch = false;
|
|
790
|
+
});
|
|
791
|
+
addTemplate({
|
|
792
|
+
filename: "docs/panels.d.mts",
|
|
793
|
+
write: true,
|
|
794
|
+
getContents: () => `import type { DocsPanelLoaders } from "@vite-hub/docs"\ndeclare const panels: DocsPanelLoaders\nexport default panels\n`
|
|
795
|
+
});
|
|
796
|
+
addTemplate({
|
|
797
|
+
filename: "docs/app-manifest.d.mts",
|
|
798
|
+
getContents: () => `import type { DocsAppPage, DocsManifest } from "@vite-hub/docs"\ndeclare const manifest: DocsManifest<DocsAppPage>\nexport default manifest\n`,
|
|
799
|
+
write: true
|
|
800
|
+
});
|
|
801
|
+
nuxt.options.alias["#docs/navigation"] = resolver.resolve("./navigation.js");
|
|
802
|
+
nuxt.options.alias["#docs/primitive-rail"] = resolver.resolve("./primitive-rail.js");
|
|
803
|
+
nuxt.options.alias["#docs/comark-css"] = addTemplate({
|
|
804
|
+
filename: "docs/comark-css.mjs",
|
|
805
|
+
write: true,
|
|
806
|
+
getContents: () => `export default ${JSON.stringify(comarkCssFile)}\nexport const names = ${JSON.stringify(comarkCssNames)}\n`
|
|
807
|
+
}).dst;
|
|
808
|
+
addTemplate({
|
|
809
|
+
filename: "docs/comark-css.d.mts",
|
|
810
|
+
write: true,
|
|
811
|
+
getContents: () => "declare const file: string\nexport default file\nexport declare const names: string[]\n"
|
|
812
|
+
});
|
|
813
|
+
const contentEntry = await findContentEntry({
|
|
814
|
+
projectRoot: nuxt.options.rootDir,
|
|
815
|
+
serverDirs: [nuxt.options.serverDir]
|
|
816
|
+
});
|
|
817
|
+
const contentFile = addTemplate({
|
|
818
|
+
filename: "docs/content.mjs",
|
|
819
|
+
write: true,
|
|
820
|
+
getContents: () => contentEntry ? `export { default as content } from ${JSON.stringify(contentEntry)}\n` : "export const content = undefined\n"
|
|
821
|
+
}).dst;
|
|
822
|
+
const parserEntry = options.parser ? resolve(nuxt.options.rootDir, options.parser) : null;
|
|
823
|
+
const parserFile = addTemplate({
|
|
824
|
+
filename: "docs/parser.mjs",
|
|
825
|
+
write: true,
|
|
826
|
+
getContents: () => `${parserEntry ? `export { default } from ${JSON.stringify(parserEntry)}` : "export default {}"}\nexport const githubRepo = ${JSON.stringify(options.github ? options.github.repo : null)}\n`
|
|
827
|
+
}).dst;
|
|
828
|
+
const publicDirs = () => nuxt.options._layers.map((layer) => resolve(layer.cwd, layer.config.dir?.public ?? "public"));
|
|
829
|
+
const imageSizesFile = addTemplate({
|
|
830
|
+
filename: "docs/image-sizes.mjs",
|
|
831
|
+
write: true,
|
|
832
|
+
getContents: async () => `export default ${JSON.stringify(await publicImageSizes(publicDirs()))}\n`
|
|
833
|
+
}).dst;
|
|
834
|
+
const componentsEntry = options.components ? resolve(nuxt.options.rootDir, options.components) : null;
|
|
835
|
+
nuxt.options.alias["#docs/custom-components"] = addTemplate({
|
|
836
|
+
filename: "docs/custom-components.mjs",
|
|
837
|
+
write: true,
|
|
838
|
+
getContents: () => componentsEntry ? `export { default } from ${JSON.stringify(componentsEntry)}\n` : "export default {}\n"
|
|
839
|
+
}).dst;
|
|
840
|
+
addTemplate({
|
|
841
|
+
filename: "docs/custom-components.d.mts",
|
|
842
|
+
write: true,
|
|
843
|
+
getContents: () => `import type { Component } from "vue"\ndeclare const components: Record<string, Component>\nexport default components\n`
|
|
844
|
+
});
|
|
845
|
+
nuxt.options.alias["#docs/blocks"] = addTemplate({
|
|
846
|
+
filename: "docs/blocks.mjs",
|
|
847
|
+
write: true,
|
|
848
|
+
getContents: () => comarkBlocksSource()
|
|
849
|
+
}).dst;
|
|
850
|
+
addTemplate({
|
|
851
|
+
filename: "docs/blocks.d.mts",
|
|
852
|
+
write: true,
|
|
853
|
+
getContents: () => `import type { Component } from "vue"\ndeclare const blocks: Record<string, Component>\nexport default blocks\n`
|
|
854
|
+
});
|
|
855
|
+
addTypeTemplate({
|
|
856
|
+
filename: "types/docs-page-meta.d.ts",
|
|
857
|
+
getContents: () => `declare module "#app" {\n interface PageMeta {\n /** \`false\` hides the docs sidebar. \`"collapsed"\` shows a narrow strip with a button that opens it. */\n sidebar?: boolean | "collapsed"\n }\n}\nexport {}\n`
|
|
858
|
+
});
|
|
859
|
+
const examplesDir = resolve(nuxt.options.srcDir, options.examples ?? "examples");
|
|
860
|
+
const exampleFiles = () => existsSync(examplesDir) ? readdirSync(examplesDir).filter((file) => file.endsWith(".vue")).sort() : [];
|
|
861
|
+
nuxt.options.alias["#docs/examples"] = addTemplate({
|
|
862
|
+
filename: "docs/examples.mjs",
|
|
863
|
+
write: true,
|
|
864
|
+
getContents: () => `export default {\n${exampleFiles().map((file) => ` ${JSON.stringify(file.slice(0, -4))}: () => import(${JSON.stringify(join(examplesDir, file))}),`).join("\n")}\n}\n`
|
|
865
|
+
}).dst;
|
|
866
|
+
addTemplate({
|
|
867
|
+
filename: "docs/examples.d.mts",
|
|
868
|
+
write: true,
|
|
869
|
+
getContents: () => `import type { Component } from "vue"\ndeclare const examples: Record<string, (() => Promise<{ default: Component }>) | undefined>\nexport default examples\n`
|
|
870
|
+
});
|
|
871
|
+
const exampleSourcesFile = addTemplate({
|
|
872
|
+
filename: "docs/example-sources.mjs",
|
|
873
|
+
write: true,
|
|
874
|
+
getContents: () => `export default ${JSON.stringify(Object.fromEntries(exampleFiles().map((file) => [file.slice(0, -4), readFileSync(join(examplesDir, file), "utf8")])))}\n`
|
|
875
|
+
}).dst;
|
|
876
|
+
nuxt.hook("builder:watch", async (_event, path) => {
|
|
877
|
+
if (resolve(nuxt.options.srcDir, path).startsWith(`${examplesDir}${sep}`)) await updateTemplates({ filter: (template) => template.filename.startsWith("docs/example") });
|
|
878
|
+
});
|
|
879
|
+
if (nuxt.options.dev) {
|
|
880
|
+
nuxt.options.watch = [.../* @__PURE__ */ new Set([...nuxt.options.watch ?? [], examplesDir])];
|
|
881
|
+
let timer;
|
|
882
|
+
let regeneration = Promise.resolve();
|
|
883
|
+
let closed = false;
|
|
884
|
+
let viteServer;
|
|
885
|
+
nuxt.hook("vite:serverCreated", (server) => {
|
|
886
|
+
viteServer = server;
|
|
887
|
+
});
|
|
888
|
+
const logError = (error) => useLogger("@vite-hub/docs").error(error);
|
|
889
|
+
const watchers = contentDirsToWatch.map((contentDir) => {
|
|
890
|
+
let watchDir = contentDir;
|
|
891
|
+
while (!existsSync(watchDir) && dirname(watchDir) !== watchDir) watchDir = dirname(watchDir);
|
|
892
|
+
return watch(watchDir, { recursive: true }, (event, file) => {
|
|
893
|
+
if (file) {
|
|
894
|
+
const changedPath = resolve(watchDir, file);
|
|
895
|
+
if (changedPath !== contentDir && !changedPath.startsWith(`${contentDir}${sep}`) && !contentDir.startsWith(`${changedPath}${sep}`)) return;
|
|
896
|
+
if (event === "change" && !/(\.md|\.navigation\.yml)$/.test(file)) return;
|
|
897
|
+
}
|
|
898
|
+
clearTimeout(timer);
|
|
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);
|
|
917
|
+
});
|
|
918
|
+
});
|
|
919
|
+
nuxt.hook("close", async () => {
|
|
920
|
+
closed = true;
|
|
921
|
+
clearTimeout(timer);
|
|
922
|
+
for (const watcher of watchers) watcher.close();
|
|
923
|
+
await regeneration;
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
const designClasses = addTemplate({
|
|
927
|
+
filename: "docs/design.json",
|
|
928
|
+
write: true,
|
|
929
|
+
getContents: () => JSON.stringify(design, null, 1)
|
|
930
|
+
}).dst;
|
|
931
|
+
const cssSources = [
|
|
932
|
+
join(runtime, "app"),
|
|
933
|
+
designClasses,
|
|
934
|
+
...sourceDirs ?? [contentDir]
|
|
935
|
+
].map((source) => `@source "${source}";`).join("\n");
|
|
936
|
+
nuxt.hook("app:templates", (app) => {
|
|
937
|
+
const ui = app.templates.find((template) => template.filename === "ui.css");
|
|
938
|
+
const getContents = ui?.getContents;
|
|
939
|
+
if (ui && getContents) ui.getContents = async (data) => `${await getContents(data)}\n${cssSources}\n`;
|
|
940
|
+
});
|
|
941
|
+
const sharedTheme = dependency("@vite-hub/ui/theme.css");
|
|
942
|
+
const scopedTheme = ownsApp ? null : addTemplate({
|
|
943
|
+
filename: "docs/theme.css",
|
|
944
|
+
write: true,
|
|
945
|
+
getContents: () => docsThemeCss(sharedTheme)
|
|
946
|
+
});
|
|
947
|
+
const docsCss = addTemplate({
|
|
948
|
+
filename: "docs/docs.css",
|
|
949
|
+
write: true,
|
|
950
|
+
getContents: () => [
|
|
951
|
+
`@layer theme, base, comark, components, utilities;`,
|
|
952
|
+
...importsNuxtUi(nuxt.options.css, nuxt.options.alias, docsCss.dst) ? [] : [`@import "${stylesheet("tailwindcss")}";`, `@import "${stylesheet("@nuxt/ui")}";`],
|
|
953
|
+
`@import "${scopedTheme?.dst ?? sharedTheme}";`,
|
|
954
|
+
`@import "${join(runtime, "theme/design.css")}";`,
|
|
955
|
+
""
|
|
956
|
+
].join("\n")
|
|
957
|
+
});
|
|
958
|
+
nuxt.options.css.unshift(docsCss.dst);
|
|
959
|
+
Reflect.apply(nuxt.hook, nuxt, ["icon:clientBundleIcons", (icons) => {
|
|
960
|
+
const names = [
|
|
961
|
+
...docsManifestPages(manifest).flatMap((page) => readPage(page).match(markdownIconName) ?? []),
|
|
962
|
+
...shellIcons,
|
|
963
|
+
...Object.values(vitehubTheme.icons),
|
|
964
|
+
config.icons.page,
|
|
965
|
+
config.icons.section,
|
|
966
|
+
...[...config.start?.links ?? [], ...config.socials].map((link) => link.icon),
|
|
967
|
+
...docsManifestPages(manifest).map((page) => docsPageIcon(config.icons, page)),
|
|
968
|
+
...manifest.sections.flatMap((section) => [docsSectionIcon(config.icons, section), docsRailIcon(config.icons, section)]),
|
|
969
|
+
...config.groups.map((group) => group.icon)
|
|
970
|
+
];
|
|
971
|
+
for (const name of names) {
|
|
972
|
+
const icon = name && iconifyName(name);
|
|
973
|
+
if (icon) icons.add(icon);
|
|
974
|
+
}
|
|
975
|
+
}]);
|
|
976
|
+
const contentDirs = [join(runtime, "app/components/content"), ...nuxt.options._layers.map((layer) => join(layer.config.srcDir, "components/content")).filter((dir) => existsSync(dir))];
|
|
977
|
+
addComponentsDir({
|
|
978
|
+
path: contentDirs[0],
|
|
979
|
+
pathPrefix: false,
|
|
980
|
+
priority: -1
|
|
981
|
+
});
|
|
982
|
+
addComponentsDir({
|
|
983
|
+
path: join(runtime, "app/components"),
|
|
984
|
+
pathPrefix: false,
|
|
985
|
+
priority: -1,
|
|
986
|
+
ignore: ["content/**"]
|
|
987
|
+
});
|
|
988
|
+
nuxt.hook("components:dirs", (dirs) => {
|
|
989
|
+
for (const path of contentDirs.slice(1)) dirs.unshift({
|
|
990
|
+
path,
|
|
991
|
+
pathPrefix: false,
|
|
992
|
+
prefix: ""
|
|
993
|
+
});
|
|
994
|
+
});
|
|
995
|
+
let contentComponents = [];
|
|
996
|
+
nuxt.hook("components:extend", (components) => {
|
|
997
|
+
contentComponents = components.filter((component) => contentDirs.some((dir) => component.filePath.startsWith(`${dir}/`)));
|
|
998
|
+
});
|
|
999
|
+
nuxt.options.alias["#docs/components"] = addTemplate({
|
|
1000
|
+
filename: "docs/components.mjs",
|
|
1001
|
+
write: true,
|
|
1002
|
+
getContents: () => [
|
|
1003
|
+
`export default {\n${contentComponents.map((component) => ` ${JSON.stringify(component.kebabName)}: () => import(${JSON.stringify(component.filePath)}),`).join("\n")}\n}`,
|
|
1004
|
+
`export const pageBlocks = ${JSON.stringify(contentComponents.filter((component) => !component.filePath.startsWith(`${contentDirs[0]}/`)).map((component) => component.kebabName))}`,
|
|
1005
|
+
""
|
|
1006
|
+
].join("\n")
|
|
1007
|
+
}).dst;
|
|
1008
|
+
addTemplate({
|
|
1009
|
+
filename: "docs/components.d.mts",
|
|
1010
|
+
write: true,
|
|
1011
|
+
getContents: () => `import type { Component } from "vue"\ndeclare const components: Record<string, (() => Promise<{ default: Component }>) | undefined>\nexport default components\nexport declare const pageBlocks: string[]\n`
|
|
1012
|
+
});
|
|
1013
|
+
addImportsDir([join(runtime, "app/composables"), join(runtime, "app/utils")]);
|
|
1014
|
+
nuxt.hook("app:templates", (app) => {
|
|
1015
|
+
app.layouts.docs ??= {
|
|
1016
|
+
file: join(runtime, "app/layouts/docs.vue"),
|
|
1017
|
+
name: "docs"
|
|
1018
|
+
};
|
|
1019
|
+
app.layouts[articleLayout] ??= {
|
|
1020
|
+
file: join(runtime, "app/layouts/default.vue"),
|
|
1021
|
+
name: articleLayout
|
|
1022
|
+
};
|
|
1023
|
+
});
|
|
1024
|
+
if (!nuxt.options._layers.some((layer) => layer.config.experimental?.defaults?.nuxtLink?.prefetchOn)) nuxt.options.experimental.defaults.nuxtLink.prefetchOn = {
|
|
1025
|
+
visibility: false,
|
|
1026
|
+
interaction: true
|
|
1027
|
+
};
|
|
1028
|
+
addPlugin({
|
|
1029
|
+
src: join(runtime, "app/plugins/theme-color.ts"),
|
|
1030
|
+
mode: "all"
|
|
1031
|
+
});
|
|
1032
|
+
addPlugin({
|
|
1033
|
+
src: join(runtime, "app/plugins/comark-css.ts"),
|
|
1034
|
+
mode: "all"
|
|
1035
|
+
});
|
|
1036
|
+
addPlugin({
|
|
1037
|
+
src: join(runtime, "app/plugins/icon-stroke.ts"),
|
|
1038
|
+
mode: "all"
|
|
1039
|
+
});
|
|
1040
|
+
addRouteMiddleware({
|
|
1041
|
+
name: "docs-layout",
|
|
1042
|
+
path: join(runtime, "app/middleware/docs-layout.ts"),
|
|
1043
|
+
global: true
|
|
1044
|
+
});
|
|
1045
|
+
extendPages((pages) => {
|
|
1046
|
+
const mount = docsMount(manifest);
|
|
1047
|
+
if (replacesDocsPage(pages, mount)) return;
|
|
1048
|
+
pages.push({
|
|
1049
|
+
name: "docs-page",
|
|
1050
|
+
path: `${mount === "/" ? "" : mount}/:slug(.*)*`,
|
|
1051
|
+
file: join(runtime, "app/pages/docs-page.vue")
|
|
1052
|
+
});
|
|
1053
|
+
});
|
|
1054
|
+
const nuxtApp = [resolve(nuxt.options.appDir, "components/welcome.vue"), resolve(nuxt.options.appDir, "../pages/runtime/app.vue")];
|
|
1055
|
+
const nuxtErrorPage = resolve(nuxt.options.appDir, "components/nuxt-error-page.vue");
|
|
1056
|
+
nuxt.hook("app:resolve", (app) => {
|
|
1057
|
+
if (ownsApp && (!app.mainComponent || nuxtApp.includes(app.mainComponent) || app.mainComponent.includes("@nuxt/ui-templates"))) app.mainComponent = join(runtime, "app/app.vue");
|
|
1058
|
+
if (ownsApp && (!app.errorComponent || app.errorComponent === nuxtErrorPage)) app.errorComponent = join(runtime, "app/error.vue");
|
|
1059
|
+
if (!ownsApp && app.mainComponent) warnAppComponent(app.mainComponent);
|
|
1060
|
+
});
|
|
1061
|
+
nuxt.hook("builder:watch", (event, path) => {
|
|
1062
|
+
if ((event === "add" || event === "unlink") && /(^|\/)app\.\w+$/i.test(path) && hasAppComponent(nuxt.options._layers.map((layer) => layer.config.srcDir), nuxt.options.extensions) === ownsApp) Promise.resolve(nuxt.callHook("restart")).catch((error) => useLogger("@vite-hub/docs").error(error));
|
|
1063
|
+
});
|
|
1064
|
+
addServerHandler({
|
|
1065
|
+
route: "/api/_docs/page/**",
|
|
1066
|
+
handler: resolver.resolve("./runtime/server/page.js")
|
|
1067
|
+
});
|
|
1068
|
+
addServerHandler({
|
|
1069
|
+
route: "/api/_docs/search.json",
|
|
1070
|
+
handler: resolver.resolve("./runtime/server/search.js")
|
|
1071
|
+
});
|
|
1072
|
+
addServerHandler({
|
|
1073
|
+
route: "/sitemap.xml",
|
|
1074
|
+
handler: resolver.resolve("./runtime/server/sitemap.js")
|
|
1075
|
+
});
|
|
1076
|
+
addServerHandler({
|
|
1077
|
+
middleware: true,
|
|
1078
|
+
handler: resolver.resolve("./runtime/server/trailing-slash.js")
|
|
1079
|
+
});
|
|
1080
|
+
for (const method of ["get", "head"]) for (const route of [
|
|
1081
|
+
"/llms.txt",
|
|
1082
|
+
"/llms-full.txt",
|
|
1083
|
+
"/sitemap.md"
|
|
1084
|
+
]) addServerHandler({
|
|
1085
|
+
route,
|
|
1086
|
+
method,
|
|
1087
|
+
handler: resolver.resolve("./runtime/server/llms.js")
|
|
1088
|
+
});
|
|
1089
|
+
if (config.mcp) addServerHandler({
|
|
1090
|
+
route: "/mcp",
|
|
1091
|
+
handler: resolver.resolve("./runtime/server/mcp.js")
|
|
1092
|
+
});
|
|
1093
|
+
if (config.markdownPages) addServerHandler({
|
|
1094
|
+
middleware: true,
|
|
1095
|
+
handler: resolver.resolve("./runtime/server/markdown.js")
|
|
1096
|
+
});
|
|
1097
|
+
/**
|
|
1098
|
+
* The routes that the build prerenders. Nuxt lets the client read `_payload.json` only when the Nitro config lists
|
|
1099
|
+
* prerender routes. Routes from the `prerender:routes` hook come too late: the prerendered HTML then has no page
|
|
1100
|
+
* data, and every static page hydrates to "Page not found".
|
|
1101
|
+
*/
|
|
1102
|
+
function prerenderRoutes() {
|
|
1103
|
+
return [
|
|
1104
|
+
...docsIndexedPages(manifest).flatMap((page) => [page.path, `/api/_docs/page${page.path === "/" ? "/index" : page.path}.json`]),
|
|
1105
|
+
...docsManifestPages(manifest).map((page) => docsRawPath(page.path)),
|
|
1106
|
+
"/api/_docs/search.json",
|
|
1107
|
+
"/sitemap.xml",
|
|
1108
|
+
"/sitemap.md",
|
|
1109
|
+
"/llms.txt",
|
|
1110
|
+
"/llms-full.txt"
|
|
1111
|
+
];
|
|
1112
|
+
}
|
|
1113
|
+
Reflect.apply(nuxt.hook, nuxt, ["nitro:init", (nitro) => {
|
|
1114
|
+
const building = !nuxt.options.dev && !Reflect.get(nuxt.options, "_prepare");
|
|
1115
|
+
if (options.linkChecker !== false && building) {
|
|
1116
|
+
const problems = docsRedirectProblems(manifest, docsRedirects(nitro.options.routeRules ?? {}));
|
|
1117
|
+
if (problems.length) throw docsRedirectError(problems);
|
|
1118
|
+
nitro.hooks?.hook("compiled", () => {
|
|
1119
|
+
if (!nitro.options.output) return;
|
|
1120
|
+
const redirects = docsRedirects(nitro.options.routeRules ?? {});
|
|
1121
|
+
const settings = options.linkChecker || {};
|
|
1122
|
+
const result = checkDocsLinks({
|
|
1123
|
+
dir: nitro.options.output.publicDir,
|
|
1124
|
+
siteUrl: config.site.url || "https://docs.local",
|
|
1125
|
+
appBase: config.appBase,
|
|
1126
|
+
...settings,
|
|
1127
|
+
isRuntimePath: docsRuntimePath(nitro.options, config.appBase, docsMount(manifest)),
|
|
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
|
+
]
|
|
1134
|
+
});
|
|
1135
|
+
useLogger("@vite-hub/docs").info?.(`Checked links and fragments of ${result.pages} pages`);
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
const seoAudit = options.seoAudit ?? "warn";
|
|
1139
|
+
if (seoAudit && building) {
|
|
1140
|
+
const origin = `${config.site.url || "http://docs.invalid"}${config.appBase.replace(/\/+$/, "")}`;
|
|
1141
|
+
const pages = [];
|
|
1142
|
+
let sitemap = [];
|
|
1143
|
+
nitro.hooks?.hook("prerender:generate", (route) => {
|
|
1144
|
+
if (route.error || !route.contents) return;
|
|
1145
|
+
if (route.route === "/sitemap.xml") sitemap = docsSitemapPaths(route.contents, origin);
|
|
1146
|
+
else if (route.fileName?.endsWith(".html") && route.contentType?.includes("text/html")) pages.push(readDocsSeoPage(route.route, route.contents, origin));
|
|
1147
|
+
});
|
|
1148
|
+
nitro.hooks?.hook("prerender:done", () => {
|
|
1149
|
+
const problems = docsSeoProblems(pages, sitemap, {
|
|
1150
|
+
endpoints: config.mcp ? ["/mcp"] : [],
|
|
1151
|
+
siteUrl: Boolean(config.site.url)
|
|
1152
|
+
});
|
|
1153
|
+
if (!problems.length) return;
|
|
1154
|
+
const error = docsSeoError(problems);
|
|
1155
|
+
if (seoAudit === "error" || seoAudit === true) throw error;
|
|
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.`);
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
}]);
|
|
1160
|
+
Reflect.apply(nuxt.hook, nuxt, ["nitro:config", (nitro) => {
|
|
1161
|
+
if (config.appBase !== "/") {
|
|
1162
|
+
for (const link of [...nitro.runtimeConfig?.agentDiscovery?.links ?? [], ...nitro.runtimeConfig?.public?.agentDiscovery?.resources ?? []]) {
|
|
1163
|
+
link.href = docsAppPath(link.href, config.appBase);
|
|
1164
|
+
if (link.anchor) link.anchor = docsAppPath(link.anchor, config.appBase);
|
|
1165
|
+
}
|
|
1166
|
+
for (const rule of Object.values(nitro.routeRules ?? {})) for (const key of Object.keys(rule.headers ?? {})) if (key.toLowerCase() === "link") rule.headers[key] = rule.headers[key].replace(/<(\/[^>]+)>/g, (_match, path) => `<${docsAppPath(path, config.appBase)}>`);
|
|
1167
|
+
}
|
|
1168
|
+
nitro.handlers = [...nitro.handlers ?? [], ...["get", "head"].map((method) => ({
|
|
1169
|
+
route: "/raw/**",
|
|
1170
|
+
method,
|
|
1171
|
+
handler: resolver.resolve("./runtime/server/raw.js")
|
|
1172
|
+
}))];
|
|
1173
|
+
nitro.alias = {
|
|
1174
|
+
...nitro.alias,
|
|
1175
|
+
"#docs/manifest": manifestFile,
|
|
1176
|
+
"#docs/content": contentFile,
|
|
1177
|
+
"#docs/parser": parserFile,
|
|
1178
|
+
"#docs/example-sources": exampleSourcesFile,
|
|
1179
|
+
"#docs/image-sizes": imageSizesFile,
|
|
1180
|
+
"#docs/agent": agentFile,
|
|
1181
|
+
"mocked-exports/proxy": mockedExportsProxy()
|
|
1182
|
+
};
|
|
1183
|
+
const stores = [...sourceDirs ? sourceDirs.map((dir, index) => ({
|
|
1184
|
+
name: `docs-${index}`,
|
|
1185
|
+
dir
|
|
1186
|
+
})) : [{
|
|
1187
|
+
name: "docs",
|
|
1188
|
+
dir: contentDir
|
|
1189
|
+
}], {
|
|
1190
|
+
name: "docs-agent",
|
|
1191
|
+
dir: agentDir
|
|
1192
|
+
}];
|
|
1193
|
+
const order = () => docsManifestPages(manifest).flatMap((page) => [[page.source ?? "docs", page.file], ["docs-agent", `${docsContentSource(page)}/${page.file}`]]);
|
|
1194
|
+
nitro.virtual = {
|
|
1195
|
+
...nitro.virtual,
|
|
1196
|
+
"#docs/files": nuxt.options.dev ? () => docsDevFilesModule(stores) : () => docsFilesModule(stores, order())
|
|
1197
|
+
};
|
|
1198
|
+
nitro.publicAssets = [...nitro.publicAssets ?? [], {
|
|
1199
|
+
baseURL: "/_docs",
|
|
1200
|
+
dir: stylesDir,
|
|
1201
|
+
maxAge: 31536e3
|
|
1202
|
+
}];
|
|
1203
|
+
nitro.prerender = defu(nitro.prerender, {
|
|
1204
|
+
crawlLinks: docsMount(manifest) === "/",
|
|
1205
|
+
autoSubfolderIndex: false,
|
|
1206
|
+
routes: nuxt.options.dev ? [] : prerenderRoutes()
|
|
1207
|
+
});
|
|
1208
|
+
const unindexed = new Set(docsManifestPages(manifest).filter((page) => !docsPageIndexed(page)).flatMap((page) => [page.path, `/api/_docs/page${page.path}.json`]));
|
|
1209
|
+
if (unindexed.size) {
|
|
1210
|
+
const prefix = config.appBase.replace(/\/+$/, "");
|
|
1211
|
+
nitro.prerender.ignore = [...nitro.prerender.ignore ?? [], (path) => {
|
|
1212
|
+
const route = path.split(/[?#]/)[0];
|
|
1213
|
+
return unindexed.has(normalizeDocsPath(prefix && route.startsWith(`${prefix}/`) ? route.slice(prefix.length) : route));
|
|
1214
|
+
}];
|
|
1215
|
+
}
|
|
1216
|
+
}]);
|
|
1217
|
+
}
|
|
1218
|
+
});
|
|
1219
|
+
/** Match Nitro's prerender policy, including the Console exclusions installed by vite-hub/nuxt. */
|
|
1220
|
+
function docsRuntimePath(nitro, appBase, mount) {
|
|
1221
|
+
const routes = createRouter();
|
|
1222
|
+
for (const [path, rule] of Object.entries(nitro.routeRules ?? {})) addRoute(routes, void 0, path, rule);
|
|
1223
|
+
const ignored = (nitro.prerender?.ignore ?? []).map((pattern) => typeof pattern === "string" ? /[*:]/.test(pattern) ? routeToRegExp(pattern) : (path) => path.startsWith(pattern) : pattern);
|
|
1224
|
+
const base = appBase.replace(/\/+$/, "");
|
|
1225
|
+
return (pathname) => {
|
|
1226
|
+
const appPath = pathname === base ? "/" : pathname.startsWith(`${base}/`) ? pathname.slice(base.length) : void 0;
|
|
1227
|
+
if ([.../* @__PURE__ */ new Set([pathname, appPath])].some((path) => path !== void 0 && ignored.some((pattern) => {
|
|
1228
|
+
if (typeof pattern === "function") return pattern(path) === true;
|
|
1229
|
+
pattern.lastIndex = 0;
|
|
1230
|
+
return pattern.test(path);
|
|
1231
|
+
}))) return true;
|
|
1232
|
+
if (appPath === void 0) return false;
|
|
1233
|
+
if (mount !== "/" && !isDocsPath(appPath, mount) && !appPath.startsWith("/raw/")) return true;
|
|
1234
|
+
return findAllRoutes(routes, void 0, appPath).reverse().find((route) => route.data.prerender !== void 0)?.data.prerender === false;
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
/** Icons of the shell components. The icons of the theme come from `vitehubTheme`. */
|
|
1238
|
+
const shellIcons = [
|
|
1239
|
+
"i-lucide-arrow-left",
|
|
1240
|
+
"i-lucide-arrow-right",
|
|
1241
|
+
"i-lucide-book-open",
|
|
1242
|
+
"i-lucide-check",
|
|
1243
|
+
"i-lucide-chevron-down",
|
|
1244
|
+
"i-lucide-chevron-right",
|
|
1245
|
+
"i-lucide-copy",
|
|
1246
|
+
"i-lucide-file",
|
|
1247
|
+
"i-lucide-folder-open",
|
|
1248
|
+
"i-lucide-link",
|
|
1249
|
+
"i-lucide-panel-left",
|
|
1250
|
+
"i-lucide-plug",
|
|
1251
|
+
"i-lucide-search",
|
|
1252
|
+
"i-lucide-x",
|
|
1253
|
+
"i-simple-icons-anthropic",
|
|
1254
|
+
"i-simple-icons-cursor",
|
|
1255
|
+
"i-simple-icons-github",
|
|
1256
|
+
"i-simple-icons-markdown",
|
|
1257
|
+
"i-simple-icons-openai",
|
|
1258
|
+
"i-simple-icons-visualstudiocode",
|
|
1259
|
+
"i-vscode-icons-file-type-dotenv",
|
|
1260
|
+
"i-vscode-icons-file-type-js",
|
|
1261
|
+
"i-vscode-icons-file-type-js-official",
|
|
1262
|
+
"i-vscode-icons-file-type-json",
|
|
1263
|
+
"i-vscode-icons-file-type-markdown",
|
|
1264
|
+
"i-vscode-icons-file-type-nuxt",
|
|
1265
|
+
"i-vscode-icons-file-type-node",
|
|
1266
|
+
"i-vscode-icons-file-type-text",
|
|
1267
|
+
"i-vscode-icons-file-type-typescript",
|
|
1268
|
+
"i-vscode-icons-file-type-vue",
|
|
1269
|
+
"i-vscode-icons-file-type-yaml"
|
|
1270
|
+
];
|
|
1271
|
+
/** An icon name in Markdown, such as `i-lucide-sun`. A name that is no icon is dropped when @nuxt/icon cannot resolve it. */
|
|
1272
|
+
const markdownIconName = /(?<![\w-])i-[a-z0-9]+(?:-[a-z0-9]+)+/g;
|
|
1273
|
+
/**
|
|
1274
|
+
* `i-lucide-sun` as @nuxt/icon bundles it: `lucide:sun`. Collection names with one hyphen end in `-icons`, such as
|
|
1275
|
+
* `simple-icons`. Rail icon names such as `kv` are not Iconify names and return `null`.
|
|
1276
|
+
*/
|
|
1277
|
+
function iconifyName(icon) {
|
|
1278
|
+
const match = /^i-([a-z0-9]+(?:-icons)?)-(.+)$/.exec(icon);
|
|
1279
|
+
return match ? `${match[1]}:${match[2]}` : icon.includes(":") ? icon : null;
|
|
1280
|
+
}
|
|
1281
|
+
/** The head of every page of a docs site. */
|
|
1282
|
+
function setDocsHead(head, siteName) {
|
|
1283
|
+
const meta = head.meta ??= [];
|
|
1284
|
+
const viewport = meta.find((tag) => tag.name === "viewport");
|
|
1285
|
+
if (!viewport?.content || viewport.content === "width=device-width, initial-scale=1") {
|
|
1286
|
+
if (viewport) meta.splice(meta.indexOf(viewport), 1);
|
|
1287
|
+
meta.push({
|
|
1288
|
+
name: "viewport",
|
|
1289
|
+
content: "width=device-width, initial-scale=1, viewport-fit=cover, interactive-widget=resizes-content"
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
meta.push({
|
|
1293
|
+
name: "color-scheme",
|
|
1294
|
+
content: "light dark"
|
|
1295
|
+
});
|
|
1296
|
+
head.htmlAttrs = {
|
|
1297
|
+
lang: "en",
|
|
1298
|
+
dir: "ltr",
|
|
1299
|
+
...head.htmlAttrs,
|
|
1300
|
+
class: [head.htmlAttrs?.class, "vh-docs"].filter(Boolean).join(" ")
|
|
1301
|
+
};
|
|
1302
|
+
head.titleTemplate ??= `%s · ${siteName}`;
|
|
1303
|
+
}
|
|
1304
|
+
const pictures = /\.(?:avif|gif|jpe?g|png|svg|webp)$/i;
|
|
1305
|
+
/** The size of each picture in the folders, by its URL path, such as `/screenshots/console.png`. The first folder wins. */
|
|
1306
|
+
async function publicImageSizes(dirs) {
|
|
1307
|
+
const sizes = {};
|
|
1308
|
+
for (const dir of dirs) {
|
|
1309
|
+
if (!existsSync(dir)) continue;
|
|
1310
|
+
for (const file of await readdir(dir, { recursive: true })) {
|
|
1311
|
+
const path = encodeURI(`/${file.split(sep).join("/")}`);
|
|
1312
|
+
if (!pictures.test(file) || sizes[path]) continue;
|
|
1313
|
+
const size = await sizeOf(await readFile(join(dir, file)));
|
|
1314
|
+
if (size) sizes[path] = [size.width, size.height];
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
return sizes;
|
|
1318
|
+
}
|
|
1319
|
+
/** Whether a layer has an `app.vue`, as Nuxt looks for it: `app` or `App` with any Nuxt extension. */
|
|
1320
|
+
function hasAppComponent(srcDirs, extensions) {
|
|
1321
|
+
return srcDirs.some((dir) => ["app", "App"].some((name) => extensions.some((extension) => existsSync(join(dir, `${name}${extension}`)))));
|
|
1322
|
+
}
|
|
1323
|
+
/** The docs pages need Nuxt UI's `<UApp>` and a `<NuxtLayout>` in the app's own `app.vue`. Say so when one is missing. */
|
|
1324
|
+
function warnAppComponent(file) {
|
|
1325
|
+
if (!existsSync(file)) return;
|
|
1326
|
+
const source = readFileSync(file, "utf8");
|
|
1327
|
+
const missing = [/<(UApp|u-app)\b/.test(source) ? null : "`<UApp>`, which Nuxt UI needs for search, tooltips, and menus", /<(NuxtLayout|nuxt-layout)\b/.test(source) ? null : "`<NuxtLayout>`, which draws the docs navigation"].filter(Boolean);
|
|
1328
|
+
if (missing.length) useLogger("@vite-hub/docs").warn(`${file} has no ${missing.join(", and no ")}. Wrap \`<NuxtPage />\` in both, or remove app.vue to use the docs one.`);
|
|
1329
|
+
}
|
|
1330
|
+
/** Whether a stylesheet of the app imports Nuxt UI, and so starts a Tailwind build of its own. */
|
|
1331
|
+
function importsNuxtUi(css, alias, docsCss) {
|
|
1332
|
+
return css.some((entry) => {
|
|
1333
|
+
const src = typeof entry === "string" ? entry : entry.src;
|
|
1334
|
+
if (!src?.endsWith(".css") || src === docsCss) return false;
|
|
1335
|
+
const prefix = Object.keys(alias).filter((key) => src.startsWith(`${key}/`)).sort((left, right) => right.length - left.length)[0];
|
|
1336
|
+
const file = prefix ? join(alias[prefix], src.slice(prefix.length)) : src;
|
|
1337
|
+
return existsSync(file) && /@import\s+["']@nuxt\/ui["']/.test(readFileSync(file, "utf8"));
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
/** A module that this package depends on, by file path, so Nuxt finds it and transpiles its runtime. */
|
|
1341
|
+
function dependency(name) {
|
|
1342
|
+
return fileURLToPath(import.meta.resolve(name));
|
|
1343
|
+
}
|
|
1344
|
+
/** The ESM proxy of `mocked-exports`, from the copy that nuxt-og-image depends on. */
|
|
1345
|
+
function mockedExportsProxy() {
|
|
1346
|
+
return createRequire(dependency("nuxt-og-image")).resolve("mocked-exports/proxy-mjs");
|
|
1347
|
+
}
|
|
1348
|
+
/** The file a CSS `@import "<name>"` loads: the package's `style` export. */
|
|
1349
|
+
function stylesheet(name) {
|
|
1350
|
+
let root = dirname(fileURLToPath(import.meta.resolve(name)));
|
|
1351
|
+
while (!existsSync(join(root, "package.json")) || JSON.parse(readFileSync(join(root, "package.json"), "utf8")).name !== name) {
|
|
1352
|
+
if (dirname(root) === root) throw invariantError(`a resolved package has a package.json above its entry, but ${name} has none`);
|
|
1353
|
+
root = dirname(root);
|
|
1354
|
+
}
|
|
1355
|
+
const { exports } = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
1356
|
+
return join(root, exports["."].style);
|
|
1357
|
+
}
|
|
1358
|
+
function docsLogo(logo, appBase) {
|
|
1359
|
+
if (!logo) return null;
|
|
1360
|
+
if (typeof logo === "string") return {
|
|
1361
|
+
src: docsAppPath(logo, appBase),
|
|
1362
|
+
dark: null,
|
|
1363
|
+
mask: true
|
|
1364
|
+
};
|
|
1365
|
+
return {
|
|
1366
|
+
src: docsAppPath(logo.light, appBase),
|
|
1367
|
+
dark: logo.dark ? docsAppPath(logo.dark, appBase) : null,
|
|
1368
|
+
mask: false
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1371
|
+
const docsRuntimeConfigTypes = `import type { DocsPublicConfig } from "@vite-hub/docs"
|
|
1372
|
+
|
|
1373
|
+
declare module "nuxt/schema" {
|
|
1374
|
+
interface PublicRuntimeConfig { docs: DocsPublicConfig }
|
|
1375
|
+
interface CustomAppConfig { icon?: { customize?: (content: string, name?: string, prefix?: string) => string } }
|
|
1376
|
+
}
|
|
1377
|
+
declare module "@nuxt/schema" {
|
|
1378
|
+
interface PublicRuntimeConfig { docs: DocsPublicConfig }
|
|
1379
|
+
interface CustomAppConfig { icon?: { customize?: (content: string, name?: string, prefix?: string) => string } }
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
export {}
|
|
1383
|
+
`;
|
|
1384
|
+
function publicConfig(options, base, appBase) {
|
|
1385
|
+
const site = options.site ?? {};
|
|
1386
|
+
const url = (site.url ?? "").replace(/\/+$/, "");
|
|
1387
|
+
const dir = options.dir ?? "content";
|
|
1388
|
+
return {
|
|
1389
|
+
appBase: docsAppPath("/", appBase),
|
|
1390
|
+
base,
|
|
1391
|
+
site: {
|
|
1392
|
+
name: site.name ?? "Docs",
|
|
1393
|
+
url,
|
|
1394
|
+
description: site.description ?? "",
|
|
1395
|
+
logo: docsLogo(site.logo, appBase),
|
|
1396
|
+
badge: site.badge ? {
|
|
1397
|
+
label: site.badge.label,
|
|
1398
|
+
tooltip: site.badge.tooltip ?? null
|
|
1399
|
+
} : null
|
|
1400
|
+
},
|
|
1401
|
+
categories: options.categories ?? [],
|
|
1402
|
+
railExclude: options.railExclude ?? [],
|
|
1403
|
+
groups: options.groups ?? [],
|
|
1404
|
+
start: options.start ? {
|
|
1405
|
+
section: options.start.section,
|
|
1406
|
+
links: options.start.links ?? []
|
|
1407
|
+
} : void 0,
|
|
1408
|
+
socials: options.socials ?? [],
|
|
1409
|
+
footer: options.footer ?? [],
|
|
1410
|
+
banner: options.banner ?? null,
|
|
1411
|
+
sitemap: options.sitemap ?? [],
|
|
1412
|
+
github: options.github ? {
|
|
1413
|
+
branch: "main",
|
|
1414
|
+
dir,
|
|
1415
|
+
...options.github,
|
|
1416
|
+
url: `https://github.com/${options.github.repo}`,
|
|
1417
|
+
stars: null
|
|
1418
|
+
} : false,
|
|
1419
|
+
icons: {
|
|
1420
|
+
rail: {},
|
|
1421
|
+
sections: {},
|
|
1422
|
+
pages: {},
|
|
1423
|
+
aliases: {},
|
|
1424
|
+
family: "",
|
|
1425
|
+
page: "i-lucide-file-text",
|
|
1426
|
+
section: "i-lucide-folder",
|
|
1427
|
+
stroke: 1.5,
|
|
1428
|
+
...options.icons
|
|
1429
|
+
},
|
|
1430
|
+
mcp: options.mcp === false ? false : {
|
|
1431
|
+
name: options.mcp?.name ?? (site.name ?? "docs").toLowerCase(),
|
|
1432
|
+
url: `${url}${docsAppPath("/mcp", appBase)}`,
|
|
1433
|
+
guide: options.mcp?.guide ?? null
|
|
1434
|
+
},
|
|
1435
|
+
markdownPages: options.markdownPages !== false,
|
|
1436
|
+
assistant: options.assistant ? { agent: options.assistant === true ? "docs" : options.assistant.agent ?? "docs" } : false,
|
|
1437
|
+
ogImage: options.ogImage === false ? false : { component: options.ogImage?.component ?? "DocsPage" }
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
/**
|
|
1441
|
+
* comark-ui's `style.css` for the page to link, and the names to mark the link with. A comark-ui component adds its
|
|
1442
|
+
* styles on mount unless the page has a `link` or `style` with `data-comark-<name>`. The file holds the styles of every
|
|
1443
|
+
* comark-* package comark-ui depends on, the Mermaid wrapper's, and the issues box's. comark-time's component still adds
|
|
1444
|
+
* its own, since they hold a query the file leaves out. The file names the layer order first, the same as the app's CSS,
|
|
1445
|
+
* so it can load before or after it.
|
|
1446
|
+
*/
|
|
1447
|
+
function comarkStylesheet() {
|
|
1448
|
+
const layers = "@layer theme, base, comark, components, utilities;";
|
|
1449
|
+
const require = createRequire(import.meta.url);
|
|
1450
|
+
let ui;
|
|
1451
|
+
try {
|
|
1452
|
+
ui = require.resolve("comark-ui/package.json");
|
|
1453
|
+
} catch {
|
|
1454
|
+
return {
|
|
1455
|
+
css: layers,
|
|
1456
|
+
names: []
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
const { dependencies = {} } = JSON.parse(readFileSync(ui, "utf8"));
|
|
1460
|
+
const names = Object.keys(dependencies).filter((name) => name.startsWith("comark-") && name !== "comark-time").map((name) => name.slice(7));
|
|
1461
|
+
return {
|
|
1462
|
+
css: `${layers}\n${readFileSync(require.resolve("comark-ui/style.css"), "utf8")}`,
|
|
1463
|
+
names: [
|
|
1464
|
+
...names,
|
|
1465
|
+
"mermaid",
|
|
1466
|
+
"issues"
|
|
1467
|
+
]
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1470
|
+
async function githubStars(repo) {
|
|
1471
|
+
try {
|
|
1472
|
+
const response = await fetch(`https://api.github.com/repos/${repo}`, {
|
|
1473
|
+
headers: { accept: "application/vnd.github+json" },
|
|
1474
|
+
signal: AbortSignal.timeout(5e3)
|
|
1475
|
+
});
|
|
1476
|
+
if (!response.ok) return null;
|
|
1477
|
+
const body = await response.json();
|
|
1478
|
+
const stars = typeof body === "object" && body !== null && "stargazers_count" in body ? body.stargazers_count : null;
|
|
1479
|
+
return typeof stars === "number" ? stars : null;
|
|
1480
|
+
} catch {
|
|
1481
|
+
return null;
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
//#endregion
|
|
1485
|
+
export { docsNuxtModule as default };
|