@farming-labs/docs 0.1.1-beta.4 → 0.1.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.
@@ -0,0 +1,100 @@
1
+ import { A as SidebarConfig, C as OpenGraphImage, D as PageOpenGraph, E as PageFrontmatter, F as ThemeToggleConfig, I as TypographyConfig, L as UIConfig, M as SidebarNode, N as SidebarPageNode, O as PageTwitter, P as SidebarTree, S as OpenDocsProvider, T as PageActionsConfig, _ as GithubConfig, a as CopyMarkdownConfig, b as OGConfig, c as DocsFeedbackValue, d as DocsMcpToolsConfig, f as DocsMetadata, g as FontStyle, h as FeedbackConfig, i as CodeBlockCopyData, j as SidebarFolderNode, k as SidebarComponentProps, l as DocsI18nConfig, m as DocsTheme, n as ApiReferenceConfig, o as DocsConfig, p as DocsNav, r as BreadcrumbConfig, s as DocsFeedbackData, t as AIConfig, u as DocsMcpConfig, v as LastUpdatedConfig, w as OrderingItem, x as OpenDocsConfig, y as LlmsTxtConfig } from "./types-Bd3kyFF1.mjs";
2
+
3
+ //#region src/define-docs.d.ts
4
+ /**
5
+ * Define docs configuration. Validates and returns the config.
6
+ */
7
+ declare function defineDocs(config: DocsConfig): DocsConfig;
8
+ //#endregion
9
+ //#region src/utils.d.ts
10
+ /**
11
+ * Deep merge utility for theme overrides.
12
+ * Merges objects recursively; later values override earlier ones.
13
+ */
14
+ declare function deepMerge<T extends Record<string, unknown>>(target: T, ...sources: Partial<T>[]): T;
15
+ //#endregion
16
+ //#region src/create-theme.d.ts
17
+ /**
18
+ * Create a theme preset factory.
19
+ *
20
+ * Returns a function that accepts optional overrides and deep-merges them
21
+ * with the base theme defaults. This is the same pattern used by the
22
+ * built-in `fumadocs()`, `darksharp()`, and `pixelBorder()` presets.
23
+ *
24
+ * @param baseTheme - The default theme configuration
25
+ * @returns A factory function `(overrides?) => DocsTheme`
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { createTheme } from "@farming-labs/docs";
30
+ *
31
+ * export const myTheme = createTheme({
32
+ * name: "my-theme",
33
+ * ui: {
34
+ * colors: { primary: "#6366f1" },
35
+ * layout: { contentWidth: 800 },
36
+ * },
37
+ * });
38
+ * ```
39
+ */
40
+ declare function createTheme(baseTheme: DocsTheme): (overrides?: Partial<DocsTheme>) => DocsTheme;
41
+ /**
42
+ * Extend an existing theme preset with additional defaults.
43
+ *
44
+ * Useful when you want to build on top of an existing theme (e.g. fumadocs)
45
+ * rather than starting from scratch.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { extendTheme } from "@farming-labs/docs";
50
+ * import { fumadocs } from "@farming-labs/theme/default";
51
+ *
52
+ * // Start with fumadocs defaults, override some values
53
+ * export const myTheme = extendTheme(fumadocs(), {
54
+ * name: "my-custom-fumadocs",
55
+ * ui: { colors: { primary: "#22c55e" } },
56
+ * });
57
+ * ```
58
+ */
59
+ declare function extendTheme(baseTheme: DocsTheme, extensions: Partial<DocsTheme>): DocsTheme;
60
+ //#endregion
61
+ //#region src/i18n.d.ts
62
+ interface ResolvedDocsI18n {
63
+ locales: string[];
64
+ defaultLocale: string;
65
+ }
66
+ interface DocsPathMatch {
67
+ /** Slug path relative to the docs root (no leading slash). */
68
+ slug: string;
69
+ /** Entry path used for URLs (no locale segment). */
70
+ entryPath: string;
71
+ }
72
+ declare function resolveDocsI18n(config?: DocsI18nConfig | null): ResolvedDocsI18n | null;
73
+ declare function resolveDocsLocale(searchParams: URLSearchParams, i18n?: ResolvedDocsI18n | null): string | undefined;
74
+ declare function resolveDocsPath(pathname: string, entry: string): DocsPathMatch;
75
+ //#endregion
76
+ //#region src/metadata.d.ts
77
+ /**
78
+ * Resolve page title using metadata titleTemplate.
79
+ * %s is replaced with page title.
80
+ */
81
+ declare function resolveTitle(pageTitle: string, metadata?: DocsMetadata): string;
82
+ /**
83
+ * Resolve OG image URL for a page.
84
+ * Prefers page.openGraph.images[0], then page.ogImage, then config endpoint/default.
85
+ */
86
+ declare function resolveOGImage(page: PageFrontmatter, ogConfig?: OGConfig, baseUrl?: string): string | undefined;
87
+ /**
88
+ * Build the Open Graph metadata object for a page.
89
+ * When the page has openGraph in frontmatter, uses it (with title/description filled from page if omitted).
90
+ * Otherwise uses ogImage or config (dynamic endpoint / defaultImage).
91
+ */
92
+ declare function buildPageOpenGraph(page: Pick<PageFrontmatter, "title" | "description" | "ogImage" | "openGraph">, ogConfig?: OGConfig, baseUrl?: string): PageOpenGraph | undefined;
93
+ /**
94
+ * Build the Twitter card metadata object for a page.
95
+ * When the page has twitter in frontmatter, uses it.
96
+ * Otherwise builds from ogImage or config (dynamic endpoint).
97
+ */
98
+ declare function buildPageTwitter(page: Pick<PageFrontmatter, "title" | "description" | "ogImage" | "openGraph" | "twitter">, ogConfig?: OGConfig, baseUrl?: string): PageTwitter | undefined;
99
+ //#endregion
100
+ export { type AIConfig, type ApiReferenceConfig, type BreadcrumbConfig, type CodeBlockCopyData, type CopyMarkdownConfig, type DocsConfig, type DocsFeedbackData, type DocsFeedbackValue, type DocsI18nConfig, type DocsMcpConfig, type DocsMcpToolsConfig, type DocsMetadata, type DocsNav, type DocsPathMatch, type DocsTheme, type FeedbackConfig, type FontStyle, type GithubConfig, type LastUpdatedConfig, type LlmsTxtConfig, type OGConfig, type OpenDocsConfig, type OpenDocsProvider, type OpenGraphImage, type OrderingItem, type PageActionsConfig, type PageFrontmatter, type PageOpenGraph, type PageTwitter, type ResolvedDocsI18n, type SidebarComponentProps, type SidebarConfig, type SidebarFolderNode, type SidebarNode, type SidebarPageNode, type SidebarTree, type ThemeToggleConfig, type TypographyConfig, type UIConfig, buildPageOpenGraph, buildPageTwitter, createTheme, deepMerge, defineDocs, extendTheme, resolveDocsI18n, resolveDocsLocale, resolveDocsPath, resolveOGImage, resolveTitle };
package/dist/index.mjs ADDED
@@ -0,0 +1,227 @@
1
+ //#region src/define-docs.ts
2
+ /**
3
+ * Define docs configuration. Validates and returns the config.
4
+ */
5
+ function defineDocs(config) {
6
+ return {
7
+ entry: config.entry ?? "docs",
8
+ contentDir: config.contentDir,
9
+ i18n: config.i18n,
10
+ theme: config.theme,
11
+ nav: config.nav,
12
+ github: config.github,
13
+ themeToggle: config.themeToggle,
14
+ breadcrumb: config.breadcrumb,
15
+ sidebar: config.sidebar,
16
+ components: config.components,
17
+ onCopyClick: config.onCopyClick,
18
+ feedback: config.feedback,
19
+ mcp: config.mcp,
20
+ icons: config.icons,
21
+ pageActions: config.pageActions,
22
+ lastUpdated: config.lastUpdated,
23
+ llmsTxt: config.llmsTxt,
24
+ ai: config.ai,
25
+ ordering: config.ordering,
26
+ metadata: config.metadata,
27
+ og: config.og,
28
+ apiReference: config.apiReference
29
+ };
30
+ }
31
+
32
+ //#endregion
33
+ //#region src/utils.ts
34
+ /**
35
+ * Deep merge utility for theme overrides.
36
+ * Merges objects recursively; later values override earlier ones.
37
+ */
38
+ function deepMerge(target, ...sources) {
39
+ if (!sources.length) return target;
40
+ const source = sources.shift();
41
+ if (!source) return target;
42
+ const result = { ...target };
43
+ for (const key of Object.keys(source)) {
44
+ const sourceVal = source[key];
45
+ const targetVal = result[key];
46
+ if (sourceVal && typeof sourceVal === "object" && !Array.isArray(sourceVal) && targetVal && typeof targetVal === "object" && !Array.isArray(targetVal)) result[key] = deepMerge(targetVal, sourceVal);
47
+ else if (sourceVal !== void 0) result[key] = sourceVal;
48
+ }
49
+ if (sources.length) return deepMerge(result, ...sources);
50
+ return result;
51
+ }
52
+
53
+ //#endregion
54
+ //#region src/create-theme.ts
55
+ /**
56
+ * Create a theme preset factory.
57
+ *
58
+ * Returns a function that accepts optional overrides and deep-merges them
59
+ * with the base theme defaults. This is the same pattern used by the
60
+ * built-in `fumadocs()`, `darksharp()`, and `pixelBorder()` presets.
61
+ *
62
+ * @param baseTheme - The default theme configuration
63
+ * @returns A factory function `(overrides?) => DocsTheme`
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import { createTheme } from "@farming-labs/docs";
68
+ *
69
+ * export const myTheme = createTheme({
70
+ * name: "my-theme",
71
+ * ui: {
72
+ * colors: { primary: "#6366f1" },
73
+ * layout: { contentWidth: 800 },
74
+ * },
75
+ * });
76
+ * ```
77
+ */
78
+ function createTheme(baseTheme) {
79
+ return function themeFactory(overrides = {}) {
80
+ const merged = deepMerge(baseTheme, overrides);
81
+ if (overrides.ui?.colors) merged._userColorOverrides = { ...overrides.ui.colors };
82
+ return merged;
83
+ };
84
+ }
85
+ /**
86
+ * Extend an existing theme preset with additional defaults.
87
+ *
88
+ * Useful when you want to build on top of an existing theme (e.g. fumadocs)
89
+ * rather than starting from scratch.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * import { extendTheme } from "@farming-labs/docs";
94
+ * import { fumadocs } from "@farming-labs/theme/default";
95
+ *
96
+ * // Start with fumadocs defaults, override some values
97
+ * export const myTheme = extendTheme(fumadocs(), {
98
+ * name: "my-custom-fumadocs",
99
+ * ui: { colors: { primary: "#22c55e" } },
100
+ * });
101
+ * ```
102
+ */
103
+ function extendTheme(baseTheme, extensions) {
104
+ return deepMerge(baseTheme, extensions);
105
+ }
106
+
107
+ //#endregion
108
+ //#region src/i18n.ts
109
+ function normalizeSegment(value) {
110
+ return value.replace(/^\/+|\/+$/g, "");
111
+ }
112
+ function splitSegments(value) {
113
+ const cleaned = normalizeSegment(value);
114
+ return cleaned ? cleaned.split("/").filter(Boolean) : [];
115
+ }
116
+ function resolveDocsI18n(config) {
117
+ if (!config || !Array.isArray(config.locales)) return null;
118
+ const locales = Array.from(new Set(config.locales.map((l) => l.trim()).filter(Boolean)));
119
+ if (locales.length === 0) return null;
120
+ return {
121
+ locales,
122
+ defaultLocale: config.defaultLocale && locales.includes(config.defaultLocale) ? config.defaultLocale : locales[0]
123
+ };
124
+ }
125
+ function resolveDocsLocale(searchParams, i18n) {
126
+ if (!i18n) return void 0;
127
+ const raw = searchParams.get("lang") ?? searchParams.get("locale");
128
+ if (!raw) return void 0;
129
+ if (i18n.locales.includes(raw)) return raw;
130
+ return i18n.defaultLocale;
131
+ }
132
+ function resolveDocsPath(pathname, entry) {
133
+ const entryBase = normalizeSegment(entry || "docs") || "docs";
134
+ const entryParts = splitSegments(entryBase);
135
+ const pathParts = splitSegments(pathname);
136
+ let rest = pathParts;
137
+ if (entryParts.length > 0) {
138
+ if (pathParts.slice(0, entryParts.length).join("/") === entryParts.join("/")) rest = pathParts.slice(entryParts.length);
139
+ }
140
+ return {
141
+ slug: rest.join("/"),
142
+ entryPath: entryBase
143
+ };
144
+ }
145
+
146
+ //#endregion
147
+ //#region src/metadata.ts
148
+ /**
149
+ * Resolve page title using metadata titleTemplate.
150
+ * %s is replaced with page title.
151
+ */
152
+ function resolveTitle(pageTitle, metadata) {
153
+ return (metadata?.titleTemplate ?? "%s").replace("%s", pageTitle);
154
+ }
155
+ /**
156
+ * Resolve OG image URL for a page.
157
+ * Prefers page.openGraph.images[0], then page.ogImage, then config endpoint/default.
158
+ */
159
+ function resolveOGImage(page, ogConfig, baseUrl) {
160
+ if (page.openGraph?.images?.length) return resolveImageUrl(page.openGraph.images[0].url, baseUrl);
161
+ if (!ogConfig?.enabled) return void 0;
162
+ if (page.ogImage) return resolveImageUrl(page.ogImage, baseUrl);
163
+ if (ogConfig.type === "dynamic" && ogConfig.endpoint) return `${baseUrl ?? ""}${ogConfig.endpoint}`;
164
+ return ogConfig.defaultImage;
165
+ }
166
+ function resolveImageUrl(url, baseUrl) {
167
+ if (url.startsWith("/") || url.startsWith("http")) return url;
168
+ const base = baseUrl ?? "";
169
+ return `${base}${base.length > 0 && !base.endsWith("/") ? "/" : ""}${url}`;
170
+ }
171
+ /**
172
+ * Build the Open Graph metadata object for a page.
173
+ * When the page has openGraph in frontmatter, uses it (with title/description filled from page if omitted).
174
+ * Otherwise uses ogImage or config (dynamic endpoint / defaultImage).
175
+ */
176
+ function buildPageOpenGraph(page, ogConfig, baseUrl) {
177
+ if (page.openGraph) {
178
+ const images = page.openGraph.images?.length ? page.openGraph.images.map((img) => ({
179
+ url: resolveImageUrl(img.url, baseUrl),
180
+ width: img.width ?? 1200,
181
+ height: img.height ?? 630
182
+ })) : void 0;
183
+ return {
184
+ title: page.openGraph.title ?? page.title,
185
+ description: page.openGraph.description ?? page.description,
186
+ ...images && { images }
187
+ };
188
+ }
189
+ const url = resolveOGImage(page, ogConfig, baseUrl);
190
+ if (!url) return void 0;
191
+ return {
192
+ title: page.title,
193
+ ...page.description && { description: page.description },
194
+ images: [{
195
+ url,
196
+ width: 1200,
197
+ height: 630
198
+ }]
199
+ };
200
+ }
201
+ /**
202
+ * Build the Twitter card metadata object for a page.
203
+ * When the page has twitter in frontmatter, uses it.
204
+ * Otherwise builds from ogImage or config (dynamic endpoint).
205
+ */
206
+ function buildPageTwitter(page, ogConfig, baseUrl) {
207
+ if (page.twitter) {
208
+ const images = page.twitter.images?.length ? page.twitter.images.map((url) => resolveImageUrl(url, baseUrl)) : void 0;
209
+ return {
210
+ ...page.twitter.card && { card: page.twitter.card },
211
+ ...page.twitter.title !== void 0 && { title: page.twitter.title },
212
+ ...page.twitter.description !== void 0 && { description: page.twitter.description },
213
+ ...images && { images }
214
+ };
215
+ }
216
+ const url = resolveOGImage(page, ogConfig, baseUrl);
217
+ if (!url) return void 0;
218
+ return {
219
+ card: "summary_large_image",
220
+ title: page.title,
221
+ ...page.description && { description: page.description },
222
+ images: [url]
223
+ };
224
+ }
225
+
226
+ //#endregion
227
+ export { buildPageOpenGraph, buildPageTwitter, createTheme, deepMerge, defineDocs, extendTheme, resolveDocsI18n, resolveDocsLocale, resolveDocsPath, resolveOGImage, resolveTitle };
package/dist/mcp.d.mts ADDED
@@ -0,0 +1,86 @@
1
+ import { u as DocsMcpConfig, w as OrderingItem } from "./types-Bd3kyFF1.mjs";
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp";
3
+
4
+ //#region src/mcp.d.ts
5
+ interface DocsMcpPage {
6
+ slug: string;
7
+ url: string;
8
+ title: string;
9
+ description?: string;
10
+ icon?: string;
11
+ content: string;
12
+ rawContent?: string;
13
+ }
14
+ interface DocsMcpPageNode {
15
+ type: "page";
16
+ name: string;
17
+ url: string;
18
+ icon?: string;
19
+ description?: string;
20
+ }
21
+ interface DocsMcpFolderNode {
22
+ type: "folder";
23
+ name: string;
24
+ icon?: string;
25
+ index?: DocsMcpPageNode;
26
+ children: DocsMcpNavigationNode[];
27
+ }
28
+ type DocsMcpNavigationNode = DocsMcpPageNode | DocsMcpFolderNode;
29
+ interface DocsMcpNavigationTree {
30
+ name: string;
31
+ children: DocsMcpNavigationNode[];
32
+ }
33
+ interface DocsMcpSource {
34
+ entry?: string;
35
+ siteTitle?: string;
36
+ getPages(locale?: string): DocsMcpPage[] | Promise<DocsMcpPage[]>;
37
+ getNavigation(locale?: string): DocsMcpNavigationTree | Promise<DocsMcpNavigationTree>;
38
+ }
39
+ interface DocsMcpResolvedConfig {
40
+ enabled: boolean;
41
+ route: string;
42
+ name: string;
43
+ version: string;
44
+ tools: {
45
+ listPages: boolean;
46
+ readPage: boolean;
47
+ searchDocs: boolean;
48
+ getNavigation: boolean;
49
+ };
50
+ }
51
+ interface DocsMcpHttpHandlers {
52
+ GET: (context: {
53
+ request: Request;
54
+ }) => Promise<Response>;
55
+ POST: (context: {
56
+ request: Request;
57
+ }) => Promise<Response>;
58
+ DELETE: (context: {
59
+ request: Request;
60
+ }) => Promise<Response>;
61
+ }
62
+ interface CreateDocsMcpServerOptions {
63
+ source: DocsMcpSource;
64
+ mcp?: boolean | DocsMcpConfig;
65
+ defaultName?: string;
66
+ defaultVersion?: string;
67
+ }
68
+ interface CreateFilesystemDocsMcpSourceOptions {
69
+ rootDir?: string;
70
+ entry?: string;
71
+ contentDir?: string;
72
+ siteTitle?: string;
73
+ ordering?: "alphabetical" | "numeric" | OrderingItem[];
74
+ }
75
+ declare function normalizeDocsMcpRoute(route?: string): string;
76
+ declare function resolveDocsMcpConfig(mcp?: boolean | DocsMcpConfig, defaults?: {
77
+ defaultName?: string;
78
+ defaultVersion?: string;
79
+ defaultRoute?: string;
80
+ }): DocsMcpResolvedConfig;
81
+ declare function createFilesystemDocsMcpSource(options?: CreateFilesystemDocsMcpSourceOptions): DocsMcpSource;
82
+ declare function createDocsMcpServer(options: CreateDocsMcpServerOptions): Promise<McpServer>;
83
+ declare function createDocsMcpHttpHandler(options: CreateDocsMcpServerOptions): DocsMcpHttpHandlers;
84
+ declare function runDocsMcpStdio(options: CreateDocsMcpServerOptions): Promise<void>;
85
+ //#endregion
86
+ export { DocsMcpFolderNode, DocsMcpHttpHandlers, DocsMcpNavigationNode, DocsMcpNavigationTree, DocsMcpPage, DocsMcpPageNode, DocsMcpResolvedConfig, DocsMcpSource, createDocsMcpHttpHandler, createDocsMcpServer, createFilesystemDocsMcpSource, normalizeDocsMcpRoute, resolveDocsMcpConfig, runDocsMcpStdio };