@vite-hub/docs 0.0.0 → 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 +454 -0
- 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 +144 -1
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
//#region src/navigation.ts
|
|
2
|
+
/** Every page of the manifest, root first. */
|
|
3
|
+
function docsManifestPages(manifest) {
|
|
4
|
+
return [
|
|
5
|
+
...manifest.root ? [manifest.root] : [],
|
|
6
|
+
...manifest.sections.flatMap((section) => section.pages),
|
|
7
|
+
...manifest.pages
|
|
8
|
+
];
|
|
9
|
+
}
|
|
10
|
+
/** A URL path without a trailing slash or `/index`, as the manifest stores it. */
|
|
11
|
+
function normalizeDocsPath(path) {
|
|
12
|
+
return path.replace(/\/index$/, "").replace(/(.)\/+$/, "$1") || "/";
|
|
13
|
+
}
|
|
14
|
+
/** A browser URL for an app-relative route or asset. Router links keep their app-relative paths. */
|
|
15
|
+
function docsAppPath(path, appBase = "/") {
|
|
16
|
+
if (!path.startsWith("/") || path.startsWith("//")) return path;
|
|
17
|
+
const base = appBase.replace(/^\/+|\/+$/g, "");
|
|
18
|
+
return base ? `/${base}${path}` : path;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The one URL that search engines index for an app path: the site origin, the app base, and no trailing slash or
|
|
22
|
+
* `/index`. The home of the app keeps its slash, as `https://example.com/portal/`: Nitro serves an app below its base
|
|
23
|
+
* only. The canonical link, the sitemap, and the trailing-slash redirect all use it, so they name one URL per page.
|
|
24
|
+
*/
|
|
25
|
+
function docsCanonicalUrl(siteUrl, path, appBase = "/") {
|
|
26
|
+
return `${siteUrl}${docsAppPath(normalizeDocsPath(path), appBase)}`;
|
|
27
|
+
}
|
|
28
|
+
/** A docs base with one leading slash and no trailing slash: `docs/` is `/docs`, and `/` stays `/`. */
|
|
29
|
+
function normalizeDocsBase(base) {
|
|
30
|
+
const trimmed = base.replace(/\/+$/, "");
|
|
31
|
+
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
32
|
+
}
|
|
33
|
+
/** Whether a path is the docs base or a page under it. Every path is under a base of `/`. */
|
|
34
|
+
function isDocsPath(path, base) {
|
|
35
|
+
return base === "/" || path === base || path.startsWith(`${base}/`);
|
|
36
|
+
}
|
|
37
|
+
/** The page at a URL. A trailing slash and `/index` resolve to the same page. */
|
|
38
|
+
function findDocsPage(manifest, path) {
|
|
39
|
+
const normalized = normalizeDocsPath(path);
|
|
40
|
+
for (const section of manifest.sections) {
|
|
41
|
+
const page = section.pages.find((candidate) => candidate.path === normalized);
|
|
42
|
+
if (page) return {
|
|
43
|
+
page,
|
|
44
|
+
section
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const page = docsManifestPages(manifest).find((candidate) => candidate.path === normalized);
|
|
48
|
+
return page ? {
|
|
49
|
+
page,
|
|
50
|
+
section: null
|
|
51
|
+
} : null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Adds the pages of every panel that holds `path` to the app manifest, so the panel's sidebar and its pages resolve.
|
|
55
|
+
* Pages that the manifest already has stay as they are, so loading twice, or a full manifest, changes nothing.
|
|
56
|
+
*/
|
|
57
|
+
async function loadDocsPanels(manifest, path, loaders) {
|
|
58
|
+
const normalized = normalizeDocsPath(path);
|
|
59
|
+
const section = docsSectionForPath(manifest, normalized);
|
|
60
|
+
if (!section) return;
|
|
61
|
+
for (const panel of section.pages.filter((page) => page.panel && (normalized === page.path || normalized.startsWith(`${page.path}/`)))) {
|
|
62
|
+
const load = loaders[panel.path];
|
|
63
|
+
if (!load) continue;
|
|
64
|
+
const { default: pages } = await load();
|
|
65
|
+
const known = new Set(section.pages.map((page) => page.path));
|
|
66
|
+
section.pages.push(...pages.filter((page) => !known.has(page.path)));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** The section that owns a path, such as `kv` for `/docs/kv/configure`. */
|
|
70
|
+
function docsSectionForPath(manifest, path) {
|
|
71
|
+
const normalized = normalizeDocsPath(path);
|
|
72
|
+
return manifest.sections.find((section) => normalized === section.path || normalized.startsWith(`${section.path}/`)) ?? null;
|
|
73
|
+
}
|
|
74
|
+
/** The page that a section link opens: its Overview, else its first listed page. A section without `index.md` has no page at its own path. */
|
|
75
|
+
function docsSectionHome(section) {
|
|
76
|
+
return (section.pages.find((page) => page.path === section.path) ?? section.pages.find((page) => page.navigation) ?? section.pages[0])?.path ?? section.path;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The first start link that opens a docs page outside the docs base, such as an Introduction outside every section.
|
|
80
|
+
* It leads the start section, so the links that open it begin there. `null` when no start link is a docs page.
|
|
81
|
+
*/
|
|
82
|
+
function docsStartPage(manifest, start) {
|
|
83
|
+
const pages = new Set(docsManifestPages(manifest).filter((page) => page !== manifest.root && page.layout !== "home").map((page) => page.path));
|
|
84
|
+
const link = start ? start.links?.find((candidate) => pages.has(normalizeDocsPath(candidate.to))) : void 0;
|
|
85
|
+
return link ? normalizeDocsPath(link.to) : null;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The page that a "Docs" link opens: the docs base page, unless it is a `home` landing page, else the first start link
|
|
89
|
+
* that is a docs page, else the start section, else the first section. `null` when the site has no docs pages.
|
|
90
|
+
*/
|
|
91
|
+
function docsHomePath(manifest, start) {
|
|
92
|
+
if (manifest.root && manifest.root.layout !== "home") return manifest.root.path;
|
|
93
|
+
const first = (start ? manifest.sections.find((section) => section.id === start.section) : void 0) ?? manifest.sections[0];
|
|
94
|
+
return docsStartPage(manifest, start) ?? (first ? docsSectionHome(first) : null);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Whether the site shows the section rail. A rail of three or fewer items, or of sections without their own icons,
|
|
98
|
+
* shows the same fallback icon several times and carries no information, so the sidebar lists every section instead.
|
|
99
|
+
* The sections of one group count as one item. Only items placed in the rail count.
|
|
100
|
+
*/
|
|
101
|
+
function docsHasRail(manifest, icons, groups = [], options = {
|
|
102
|
+
categories: [],
|
|
103
|
+
railExclude: []
|
|
104
|
+
}) {
|
|
105
|
+
const entries = docsRailEntries(manifest, {
|
|
106
|
+
...options,
|
|
107
|
+
groups
|
|
108
|
+
}).flat();
|
|
109
|
+
return entries.length > 3 && entries.some((entry) => {
|
|
110
|
+
const section = entry.sections[0];
|
|
111
|
+
return Boolean(entry.icon || section.icon || icons.rail[section.id] || icons.sections[section.id]);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/** Title of the group of a section: the `groups` entry that lists it, else the `group` of its `.navigation.yml`. */
|
|
115
|
+
function docsSectionGroup(section, groups) {
|
|
116
|
+
return groups.find((group) => group.sections?.includes(section.id))?.title ?? section.group ?? null;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The sections that share a section's sidebar under the rail, or `null` when it lists its own pages. A group lists all
|
|
120
|
+
* its sections. A section whose only listed page is its home would list that one link, so it lists its category.
|
|
121
|
+
*/
|
|
122
|
+
function docsSidebarGroup(manifest, section, groups) {
|
|
123
|
+
const title = docsSectionGroup(section, groups);
|
|
124
|
+
if (title !== null) {
|
|
125
|
+
const sections = manifest.sections.filter((candidate) => docsSectionGroup(candidate, groups) === title);
|
|
126
|
+
return sections.length > 1 ? {
|
|
127
|
+
title,
|
|
128
|
+
sections
|
|
129
|
+
} : null;
|
|
130
|
+
}
|
|
131
|
+
const { category } = section;
|
|
132
|
+
const pages = section.pages.filter((page) => page.navigation);
|
|
133
|
+
if (!category || pages.length !== 1 || pages[0]?.path !== docsSectionHome(section)) return null;
|
|
134
|
+
const sections = manifest.sections.filter((candidate) => candidate.category === category);
|
|
135
|
+
return sections.length > 1 ? {
|
|
136
|
+
title: category,
|
|
137
|
+
sections
|
|
138
|
+
} : null;
|
|
139
|
+
}
|
|
140
|
+
/** Sections grouped by category, in the order of `categories`. Sections of other categories are left out. */
|
|
141
|
+
function docsCatalog(manifest, categories) {
|
|
142
|
+
return categories.map((category) => ({
|
|
143
|
+
category,
|
|
144
|
+
sections: manifest.sections.filter((section) => section.category === category)
|
|
145
|
+
})).filter((group) => group.sections.length > 0);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Rail groups: one per catalog category except `railExclude`, then the sections without a known category.
|
|
149
|
+
* Excluded topics stay reachable from the catalog and the start section.
|
|
150
|
+
*/
|
|
151
|
+
function docsRailGroups(manifest, categories, railExclude) {
|
|
152
|
+
const known = new Set(categories);
|
|
153
|
+
return [...docsCatalog(manifest, categories).filter((group) => !railExclude.includes(group.category)).map((group) => group.sections), manifest.sections.filter((section) => !section.category || !known.has(section.category))].filter((sections) => sections.length > 0);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Rail items in rail groups: `docsRailGroups()`, with the sections of one group in one item. The item takes the place
|
|
157
|
+
* of the first section of its group that the rail shows. It holds every section of the group in manifest order, also
|
|
158
|
+
* one whose category `railExclude` leaves out of the rail.
|
|
159
|
+
*/
|
|
160
|
+
function docsRailEntries(manifest, options) {
|
|
161
|
+
const railGroups = docsRailGroups(manifest, options.categories, options.railExclude);
|
|
162
|
+
const members = /* @__PURE__ */ new Map();
|
|
163
|
+
for (const section of manifest.sections) {
|
|
164
|
+
const title = docsSectionGroup(section, options.groups);
|
|
165
|
+
if (title !== null) members.set(title, [...members.get(title) ?? [], section]);
|
|
166
|
+
}
|
|
167
|
+
const placed = /* @__PURE__ */ new Set();
|
|
168
|
+
return railGroups.map((sections) => sections.flatMap((section) => {
|
|
169
|
+
const title = docsSectionGroup(section, options.groups);
|
|
170
|
+
if (title === null) return [{
|
|
171
|
+
title: section.title,
|
|
172
|
+
icon: null,
|
|
173
|
+
sections: [section]
|
|
174
|
+
}];
|
|
175
|
+
if (placed.has(title)) return [];
|
|
176
|
+
placed.add(title);
|
|
177
|
+
return [{
|
|
178
|
+
title,
|
|
179
|
+
icon: options.groups.find((group) => group.title === title)?.icon ?? null,
|
|
180
|
+
sections: members.get(title)
|
|
181
|
+
}];
|
|
182
|
+
})).filter((entries) => entries.length > 0);
|
|
183
|
+
}
|
|
184
|
+
/** The rail item of a section, or `null` for a section outside every group that the rail leaves out. */
|
|
185
|
+
function docsRailEntry(manifest, options, section) {
|
|
186
|
+
return docsRailEntries(manifest, options).flat().find((entry) => entry.sections.some((candidate) => candidate.id === section.id)) ?? null;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Blocks of a sidebar that lists several sections, such as a group or a site without a rail. Each section shows its
|
|
190
|
+
* home page, then its other listed pages. When the sections span several categories, each run of one category is a
|
|
191
|
+
* block with that category as its heading.
|
|
192
|
+
*/
|
|
193
|
+
function docsSidebarSections(sections) {
|
|
194
|
+
const headed = new Set(sections.map((section) => section.category)).size > 1;
|
|
195
|
+
const blocks = [];
|
|
196
|
+
for (const section of sections) {
|
|
197
|
+
const homePath = docsSectionHome(section);
|
|
198
|
+
const home = section.pages.find((page) => page.path === homePath && page.navigation) ?? null;
|
|
199
|
+
const entry = {
|
|
200
|
+
section,
|
|
201
|
+
home,
|
|
202
|
+
groups: docsSidebarGroups({
|
|
203
|
+
...section,
|
|
204
|
+
pages: section.pages.filter((page) => page !== home)
|
|
205
|
+
})
|
|
206
|
+
};
|
|
207
|
+
const category = headed ? section.category : null;
|
|
208
|
+
const last = blocks.at(-1);
|
|
209
|
+
if (last && last.category === category) last.sections.push(entry);
|
|
210
|
+
else blocks.push({
|
|
211
|
+
category,
|
|
212
|
+
sections: [entry]
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return blocks;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Sidebar rows of a section: listed pages in order, grouped by `navigation.group` in order of first appearance. Pages
|
|
219
|
+
* inside a panel are left out: the section sidebar links to each panel once, with `docsSectionPanels()`.
|
|
220
|
+
*/
|
|
221
|
+
function docsSidebarGroups(section) {
|
|
222
|
+
return sidebarGroups(docsPanelPages(section, null), section.fold);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* How many links of a panel group the sidebar renders around the current page. A panel of a thousand codes would
|
|
226
|
+
* otherwise put every code in the HTML of each of its pages, which made each page about 240 KB larger.
|
|
227
|
+
*/
|
|
228
|
+
const docsPanelWindow = 60;
|
|
229
|
+
/**
|
|
230
|
+
* The pages of a panel group that the sidebar renders before the reader asks for more: up to {@link docsPanelWindow}
|
|
231
|
+
* pages around the current one, or none in a group that does not hold it, because that group starts folded.
|
|
232
|
+
*/
|
|
233
|
+
function docsPanelGroupWindow(pages, currentPath, size = 60) {
|
|
234
|
+
const index = pages.findIndex((page) => normalizeDocsPath(page.path) === normalizeDocsPath(currentPath));
|
|
235
|
+
if (index < 0) return [];
|
|
236
|
+
if (pages.length <= size) return [...pages];
|
|
237
|
+
const start = Math.max(0, Math.min(index - Math.floor(size / 2), pages.length - size));
|
|
238
|
+
return pages.slice(start, start + size);
|
|
239
|
+
}
|
|
240
|
+
/** Sidebar rows of a panel: its listed pages without its Overview, grouped like a section. Panels hold long lists, so their groups fold. */
|
|
241
|
+
function docsPanelSidebarGroups(section, panel) {
|
|
242
|
+
return sidebarGroups(docsPanelPages(section, panel).filter((page) => page.id !== panel.id), true);
|
|
243
|
+
}
|
|
244
|
+
function sidebarGroups(pages, fold) {
|
|
245
|
+
const groups = /* @__PURE__ */ new Map();
|
|
246
|
+
for (const page of pages) {
|
|
247
|
+
if (!page.navigation) continue;
|
|
248
|
+
const label = page.group?.trim() || null;
|
|
249
|
+
groups.set(label, [...groups.get(label) ?? [], page]);
|
|
250
|
+
}
|
|
251
|
+
return [...groups].map(([label, groupPages]) => {
|
|
252
|
+
const heading = groupPages.length > 1 ? label : null;
|
|
253
|
+
return {
|
|
254
|
+
label: heading,
|
|
255
|
+
pages: groupPages,
|
|
256
|
+
fold: fold && heading !== null
|
|
257
|
+
};
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* The panel that holds a page: the Overview of the nearest folder with `navigation.panel: true`, or `null` for a page
|
|
262
|
+
* outside every panel. A panel's Overview is inside its own panel.
|
|
263
|
+
*/
|
|
264
|
+
function docsPanelOf(section, page) {
|
|
265
|
+
return panelOf(section.pages.filter((candidate) => candidate.panel), page);
|
|
266
|
+
}
|
|
267
|
+
function panelOf(panels, page) {
|
|
268
|
+
let found = null;
|
|
269
|
+
for (const panel of panels) {
|
|
270
|
+
if (page.id !== panel.id && !page.id.startsWith(`${panel.id}/`)) continue;
|
|
271
|
+
if (!found || panel.id.length > found.id.length) found = panel;
|
|
272
|
+
}
|
|
273
|
+
return found;
|
|
274
|
+
}
|
|
275
|
+
/** The pages of one panel, or with `null` the pages of the section outside every panel. */
|
|
276
|
+
function docsPanelPages(section, panel) {
|
|
277
|
+
const panels = section.pages.filter((candidate) => candidate.panel);
|
|
278
|
+
if (!panels.length) return panel ? [] : [...section.pages];
|
|
279
|
+
return section.pages.filter((page) => panelOf(panels, page)?.id === panel?.id);
|
|
280
|
+
}
|
|
281
|
+
/** The listed panels of a section, each with the number of listed pages inside it. The section sidebar links to each one. */
|
|
282
|
+
function docsSectionPanels(section) {
|
|
283
|
+
return section.pages.filter((page) => page.panel && page.navigation && !section.pages.some((outer) => outer.panel && page.id.startsWith(`${outer.id}/`))).map((page) => ({
|
|
284
|
+
page,
|
|
285
|
+
count: page.panelSize ?? docsPanelPages(section, page).filter((candidate) => candidate.navigation && candidate.id !== page.id).length
|
|
286
|
+
}));
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* The page that a rail item opens. Inside a panel, the rail keeps the reader in it: a section with a panel of the same
|
|
290
|
+
* folder name opens that panel. Any other section opens its home page.
|
|
291
|
+
*/
|
|
292
|
+
function docsRailTarget(section, panel) {
|
|
293
|
+
return (panel ? section.pages.find((page) => page.panel && page.id === panel.id) : void 0)?.path ?? docsSectionHome(section);
|
|
294
|
+
}
|
|
295
|
+
/** Whether search engines may index a page. `seo.index: false` keeps it out of the sitemap, llms.txt, and the prerender, and search lists only its title. */
|
|
296
|
+
function docsPageIndexed(page) {
|
|
297
|
+
return page.seo?.index !== false;
|
|
298
|
+
}
|
|
299
|
+
/** Every page that search engines may index, root first. */
|
|
300
|
+
function docsIndexedPages(manifest) {
|
|
301
|
+
return docsManifestPages(manifest).filter(docsPageIndexed);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* One search record for each page that search engines skip: its title and description, without its headings. The record
|
|
305
|
+
* ranks as a heading under its section, so a long tail of generated pages, such as error codes, stays below the real pages.
|
|
306
|
+
*/
|
|
307
|
+
function docsUnindexedSearchSections(manifest) {
|
|
308
|
+
const record = (page, titles) => ({
|
|
309
|
+
id: page.path,
|
|
310
|
+
title: page.sourceTitle,
|
|
311
|
+
titles,
|
|
312
|
+
level: 2,
|
|
313
|
+
content: page.description ?? "",
|
|
314
|
+
indexed: false
|
|
315
|
+
});
|
|
316
|
+
return [...manifest.sections.flatMap((section) => section.pages.filter((page) => !docsPageIndexed(page)).map((page) => record(page, [section.title]))), ...[...manifest.root ? [manifest.root] : [], ...manifest.pages].filter((page) => !docsPageIndexed(page)).map((page) => record(page, []))];
|
|
317
|
+
}
|
|
318
|
+
/** Sections listed under Related, in the order that `.navigation.yml` declares them. */
|
|
319
|
+
function docsRelatedSections(manifest, section) {
|
|
320
|
+
return section.related.map((id) => manifest.sections.find((candidate) => candidate.id === id)).filter((candidate) => candidate !== void 0 && candidate.id !== section.id);
|
|
321
|
+
}
|
|
322
|
+
function iconOf(icons, icon, fallback) {
|
|
323
|
+
if (!icon) return fallback;
|
|
324
|
+
const family = typeof icons.family === "string" ? [icons.family] : icons.family;
|
|
325
|
+
const allowed = family.length === 0 || family.some((prefix) => icon.startsWith(prefix));
|
|
326
|
+
return icons.aliases[icon] ?? (allowed ? icon : fallback);
|
|
327
|
+
}
|
|
328
|
+
/** Sidebar icon of a page. */
|
|
329
|
+
function docsPageIcon(icons, page) {
|
|
330
|
+
return icons.pages[normalizeDocsPath(page.path)] ?? iconOf(icons, page.icon, icons.page);
|
|
331
|
+
}
|
|
332
|
+
/** Sidebar and catalog icon of a section. */
|
|
333
|
+
function docsSectionIcon(icons, section) {
|
|
334
|
+
return icons.sections[section.id] ?? iconOf(icons, section.icon, icons.section);
|
|
335
|
+
}
|
|
336
|
+
/** Rail icon of a section. Without a rail entry the rail shows the sidebar icon. */
|
|
337
|
+
function docsRailIcon(icons, section) {
|
|
338
|
+
return icons.rail[section.id] ?? docsSectionIcon(icons, section);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Draws a 2px line icon with `stroke` instead. @nuxt/icon passes only the icon body in its CSS mode, so the icon is
|
|
342
|
+
* recognized by its body: Lucide draws `stroke-width="2"` with round joins. Filled icons, such as brand logos, have no
|
|
343
|
+
* stroke and stay as they are. Not reported upstream yet (fix branch:
|
|
344
|
+
* https://github.com/onmax/icon/tree/fix/customize-name-css-mode).
|
|
345
|
+
*/
|
|
346
|
+
function docsIconStroke(body, stroke) {
|
|
347
|
+
if (!body.includes("stroke-linejoin=\"round\"")) return body;
|
|
348
|
+
return body.replaceAll("stroke-width=\"2\"", `stroke-width="${stroke}"`);
|
|
349
|
+
}
|
|
350
|
+
/** URL of the raw Markdown twin of a page path, such as `/raw/docs/kv.md`. `/` has `/raw/index.md`. */
|
|
351
|
+
function docsRawPath(path) {
|
|
352
|
+
const normalized = normalizeDocsPath(path);
|
|
353
|
+
return normalized === "/" ? "/raw/index.md" : `/raw${normalized}.md`;
|
|
354
|
+
}
|
|
355
|
+
/** File of the raw Markdown twin in the build's raw folder, such as `docs/kv.md`. */
|
|
356
|
+
function docsRawFile(path) {
|
|
357
|
+
return docsRawPath(path).slice(5);
|
|
358
|
+
}
|
|
359
|
+
/** Identifies the generated footer even when runtime config overrides its build-time URLs. */
|
|
360
|
+
const docsRawSectionLinksMarker = "\n<!-- vitehub-docs:section-links -->\n";
|
|
361
|
+
/**
|
|
362
|
+
* The end of a page's raw Markdown copy: the pages of its section in sidebar order, the next page, and the llms.txt
|
|
363
|
+
* index. An agent that reads one page finds the pages beside it without loading the index of the whole site. A sidebar
|
|
364
|
+
* group other than the page's own shows as one link to its first page, so a large section stays short.
|
|
365
|
+
* `siteUrl` is the public origin with the app base, such as `https://docs.example.com/portal`.
|
|
366
|
+
*/
|
|
367
|
+
function docsRawSectionLinks(manifest, path, siteUrl) {
|
|
368
|
+
const found = findDocsPage(manifest, path);
|
|
369
|
+
const section = found?.section;
|
|
370
|
+
const pages = section?.pages.filter((page) => page.navigation) ?? [];
|
|
371
|
+
const index = pages.findIndex((page) => page.path === found?.page.path);
|
|
372
|
+
const url = (page) => `${siteUrl}${docsRawPath(page.path)}`;
|
|
373
|
+
const item = (page) => `[${page.title}](${url(page)})${page === pages[index] ? " (this page)" : ""}`;
|
|
374
|
+
const blocks = [];
|
|
375
|
+
if (section && pages.length > 1) {
|
|
376
|
+
const lines = docsSidebarGroups(section).flatMap(({ label, pages: grouped }) => {
|
|
377
|
+
if (label === null) return grouped.map((page) => `- ${item(page)}`);
|
|
378
|
+
if (!grouped.includes(pages[index])) return [`- [${label}](${url(grouped[0])})`];
|
|
379
|
+
return [`- ${label}`, ...grouped.map((page) => ` - ${item(page)}`)];
|
|
380
|
+
});
|
|
381
|
+
blocks.push("## In this section", lines.join("\n"));
|
|
382
|
+
const next = index >= 0 ? pages[index + 1] : void 0;
|
|
383
|
+
if (next) blocks.push(`Next: [${next.title}](${url(next)})`);
|
|
384
|
+
}
|
|
385
|
+
blocks.push(`All pages: [llms.txt](${siteUrl}/llms.txt)`);
|
|
386
|
+
return `${docsRawSectionLinksMarker}${blocks.join("\n\n")}\n`;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Cookie that keeps a collapsed sidebar open after the reader opens it, on every page that starts collapsed. A host
|
|
390
|
+
* that serves prerendered HTML reads it.
|
|
391
|
+
*/
|
|
392
|
+
const docsTutorialNavigationCookie = "vh-tutorial-navigation";
|
|
393
|
+
/** Whether a docs page starts with its sidebar collapsed: `sidebar: "collapsed"`, or a code panel tutorial that keeps it. */
|
|
394
|
+
function docsSidebarCollapses(page) {
|
|
395
|
+
return page.sidebar === "collapsed" || page.codePanel === true && page.sidebar !== false;
|
|
396
|
+
}
|
|
397
|
+
/** Page action links of a docs page. `site.url` is the canonical origin. */
|
|
398
|
+
function docsMarkdownLinks(site, path, appBase = "/") {
|
|
399
|
+
const markdownPath = docsAppPath(docsRawPath(path), appBase);
|
|
400
|
+
const markdownUrl = `${site.url}${markdownPath}`;
|
|
401
|
+
const prompt = `Read ${markdownUrl} from the ${site.name} documentation. Use it as context to answer my questions and to help me apply it in my project.`;
|
|
402
|
+
return {
|
|
403
|
+
markdownPath,
|
|
404
|
+
markdownUrl,
|
|
405
|
+
prompt,
|
|
406
|
+
chatGptUrl: `https://chatgpt.com/?hints=search&q=${encodeURIComponent(prompt)}`,
|
|
407
|
+
claudeUrl: `https://claude.ai/new?q=${encodeURIComponent(prompt)}`
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
/** Install deeplinks of an HTTP MCP server. The formats match the @nuxtjs/mcp-toolkit deeplink route. */
|
|
411
|
+
function docsMcpInstallLinks(server) {
|
|
412
|
+
const config = btoa(JSON.stringify({
|
|
413
|
+
type: "http",
|
|
414
|
+
url: server.url
|
|
415
|
+
}));
|
|
416
|
+
return {
|
|
417
|
+
cursor: `cursor://anysphere.cursor-deeplink/mcp/install?name=${encodeURIComponent(server.name)}&config=${encodeURIComponent(config)}`,
|
|
418
|
+
vscode: `vscode:mcp/install?${encodeURIComponent(JSON.stringify({
|
|
419
|
+
name: server.name,
|
|
420
|
+
type: "http",
|
|
421
|
+
url: server.url
|
|
422
|
+
}))}`
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
/** Words of a search text: lowercase letters and digits. `KV_INVALID_TTL` has the words `kv`, `invalid`, and `ttl`. */
|
|
426
|
+
function searchWords(text) {
|
|
427
|
+
return text.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);
|
|
428
|
+
}
|
|
429
|
+
function allowedTypos(word) {
|
|
430
|
+
return word.length < 4 ? 0 : word.length < 8 ? 1 : 2;
|
|
431
|
+
}
|
|
432
|
+
/** Edit distance with swapped neighbors as one edit, so "chatgtp" is one edit from "chatgpt". Stops early past `max`. */
|
|
433
|
+
function editDistance(left, right, max) {
|
|
434
|
+
if (Math.abs(left.length - right.length) > max) return max + 1;
|
|
435
|
+
let before = [];
|
|
436
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
437
|
+
for (let i = 1; i <= left.length; i++) {
|
|
438
|
+
const current = [i];
|
|
439
|
+
let best = i;
|
|
440
|
+
for (let j = 1; j <= right.length; j++) {
|
|
441
|
+
const cost = left[i - 1] === right[j - 1] ? 0 : 1;
|
|
442
|
+
let value = Math.min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + cost);
|
|
443
|
+
if (i > 1 && j > 1 && left[i - 1] === right[j - 2] && left[i - 2] === right[j - 1]) value = Math.min(value, before[j - 2] + 1);
|
|
444
|
+
current[j] = value;
|
|
445
|
+
best = Math.min(best, value);
|
|
446
|
+
}
|
|
447
|
+
if (best > max) return max + 1;
|
|
448
|
+
before = previous;
|
|
449
|
+
previous = current;
|
|
450
|
+
}
|
|
451
|
+
return previous[right.length];
|
|
452
|
+
}
|
|
453
|
+
function wordMatch(query, words, fuzzy) {
|
|
454
|
+
let best = 0;
|
|
455
|
+
for (const word of words) {
|
|
456
|
+
if (word === query) return 1;
|
|
457
|
+
if (word.startsWith(query)) best = Math.max(best, .8);
|
|
458
|
+
else if (query.length >= 3 && word.includes(query)) best = Math.max(best, .4);
|
|
459
|
+
else if (fuzzy && best < .6) {
|
|
460
|
+
const typos = allowedTypos(query);
|
|
461
|
+
if (typos && editDistance(query, word, typos) <= typos) best = .6;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return best;
|
|
465
|
+
}
|
|
466
|
+
const pageTitleWeight = 100;
|
|
467
|
+
const headingWeight = 40;
|
|
468
|
+
const keywordWeight = 30;
|
|
469
|
+
const trailWeight = 15;
|
|
470
|
+
const contentWeight = 5;
|
|
471
|
+
/**
|
|
472
|
+
* The search of the docs dialog. Every query word must match the record. Records whose titles or keywords match more
|
|
473
|
+
* query words come first, then the higher score: page titles over headings and keywords over text. Titles tolerate typos and prefixes, text
|
|
474
|
+
* matches whole words and prefixes. Ties keep the order of the index, which follows the navigation.
|
|
475
|
+
*/
|
|
476
|
+
function createDocsSearch(records) {
|
|
477
|
+
const entries = records.map((record, order) => ({
|
|
478
|
+
record,
|
|
479
|
+
order,
|
|
480
|
+
title: searchWords(record.title),
|
|
481
|
+
keywords: searchWords((record.keywords ?? []).join(" ")),
|
|
482
|
+
trail: searchWords(record.titles.join(" ")),
|
|
483
|
+
content: [...new Set(searchWords(record.content))]
|
|
484
|
+
}));
|
|
485
|
+
return (query, limit) => {
|
|
486
|
+
const words = [...new Set(searchWords(query))];
|
|
487
|
+
if (!words.length) return [];
|
|
488
|
+
const hits = [];
|
|
489
|
+
for (const entry of entries) {
|
|
490
|
+
const titleWeight = entry.record.level === 1 ? pageTitleWeight : headingWeight;
|
|
491
|
+
let inTitles = 0;
|
|
492
|
+
let score = 0;
|
|
493
|
+
let missed = false;
|
|
494
|
+
for (const word of words) {
|
|
495
|
+
const title = wordMatch(word, entry.title, true) * titleWeight;
|
|
496
|
+
const keyword = wordMatch(word, entry.keywords, true) * keywordWeight;
|
|
497
|
+
const trail = wordMatch(word, entry.trail, true) * trailWeight;
|
|
498
|
+
const content = wordMatch(word, entry.content, false) * contentWeight;
|
|
499
|
+
const best = Math.max(title, keyword, trail, content);
|
|
500
|
+
if (!best) {
|
|
501
|
+
missed = true;
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
504
|
+
if (title || keyword || trail) inTitles++;
|
|
505
|
+
score += best;
|
|
506
|
+
}
|
|
507
|
+
if (missed) continue;
|
|
508
|
+
if (entry.title.join(" ") === words.join(" ")) score += titleWeight / 2;
|
|
509
|
+
hits.push({
|
|
510
|
+
entry,
|
|
511
|
+
inTitles,
|
|
512
|
+
score
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
hits.sort((left, right) => right.inTitles - left.inTitles || Number(left.entry.record.indexed === false) - Number(right.entry.record.indexed === false) || right.score - left.score || left.entry.title.length - right.entry.title.length || left.entry.order - right.entry.order);
|
|
516
|
+
return hits.slice(0, limit).map((hit) => hit.entry.record);
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
//#endregion
|
|
520
|
+
export { createDocsSearch, docsAppPath, docsCanonicalUrl, docsCatalog, docsHasRail, docsHomePath, docsIconStroke, docsIndexedPages, docsManifestPages, docsMarkdownLinks, docsMcpInstallLinks, docsPageIcon, docsPageIndexed, docsPanelGroupWindow, docsPanelOf, docsPanelPages, docsPanelSidebarGroups, docsPanelWindow, docsRailEntries, docsRailEntry, docsRailGroups, docsRailIcon, docsRailTarget, docsRawFile, docsRawPath, docsRawSectionLinks, docsRawSectionLinksMarker, docsRelatedSections, docsSectionForPath, docsSectionGroup, docsSectionHome, docsSectionIcon, docsSectionPanels, docsSidebarCollapses, docsSidebarGroup, docsSidebarGroups, docsSidebarSections, docsStartPage, docsTutorialNavigationCookie, docsUnindexedSearchSections, findDocsPage, isDocsPath, loadDocsPanels, normalizeDocsBase, normalizeDocsPath };
|