@farming-labs/docs 0.0.33-beta.1 → 0.0.34
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/package.json +1 -1
- package/dist/cli/index.d.mts +0 -5
- package/dist/cli/index.mjs +0 -2812
- package/dist/index.d.mts +0 -1380
- package/dist/index.mjs +0 -223
package/dist/index.mjs
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
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
|
-
icons: config.icons,
|
|
18
|
-
pageActions: config.pageActions,
|
|
19
|
-
lastUpdated: config.lastUpdated,
|
|
20
|
-
llmsTxt: config.llmsTxt,
|
|
21
|
-
ai: config.ai,
|
|
22
|
-
ordering: config.ordering,
|
|
23
|
-
metadata: config.metadata,
|
|
24
|
-
og: config.og
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region src/utils.ts
|
|
30
|
-
/**
|
|
31
|
-
* Deep merge utility for theme overrides.
|
|
32
|
-
* Merges objects recursively; later values override earlier ones.
|
|
33
|
-
*/
|
|
34
|
-
function deepMerge(target, ...sources) {
|
|
35
|
-
if (!sources.length) return target;
|
|
36
|
-
const source = sources.shift();
|
|
37
|
-
if (!source) return target;
|
|
38
|
-
const result = { ...target };
|
|
39
|
-
for (const key of Object.keys(source)) {
|
|
40
|
-
const sourceVal = source[key];
|
|
41
|
-
const targetVal = result[key];
|
|
42
|
-
if (sourceVal && typeof sourceVal === "object" && !Array.isArray(sourceVal) && targetVal && typeof targetVal === "object" && !Array.isArray(targetVal)) result[key] = deepMerge(targetVal, sourceVal);
|
|
43
|
-
else if (sourceVal !== void 0) result[key] = sourceVal;
|
|
44
|
-
}
|
|
45
|
-
if (sources.length) return deepMerge(result, ...sources);
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region src/create-theme.ts
|
|
51
|
-
/**
|
|
52
|
-
* Create a theme preset factory.
|
|
53
|
-
*
|
|
54
|
-
* Returns a function that accepts optional overrides and deep-merges them
|
|
55
|
-
* with the base theme defaults. This is the same pattern used by the
|
|
56
|
-
* built-in `fumadocs()`, `darksharp()`, and `pixelBorder()` presets.
|
|
57
|
-
*
|
|
58
|
-
* @param baseTheme - The default theme configuration
|
|
59
|
-
* @returns A factory function `(overrides?) => DocsTheme`
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```ts
|
|
63
|
-
* import { createTheme } from "@farming-labs/docs";
|
|
64
|
-
*
|
|
65
|
-
* export const myTheme = createTheme({
|
|
66
|
-
* name: "my-theme",
|
|
67
|
-
* ui: {
|
|
68
|
-
* colors: { primary: "#6366f1" },
|
|
69
|
-
* layout: { contentWidth: 800 },
|
|
70
|
-
* },
|
|
71
|
-
* });
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
function createTheme(baseTheme) {
|
|
75
|
-
return function themeFactory(overrides = {}) {
|
|
76
|
-
const merged = deepMerge(baseTheme, overrides);
|
|
77
|
-
if (overrides.ui?.colors) merged._userColorOverrides = { ...overrides.ui.colors };
|
|
78
|
-
return merged;
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Extend an existing theme preset with additional defaults.
|
|
83
|
-
*
|
|
84
|
-
* Useful when you want to build on top of an existing theme (e.g. fumadocs)
|
|
85
|
-
* rather than starting from scratch.
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```ts
|
|
89
|
-
* import { extendTheme } from "@farming-labs/docs";
|
|
90
|
-
* import { fumadocs } from "@farming-labs/theme/default";
|
|
91
|
-
*
|
|
92
|
-
* // Start with fumadocs defaults, override some values
|
|
93
|
-
* export const myTheme = extendTheme(fumadocs(), {
|
|
94
|
-
* name: "my-custom-fumadocs",
|
|
95
|
-
* ui: { colors: { primary: "#22c55e" } },
|
|
96
|
-
* });
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
function extendTheme(baseTheme, extensions) {
|
|
100
|
-
return deepMerge(baseTheme, extensions);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
//#endregion
|
|
104
|
-
//#region src/i18n.ts
|
|
105
|
-
function normalizeSegment(value) {
|
|
106
|
-
return value.replace(/^\/+|\/+$/g, "");
|
|
107
|
-
}
|
|
108
|
-
function splitSegments(value) {
|
|
109
|
-
const cleaned = normalizeSegment(value);
|
|
110
|
-
return cleaned ? cleaned.split("/").filter(Boolean) : [];
|
|
111
|
-
}
|
|
112
|
-
function resolveDocsI18n(config) {
|
|
113
|
-
if (!config || !Array.isArray(config.locales)) return null;
|
|
114
|
-
const locales = Array.from(new Set(config.locales.map((l) => l.trim()).filter(Boolean)));
|
|
115
|
-
if (locales.length === 0) return null;
|
|
116
|
-
return {
|
|
117
|
-
locales,
|
|
118
|
-
defaultLocale: config.defaultLocale && locales.includes(config.defaultLocale) ? config.defaultLocale : locales[0]
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
function resolveDocsLocale(searchParams, i18n) {
|
|
122
|
-
if (!i18n) return void 0;
|
|
123
|
-
const raw = searchParams.get("lang") ?? searchParams.get("locale");
|
|
124
|
-
if (!raw) return void 0;
|
|
125
|
-
if (i18n.locales.includes(raw)) return raw;
|
|
126
|
-
return i18n.defaultLocale;
|
|
127
|
-
}
|
|
128
|
-
function resolveDocsPath(pathname, entry) {
|
|
129
|
-
const entryBase = normalizeSegment(entry || "docs") || "docs";
|
|
130
|
-
const entryParts = splitSegments(entryBase);
|
|
131
|
-
const pathParts = splitSegments(pathname);
|
|
132
|
-
let rest = pathParts;
|
|
133
|
-
if (entryParts.length > 0) {
|
|
134
|
-
if (pathParts.slice(0, entryParts.length).join("/") === entryParts.join("/")) rest = pathParts.slice(entryParts.length);
|
|
135
|
-
}
|
|
136
|
-
return {
|
|
137
|
-
slug: rest.join("/"),
|
|
138
|
-
entryPath: entryBase
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
//#endregion
|
|
143
|
-
//#region src/metadata.ts
|
|
144
|
-
/**
|
|
145
|
-
* Resolve page title using metadata titleTemplate.
|
|
146
|
-
* %s is replaced with page title.
|
|
147
|
-
*/
|
|
148
|
-
function resolveTitle(pageTitle, metadata) {
|
|
149
|
-
return (metadata?.titleTemplate ?? "%s").replace("%s", pageTitle);
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Resolve OG image URL for a page.
|
|
153
|
-
* Prefers page.openGraph.images[0], then page.ogImage, then config endpoint/default.
|
|
154
|
-
*/
|
|
155
|
-
function resolveOGImage(page, ogConfig, baseUrl) {
|
|
156
|
-
if (page.openGraph?.images?.length) return resolveImageUrl(page.openGraph.images[0].url, baseUrl);
|
|
157
|
-
if (!ogConfig?.enabled) return void 0;
|
|
158
|
-
if (page.ogImage) return resolveImageUrl(page.ogImage, baseUrl);
|
|
159
|
-
if (ogConfig.type === "dynamic" && ogConfig.endpoint) return `${baseUrl ?? ""}${ogConfig.endpoint}`;
|
|
160
|
-
return ogConfig.defaultImage;
|
|
161
|
-
}
|
|
162
|
-
function resolveImageUrl(url, baseUrl) {
|
|
163
|
-
if (url.startsWith("/") || url.startsWith("http")) return url;
|
|
164
|
-
const base = baseUrl ?? "";
|
|
165
|
-
return `${base}${base.length > 0 && !base.endsWith("/") ? "/" : ""}${url}`;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Build the Open Graph metadata object for a page.
|
|
169
|
-
* When the page has openGraph in frontmatter, uses it (with title/description filled from page if omitted).
|
|
170
|
-
* Otherwise uses ogImage or config (dynamic endpoint / defaultImage).
|
|
171
|
-
*/
|
|
172
|
-
function buildPageOpenGraph(page, ogConfig, baseUrl) {
|
|
173
|
-
if (page.openGraph) {
|
|
174
|
-
const images = page.openGraph.images?.length ? page.openGraph.images.map((img) => ({
|
|
175
|
-
url: resolveImageUrl(img.url, baseUrl),
|
|
176
|
-
width: img.width ?? 1200,
|
|
177
|
-
height: img.height ?? 630
|
|
178
|
-
})) : void 0;
|
|
179
|
-
return {
|
|
180
|
-
title: page.openGraph.title ?? page.title,
|
|
181
|
-
description: page.openGraph.description ?? page.description,
|
|
182
|
-
...images && { images }
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
const url = resolveOGImage(page, ogConfig, baseUrl);
|
|
186
|
-
if (!url) return void 0;
|
|
187
|
-
return {
|
|
188
|
-
title: page.title,
|
|
189
|
-
...page.description && { description: page.description },
|
|
190
|
-
images: [{
|
|
191
|
-
url,
|
|
192
|
-
width: 1200,
|
|
193
|
-
height: 630
|
|
194
|
-
}]
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Build the Twitter card metadata object for a page.
|
|
199
|
-
* When the page has twitter in frontmatter, uses it.
|
|
200
|
-
* Otherwise builds from ogImage or config (dynamic endpoint).
|
|
201
|
-
*/
|
|
202
|
-
function buildPageTwitter(page, ogConfig, baseUrl) {
|
|
203
|
-
if (page.twitter) {
|
|
204
|
-
const images = page.twitter.images?.length ? page.twitter.images.map((url) => resolveImageUrl(url, baseUrl)) : void 0;
|
|
205
|
-
return {
|
|
206
|
-
...page.twitter.card && { card: page.twitter.card },
|
|
207
|
-
...page.twitter.title !== void 0 && { title: page.twitter.title },
|
|
208
|
-
...page.twitter.description !== void 0 && { description: page.twitter.description },
|
|
209
|
-
...images && { images }
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
const url = resolveOGImage(page, ogConfig, baseUrl);
|
|
213
|
-
if (!url) return void 0;
|
|
214
|
-
return {
|
|
215
|
-
card: "summary_large_image",
|
|
216
|
-
title: page.title,
|
|
217
|
-
...page.description && { description: page.description },
|
|
218
|
-
images: [url]
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
//#endregion
|
|
223
|
-
export { buildPageOpenGraph, buildPageTwitter, createTheme, deepMerge, defineDocs, extendTheme, resolveDocsI18n, resolveDocsLocale, resolveDocsPath, resolveOGImage, resolveTitle };
|