@farming-labs/theme 0.1.130 → 0.1.132
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 +42 -15
- 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,
|
|
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,11 @@ function resolvePublicMarkdownRequest(entry, docsPath, url, request) {
|
|
|
1119
1119
|
return null;
|
|
1120
1120
|
}
|
|
1121
1121
|
function renderMarkdownDocument(page, options = {}) {
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
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
|
+
origin: options.origin,
|
|
1125
|
+
sitemap: options.sitemap
|
|
1126
|
+
});
|
|
1130
1127
|
}
|
|
1131
1128
|
function renderSkillDocument({ origin, entry, search, mcp, feedback, llms, sitemap, robots, openapi }) {
|
|
1132
1129
|
const normalizedEntry = normalizePathSegment(entry) || "docs";
|
|
@@ -2019,7 +2016,7 @@ function createDocsAPI(options) {
|
|
|
2019
2016
|
markdownSourcesByLocale.set(key, sources);
|
|
2020
2017
|
return sources;
|
|
2021
2018
|
}
|
|
2022
|
-
async function getMarkdownDocument(ctx, requestedPath) {
|
|
2019
|
+
async function getMarkdownDocument(ctx, requestedPath, origin) {
|
|
2023
2020
|
const normalizedRequest = normalizeRequestedMarkdownPath(ctx.entryPath, requestedPath);
|
|
2024
2021
|
const normalizedPublicRequest = normalizePublicRequestedMarkdownPath(ctx, requestedPath);
|
|
2025
2022
|
const normalizedEntry = `/${normalizePathSegment(ctx.entryPath)}`;
|
|
@@ -2027,15 +2024,27 @@ function createDocsAPI(options) {
|
|
|
2027
2024
|
for (const docsDir of ctx.docsDirs) if (isHiddenFolderIndexPageDir(relativeSlug ? path.join(docsDir, ...relativeSlug.split("/")) : docsDir)) return null;
|
|
2028
2025
|
for (const source of getMarkdownSources(ctx)) {
|
|
2029
2026
|
const page = findDocsMcpPage(ctx.entryPath, await source.getPages(), requestedPath);
|
|
2030
|
-
if (page) return renderMarkdownDocument(withPublicDocsUrl(page, ctx), {
|
|
2027
|
+
if (page) return renderMarkdownDocument(withPublicDocsUrl(page, ctx), {
|
|
2028
|
+
llmsEnabled: llmsConfig.enabled,
|
|
2029
|
+
origin,
|
|
2030
|
+
sitemap: sitemapConfig
|
|
2031
|
+
});
|
|
2031
2032
|
}
|
|
2032
2033
|
const fallbackPage = getIndexes(ctx).find((page) => {
|
|
2033
2034
|
const pageUrl = normalizeUrlPath(page.url);
|
|
2034
2035
|
return pageUrl === normalizedRequest || pageUrl === normalizedPublicRequest;
|
|
2035
2036
|
});
|
|
2036
|
-
if (fallbackPage) return renderMarkdownDocument(withPublicDocsUrl(fallbackPage, ctx), {
|
|
2037
|
+
if (fallbackPage) return renderMarkdownDocument(withPublicDocsUrl(fallbackPage, ctx), {
|
|
2038
|
+
llmsEnabled: llmsConfig.enabled,
|
|
2039
|
+
origin,
|
|
2040
|
+
sitemap: sitemapConfig
|
|
2041
|
+
});
|
|
2037
2042
|
const requestedSlug = normalizePublicDocsSlug(ctx, normalizedPublicRequest);
|
|
2038
|
-
for (const page of getIndexes(ctx)) if (normalizePublicDocsSlug(ctx, page.url) === requestedSlug) return renderMarkdownDocument(withPublicDocsUrl(page, ctx), {
|
|
2043
|
+
for (const page of getIndexes(ctx)) if (normalizePublicDocsSlug(ctx, page.url) === requestedSlug) return renderMarkdownDocument(withPublicDocsUrl(page, ctx), {
|
|
2044
|
+
llmsEnabled: llmsConfig.enabled,
|
|
2045
|
+
origin,
|
|
2046
|
+
sitemap: sitemapConfig
|
|
2047
|
+
});
|
|
2039
2048
|
return null;
|
|
2040
2049
|
}
|
|
2041
2050
|
function getLlmsContent(ctx) {
|
|
@@ -2192,7 +2201,8 @@ function createDocsAPI(options) {
|
|
|
2192
2201
|
if (sitemapResponse) return sitemapResponse;
|
|
2193
2202
|
const markdownRequest = resolveMarkdownRequest(entry, url, request) ?? resolvePublicMarkdownRequest(entry, docsPath, url, request);
|
|
2194
2203
|
if (markdownRequest) {
|
|
2195
|
-
const
|
|
2204
|
+
const markdownOrigin = llmsConfig.baseUrl || url.origin;
|
|
2205
|
+
const document = await getMarkdownDocument(ctx, markdownRequest.requestedPath, markdownOrigin);
|
|
2196
2206
|
const varyHeader = getDocsMarkdownVaryHeader(request);
|
|
2197
2207
|
const canonicalLinkHeader = getPublicMarkdownCanonicalLinkHeader({
|
|
2198
2208
|
origin: url.origin,
|
|
@@ -2200,6 +2210,13 @@ function createDocsAPI(options) {
|
|
|
2200
2210
|
requestedPath: markdownRequest.requestedPath
|
|
2201
2211
|
});
|
|
2202
2212
|
if (!document) {
|
|
2213
|
+
const recoveryPages = getIndexes(ctx).map((page) => withPublicDocsUrl(page, ctx));
|
|
2214
|
+
const recovery = resolveDocsMarkdownRecovery({
|
|
2215
|
+
entry,
|
|
2216
|
+
requestedPath: markdownRequest.requestedPath,
|
|
2217
|
+
pages: recoveryPages,
|
|
2218
|
+
sitemap: sitemapConfig
|
|
2219
|
+
});
|
|
2203
2220
|
await emitDocsAnalyticsEvent(analytics, {
|
|
2204
2221
|
type: "agent_read",
|
|
2205
2222
|
source: "server",
|
|
@@ -2224,12 +2241,22 @@ function createDocsAPI(options) {
|
|
|
2224
2241
|
found: false
|
|
2225
2242
|
}
|
|
2226
2243
|
});
|
|
2244
|
+
if (recovery.redirect) return new Response(null, {
|
|
2245
|
+
status: 307,
|
|
2246
|
+
headers: {
|
|
2247
|
+
Location: new URL(recovery.redirect.markdownUrl, url.origin).toString(),
|
|
2248
|
+
...varyHeader ? { Vary: varyHeader } : {},
|
|
2249
|
+
"X-Robots-Tag": "noindex"
|
|
2250
|
+
}
|
|
2251
|
+
});
|
|
2227
2252
|
return new Response(renderDocsMarkdownNotFound({
|
|
2228
2253
|
entry,
|
|
2229
2254
|
requestedPath: markdownRequest.requestedPath,
|
|
2255
|
+
origin: markdownOrigin,
|
|
2256
|
+
pages: recoveryPages,
|
|
2230
2257
|
sitemap: sitemapConfig
|
|
2231
2258
|
}), {
|
|
2232
|
-
status:
|
|
2259
|
+
status: 200,
|
|
2233
2260
|
headers: {
|
|
2234
2261
|
"Content-Type": "text/markdown; charset=utf-8",
|
|
2235
2262
|
...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.132",
|
|
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.132"
|
|
143
143
|
},
|
|
144
144
|
"peerDependencies": {
|
|
145
145
|
"@farming-labs/docs": ">=0.0.1",
|