@farming-labs/theme 0.1.130 → 0.1.131

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 +34 -13
  2. package/package.json +2 -2
package/dist/docs-api.mjs CHANGED
@@ -3,7 +3,7 @@ import { getNextAppDir } from "./get-app-dir.mjs";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import matter from "gray-matter";
6
- import { DEFAULT_SITEMAP_MD_DOCS_ROUTE, buildDocsAskAIContext, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsRobotsResponse, createDocsSitemapResponse, detectDocsMarkdownAgentRequest, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, formatDocsAskAIPackageHints, getDocsLlmsTxtMaxCharsIssue, getDocsMarkdownVaryHeader, hasDocsMarkdownSignatureAgent, normalizeDocsRelated, performDocsSearch, renderDocsLlmsTxt, renderDocsMarkdownNotFound, renderDocsRelatedMarkdownLines, resolveAskAISearchRequestConfig, resolveChangelogConfig, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLlmsTxtSections, resolveDocsLocale, resolveDocsSitemapConfig, resolvePageSidebarFolderIndexBehavior, resolveSearchRequestConfig, selectDocsLlmsTxtContent } from "@farming-labs/docs";
6
+ import { DEFAULT_SITEMAP_MD_DOCS_ROUTE, buildDocsAskAIContext, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsRobotsResponse, createDocsSitemapResponse, detectDocsMarkdownAgentRequest, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, formatDocsAskAIPackageHints, getDocsLlmsTxtMaxCharsIssue, getDocsMarkdownVaryHeader, hasDocsMarkdownSignatureAgent, normalizeDocsRelated, performDocsSearch, renderDocsLlmsTxt, renderDocsMarkdownDocument, renderDocsMarkdownNotFound, resolveAskAISearchRequestConfig, resolveChangelogConfig, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLlmsTxtSections, resolveDocsLocale, resolveDocsMarkdownRecovery, resolveDocsSitemapConfig, resolvePageSidebarFolderIndexBehavior, resolveSearchRequestConfig, selectDocsLlmsTxtContent } from "@farming-labs/docs";
7
7
  import { buildApiReferenceOpenApiDocumentAsync, createDocsMcpHttpHandler, createFilesystemDocsMcpSource, readDocsSitemapManifest, resolveApiReferenceConfig, resolveDocsMcpConfig } from "@farming-labs/docs/server";
8
8
 
9
9
  //#region src/docs-api.ts
@@ -1119,14 +1119,10 @@ function resolvePublicMarkdownRequest(entry, docsPath, url, request) {
1119
1119
  return null;
1120
1120
  }
1121
1121
  function renderMarkdownDocument(page, options = {}) {
1122
- if ("agentRawContent" in page && page.agentRawContent !== void 0) return page.agentRawContent;
1123
- const relatedLines = renderDocsRelatedMarkdownLines(page.related);
1124
- const lines = [`# ${page.title}`, `URL: ${page.url}`];
1125
- if (options.llmsEnabled !== false) lines.push("LLM index: /llms.txt");
1126
- if (page.description) lines.push(`Description: ${page.description}`);
1127
- lines.push(...relatedLines);
1128
- lines.push("", page.agentFallbackRawContent ?? page.rawContent ?? page.content);
1129
- return lines.join("\n");
1122
+ return renderDocsMarkdownDocument(page, {
1123
+ llms: options.llmsEnabled !== false,
1124
+ sitemap: options.sitemap
1125
+ });
1130
1126
  }
1131
1127
  function renderSkillDocument({ origin, entry, search, mcp, feedback, llms, sitemap, robots, openapi }) {
1132
1128
  const normalizedEntry = normalizePathSegment(entry) || "docs";
@@ -2027,15 +2023,24 @@ function createDocsAPI(options) {
2027
2023
  for (const docsDir of ctx.docsDirs) if (isHiddenFolderIndexPageDir(relativeSlug ? path.join(docsDir, ...relativeSlug.split("/")) : docsDir)) return null;
2028
2024
  for (const source of getMarkdownSources(ctx)) {
2029
2025
  const page = findDocsMcpPage(ctx.entryPath, await source.getPages(), requestedPath);
2030
- if (page) return renderMarkdownDocument(withPublicDocsUrl(page, ctx), { llmsEnabled: llmsConfig.enabled });
2026
+ if (page) return renderMarkdownDocument(withPublicDocsUrl(page, ctx), {
2027
+ llmsEnabled: llmsConfig.enabled,
2028
+ sitemap: sitemapConfig
2029
+ });
2031
2030
  }
2032
2031
  const fallbackPage = getIndexes(ctx).find((page) => {
2033
2032
  const pageUrl = normalizeUrlPath(page.url);
2034
2033
  return pageUrl === normalizedRequest || pageUrl === normalizedPublicRequest;
2035
2034
  });
2036
- if (fallbackPage) return renderMarkdownDocument(withPublicDocsUrl(fallbackPage, ctx), { llmsEnabled: llmsConfig.enabled });
2035
+ if (fallbackPage) return renderMarkdownDocument(withPublicDocsUrl(fallbackPage, ctx), {
2036
+ llmsEnabled: llmsConfig.enabled,
2037
+ sitemap: sitemapConfig
2038
+ });
2037
2039
  const requestedSlug = normalizePublicDocsSlug(ctx, normalizedPublicRequest);
2038
- for (const page of getIndexes(ctx)) if (normalizePublicDocsSlug(ctx, page.url) === requestedSlug) return renderMarkdownDocument(withPublicDocsUrl(page, ctx), { llmsEnabled: llmsConfig.enabled });
2040
+ for (const page of getIndexes(ctx)) if (normalizePublicDocsSlug(ctx, page.url) === requestedSlug) return renderMarkdownDocument(withPublicDocsUrl(page, ctx), {
2041
+ llmsEnabled: llmsConfig.enabled,
2042
+ sitemap: sitemapConfig
2043
+ });
2039
2044
  return null;
2040
2045
  }
2041
2046
  function getLlmsContent(ctx) {
@@ -2200,6 +2205,13 @@ function createDocsAPI(options) {
2200
2205
  requestedPath: markdownRequest.requestedPath
2201
2206
  });
2202
2207
  if (!document) {
2208
+ const recoveryPages = getIndexes(ctx).map((page) => withPublicDocsUrl(page, ctx));
2209
+ const recovery = resolveDocsMarkdownRecovery({
2210
+ entry,
2211
+ requestedPath: markdownRequest.requestedPath,
2212
+ pages: recoveryPages,
2213
+ sitemap: sitemapConfig
2214
+ });
2203
2215
  await emitDocsAnalyticsEvent(analytics, {
2204
2216
  type: "agent_read",
2205
2217
  source: "server",
@@ -2224,12 +2236,21 @@ function createDocsAPI(options) {
2224
2236
  found: false
2225
2237
  }
2226
2238
  });
2239
+ if (recovery.redirect) return new Response(null, {
2240
+ status: 307,
2241
+ headers: {
2242
+ Location: new URL(recovery.redirect.markdownUrl, url.origin).toString(),
2243
+ ...varyHeader ? { Vary: varyHeader } : {},
2244
+ "X-Robots-Tag": "noindex"
2245
+ }
2246
+ });
2227
2247
  return new Response(renderDocsMarkdownNotFound({
2228
2248
  entry,
2229
2249
  requestedPath: markdownRequest.requestedPath,
2250
+ pages: recoveryPages,
2230
2251
  sitemap: sitemapConfig
2231
2252
  }), {
2232
- status: 404,
2253
+ status: 200,
2233
2254
  headers: {
2234
2255
  "Content-Type": "text/markdown; charset=utf-8",
2235
2256
  ...varyHeader ? { Vary: varyHeader } : {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/theme",
3
- "version": "0.1.130",
3
+ "version": "0.1.131",
4
4
  "description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
5
5
  "keywords": [
6
6
  "docs",
@@ -139,7 +139,7 @@
139
139
  "tsdown": "^0.20.3",
140
140
  "typescript": "^5.9.3",
141
141
  "vitest": "^3.2.4",
142
- "@farming-labs/docs": "0.1.130"
142
+ "@farming-labs/docs": "0.1.131"
143
143
  },
144
144
  "peerDependencies": {
145
145
  "@farming-labs/docs": ">=0.0.1",