@farming-labs/docs 0.2.24 → 0.2.25
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/{agent-B7T4gauS.mjs → agent-DEr3FFdg.mjs} +300 -3
- package/dist/{agent-DpKOO7Ho.mjs → agent-DKYjtXUZ.mjs} +7 -6
- package/dist/{agents-Bhloif3y.mjs → agents-Cnc3dd_j.mjs} +5 -4
- package/dist/cli/index.mjs +27 -27
- package/dist/{cloud-DLc03Z41.mjs → cloud-B_bpA0Mh.mjs} +3 -3
- package/dist/{codeblocks-BnwZNsYO.mjs → codeblocks-CeKTPJGF.mjs} +3 -3
- package/dist/{dev-C5rHIIpC.mjs → dev-DxVevOP_.mjs} +3 -10
- package/dist/{doctor-kYJcYbcT.mjs → doctor-Dv15wAz6.mjs} +8 -8
- package/dist/{downgrade-D45M-NvV.mjs → downgrade-D7zavP20.mjs} +2 -2
- package/dist/index.d.mts +34 -3
- package/dist/index.mjs +5 -7
- package/dist/{init-D-Ki2dWn.mjs → init-CRS-LZdr.mjs} +6 -5
- package/dist/{mcp-Dvy_EkRx.mjs → mcp-ghAWpNPY.mjs} +4 -2
- package/dist/mcp.d.mts +3 -1
- package/dist/mcp.mjs +61 -2
- package/dist/{package-version-DMFdOnyC.mjs → package-version-CeNAB4NZ.mjs} +4 -4
- package/dist/{reading-time-DzuY0IRX.mjs → reading-time-CPAy1SWO.mjs} +1 -0
- package/dist/{review-DI_Ht3VO.mjs → review-Bnd4NH9y.mjs} +2 -2
- package/dist/{robots-CDdD2o-Q.mjs → robots-BcP7nSfi.mjs} +1 -2
- package/dist/{robots-DHQosx37.mjs → robots-BzO2bi0d.mjs} +4 -4
- package/dist/{search-BXupn-c-.mjs → search-BSqo7ypB.mjs} +4 -3
- package/dist/{search-D-iBv3VC.d.mts → search-CLP7-Z9w.d.mts} +1 -1
- package/dist/{search-B3JYx2zk.mjs → search-CdUxMazn.mjs} +268 -8
- package/dist/server.d.mts +2 -2
- package/dist/server.mjs +4 -4
- package/dist/{sitemap-BfViRvLP.mjs → sitemap-BSv5EDeM.mjs} +5 -4
- package/dist/{sitemap-server-CVSQQszk.mjs → sitemap-server-RZG9eOJB.mjs} +1 -1
- package/dist/{types-BCEobEGw.d.mts → types-CtF_65E4.d.mts} +69 -1
- package/dist/{upgrade-C1nInojy.mjs → upgrade-Dzej61y4.mjs} +2 -2
- package/dist/{utils-CGlOADu1.mjs → utils-CoHZJ1i4.mjs} +72 -6
- package/package.json +1 -1
- package/dist/related-BNj_NdHq.mjs +0 -50
- package/dist/sitemap-CMNj0Pt3.mjs +0 -252
- /package/dist/{config-rHQQuz98.mjs → config-De5z-2LK.mjs} +0 -0
- /package/dist/{errors-DqlZftq3.mjs → errors-Dw5gMhEZ.mjs} +0 -0
- /package/dist/{review-B7goPYUb.mjs → review-CJD85JTm.mjs} +0 -0
- /package/dist/{templates-CMcXQ0Gk.mjs → templates-BOoV0cIR.mjs} +0 -0
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
//#region src/sitemap.ts
|
|
2
|
-
const DEFAULT_SITEMAP_XML_ROUTE = "/sitemap.xml";
|
|
3
|
-
const DEFAULT_SITEMAP_MD_ROUTE = "/sitemap.md";
|
|
4
|
-
const DEFAULT_SITEMAP_MD_DOCS_ROUTE = "/docs/sitemap.md";
|
|
5
|
-
const DEFAULT_SITEMAP_MD_WELL_KNOWN_ROUTE = "/.well-known/sitemap.md";
|
|
6
|
-
const DEFAULT_SITEMAP_MANIFEST_PATH = ".farming-labs/sitemap-manifest.json";
|
|
7
|
-
function normalizeUrlPath(value) {
|
|
8
|
-
const normalized = value.replace(/\/+/g, "/");
|
|
9
|
-
if (normalized === "/") return normalized;
|
|
10
|
-
return normalized.replace(/\/+$/, "");
|
|
11
|
-
}
|
|
12
|
-
function normalizeRoutePrefix(value) {
|
|
13
|
-
if (!value) return "";
|
|
14
|
-
const normalized = normalizeUrlPath(`/${value.replace(/^\/+|\/+$/g, "")}`);
|
|
15
|
-
return normalized === "/" ? "" : normalized;
|
|
16
|
-
}
|
|
17
|
-
function joinRoute(prefix, route) {
|
|
18
|
-
return normalizeUrlPath(`${prefix}/${route.replace(/^\/+/, "")}`);
|
|
19
|
-
}
|
|
20
|
-
function normalizeDateOnly(value) {
|
|
21
|
-
if (!value) return void 0;
|
|
22
|
-
const trimmed = value.trim();
|
|
23
|
-
if (!trimmed) return void 0;
|
|
24
|
-
const dateOnly = trimmed.match(/^(\d{4}-\d{2}-\d{2})/);
|
|
25
|
-
if (dateOnly) return dateOnly[1];
|
|
26
|
-
const parsed = new Date(trimmed);
|
|
27
|
-
if (Number.isNaN(parsed.getTime())) return void 0;
|
|
28
|
-
return parsed.toISOString().slice(0, 10);
|
|
29
|
-
}
|
|
30
|
-
function normalizeBaseUrl(value) {
|
|
31
|
-
if (!value) return void 0;
|
|
32
|
-
return value.trim().replace(/\/+$/, "") || void 0;
|
|
33
|
-
}
|
|
34
|
-
function isEnabledObject(config) {
|
|
35
|
-
if (config === false) return false;
|
|
36
|
-
if (config === void 0) return true;
|
|
37
|
-
if (config === true) return true;
|
|
38
|
-
return config.enabled !== false;
|
|
39
|
-
}
|
|
40
|
-
function resolveDocsSitemapConfig(sitemap, defaults = {}) {
|
|
41
|
-
const objectConfig = sitemap && typeof sitemap === "object" ? sitemap : {};
|
|
42
|
-
const routePrefix = normalizeRoutePrefix(objectConfig.routePrefix);
|
|
43
|
-
const xmlConfig = objectConfig.xml;
|
|
44
|
-
const markdownConfig = objectConfig.markdown;
|
|
45
|
-
const xmlEnabled = xmlConfig === false ? false : typeof xmlConfig === "object" ? xmlConfig.enabled ?? true : true;
|
|
46
|
-
const markdownEnabled = markdownConfig === false ? false : typeof markdownConfig === "object" ? markdownConfig.enabled ?? true : true;
|
|
47
|
-
return {
|
|
48
|
-
enabled: isEnabledObject(sitemap),
|
|
49
|
-
routePrefix,
|
|
50
|
-
baseUrl: normalizeBaseUrl(objectConfig.baseUrl ?? defaults.baseUrl),
|
|
51
|
-
manifestPath: objectConfig.manifestPath ?? DEFAULT_SITEMAP_MANIFEST_PATH,
|
|
52
|
-
xml: {
|
|
53
|
-
enabled: xmlEnabled,
|
|
54
|
-
includeLastmod: typeof xmlConfig === "object" ? xmlConfig.includeLastmod ?? true : true,
|
|
55
|
-
route: joinRoute(routePrefix, DEFAULT_SITEMAP_XML_ROUTE)
|
|
56
|
-
},
|
|
57
|
-
markdown: {
|
|
58
|
-
enabled: markdownEnabled,
|
|
59
|
-
includeDescriptions: typeof markdownConfig === "object" ? markdownConfig.includeDescriptions ?? true : true,
|
|
60
|
-
includeLastmod: typeof markdownConfig === "object" ? markdownConfig.includeLastmod ?? true : true,
|
|
61
|
-
linkTarget: typeof markdownConfig === "object" ? markdownConfig.linkTarget ?? "both" : "both",
|
|
62
|
-
route: joinRoute(routePrefix, DEFAULT_SITEMAP_MD_ROUTE),
|
|
63
|
-
docsRoute: routePrefix ? void 0 : DEFAULT_SITEMAP_MD_DOCS_ROUTE,
|
|
64
|
-
wellKnownRoute: joinRoute(routePrefix, DEFAULT_SITEMAP_MD_WELL_KNOWN_ROUTE)
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
function resolveDocsSitemapRequest(url, sitemap) {
|
|
69
|
-
const pathname = normalizeUrlPath(url.pathname);
|
|
70
|
-
const format = url.searchParams.get("format")?.trim();
|
|
71
|
-
if (pathname === "/api/docs") {
|
|
72
|
-
if (format === "sitemap-xml") return "xml";
|
|
73
|
-
if (format === "sitemap-md" || format === "sitemap-markdown") return "markdown";
|
|
74
|
-
}
|
|
75
|
-
const resolved = resolveDocsSitemapConfig(sitemap);
|
|
76
|
-
if (!resolved.enabled) return null;
|
|
77
|
-
if (resolved.xml.enabled && pathname === resolved.xml.route) return "xml";
|
|
78
|
-
if (resolved.markdown.enabled && (pathname === resolved.markdown.route || pathname === resolved.markdown.docsRoute || pathname === resolved.markdown.wellKnownRoute)) return "markdown";
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
function toDocsSitemapMarkdownUrl(url) {
|
|
82
|
-
const normalized = normalizeUrlPath(url);
|
|
83
|
-
return normalized.endsWith(".md") ? normalized : `${normalized}.md`;
|
|
84
|
-
}
|
|
85
|
-
function absolutizeUrl(baseUrl, url) {
|
|
86
|
-
if (/^https?:\/\//i.test(url)) return url;
|
|
87
|
-
const base = normalizeBaseUrl(baseUrl);
|
|
88
|
-
return base ? `${base}${url.startsWith("/") ? url : `/${url}`}` : url;
|
|
89
|
-
}
|
|
90
|
-
function escapeXml(value) {
|
|
91
|
-
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
92
|
-
}
|
|
93
|
-
function hashString(value) {
|
|
94
|
-
let hash = 14695981039346656037n;
|
|
95
|
-
const bytes = new TextEncoder().encode(value);
|
|
96
|
-
for (const byte of bytes) {
|
|
97
|
-
hash ^= BigInt(byte);
|
|
98
|
-
hash = BigInt.asUintN(64, hash * 1099511628211n);
|
|
99
|
-
}
|
|
100
|
-
return `"fnv1a64-${hash.toString(16).padStart(16, "0")}"`;
|
|
101
|
-
}
|
|
102
|
-
function newestLastmod(pages) {
|
|
103
|
-
let newest;
|
|
104
|
-
for (const page of pages) {
|
|
105
|
-
const date = normalizeDateOnly(page.lastmod);
|
|
106
|
-
if (!date) continue;
|
|
107
|
-
if (!newest || date > newest) newest = date;
|
|
108
|
-
}
|
|
109
|
-
return newest;
|
|
110
|
-
}
|
|
111
|
-
function titleize(value) {
|
|
112
|
-
return value.replace(/-/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
|
|
113
|
-
}
|
|
114
|
-
function sitemapSectionName(entry, pageUrl) {
|
|
115
|
-
const normalizedEntry = `/${entry.replace(/^\/+|\/+$/g, "") || "docs"}`;
|
|
116
|
-
const normalizedUrl = normalizeUrlPath(pageUrl);
|
|
117
|
-
if (normalizedUrl === normalizedEntry) return "Overview";
|
|
118
|
-
const firstSegment = (normalizedUrl.startsWith(`${normalizedEntry}/`) ? normalizedUrl.slice(normalizedEntry.length + 1) : normalizedUrl.replace(/^\/+/, "")).split("/").filter(Boolean)[0];
|
|
119
|
-
return firstSegment ? titleize(firstSegment) : "Pages";
|
|
120
|
-
}
|
|
121
|
-
function buildDocsSitemapManifest(options) {
|
|
122
|
-
const baseUrl = normalizeBaseUrl(options.baseUrl);
|
|
123
|
-
const seen = /* @__PURE__ */ new Set();
|
|
124
|
-
const pages = [];
|
|
125
|
-
for (const page of options.pages) {
|
|
126
|
-
const url = normalizeUrlPath(page.url);
|
|
127
|
-
if (seen.has(url)) continue;
|
|
128
|
-
seen.add(url);
|
|
129
|
-
const resolvedLastmod = options.resolveLastmod?.(page);
|
|
130
|
-
const fallbackLastmod = normalizeDateOnly(page.lastmod ?? page.lastModified);
|
|
131
|
-
const lastmod = normalizeDateOnly(resolvedLastmod?.lastmod) ?? fallbackLastmod;
|
|
132
|
-
pages.push({
|
|
133
|
-
url,
|
|
134
|
-
absoluteUrl: absolutizeUrl(baseUrl, url),
|
|
135
|
-
markdownUrl: toDocsSitemapMarkdownUrl(url),
|
|
136
|
-
title: page.title,
|
|
137
|
-
description: page.description,
|
|
138
|
-
sourcePath: page.sourcePath,
|
|
139
|
-
lastmod,
|
|
140
|
-
lastmodSource: resolvedLastmod?.lastmodSource ?? (lastmod ? "unknown" : void 0),
|
|
141
|
-
related: page.related?.map((link) => link.href)
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
pages.sort((left, right) => left.url.localeCompare(right.url));
|
|
145
|
-
return {
|
|
146
|
-
version: 1,
|
|
147
|
-
generatedAt: options.generatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
148
|
-
baseUrl,
|
|
149
|
-
entry: options.entry ?? "docs",
|
|
150
|
-
siteTitle: options.siteTitle,
|
|
151
|
-
pages
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
function renderDocsSitemapXml(manifest, options = {}) {
|
|
155
|
-
const baseUrl = normalizeBaseUrl(options.baseUrl ?? manifest.baseUrl);
|
|
156
|
-
const includeLastmod = options.includeLastmod ?? true;
|
|
157
|
-
const lines = ["<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"];
|
|
158
|
-
for (const page of manifest.pages) {
|
|
159
|
-
lines.push(" <url>");
|
|
160
|
-
lines.push(` <loc>${escapeXml(page.absoluteUrl ?? absolutizeUrl(baseUrl, page.url))}</loc>`);
|
|
161
|
-
const lastmod = normalizeDateOnly(page.lastmod);
|
|
162
|
-
if (includeLastmod && lastmod) lines.push(` <lastmod>${lastmod}</lastmod>`);
|
|
163
|
-
lines.push(" </url>");
|
|
164
|
-
}
|
|
165
|
-
lines.push("</urlset>");
|
|
166
|
-
return `${lines.join("\n")}\n`;
|
|
167
|
-
}
|
|
168
|
-
function renderDocsSitemapMarkdown(manifest, options = {}) {
|
|
169
|
-
const siteTitle = manifest.siteTitle ?? "Documentation";
|
|
170
|
-
const includeDescriptions = options.includeDescriptions ?? true;
|
|
171
|
-
const includeLastmod = options.includeLastmod ?? true;
|
|
172
|
-
const linkTarget = options.linkTarget ?? "both";
|
|
173
|
-
const lines = [`# ${siteTitle} Sitemap`, ""];
|
|
174
|
-
const baseUrl = normalizeBaseUrl(options.baseUrl ?? manifest.baseUrl);
|
|
175
|
-
if (baseUrl) lines.push(`Base URL: ${baseUrl}`);
|
|
176
|
-
lines.push(`Docs entry: /${manifest.entry.replace(/^\/+|\/+$/g, "") || "docs"}`);
|
|
177
|
-
lines.push(`Generated: ${normalizeDateOnly(manifest.generatedAt) ?? manifest.generatedAt}`, "");
|
|
178
|
-
const groups = /* @__PURE__ */ new Map();
|
|
179
|
-
for (const page of manifest.pages) {
|
|
180
|
-
const sectionName = sitemapSectionName(manifest.entry, page.url);
|
|
181
|
-
groups.set(sectionName, [...groups.get(sectionName) ?? [], page]);
|
|
182
|
-
}
|
|
183
|
-
for (const [sectionName, pages] of groups) {
|
|
184
|
-
lines.push(`## ${sectionName}`, "");
|
|
185
|
-
for (const page of pages) {
|
|
186
|
-
const primaryHref = linkTarget === "markdown" ? page.markdownUrl : page.url;
|
|
187
|
-
lines.push(`- [${page.title}](${primaryHref})`);
|
|
188
|
-
if (linkTarget === "both" || linkTarget === "markdown") lines.push(` Markdown: ${page.markdownUrl}`);
|
|
189
|
-
if (includeDescriptions && page.description) lines.push(` Description: ${page.description}`);
|
|
190
|
-
const lastmod = normalizeDateOnly(page.lastmod);
|
|
191
|
-
if (includeLastmod && lastmod) lines.push(` Last updated: ${lastmod}`);
|
|
192
|
-
if (page.related && page.related.length > 0) lines.push(` Related: ${page.related.join(", ")}`);
|
|
193
|
-
lines.push("");
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return lines.join("\n").replace(/\n{3,}/g, "\n\n");
|
|
197
|
-
}
|
|
198
|
-
function readDocsSitemapManifestFromContentMap(contentMap) {
|
|
199
|
-
if (!contentMap) return null;
|
|
200
|
-
const raw = contentMap[`/${DEFAULT_SITEMAP_MANIFEST_PATH}`] ?? contentMap[DEFAULT_SITEMAP_MANIFEST_PATH];
|
|
201
|
-
if (!raw) return null;
|
|
202
|
-
try {
|
|
203
|
-
return JSON.parse(raw);
|
|
204
|
-
} catch {
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
function resolveDocsSitemapPageLastmod(manifest, url) {
|
|
209
|
-
if (!manifest) return void 0;
|
|
210
|
-
const normalizedUrl = normalizeUrlPath(url);
|
|
211
|
-
return normalizeDateOnly(manifest.pages.find((entry) => normalizeUrlPath(entry.url) === normalizedUrl)?.lastmod);
|
|
212
|
-
}
|
|
213
|
-
function createDocsSitemapResponse({ request, sitemap, entry = "docs", siteTitle, baseUrl, pages, manifest }) {
|
|
214
|
-
const url = new URL(request.url);
|
|
215
|
-
const format = resolveDocsSitemapRequest(url, sitemap);
|
|
216
|
-
if (!format) return null;
|
|
217
|
-
const resolved = resolveDocsSitemapConfig(sitemap, { baseUrl });
|
|
218
|
-
if (!resolved.enabled) return null;
|
|
219
|
-
if (format === "xml" && !resolved.xml.enabled) return null;
|
|
220
|
-
if (format === "markdown" && !resolved.markdown.enabled) return null;
|
|
221
|
-
const nextManifest = manifest ?? buildDocsSitemapManifest({
|
|
222
|
-
pages,
|
|
223
|
-
entry,
|
|
224
|
-
siteTitle,
|
|
225
|
-
baseUrl: resolved.baseUrl ?? url.origin
|
|
226
|
-
});
|
|
227
|
-
const responseBaseUrl = resolved.baseUrl ?? nextManifest.baseUrl ?? url.origin;
|
|
228
|
-
const body = format === "xml" ? renderDocsSitemapXml(nextManifest, {
|
|
229
|
-
baseUrl: responseBaseUrl,
|
|
230
|
-
includeLastmod: resolved.xml.includeLastmod
|
|
231
|
-
}) : renderDocsSitemapMarkdown(nextManifest, {
|
|
232
|
-
baseUrl: responseBaseUrl,
|
|
233
|
-
includeDescriptions: resolved.markdown.includeDescriptions,
|
|
234
|
-
includeLastmod: resolved.markdown.includeLastmod,
|
|
235
|
-
linkTarget: resolved.markdown.linkTarget
|
|
236
|
-
});
|
|
237
|
-
const headers = new Headers({
|
|
238
|
-
"Content-Type": format === "xml" ? "application/xml; charset=utf-8" : "text/markdown; charset=utf-8",
|
|
239
|
-
"Cache-Control": "public, max-age=0, must-revalidate",
|
|
240
|
-
ETag: hashString(body)
|
|
241
|
-
});
|
|
242
|
-
const lastModified = newestLastmod(nextManifest.pages);
|
|
243
|
-
if (lastModified) headers.set("Last-Modified", (/* @__PURE__ */ new Date(`${lastModified}T00:00:00.000Z`)).toUTCString());
|
|
244
|
-
if (request.headers.get("if-none-match") === headers.get("ETag")) return new Response(null, {
|
|
245
|
-
status: 304,
|
|
246
|
-
headers
|
|
247
|
-
});
|
|
248
|
-
return new Response(body, { headers });
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
//#endregion
|
|
252
|
-
export { DEFAULT_SITEMAP_XML_ROUTE as a, readDocsSitemapManifestFromContentMap as c, resolveDocsSitemapConfig as d, resolveDocsSitemapPageLastmod as f, DEFAULT_SITEMAP_MD_WELL_KNOWN_ROUTE as i, renderDocsSitemapMarkdown as l, toDocsSitemapMarkdownUrl as m, DEFAULT_SITEMAP_MD_DOCS_ROUTE as n, buildDocsSitemapManifest as o, resolveDocsSitemapRequest as p, DEFAULT_SITEMAP_MD_ROUTE as r, createDocsSitemapResponse as s, DEFAULT_SITEMAP_MANIFEST_PATH as t, renderDocsSitemapXml as u };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|