@farming-labs/theme 0.1.28 → 0.1.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.
Files changed (2) hide show
  1. package/dist/docs-api.mjs +35 -4
  2. package/package.json +2 -2
package/dist/docs-api.mjs CHANGED
@@ -156,6 +156,8 @@ function isSearchEnabled(search) {
156
156
  }
157
157
  function buildAgentSpec({ origin, entry, i18n, search, mcp, feedback, llms }) {
158
158
  const normalizedEntry = normalizePathSegment(entry) || "docs";
159
+ const localesEnabled = i18n !== null;
160
+ const searchEnabled = isSearchEnabled(search);
159
161
  return {
160
162
  version: "1",
161
163
  name: "@farming-labs/docs",
@@ -167,12 +169,23 @@ function buildAgentSpec({ origin, entry, i18n, search, mcp, feedback, llms }) {
167
169
  baseUrl: llms.baseUrl ?? origin
168
170
  },
169
171
  locales: {
170
- enabled: i18n !== null,
172
+ enabled: localesEnabled,
171
173
  available: i18n?.locales ?? [],
172
174
  default: i18n?.defaultLocale ?? null,
173
175
  queryParam: "lang",
174
176
  fallbackQueryParam: "locale"
175
177
  },
178
+ capabilities: {
179
+ markdownRoutes: true,
180
+ agentMdOverrides: true,
181
+ agentBlocks: true,
182
+ llms: llms.enabled,
183
+ skills: true,
184
+ mcp: mcp.enabled,
185
+ search: searchEnabled,
186
+ agentFeedback: feedback.enabled,
187
+ locales: localesEnabled
188
+ },
176
189
  api: {
177
190
  docs: DEFAULT_DOCS_API_ROUTE,
178
191
  agentSpec: DEFAULT_AGENT_SPEC_ROUTE,
@@ -180,6 +193,7 @@ function buildAgentSpec({ origin, entry, i18n, search, mcp, feedback, llms }) {
180
193
  },
181
194
  markdown: {
182
195
  enabled: true,
196
+ acceptHeader: "text/markdown",
183
197
  pagePattern: `/${normalizedEntry}/{slug}.md`,
184
198
  rootPage: `/${normalizedEntry}.md`,
185
199
  apiPattern: `${DEFAULT_DOCS_API_ROUTE}?format=markdown&path={slug}`,
@@ -195,7 +209,7 @@ function buildAgentSpec({ origin, entry, i18n, search, mcp, feedback, llms }) {
195
209
  full: `${DEFAULT_DOCS_API_ROUTE}?format=llms-full`
196
210
  },
197
211
  search: {
198
- enabled: isSearchEnabled(search),
212
+ enabled: searchEnabled,
199
213
  endpoint: `${DEFAULT_DOCS_API_ROUTE}?query={query}`,
200
214
  method: "GET",
201
215
  queryParam: "query",
@@ -728,13 +742,30 @@ function findDocsMcpPage(entry, pages, requestedPath) {
728
742
  for (const page of pages) if (normalizePathSegment(page.slug) === normalizedSlug) return page;
729
743
  return null;
730
744
  }
731
- function resolveMarkdownRequest(entry, url) {
745
+ function acceptsMarkdown(request) {
746
+ const accept = request.headers.get("accept");
747
+ if (!accept) return false;
748
+ return accept.split(",").map((value) => value.trim()).some((value) => {
749
+ const [mediaType, ...params] = value.split(";").map((part) => part.trim().toLowerCase());
750
+ if (mediaType !== "text/markdown") return false;
751
+ const qualityParam = params.find((param) => param.split("=", 1)[0]?.trim() === "q");
752
+ if (!qualityParam) return true;
753
+ const qualityValue = qualityParam.slice(qualityParam.indexOf("=") + 1).trim();
754
+ const quality = Number.parseFloat(qualityValue);
755
+ return Number.isFinite(quality) ? quality > 0 : true;
756
+ });
757
+ }
758
+ function resolveMarkdownRequest(entry, url, request) {
732
759
  if (url.searchParams.get("format")?.trim() === "markdown") return { requestedPath: url.searchParams.get("path")?.trim() ?? "" };
733
760
  const pathname = normalizeUrlPath(url.pathname);
734
761
  const normalizedEntry = `/${normalizePathSegment(entry)}`;
735
762
  if (pathname === `${normalizedEntry}.md`) return { requestedPath: "" };
736
763
  const slugPrefix = `${normalizedEntry}/`;
737
764
  if (pathname.startsWith(slugPrefix) && pathname.endsWith(".md")) return { requestedPath: pathname.slice(slugPrefix.length, -3) };
765
+ if (acceptsMarkdown(request)) {
766
+ if (pathname === normalizedEntry) return { requestedPath: "" };
767
+ if (pathname.startsWith(slugPrefix)) return { requestedPath: pathname.slice(slugPrefix.length) };
768
+ }
738
769
  return null;
739
770
  }
740
771
  function renderMarkdownDocument(page) {
@@ -1041,7 +1072,7 @@ function createDocsAPI(options) {
1041
1072
  "X-Robots-Tag": "noindex"
1042
1073
  } });
1043
1074
  }
1044
- const markdownRequest = resolveMarkdownRequest(entry, url);
1075
+ const markdownRequest = resolveMarkdownRequest(entry, url, request);
1045
1076
  if (markdownRequest) {
1046
1077
  const document = await getMarkdownDocument(ctx, markdownRequest.requestedPath);
1047
1078
  if (!document) return new Response("Not Found", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/theme",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
5
5
  "keywords": [
6
6
  "docs",
@@ -133,7 +133,7 @@
133
133
  "tsdown": "^0.20.3",
134
134
  "typescript": "^5.9.3",
135
135
  "vitest": "^3.2.4",
136
- "@farming-labs/docs": "0.1.28"
136
+ "@farming-labs/docs": "0.1.30"
137
137
  },
138
138
  "peerDependencies": {
139
139
  "@farming-labs/docs": ">=0.0.1",