@farming-labs/theme 0.1.29 → 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 +20 -2
  2. package/package.json +2 -2
package/dist/docs-api.mjs CHANGED
@@ -193,6 +193,7 @@ function buildAgentSpec({ origin, entry, i18n, search, mcp, feedback, llms }) {
193
193
  },
194
194
  markdown: {
195
195
  enabled: true,
196
+ acceptHeader: "text/markdown",
196
197
  pagePattern: `/${normalizedEntry}/{slug}.md`,
197
198
  rootPage: `/${normalizedEntry}.md`,
198
199
  apiPattern: `${DEFAULT_DOCS_API_ROUTE}?format=markdown&path={slug}`,
@@ -741,13 +742,30 @@ function findDocsMcpPage(entry, pages, requestedPath) {
741
742
  for (const page of pages) if (normalizePathSegment(page.slug) === normalizedSlug) return page;
742
743
  return null;
743
744
  }
744
- 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) {
745
759
  if (url.searchParams.get("format")?.trim() === "markdown") return { requestedPath: url.searchParams.get("path")?.trim() ?? "" };
746
760
  const pathname = normalizeUrlPath(url.pathname);
747
761
  const normalizedEntry = `/${normalizePathSegment(entry)}`;
748
762
  if (pathname === `${normalizedEntry}.md`) return { requestedPath: "" };
749
763
  const slugPrefix = `${normalizedEntry}/`;
750
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
+ }
751
769
  return null;
752
770
  }
753
771
  function renderMarkdownDocument(page) {
@@ -1054,7 +1072,7 @@ function createDocsAPI(options) {
1054
1072
  "X-Robots-Tag": "noindex"
1055
1073
  } });
1056
1074
  }
1057
- const markdownRequest = resolveMarkdownRequest(entry, url);
1075
+ const markdownRequest = resolveMarkdownRequest(entry, url, request);
1058
1076
  if (markdownRequest) {
1059
1077
  const document = await getMarkdownDocument(ctx, markdownRequest.requestedPath);
1060
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.29",
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.29"
136
+ "@farming-labs/docs": "0.1.30"
137
137
  },
138
138
  "peerDependencies": {
139
139
  "@farming-labs/docs": ">=0.0.1",