@farming-labs/theme 0.1.3 → 0.1.4

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.
@@ -26,8 +26,11 @@ interface AIOptions {
26
26
  maxResults?: number;
27
27
  }
28
28
  interface DocsAPIOptions {
29
+ rootDir?: string;
29
30
  /** Docs entry folder (default: read from docs.config) */
30
31
  entry?: string;
32
+ /** Override the docs content directory when it does not live in app/<entry>. */
33
+ contentDir?: string;
31
34
  /** Search language (default: "english") */
32
35
  language?: string;
33
36
  /** AI chat configuration */
@@ -67,6 +70,10 @@ interface DocsMCPAPIOptions {
67
70
  *
68
71
  * @param options - Optional overrides (entry, language, ai config)
69
72
  */
73
+ /**
74
+ * @deprecated Prefer `createDocsAPI` from `@farming-labs/next/api` in Next.js apps.
75
+ * The `@farming-labs/theme/api` path is kept for compatibility and will be phased out.
76
+ */
70
77
  declare function createDocsAPI(options?: DocsAPIOptions): {
71
78
  /**
72
79
  * GET handler — search, llms.txt, or llms-full.txt depending on query params.
@@ -84,6 +91,10 @@ declare function createDocsAPI(options?: DocsAPIOptions): {
84
91
  *
85
92
  * Returns `{ GET, POST, DELETE }` for use in a Next.js route handler.
86
93
  */
94
+ /**
95
+ * @deprecated Prefer `createDocsMCPAPI` from `@farming-labs/next/api` in Next.js apps.
96
+ * The `@farming-labs/theme/api` path is kept for compatibility and will be phased out.
97
+ */
87
98
  declare function createDocsMCPAPI(options?: DocsMCPAPIOptions): {
88
99
  GET(request: Request): Promise<Response>;
89
100
  POST(request: Request): Promise<Response>;
package/dist/docs-api.mjs CHANGED
@@ -454,14 +454,38 @@ function generateLlmsTxt(indexes, options) {
454
454
  *
455
455
  * @param options - Optional overrides (entry, language, ai config)
456
456
  */
457
+ /**
458
+ * @deprecated Prefer `createDocsAPI` from `@farming-labs/next/api` in Next.js apps.
459
+ * The `@farming-labs/theme/api` path is kept for compatibility and will be phased out.
460
+ */
457
461
  function createDocsAPI(options) {
458
- const root = process.cwd();
462
+ const root = options?.rootDir ?? process.cwd();
459
463
  const entry = options?.entry ?? readEntry(root);
460
464
  const appDir = getNextAppDir(root);
465
+ const contentDir = options?.contentDir ?? path.join(appDir, entry);
461
466
  const i18n = resolveDocsI18n(options?.i18n ?? readI18nConfig(root));
462
467
  const aiConfig = options?.ai ?? readAIConfig(root);
463
468
  const searchConfig = options?.search;
464
469
  const llmsConfig = readLlmsTxtConfig(root);
470
+ function resolveDocsDirCandidates(locale) {
471
+ const relativeCandidates = /* @__PURE__ */ new Set();
472
+ if (path.isAbsolute(contentDir)) return [locale ? path.join(contentDir, locale) : contentDir];
473
+ relativeCandidates.add(contentDir);
474
+ relativeCandidates.add(path.join("app", entry));
475
+ relativeCandidates.add(path.join("src", "app", entry));
476
+ const rootCandidates = new Set([root]);
477
+ if (path.basename(root) === "server") rootCandidates.add(path.resolve(root, "..", ".."));
478
+ else {
479
+ rootCandidates.add(path.join(root, ".next", "server"));
480
+ rootCandidates.add(path.join(root, ".next-build", "server"));
481
+ }
482
+ const resolved = /* @__PURE__ */ new Set();
483
+ for (const base of rootCandidates) for (const relative of relativeCandidates) {
484
+ const candidate = path.join(base, relative);
485
+ resolved.add(locale ? path.join(candidate, locale) : candidate);
486
+ }
487
+ return [...resolved];
488
+ }
465
489
  function resolveLocaleFromRequest(request) {
466
490
  if (!i18n) return void 0;
467
491
  const direct = resolveDocsLocale(new URL(request.url).searchParams, i18n);
@@ -476,13 +500,13 @@ function createDocsAPI(options) {
476
500
  function resolveContextFromRequest(request) {
477
501
  if (!i18n) return {
478
502
  entryPath: entry,
479
- docsDir: path.join(root, appDir, entry)
503
+ docsDirs: resolveDocsDirCandidates()
480
504
  };
481
505
  const locale = resolveLocaleFromRequest(request) ?? i18n.defaultLocale;
482
506
  return {
483
507
  entryPath: entry,
484
508
  locale,
485
- docsDir: path.join(root, appDir, entry, locale)
509
+ docsDirs: resolveDocsDirCandidates(locale)
486
510
  };
487
511
  }
488
512
  const indexesByLocale = /* @__PURE__ */ new Map();
@@ -491,7 +515,11 @@ function createDocsAPI(options) {
491
515
  const key = ctx.locale ?? "__default__";
492
516
  const cached = indexesByLocale.get(key);
493
517
  if (cached) return cached;
494
- const next = scanDocsDir(ctx.docsDir, ctx.entryPath, ctx.locale);
518
+ let next = [];
519
+ for (const docsDir of ctx.docsDirs) {
520
+ next = scanDocsDir(docsDir, ctx.entryPath, ctx.locale);
521
+ if (next.length > 0) break;
522
+ }
495
523
  indexesByLocale.set(key, next);
496
524
  return next;
497
525
  }
@@ -543,6 +571,10 @@ function createDocsAPI(options) {
543
571
  *
544
572
  * Returns `{ GET, POST, DELETE }` for use in a Next.js route handler.
545
573
  */
574
+ /**
575
+ * @deprecated Prefer `createDocsMCPAPI` from `@farming-labs/next/api` in Next.js apps.
576
+ * The `@farming-labs/theme/api` path is kept for compatibility and will be phased out.
577
+ */
546
578
  function createDocsMCPAPI(options = {}) {
547
579
  const rootDir = options.rootDir ?? process.cwd();
548
580
  const entry = options.entry ?? readEntry(rootDir);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/theme",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
5
5
  "keywords": [
6
6
  "docs",
@@ -127,7 +127,7 @@
127
127
  "tsdown": "^0.20.3",
128
128
  "typescript": "^5.9.3",
129
129
  "vitest": "^3.2.4",
130
- "@farming-labs/docs": "0.1.3"
130
+ "@farming-labs/docs": "0.1.4"
131
131
  },
132
132
  "peerDependencies": {
133
133
  "@farming-labs/docs": ">=0.0.1",