@vite-hub/docs 0.0.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +456 -0
- package/dist/agent-copy-xPaWye_g.js +33 -0
- package/dist/assistant-pages-BN7hNsSZ.js +37 -0
- package/dist/assistant-shared-CWIKRtBv.d.ts +28 -0
- package/dist/assistant-shared-WzButktj.js +113 -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-CPZGnn3S.js +141 -0
- package/dist/draft-BjWmaiLn.js +45 -0
- package/dist/error-diagnostics-B_ZOy7kF.js +93 -0
- package/dist/files-UY4h1_36.js +38 -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-CMoxcwPm.d.ts +80 -0
- package/dist/manifest-ZdxLrcvt.js +434 -0
- package/dist/markdown-DUWnEMPp.js +378 -0
- package/dist/navigation.d.ts +283 -0
- package/dist/navigation.js +519 -0
- package/dist/nuxt-CAGpKl_-.d.ts +241 -0
- package/dist/nuxt.d.ts +3 -0
- package/dist/nuxt.js +1868 -0
- package/dist/page-Dx2JD3y1.d.ts +74 -0
- package/dist/page-GPt09oex.js +82 -0
- package/dist/primitive-rail.d.ts +110 -0
- package/dist/primitive-rail.js +289 -0
- package/dist/raw-BChwipz_.js +857 -0
- package/dist/redirects-CmR1yu5A.js +74 -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/McpClient.vue +170 -0
- package/dist/runtime/app/components/content/McpInstall.vue +238 -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,80 @@
|
|
|
1
|
+
import { d as DocsSectionFile, n as DocsManifest } from "./types-BhG6vGfG.js";
|
|
2
|
+
import "nostics";
|
|
3
|
+
import { ContentCheckOptions, ContentRuntime } from "@vite-hub/content";
|
|
4
|
+
import { Source } from "@vite-hub/source";
|
|
5
|
+
//#region src/check-links.d.ts
|
|
6
|
+
interface DocsLinkCheckOptions {
|
|
7
|
+
dir: string;
|
|
8
|
+
siteUrl: string;
|
|
9
|
+
appBase?: string;
|
|
10
|
+
excludeLinks?: Array<string | RegExp>;
|
|
11
|
+
/** Public page paths that are embedded documents rather than standalone pages. */
|
|
12
|
+
excludePages?: Array<string | RegExp>;
|
|
13
|
+
/** Pages whose fragment holds application state rather than an element id. */
|
|
14
|
+
ignoreFragments?: Array<string | RegExp>;
|
|
15
|
+
/** Accept missing output files for known server routes. Built files still have their fragments checked. */
|
|
16
|
+
isRuntimePath?: (pathname: string) => boolean;
|
|
17
|
+
/** Application redirects that the route rules cannot describe, such as legacy host redirects. */
|
|
18
|
+
redirect?: (url: URL) => string | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** Check built HTML against the files and fragment ids in the same output, without fetching remote URLs. */
|
|
21
|
+
declare function checkDocsLinks(options: DocsLinkCheckOptions): {
|
|
22
|
+
pages: number;
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/manifest.d.ts
|
|
26
|
+
/**
|
|
27
|
+
* Pages from a Content Source, such as `glob()` or `github()` from `@vite-hub/source`. The build reads its `.md` files
|
|
28
|
+
* and its `.navigation.yml` files.
|
|
29
|
+
*/
|
|
30
|
+
type DocsContentSource = Source<string, unknown, object>;
|
|
31
|
+
interface DocsSource {
|
|
32
|
+
/**
|
|
33
|
+
* A folder of Markdown pages, or a Content Source such as `github({ repo, root })`. A folder is relative to the app
|
|
34
|
+
* root for the Nuxt module and absolute for `createDocsManifest()`. The module watches a folder in development.
|
|
35
|
+
*/
|
|
36
|
+
source: string | DocsContentSource;
|
|
37
|
+
/** Public path at which these pages are mounted. Defaults to `/`. */
|
|
38
|
+
mount?: string;
|
|
39
|
+
/** File globs relative to this source to leave out, such as `partials/**`. */
|
|
40
|
+
exclude?: string[];
|
|
41
|
+
/** Adapt legacy or generated metadata before validation, without changing the source file. */
|
|
42
|
+
frontmatter?: (data: Record<string, unknown>, page: {
|
|
43
|
+
file: string;
|
|
44
|
+
path: string;
|
|
45
|
+
markdown: string;
|
|
46
|
+
}) => Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
/** One entry of `sources`: a folder, a Content Source, or either one with a mount, excludes, or a frontmatter adapter. */
|
|
49
|
+
type DocsSourceInput = string | DocsContentSource | DocsSource;
|
|
50
|
+
/** A docs source with its folder made absolute: `dir` for a folder, `source` for a Content Source. */
|
|
51
|
+
interface ResolvedDocsSource extends Omit<DocsSource, "source"> {
|
|
52
|
+
dir?: string;
|
|
53
|
+
source?: DocsContentSource;
|
|
54
|
+
}
|
|
55
|
+
interface DocsManifestOptions {
|
|
56
|
+
/** Absolute path of the content directory. Used when sources is omitted. */
|
|
57
|
+
dir: string;
|
|
58
|
+
base: string;
|
|
59
|
+
/** Pages from folders and Content Sources. Replaces dir when supplied. */
|
|
60
|
+
sources?: readonly DocsSourceInput[];
|
|
61
|
+
/** Folder that relative folders and the paths of a `glob()` Source resolve from. Defaults to the working directory. */
|
|
62
|
+
rootDir?: string;
|
|
63
|
+
/** Section metadata, overriding the corresponding .navigation.yml fields. */
|
|
64
|
+
sections?: Record<string, DocsSectionFile>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* One Content Source per docs source, with its Markdown pages and its `.navigation.yml` files as YAML documents. A
|
|
68
|
+
* folder is a `glob()` Source of those files. A Content Source, such as `github()`, is read as it is, from `rootDir`.
|
|
69
|
+
*/
|
|
70
|
+
declare function createDocsContent(sources: readonly Pick<ResolvedDocsSource, "dir" | "source">[], rootDir?: string, options?: DocsContentOptions): ContentRuntime;
|
|
71
|
+
/** What `createDocsContent()` adds for `content.check()`. */
|
|
72
|
+
interface DocsContentOptions {
|
|
73
|
+
/** The page URL of a document of the source at `index`, by its Content id, such as `guide/start`, or null for no page. */
|
|
74
|
+
url?: (index: number, id: string) => string | null;
|
|
75
|
+
check?: ContentCheckOptions;
|
|
76
|
+
}
|
|
77
|
+
/** Read every docs source through Content and compute sections, pages, and their order. */
|
|
78
|
+
declare function createDocsManifest(options: DocsManifestOptions): Promise<DocsManifest>;
|
|
79
|
+
//#endregion
|
|
80
|
+
export { createDocsContent as a, checkDocsLinks as c, DocsSourceInput as i, DocsManifestOptions as n, createDocsManifest as o, DocsSource as r, DocsLinkCheckOptions as s, DocsContentSource as t };
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { docsManifestPages, docsPanelOf, docsPanelPages, normalizeDocsBase } from "./navigation.js";
|
|
2
|
+
import { a as docsSectionSchema, i as docsPageSchema, t as docsFrontmatter } from "./schema-DwpXW0VZ.js";
|
|
3
|
+
import { n as docsPageOf, r as docsPagePath } from "./page-GPt09oex.js";
|
|
4
|
+
import { t as docsErrorDiagnostics } from "./error-diagnostics-B_ZOy7kF.js";
|
|
5
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
6
|
+
import { join, matchesGlob, posix, relative, resolve, sep } from "node:path";
|
|
7
|
+
import { ELEMENT_NODE, parse as parse$1, walkSync } from "ultrahtml";
|
|
8
|
+
import { contentSource, defineContent } from "@vite-hub/content";
|
|
9
|
+
import { glob, useSource } from "@vite-hub/source";
|
|
10
|
+
import { parseFrontmatter } from "comark/parse";
|
|
11
|
+
import yaml from "comark-content/plugins/yaml";
|
|
12
|
+
//#region src/check-links.ts
|
|
13
|
+
/** `DOCS_LINKS_BROKEN`, with the list of problems in `problems`. */
|
|
14
|
+
function docsLinkError(problems) {
|
|
15
|
+
return Object.assign(docsErrorDiagnostics.DOCS_LINKS_BROKEN({ problems }), { problems });
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Tests a value against paths, globs, and regular expressions. A site passes one path per page, and a large site checks
|
|
19
|
+
* thousands of links against them, so a plain path is a set lookup and only a pattern with glob characters, extglobs
|
|
20
|
+
* such as `@(a|b)` included, is a glob.
|
|
21
|
+
*/
|
|
22
|
+
function matcher(patterns) {
|
|
23
|
+
const paths = /* @__PURE__ */ new Set();
|
|
24
|
+
const tests = [];
|
|
25
|
+
for (const pattern of patterns ?? []) if (typeof pattern !== "string") tests.push((value) => {
|
|
26
|
+
pattern.lastIndex = 0;
|
|
27
|
+
return pattern.test(value);
|
|
28
|
+
});
|
|
29
|
+
else {
|
|
30
|
+
paths.add(pattern);
|
|
31
|
+
if (/[*?[\]{}(]/.test(pattern)) tests.push((value) => posix.matchesGlob(value, pattern));
|
|
32
|
+
}
|
|
33
|
+
return (value) => paths.has(value) || tests.some((test) => test(value));
|
|
34
|
+
}
|
|
35
|
+
function docsLinkExclusion(patterns) {
|
|
36
|
+
const excluded = matcher(patterns);
|
|
37
|
+
return (url, href) => excluded(href) || excluded(url.pathname) || excluded(url.pathname + url.hash);
|
|
38
|
+
}
|
|
39
|
+
function docsOutputFile(dir, base = "/") {
|
|
40
|
+
const root = resolve(dir);
|
|
41
|
+
const appBase = `/${base.replace(/^\/+|\/+$/g, "")}`.replace(/\/$/, "");
|
|
42
|
+
return (pathname) => {
|
|
43
|
+
if (appBase && pathname !== appBase && !pathname.startsWith(`${appBase}/`)) return;
|
|
44
|
+
let path;
|
|
45
|
+
try {
|
|
46
|
+
path = decodeURIComponent(pathname.slice(appBase.length));
|
|
47
|
+
} catch {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const page = path.replace(/\/$/, "");
|
|
51
|
+
return [
|
|
52
|
+
path,
|
|
53
|
+
`${page}.html`,
|
|
54
|
+
`${page}/index.html`
|
|
55
|
+
].map((candidate) => resolve(root, `.${candidate.startsWith("/") ? candidate : `/${candidate}`}`)).find((file) => file.startsWith(`${root}${sep}`) && existsSync(file) && statSync(file).isFile());
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Check built HTML against the files and fragment ids in the same output, without fetching remote URLs. */
|
|
59
|
+
function checkDocsLinks(options) {
|
|
60
|
+
const root = resolve(options.dir);
|
|
61
|
+
if (!existsSync(root)) throw docsErrorDiagnostics.DOCS_OUTPUT_MISSING({ root });
|
|
62
|
+
const origin = new URL(options.siteUrl).origin;
|
|
63
|
+
const appBase = `/${(options.appBase ?? "/").replace(/^\/+|\/+$/g, "")}`.replace(/\/$/, "");
|
|
64
|
+
const excludedPage = matcher(options.excludePages);
|
|
65
|
+
const excludedLink = docsLinkExclusion(options.excludeLinks);
|
|
66
|
+
const ignoredFragment = matcher(options.ignoreFragments);
|
|
67
|
+
const cache = /* @__PURE__ */ new Map();
|
|
68
|
+
const document = (file) => {
|
|
69
|
+
const cached = cache.get(file);
|
|
70
|
+
if (cached) return cached;
|
|
71
|
+
const result = {
|
|
72
|
+
ids: /* @__PURE__ */ new Set(),
|
|
73
|
+
links: []
|
|
74
|
+
};
|
|
75
|
+
walkSync(parse$1(readFileSync(file, "utf8")), (node) => {
|
|
76
|
+
if (node.type !== ELEMENT_NODE) return;
|
|
77
|
+
for (const key of ["id", "name"]) if (node.attributes[key]) result.ids.add(decode(node.attributes[key]));
|
|
78
|
+
if (node.name === "base" && node.attributes.href && !result.base) result.base = decode(node.attributes.href);
|
|
79
|
+
if (node.name !== "base" && node.attributes.href) result.links.push(decode(node.attributes.href));
|
|
80
|
+
if (/^(audio|embed|iframe|img|input|script|source|track|video)$/.test(node.name) && node.attributes.src) result.links.push(decode(node.attributes.src));
|
|
81
|
+
});
|
|
82
|
+
cache.set(file, result);
|
|
83
|
+
return result;
|
|
84
|
+
};
|
|
85
|
+
const fileOf = docsOutputFile(root, appBase);
|
|
86
|
+
const files = readdirSync(root, {
|
|
87
|
+
recursive: true,
|
|
88
|
+
withFileTypes: true
|
|
89
|
+
}).filter((entry) => entry.isFile() && entry.name.endsWith(".html")).map((entry) => join(entry.parentPath, entry.name));
|
|
90
|
+
const problems = /* @__PURE__ */ new Set();
|
|
91
|
+
let pages = 0;
|
|
92
|
+
for (const file of files) {
|
|
93
|
+
const path = `${appBase}/${relative(root, file).replaceAll("\\", "/")}`.replace(/\/index\.html$/, "/").replace(/\.html$/, "");
|
|
94
|
+
if (excludedPage(path)) continue;
|
|
95
|
+
pages++;
|
|
96
|
+
const page = document(file);
|
|
97
|
+
const pageUrl = new URL(path, origin);
|
|
98
|
+
const base = page.base ? new URL(page.base, pageUrl) : pageUrl;
|
|
99
|
+
for (const link of page.links) {
|
|
100
|
+
let url;
|
|
101
|
+
try {
|
|
102
|
+
url = new URL(link, base);
|
|
103
|
+
} catch {
|
|
104
|
+
problems.add(`${path} has an invalid URL: ${link}`);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (url.origin !== origin || excludedLink(url, link)) continue;
|
|
108
|
+
const redirect = options.redirect?.(url);
|
|
109
|
+
if (redirect) {
|
|
110
|
+
problems.add(`${path} links to ${url.pathname}${url.hash}, which redirects to ${redirect}`);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const target = fileOf(url.pathname);
|
|
114
|
+
if (!target) {
|
|
115
|
+
if (options.isRuntimePath?.(url.pathname)) continue;
|
|
116
|
+
problems.add(`${path} links to ${url.pathname}, which has no page or file`);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (url.hash.length <= 1 || !target.endsWith(".html") || ignoredFragment(url.pathname)) continue;
|
|
120
|
+
let id;
|
|
121
|
+
try {
|
|
122
|
+
id = decodeURIComponent(url.hash.slice(1));
|
|
123
|
+
} catch {
|
|
124
|
+
problems.add(`${path} has an invalid fragment: ${link}`);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (!document(target).ids.has(id)) problems.add(`${path} links to ${url.pathname}${url.hash}, but that page has no element with id "${id}"`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (problems.size) throw docsLinkError([...problems].sort());
|
|
131
|
+
return { pages };
|
|
132
|
+
}
|
|
133
|
+
function decode(text) {
|
|
134
|
+
const named = {
|
|
135
|
+
amp: "&",
|
|
136
|
+
quot: "\"",
|
|
137
|
+
apos: "'",
|
|
138
|
+
lt: "<",
|
|
139
|
+
gt: ">",
|
|
140
|
+
nbsp: "\xA0"
|
|
141
|
+
};
|
|
142
|
+
return text.replace(/&(#x[\da-f]+|#\d+|amp|quot|apos|lt|gt|nbsp);/gi, (entity, code) => {
|
|
143
|
+
if (!code.startsWith("#")) return named[code.toLowerCase()] ?? entity;
|
|
144
|
+
const value = code[1]?.toLowerCase() === "x" ? Number.parseInt(code.slice(2), 16) : Number(code.slice(1));
|
|
145
|
+
return value > 0 && value <= 1114111 ? String.fromCodePoint(value) : "�";
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/manifest.ts
|
|
150
|
+
const isContentSource = (input) => "getKeys" in input;
|
|
151
|
+
/** The `sources` entries with absolute folders, in order. Page `source` names, such as `docs-1`, follow this order. */
|
|
152
|
+
function resolveDocsSources(inputs, rootDir = process.cwd()) {
|
|
153
|
+
return inputs.map((input) => {
|
|
154
|
+
const { source, ...options } = typeof input === "string" || isContentSource(input) ? { source: input } : input;
|
|
155
|
+
const mount = normalizeDocsBase(options.mount ?? "/");
|
|
156
|
+
if (mount.split("/").some((part) => part === "." || part === "..") || /[?#\\]/.test(mount)) throw docsErrorDiagnostics.DOCS_SOURCE_MOUNT_INVALID({ mount });
|
|
157
|
+
return typeof source === "string" ? {
|
|
158
|
+
...options,
|
|
159
|
+
dir: resolve(rootDir, source)
|
|
160
|
+
} : {
|
|
161
|
+
...options,
|
|
162
|
+
source
|
|
163
|
+
};
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
/** A page whose frontmatter or section file does not match the schema: `DOCS_CONTENT_INVALID`. The build stops on it. */
|
|
167
|
+
function docsContentError(file, issues) {
|
|
168
|
+
const details = issues.map((issue) => `${issue.path.map(String).join(".") || "(root)"}: ${issue.message}`).join("; ");
|
|
169
|
+
return docsErrorDiagnostics.DOCS_CONTENT_INVALID({
|
|
170
|
+
details,
|
|
171
|
+
file
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/** The name of the Content Source of a docs source. Content names allow no `-`, so it is not the page's `docs-<index>`. */
|
|
175
|
+
const contentName = (index) => `docs_${index}`;
|
|
176
|
+
/**
|
|
177
|
+
* One Content Source per docs source, with its Markdown pages and its `.navigation.yml` files as YAML documents. A
|
|
178
|
+
* folder is a `glob()` Source of those files. A Content Source, such as `github()`, is read as it is, from `rootDir`.
|
|
179
|
+
*/
|
|
180
|
+
function createDocsContent(sources, rootDir = process.cwd(), options = {}) {
|
|
181
|
+
return defineContent({
|
|
182
|
+
route: false,
|
|
183
|
+
live: false,
|
|
184
|
+
plugins: [yaml({ onError: "throw" })],
|
|
185
|
+
...options.check ? { check: options.check } : {},
|
|
186
|
+
sources: Object.fromEntries(sources.map(({ dir, source }, index) => {
|
|
187
|
+
const input = source ? () => useSource(source, { rootDir }) : dir && existsSync(dir) ? () => useSource(glob({
|
|
188
|
+
include: ["**/*.md", "**/.navigation.yml"],
|
|
189
|
+
dot: true
|
|
190
|
+
}), { rootDir: dir }) : { items: async () => [] };
|
|
191
|
+
const url = options.url;
|
|
192
|
+
return [contentName(index), url ? contentSource(input, { url: ({ id }) => url(index, id) }) : input];
|
|
193
|
+
}))
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* The pages and `.navigation.yml` files of each docs source, from `content.list()`. Content keys a document by its
|
|
198
|
+
* URL, so it lists one of two files with the same URL, such as `guide.md` and `guide/index.md`, and no empty file.
|
|
199
|
+
* Those are read from the Source, so the manifest still names both files or the empty one in a `DOCS_CONTENT_INVALID` error.
|
|
200
|
+
*/
|
|
201
|
+
async function listDocsContent(content, sources) {
|
|
202
|
+
const files = [];
|
|
203
|
+
for (const [index, source] of sources.entries()) {
|
|
204
|
+
const name = contentName(index);
|
|
205
|
+
const reader = content.getSource(name);
|
|
206
|
+
const listed = new Map((await content.list(name)).map((file) => [file.meta.key.slice(name.length + 1), file.data]));
|
|
207
|
+
for (const file of (await reader.keys()).sort()) {
|
|
208
|
+
const navigation = file === ".navigation.yml" || file.endsWith("/.navigation.yml");
|
|
209
|
+
if (!navigation && !file.endsWith(".md")) continue;
|
|
210
|
+
if (source.exclude?.some((pattern) => matchesGlob(file, pattern))) continue;
|
|
211
|
+
const markdown = !navigation && (source.frontmatter || source.source || !listed.has(file)) ? String(await reader.getItem(file)) : void 0;
|
|
212
|
+
const data = listed.get(file) ?? (markdown === void 0 ? {} : parseFrontmatter(markdown).data);
|
|
213
|
+
const label = source.dir ? join(source.dir, file) : file;
|
|
214
|
+
files.push({
|
|
215
|
+
file,
|
|
216
|
+
label,
|
|
217
|
+
data,
|
|
218
|
+
...markdown === void 0 ? {} : { markdown },
|
|
219
|
+
source,
|
|
220
|
+
index
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return files;
|
|
225
|
+
}
|
|
226
|
+
/** Read every docs source through Content and compute sections, pages, and their order. */
|
|
227
|
+
async function createDocsManifest(options) {
|
|
228
|
+
return (await readDocsContent(options)).manifest;
|
|
229
|
+
}
|
|
230
|
+
/** Like `createDocsManifest()`, and also returns the Markdown of the pages of Content Sources. */
|
|
231
|
+
async function readDocsContent(options) {
|
|
232
|
+
const sources = options.sources ? resolveDocsSources(options.sources, options.rootDir) : [{ dir: options.dir }];
|
|
233
|
+
const listed = await listDocsContent(createDocsContent(sources, options.rootDir), sources);
|
|
234
|
+
return {
|
|
235
|
+
manifest: docsManifestOf(options, listed),
|
|
236
|
+
files: listed.flatMap((entry) => entry.source.source && entry.markdown !== void 0 && entry.file.endsWith(".md") ? [{
|
|
237
|
+
source: `docs-${entry.index}`,
|
|
238
|
+
file: entry.file,
|
|
239
|
+
markdown: entry.markdown
|
|
240
|
+
}] : [])
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function docsManifestOf(options, listed) {
|
|
244
|
+
const base = normalizeDocsBase(options.base);
|
|
245
|
+
const files = /* @__PURE__ */ new Map();
|
|
246
|
+
/** The `.navigation.yml` files of each logical folder, such as `docs/kv`, in source order. */
|
|
247
|
+
const folders = /* @__PURE__ */ new Map();
|
|
248
|
+
for (const entry of listed) {
|
|
249
|
+
const logical = joinPath(normalizeDocsBase(entry.source.mount ?? "/"), entry.file).slice(1);
|
|
250
|
+
if (!entry.file.endsWith(".md")) {
|
|
251
|
+
const folder = logical.replace(/\/?\.navigation\.yml$/, "");
|
|
252
|
+
folders.set(folder, [...folders.get(folder) ?? [], entry]);
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
const previous = files.get(logical);
|
|
256
|
+
if (previous) throw docsContentError(entry.label, [{
|
|
257
|
+
path: ["path"],
|
|
258
|
+
message: `${logical} is also produced by ${previous.label}`
|
|
259
|
+
}]);
|
|
260
|
+
files.set(logical, entry);
|
|
261
|
+
}
|
|
262
|
+
const read = (logical, id, path) => {
|
|
263
|
+
const entry = files.get(logical);
|
|
264
|
+
const fields = entry.source.frontmatter ? entry.source.frontmatter(entry.data, {
|
|
265
|
+
file: entry.file,
|
|
266
|
+
path,
|
|
267
|
+
markdown: entry.markdown ?? ""
|
|
268
|
+
}) : entry.data;
|
|
269
|
+
return {
|
|
270
|
+
...docsPageOf(parse$2(entry.label, docsPageSchema, docsFrontmatter(fields)), {
|
|
271
|
+
id,
|
|
272
|
+
path,
|
|
273
|
+
file: entry.file
|
|
274
|
+
}),
|
|
275
|
+
...options.sources ? { source: `docs-${entry.index}` } : {}
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
const prefix = base === "/" ? "" : `${base.slice(1)}/`;
|
|
279
|
+
const rootFile = `${prefix}index.md`;
|
|
280
|
+
const sections = [...new Set([...files.keys()].filter((file) => file.startsWith(prefix) && file.slice(prefix.length).includes("/")).map((file) => file.slice(prefix.length).split("/")[0]))].map((id, index) => {
|
|
281
|
+
const sectionPrefix = `${prefix}${id}/`;
|
|
282
|
+
const pages = [...files.keys()].filter((file) => file.startsWith(sectionPrefix)).map((file) => {
|
|
283
|
+
const pageId = idOf(file.slice(sectionPrefix.length));
|
|
284
|
+
return read(file, pageId, pageId === "index" ? joinPath(base, id) : joinPath(base, id, pageId));
|
|
285
|
+
}).sort((left, right) => left.id === "index" ? -1 : right.id === "index" ? 1 : left.order - right.order || left.id.localeCompare(right.id));
|
|
286
|
+
let fields = {};
|
|
287
|
+
for (const file of folders.get(sectionPrefix.slice(0, -1)) ?? []) fields = {
|
|
288
|
+
...fields,
|
|
289
|
+
...parse$2(file.label, docsSectionSchema, file.data)
|
|
290
|
+
};
|
|
291
|
+
const navigation = parse$2(id, docsSectionSchema, {
|
|
292
|
+
...fields,
|
|
293
|
+
...options.sections?.[id]
|
|
294
|
+
});
|
|
295
|
+
const overview = pages.find((page) => page.id === "index");
|
|
296
|
+
return {
|
|
297
|
+
id,
|
|
298
|
+
path: joinPath(base, id),
|
|
299
|
+
title: navigation.title ?? overview?.sourceTitle ?? titleCase(id),
|
|
300
|
+
description: overview?.description ?? null,
|
|
301
|
+
icon: navigation.icon ?? overview?.icon ?? null,
|
|
302
|
+
category: navigation.category ?? null,
|
|
303
|
+
group: navigation.group ?? null,
|
|
304
|
+
fold: navigation.fold ?? false,
|
|
305
|
+
related: navigation.related ?? [],
|
|
306
|
+
order: navigation.order ?? index,
|
|
307
|
+
pages
|
|
308
|
+
};
|
|
309
|
+
}).sort((left, right) => left.order - right.order || left.title.localeCompare(right.title));
|
|
310
|
+
const pages = [...files.keys()].filter((file) => !file.startsWith(prefix) || !file.slice(prefix.length).includes("/") && file !== rootFile).map((file) => read(file, "", docsPagePath(file))).sort((left, right) => left.path.localeCompare(right.path));
|
|
311
|
+
const manifest = {
|
|
312
|
+
base,
|
|
313
|
+
root: files.has(rootFile) ? read(rootFile, "index", base) : null,
|
|
314
|
+
sections,
|
|
315
|
+
pages
|
|
316
|
+
};
|
|
317
|
+
const paths = /* @__PURE__ */ new Map();
|
|
318
|
+
for (const page of docsManifestPages(manifest)) {
|
|
319
|
+
const existing = paths.get(page.path);
|
|
320
|
+
if (existing) throw docsContentError(join(options.dir, page.file), [{
|
|
321
|
+
path: ["path"],
|
|
322
|
+
message: `${page.path} is also produced by ${existing}`
|
|
323
|
+
}]);
|
|
324
|
+
paths.set(page.path, page.file);
|
|
325
|
+
}
|
|
326
|
+
return manifest;
|
|
327
|
+
}
|
|
328
|
+
function parse$2(file, schema, input) {
|
|
329
|
+
const result = schema.safeParse(input);
|
|
330
|
+
if (!result.success) throw docsContentError(file, result.error.issues);
|
|
331
|
+
return result.data;
|
|
332
|
+
}
|
|
333
|
+
/** `index.md` is the folder's page: `operations/index.md` is `operations`. */
|
|
334
|
+
function idOf(file) {
|
|
335
|
+
return file.replaceAll("\\", "/").replace(/\.md$/, "").replace(/(^|\/)index$/, "") || "index";
|
|
336
|
+
}
|
|
337
|
+
/** A page with only its `DocsAppPage` fields. */
|
|
338
|
+
function appPage(full) {
|
|
339
|
+
return {
|
|
340
|
+
id: full.id,
|
|
341
|
+
path: full.path,
|
|
342
|
+
title: full.title,
|
|
343
|
+
sourceTitle: full.sourceTitle,
|
|
344
|
+
description: full.description,
|
|
345
|
+
icon: full.icon,
|
|
346
|
+
layout: full.layout,
|
|
347
|
+
tutorial: full.tutorial,
|
|
348
|
+
codePanel: full.codePanel,
|
|
349
|
+
sidebar: full.sidebar,
|
|
350
|
+
toc: full.toc,
|
|
351
|
+
kind: full.kind,
|
|
352
|
+
group: full.group,
|
|
353
|
+
navigation: full.navigation,
|
|
354
|
+
panel: full.panel,
|
|
355
|
+
order: full.order
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* The manifest that every page of the app loads, and the panels it loads on demand. Only a panel's own sidebar lists
|
|
360
|
+
* the pages inside it, such as the thousands of generated diagnostics pages, so they stay out of the other pages. A
|
|
361
|
+
* panel's Overview stays, with the number of listed pages inside it. A section with a panel inside another panel keeps
|
|
362
|
+
* all its pages, since loading one panel would not restore the order of the other's sidebar.
|
|
363
|
+
*/
|
|
364
|
+
function docsAppManifest(manifest, options) {
|
|
365
|
+
const panels = [];
|
|
366
|
+
const sections = manifest.sections.map((section) => {
|
|
367
|
+
const overviews = section.pages.filter((page) => page.panel);
|
|
368
|
+
const nested = overviews.some((panel) => overviews.some((outer) => panel.id.startsWith(`${outer.id}/`)));
|
|
369
|
+
if (!options.panels || !overviews.length || nested) return {
|
|
370
|
+
...section,
|
|
371
|
+
pages: section.pages.map(appPage)
|
|
372
|
+
};
|
|
373
|
+
for (const panel of overviews) {
|
|
374
|
+
const pages = docsPanelPages(section, panel).filter((page) => page.id !== panel.id);
|
|
375
|
+
if (pages.length) panels.push({
|
|
376
|
+
path: panel.path,
|
|
377
|
+
section: section.id,
|
|
378
|
+
pages: pages.map(appPage)
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
const pages = section.pages.filter((page) => page.panel || !docsPanelOf(section, page)).map((page) => page.panel ? {
|
|
382
|
+
...appPage(page),
|
|
383
|
+
panelSize: docsPanelPages(section, page).filter((candidate) => candidate.navigation && candidate.id !== page.id).length
|
|
384
|
+
} : appPage(page));
|
|
385
|
+
return {
|
|
386
|
+
...section,
|
|
387
|
+
pages
|
|
388
|
+
};
|
|
389
|
+
});
|
|
390
|
+
return {
|
|
391
|
+
manifest: {
|
|
392
|
+
...manifest,
|
|
393
|
+
root: manifest.root && appPage(manifest.root),
|
|
394
|
+
sections,
|
|
395
|
+
pages: manifest.pages.map(appPage)
|
|
396
|
+
},
|
|
397
|
+
panels
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/** JSON of app pages. A `sourceTitle` equal to `title` is left out, and the module fills it back when it loads. */
|
|
401
|
+
function appJson(value) {
|
|
402
|
+
const json = JSON.stringify(value, (_key, field) => field && typeof field === "object" && "sourceTitle" in field && "title" in field && field.sourceTitle === field.title ? {
|
|
403
|
+
...field,
|
|
404
|
+
sourceTitle: void 0
|
|
405
|
+
} : field);
|
|
406
|
+
return JSON.stringify(json);
|
|
407
|
+
}
|
|
408
|
+
/** The module that the app imports as `#docs/manifest`. */
|
|
409
|
+
function docsAppManifestSource(manifest) {
|
|
410
|
+
return [
|
|
411
|
+
`const manifest = JSON.parse(${appJson(manifest)})`,
|
|
412
|
+
"for (const page of [manifest.root, ...manifest.sections.flatMap(section => section.pages), ...manifest.pages]) if (page) page.sourceTitle ??= page.title",
|
|
413
|
+
"export default manifest",
|
|
414
|
+
""
|
|
415
|
+
].join("\n");
|
|
416
|
+
}
|
|
417
|
+
/** The module of one panel's pages. */
|
|
418
|
+
function docsAppPanelSource(panel) {
|
|
419
|
+
return [
|
|
420
|
+
`const pages = JSON.parse(${appJson(panel.pages)})`,
|
|
421
|
+
"for (const page of pages) page.sourceTitle ??= page.title",
|
|
422
|
+
"export default pages",
|
|
423
|
+
""
|
|
424
|
+
].join("\n");
|
|
425
|
+
}
|
|
426
|
+
/** With the base `/`, the section `guide` is `/guide`, not `//guide`. */
|
|
427
|
+
function joinPath(base, ...segments) {
|
|
428
|
+
return `${base.replace(/\/+$/, "")}/${segments.join("/")}`;
|
|
429
|
+
}
|
|
430
|
+
function titleCase(input) {
|
|
431
|
+
return input.split(/[-/]/g).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
|
|
432
|
+
}
|
|
433
|
+
//#endregion
|
|
434
|
+
export { docsAppManifestSource as a, resolveDocsSources as c, docsLinkExclusion as d, docsOutputFile as f, docsAppManifest as i, checkDocsLinks as l, createDocsContent as n, docsAppPanelSource as o, createDocsManifest as r, readDocsContent as s, contentName as t, docsLinkError as u };
|