@farming-labs/docs 0.0.28 → 0.0.30

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/dist/index.d.mts CHANGED
@@ -999,11 +999,23 @@ interface CodeBlockCopyData {
999
999
  /** Language / syntax hint (e.g. "tsx", "bash"), if present */
1000
1000
  language?: string;
1001
1001
  }
1002
+ interface DocsI18nConfig {
1003
+ /** Supported locale identifiers (e.g. ["en", "fr"]). */
1004
+ locales: string[];
1005
+ /** Default locale when `?lang=` is missing or invalid. Defaults to first locale. */
1006
+ defaultLocale?: string;
1007
+ }
1002
1008
  interface DocsConfig {
1003
1009
  /** Entry folder for docs (e.g. "docs" → /docs) */
1004
1010
  entry: string;
1005
1011
  /** Path to the content directory. Defaults to `entry` value. */
1006
1012
  contentDir?: string;
1013
+ /**
1014
+ * Internationalization (i18n) configuration.
1015
+ * When set, docs content is expected under `${contentDir}/{locale}` and
1016
+ * the active locale is selected by `?lang=<locale>` in the URL.
1017
+ */
1018
+ i18n?: DocsI18nConfig;
1007
1019
  /**
1008
1020
  * Set to `true` when building for full static export (e.g. Cloudflare Pages).
1009
1021
  * When using `output: 'export'` in Next.js, the `/api/docs` route is not generated.
@@ -1326,6 +1338,21 @@ declare function createTheme(baseTheme: DocsTheme): (overrides?: Partial<DocsThe
1326
1338
  */
1327
1339
  declare function extendTheme(baseTheme: DocsTheme, extensions: Partial<DocsTheme>): DocsTheme;
1328
1340
  //#endregion
1341
+ //#region src/i18n.d.ts
1342
+ interface ResolvedDocsI18n {
1343
+ locales: string[];
1344
+ defaultLocale: string;
1345
+ }
1346
+ interface DocsPathMatch {
1347
+ /** Slug path relative to the docs root (no leading slash). */
1348
+ slug: string;
1349
+ /** Entry path used for URLs (no locale segment). */
1350
+ entryPath: string;
1351
+ }
1352
+ declare function resolveDocsI18n(config?: DocsI18nConfig | null): ResolvedDocsI18n | null;
1353
+ declare function resolveDocsLocale(searchParams: URLSearchParams, i18n?: ResolvedDocsI18n | null): string | undefined;
1354
+ declare function resolveDocsPath(pathname: string, entry: string): DocsPathMatch;
1355
+ //#endregion
1329
1356
  //#region src/metadata.d.ts
1330
1357
  /**
1331
1358
  * Resolve page title using metadata titleTemplate.
@@ -1350,4 +1377,4 @@ declare function buildPageOpenGraph(page: Pick<PageFrontmatter, "title" | "descr
1350
1377
  */
1351
1378
  declare function buildPageTwitter(page: Pick<PageFrontmatter, "title" | "description" | "ogImage" | "openGraph" | "twitter">, ogConfig?: OGConfig, baseUrl?: string): PageTwitter | undefined;
1352
1379
  //#endregion
1353
- export { type AIConfig, type BreadcrumbConfig, type CodeBlockCopyData, type CopyMarkdownConfig, type DocsConfig, type DocsMetadata, type DocsNav, type DocsTheme, 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 SidebarComponentProps, type SidebarConfig, type SidebarFolderNode, type SidebarNode, type SidebarPageNode, type SidebarTree, type ThemeToggleConfig, type TypographyConfig, type UIConfig, buildPageOpenGraph, buildPageTwitter, createTheme, deepMerge, defineDocs, extendTheme, resolveOGImage, resolveTitle };
1380
+ export { type AIConfig, type BreadcrumbConfig, type CodeBlockCopyData, type CopyMarkdownConfig, type DocsConfig, type DocsI18nConfig, type DocsMetadata, type DocsNav, type DocsPathMatch, type DocsTheme, 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 CHANGED
@@ -6,6 +6,7 @@ function defineDocs(config) {
6
6
  return {
7
7
  entry: config.entry ?? "docs",
8
8
  contentDir: config.contentDir,
9
+ i18n: config.i18n,
9
10
  theme: config.theme,
10
11
  nav: config.nav,
11
12
  github: config.github,
@@ -99,6 +100,45 @@ function extendTheme(baseTheme, extensions) {
99
100
  return deepMerge(baseTheme, extensions);
100
101
  }
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
+
102
142
  //#endregion
103
143
  //#region src/metadata.ts
104
144
  /**
@@ -180,4 +220,4 @@ function buildPageTwitter(page, ogConfig, baseUrl) {
180
220
  }
181
221
 
182
222
  //#endregion
183
- export { buildPageOpenGraph, buildPageTwitter, createTheme, deepMerge, defineDocs, extendTheme, resolveOGImage, resolveTitle };
223
+ export { buildPageOpenGraph, buildPageTwitter, createTheme, deepMerge, defineDocs, extendTheme, resolveDocsI18n, resolveDocsLocale, resolveDocsPath, resolveOGImage, resolveTitle };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/docs",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "description": "Modern, flexible MDX-based docs framework — core types, config, and CLI",
5
5
  "keywords": [
6
6
  "docs",