@farming-labs/theme 0.1.129 → 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.
- package/dist/docs-api.mjs +50 -22
- 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, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, formatDocsAskAIPackageHints, getDocsLlmsTxtMaxCharsIssue, getDocsMarkdownVaryHeader, hasDocsMarkdownSignatureAgent, normalizeDocsRelated, performDocsSearch, renderDocsLlmsTxt,
|
|
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
|
|
@@ -992,6 +992,13 @@ function acceptsMarkdown(request) {
|
|
|
992
992
|
return Number.isFinite(quality) ? quality > 0 : true;
|
|
993
993
|
});
|
|
994
994
|
}
|
|
995
|
+
function resolveMarkdownHeaderDelivery(request) {
|
|
996
|
+
if (hasDocsMarkdownSignatureAgent(request)) return "signature_agent";
|
|
997
|
+
if (acceptsMarkdown(request)) return "accept_header";
|
|
998
|
+
const agentDetection = detectDocsMarkdownAgentRequest(request);
|
|
999
|
+
if (!agentDetection.detected) return null;
|
|
1000
|
+
return agentDetection.method === "heuristic" ? "heuristic" : "user_agent";
|
|
1001
|
+
}
|
|
995
1002
|
function resolveMarkdownRequest(entry, url, request) {
|
|
996
1003
|
if (url.searchParams.get("format")?.trim() === "markdown") return {
|
|
997
1004
|
requestedPath: url.searchParams.get("path")?.trim() ?? "",
|
|
@@ -1008,9 +1015,9 @@ function resolveMarkdownRequest(entry, url, request) {
|
|
|
1008
1015
|
requestedPath: pathname.slice(slugPrefix.length, -3),
|
|
1009
1016
|
delivery: "md_route"
|
|
1010
1017
|
};
|
|
1011
|
-
const
|
|
1012
|
-
if (
|
|
1013
|
-
const delivery =
|
|
1018
|
+
const headerDelivery = resolveMarkdownHeaderDelivery(request);
|
|
1019
|
+
if (headerDelivery) {
|
|
1020
|
+
const delivery = headerDelivery;
|
|
1014
1021
|
if (pathname === normalizedEntry) return {
|
|
1015
1022
|
requestedPath: "",
|
|
1016
1023
|
delivery
|
|
@@ -1078,9 +1085,9 @@ function resolvePublicMarkdownRequest(entry, docsPath, url, request) {
|
|
|
1078
1085
|
requestedPath: pathname.slice(1, -3),
|
|
1079
1086
|
delivery: "md_route"
|
|
1080
1087
|
};
|
|
1081
|
-
const
|
|
1082
|
-
if (
|
|
1083
|
-
const delivery =
|
|
1088
|
+
const headerDelivery = resolveMarkdownHeaderDelivery(request);
|
|
1089
|
+
if (headerDelivery) {
|
|
1090
|
+
const delivery = headerDelivery;
|
|
1084
1091
|
return {
|
|
1085
1092
|
requestedPath: pathname === "/" ? "" : pathname.slice(1),
|
|
1086
1093
|
delivery
|
|
@@ -1097,9 +1104,9 @@ function resolvePublicMarkdownRequest(entry, docsPath, url, request) {
|
|
|
1097
1104
|
requestedPath: pathname.slice(slugPrefix.length, -3),
|
|
1098
1105
|
delivery: "md_route"
|
|
1099
1106
|
};
|
|
1100
|
-
const
|
|
1101
|
-
if (
|
|
1102
|
-
const delivery =
|
|
1107
|
+
const headerDelivery = resolveMarkdownHeaderDelivery(request);
|
|
1108
|
+
if (headerDelivery) {
|
|
1109
|
+
const delivery = headerDelivery;
|
|
1103
1110
|
if (pathname === docsPath) return {
|
|
1104
1111
|
requestedPath: "",
|
|
1105
1112
|
delivery
|
|
@@ -1112,14 +1119,10 @@ function resolvePublicMarkdownRequest(entry, docsPath, url, request) {
|
|
|
1112
1119
|
return null;
|
|
1113
1120
|
}
|
|
1114
1121
|
function renderMarkdownDocument(page, options = {}) {
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
if (page.description) lines.push(`Description: ${page.description}`);
|
|
1120
|
-
lines.push(...relatedLines);
|
|
1121
|
-
lines.push("", page.agentFallbackRawContent ?? page.rawContent ?? page.content);
|
|
1122
|
-
return lines.join("\n");
|
|
1122
|
+
return renderDocsMarkdownDocument(page, {
|
|
1123
|
+
llms: options.llmsEnabled !== false,
|
|
1124
|
+
sitemap: options.sitemap
|
|
1125
|
+
});
|
|
1123
1126
|
}
|
|
1124
1127
|
function renderSkillDocument({ origin, entry, search, mcp, feedback, llms, sitemap, robots, openapi }) {
|
|
1125
1128
|
const normalizedEntry = normalizePathSegment(entry) || "docs";
|
|
@@ -2020,15 +2023,24 @@ function createDocsAPI(options) {
|
|
|
2020
2023
|
for (const docsDir of ctx.docsDirs) if (isHiddenFolderIndexPageDir(relativeSlug ? path.join(docsDir, ...relativeSlug.split("/")) : docsDir)) return null;
|
|
2021
2024
|
for (const source of getMarkdownSources(ctx)) {
|
|
2022
2025
|
const page = findDocsMcpPage(ctx.entryPath, await source.getPages(), requestedPath);
|
|
2023
|
-
if (page) return renderMarkdownDocument(withPublicDocsUrl(page, ctx), {
|
|
2026
|
+
if (page) return renderMarkdownDocument(withPublicDocsUrl(page, ctx), {
|
|
2027
|
+
llmsEnabled: llmsConfig.enabled,
|
|
2028
|
+
sitemap: sitemapConfig
|
|
2029
|
+
});
|
|
2024
2030
|
}
|
|
2025
2031
|
const fallbackPage = getIndexes(ctx).find((page) => {
|
|
2026
2032
|
const pageUrl = normalizeUrlPath(page.url);
|
|
2027
2033
|
return pageUrl === normalizedRequest || pageUrl === normalizedPublicRequest;
|
|
2028
2034
|
});
|
|
2029
|
-
if (fallbackPage) return renderMarkdownDocument(withPublicDocsUrl(fallbackPage, ctx), {
|
|
2035
|
+
if (fallbackPage) return renderMarkdownDocument(withPublicDocsUrl(fallbackPage, ctx), {
|
|
2036
|
+
llmsEnabled: llmsConfig.enabled,
|
|
2037
|
+
sitemap: sitemapConfig
|
|
2038
|
+
});
|
|
2030
2039
|
const requestedSlug = normalizePublicDocsSlug(ctx, normalizedPublicRequest);
|
|
2031
|
-
for (const page of getIndexes(ctx)) if (normalizePublicDocsSlug(ctx, page.url) === requestedSlug) return renderMarkdownDocument(withPublicDocsUrl(page, ctx), {
|
|
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
|
+
});
|
|
2032
2044
|
return null;
|
|
2033
2045
|
}
|
|
2034
2046
|
function getLlmsContent(ctx) {
|
|
@@ -2193,6 +2205,13 @@ function createDocsAPI(options) {
|
|
|
2193
2205
|
requestedPath: markdownRequest.requestedPath
|
|
2194
2206
|
});
|
|
2195
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
|
+
});
|
|
2196
2215
|
await emitDocsAnalyticsEvent(analytics, {
|
|
2197
2216
|
type: "agent_read",
|
|
2198
2217
|
source: "server",
|
|
@@ -2217,12 +2236,21 @@ function createDocsAPI(options) {
|
|
|
2217
2236
|
found: false
|
|
2218
2237
|
}
|
|
2219
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
|
+
});
|
|
2220
2247
|
return new Response(renderDocsMarkdownNotFound({
|
|
2221
2248
|
entry,
|
|
2222
2249
|
requestedPath: markdownRequest.requestedPath,
|
|
2250
|
+
pages: recoveryPages,
|
|
2223
2251
|
sitemap: sitemapConfig
|
|
2224
2252
|
}), {
|
|
2225
|
-
status:
|
|
2253
|
+
status: 200,
|
|
2226
2254
|
headers: {
|
|
2227
2255
|
"Content-Type": "text/markdown; charset=utf-8",
|
|
2228
2256
|
...varyHeader ? { Vary: varyHeader } : {},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/theme",
|
|
3
|
-
"version": "0.1.
|
|
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.
|
|
142
|
+
"@farming-labs/docs": "0.1.131"
|
|
143
143
|
},
|
|
144
144
|
"peerDependencies": {
|
|
145
145
|
"@farming-labs/docs": ">=0.0.1",
|