@farming-labs/svelte 0.0.2-beta.21 → 0.0.2-beta.23
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/content.js +1 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/markdown.js +2 -7
- package/dist/server.js +52 -11
- package/package.json +13 -13
package/dist/content.js
CHANGED
|
@@ -35,9 +35,7 @@ export function loadDocsContent(contentDir, entry = "docs") {
|
|
|
35
35
|
const { data, content } = matter(raw);
|
|
36
36
|
const baseName = name.replace(/\.(md|mdx|svx)$/, "");
|
|
37
37
|
const isIndex = baseName === "index" || baseName === "page" || baseName === "+page";
|
|
38
|
-
const slug = isIndex
|
|
39
|
-
? slugParts.join("/")
|
|
40
|
-
: [...slugParts, baseName].join("/");
|
|
38
|
+
const slug = isIndex ? slugParts.join("/") : [...slugParts, baseName].join("/");
|
|
41
39
|
const url = slug ? `/${entry}/${slug}` : `/${entry}`;
|
|
42
40
|
const title = data.title ??
|
|
43
41
|
baseName.replace(/-/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Provides content loading, navigation tree building, search,
|
|
6
6
|
* and server-side markdown rendering for SvelteKit-based documentation sites.
|
|
7
7
|
*/
|
|
8
|
-
export { loadDocsContent, loadDocsNavTree, flattenNavTree, type NavNode, type NavTree, type PageNode, type FolderNode } from "./content.js";
|
|
8
|
+
export { loadDocsContent, loadDocsNavTree, flattenNavTree, type NavNode, type NavTree, type PageNode, type FolderNode, } from "./content.js";
|
|
9
9
|
export { createMdsvexConfig } from "./config.js";
|
|
10
10
|
export { renderMarkdown } from "./markdown.js";
|
|
11
11
|
export { createDocsServer, type DocsServer } from "./server.js";
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Provides content loading, navigation tree building, search,
|
|
6
6
|
* and server-side markdown rendering for SvelteKit-based documentation sites.
|
|
7
7
|
*/
|
|
8
|
-
export { loadDocsContent, loadDocsNavTree, flattenNavTree } from "./content.js";
|
|
8
|
+
export { loadDocsContent, loadDocsNavTree, flattenNavTree, } from "./content.js";
|
|
9
9
|
export { createMdsvexConfig } from "./config.js";
|
|
10
10
|
export { renderMarkdown } from "./markdown.js";
|
|
11
11
|
export { createDocsServer } from "./server.js";
|
package/dist/markdown.js
CHANGED
|
@@ -74,10 +74,7 @@ function highlightCode(hl, code, lang) {
|
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
catch {
|
|
77
|
-
const escaped = trimmedCode
|
|
78
|
-
.replace(/&/g, "&")
|
|
79
|
-
.replace(/</g, "<")
|
|
80
|
-
.replace(/>/g, ">");
|
|
77
|
+
const escaped = trimmedCode.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
81
78
|
return {
|
|
82
79
|
html: `<pre class="shiki"><code>${escaped}</code></pre>`,
|
|
83
80
|
raw: trimmedCode,
|
|
@@ -128,9 +125,7 @@ export async function renderMarkdown(content) {
|
|
|
128
125
|
// ── Tabs blocks: <Tabs items={[...]}> ... </Tabs> ──
|
|
129
126
|
const tabsBlocks = [];
|
|
130
127
|
result = result.replace(/<Tabs\s+items=\{?\[([^\]]+)\]\}?>([\s\S]*?)<\/Tabs>/g, (_, itemsStr, body) => {
|
|
131
|
-
const items = itemsStr
|
|
132
|
-
.split(",")
|
|
133
|
-
.map((s) => s.trim().replace(/^["']|["']$/g, ""));
|
|
128
|
+
const items = itemsStr.split(",").map((s) => s.trim().replace(/^["']|["']$/g, ""));
|
|
134
129
|
const panels = [];
|
|
135
130
|
const tabRegex = /<Tab\s+value=["']([^"']+)["']>([\s\S]*?)<\/Tab>/g;
|
|
136
131
|
let tabMatch;
|
package/dist/server.js
CHANGED
|
@@ -65,9 +65,7 @@ function navTreeFromMap(contentMap, dirPrefix, entry, ordering) {
|
|
|
65
65
|
const slug = dirParts.join("/");
|
|
66
66
|
const url = slug ? `/${entry}/${slug}` : `/${entry}`;
|
|
67
67
|
const fallbackTitle = dirParts.length > 0
|
|
68
|
-
? dirParts[dirParts.length - 1]
|
|
69
|
-
.replace(/-/g, " ")
|
|
70
|
-
.replace(/\b\w/g, (c) => c.toUpperCase())
|
|
68
|
+
? dirParts[dirParts.length - 1].replace(/-/g, " ").replace(/\b\w/g, (c) => c.toUpperCase())
|
|
71
69
|
: "Documentation";
|
|
72
70
|
dirs.push({
|
|
73
71
|
parts: dirParts,
|
|
@@ -206,8 +204,7 @@ function searchIndexFromMap(contentMap, dirPrefix, entry) {
|
|
|
206
204
|
const slug = isIdx ? segments.join("/") : [...segments, base].join("/");
|
|
207
205
|
const url = slug ? `/${entry}/${slug}` : `/${entry}`;
|
|
208
206
|
const { data, content } = matter(raw);
|
|
209
|
-
const title = data.title ??
|
|
210
|
-
base.replace(/-/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
207
|
+
const title = data.title ?? base.replace(/-/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
211
208
|
pages.push({
|
|
212
209
|
slug,
|
|
213
210
|
url,
|
|
@@ -252,9 +249,7 @@ function findPageInMap(contentMap, dirPrefix, slug) {
|
|
|
252
249
|
export function createDocsServer(config = {}) {
|
|
253
250
|
const entry = config.entry ?? "docs";
|
|
254
251
|
const githubRaw = config.github;
|
|
255
|
-
const github = typeof githubRaw === "string"
|
|
256
|
-
? { url: githubRaw }
|
|
257
|
-
: githubRaw ?? null;
|
|
252
|
+
const github = typeof githubRaw === "string" ? { url: githubRaw } : (githubRaw ?? null);
|
|
258
253
|
const githubRepo = github?.url;
|
|
259
254
|
const githubBranch = github?.branch ?? "main";
|
|
260
255
|
const githubContentPath = github?.directory;
|
|
@@ -350,7 +345,7 @@ export function createDocsServer(config = {}) {
|
|
|
350
345
|
}
|
|
351
346
|
const fallbackTitle = isIndex
|
|
352
347
|
? "Documentation"
|
|
353
|
-
: slug.split("/").pop()?.replace(/-/g, " ") ?? "Documentation";
|
|
348
|
+
: (slug.split("/").pop()?.replace(/-/g, " ") ?? "Documentation");
|
|
354
349
|
return {
|
|
355
350
|
tree,
|
|
356
351
|
flatPages,
|
|
@@ -388,8 +383,51 @@ export function createDocsServer(config = {}) {
|
|
|
388
383
|
.filter((r) => r.score > 0)
|
|
389
384
|
.sort((a, b) => b.score - a.score);
|
|
390
385
|
}
|
|
391
|
-
// ───
|
|
386
|
+
// ─── llms.txt content builder ────────────────────────────────
|
|
387
|
+
const llmsSiteTitle = typeof config.nav === "object" &&
|
|
388
|
+
typeof config.nav?.title === "string"
|
|
389
|
+
? config.nav.title
|
|
390
|
+
: "Documentation";
|
|
391
|
+
const llmsTxtConfig = config.llmsTxt;
|
|
392
|
+
const llmsBaseUrl = typeof llmsTxtConfig === "object" ? (llmsTxtConfig.baseUrl ?? "") : "";
|
|
393
|
+
const llmsTitle = typeof llmsTxtConfig === "object" ? (llmsTxtConfig.siteTitle ?? llmsSiteTitle) : llmsSiteTitle;
|
|
394
|
+
const llmsDesc = typeof llmsTxtConfig === "object" ? llmsTxtConfig.siteDescription : undefined;
|
|
395
|
+
function buildLlmsTxt(full) {
|
|
396
|
+
const pages = getSearchIndex();
|
|
397
|
+
let out = `# ${llmsTitle}\n\n`;
|
|
398
|
+
if (llmsDesc)
|
|
399
|
+
out += `> ${llmsDesc}\n\n`;
|
|
400
|
+
if (full) {
|
|
401
|
+
for (const page of pages) {
|
|
402
|
+
out += `## ${page.title}\n\n`;
|
|
403
|
+
out += `URL: ${llmsBaseUrl}${page.url}\n\n`;
|
|
404
|
+
if (page.description)
|
|
405
|
+
out += `${page.description}\n\n`;
|
|
406
|
+
out += `${page.content}\n\n---\n\n`;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
out += `## Pages\n\n`;
|
|
411
|
+
for (const page of pages) {
|
|
412
|
+
out += `- [${page.title}](${llmsBaseUrl}${page.url})`;
|
|
413
|
+
if (page.description)
|
|
414
|
+
out += `: ${page.description}`;
|
|
415
|
+
out += `\n`;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return out;
|
|
419
|
+
}
|
|
420
|
+
// ─── GET /api/docs?query=… | ?format=llms | ?format=llms-full ──
|
|
392
421
|
function GET(event) {
|
|
422
|
+
const format = event.url.searchParams.get("format");
|
|
423
|
+
if (format === "llms" || format === "llms-full") {
|
|
424
|
+
return new Response(buildLlmsTxt(format === "llms-full"), {
|
|
425
|
+
headers: {
|
|
426
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
427
|
+
"Cache-Control": "public, max-age=3600",
|
|
428
|
+
},
|
|
429
|
+
});
|
|
430
|
+
}
|
|
393
431
|
const query = event.url.searchParams.get("query")?.toLowerCase().trim();
|
|
394
432
|
if (!query) {
|
|
395
433
|
return new Response(JSON.stringify([]), {
|
|
@@ -456,7 +494,10 @@ export function createDocsServer(config = {}) {
|
|
|
456
494
|
}
|
|
457
495
|
const lastUserMessage = [...messages].reverse().find((m) => m.role === "user");
|
|
458
496
|
if (!lastUserMessage) {
|
|
459
|
-
return new Response(JSON.stringify({ error: "At least one user message is required." }), {
|
|
497
|
+
return new Response(JSON.stringify({ error: "At least one user message is required." }), {
|
|
498
|
+
status: 400,
|
|
499
|
+
headers: { "Content-Type": "application/json" },
|
|
500
|
+
});
|
|
460
501
|
}
|
|
461
502
|
const maxResults = aiConfig.maxResults ?? 5;
|
|
462
503
|
const scored = searchByQuery(lastUserMessage.content.toLowerCase()).slice(0, maxResults);
|
package/package.json
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/svelte",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.23",
|
|
4
4
|
"description": "SvelteKit adapter for @farming-labs/docs — content loading and navigation utilities",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"docs",
|
|
7
|
+
"documentation",
|
|
8
|
+
"svelte",
|
|
9
|
+
"sveltekit"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "Farming Labs",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
5
16
|
"type": "module",
|
|
6
17
|
"main": "./dist/index.js",
|
|
7
18
|
"types": "./dist/index.d.ts",
|
|
@@ -32,17 +43,6 @@
|
|
|
32
43
|
"default": "./dist/server.js"
|
|
33
44
|
}
|
|
34
45
|
},
|
|
35
|
-
"files": [
|
|
36
|
-
"dist"
|
|
37
|
-
],
|
|
38
|
-
"keywords": [
|
|
39
|
-
"docs",
|
|
40
|
-
"svelte",
|
|
41
|
-
"sveltekit",
|
|
42
|
-
"documentation"
|
|
43
|
-
],
|
|
44
|
-
"author": "Farming Labs",
|
|
45
|
-
"license": "MIT",
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"gray-matter": "^4.0.3",
|
|
48
48
|
"shiki": "^3.2.1"
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^22.10.0",
|
|
52
52
|
"typescript": "^5.9.3",
|
|
53
|
-
"@farming-labs/docs": "0.0.2-beta.
|
|
53
|
+
"@farming-labs/docs": "0.0.2-beta.23"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@farming-labs/docs": "*"
|