@farming-labs/svelte 0.2.50 → 0.2.53
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/README.md +73 -0
- package/dist/content.d.ts +6 -1
- package/dist/content.js +8 -1
- package/dist/server.js +24 -48
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @farming-labs/svelte
|
|
2
|
+
|
|
3
|
+
The SvelteKit runtime adapter for
|
|
4
|
+
[`@farming-labs/docs`](https://www.npmjs.com/package/@farming-labs/docs).
|
|
5
|
+
|
|
6
|
+
It loads Markdown, MDX, and SVX content, builds navigation, renders page content on the server, and
|
|
7
|
+
provides SvelteKit handlers for docs, search, AI, agent discovery, MCP, and API references.
|
|
8
|
+
|
|
9
|
+
## Package responsibilities
|
|
10
|
+
|
|
11
|
+
- `@farming-labs/docs` — shared config, types, content features, and CLI
|
|
12
|
+
- `@farming-labs/svelte` — SvelteKit content loading and server handlers
|
|
13
|
+
- `@farming-labs/svelte-theme` — Svelte layout and UI components
|
|
14
|
+
- `@farming-labs/theme` — shared preset CSS
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
The CLI can wire the complete SvelteKit integration:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx @farming-labs/docs@latest init
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
For manual installation:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @farming-labs/docs @farming-labs/svelte @farming-labs/svelte-theme @farming-labs/theme
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Server integration
|
|
31
|
+
|
|
32
|
+
Preload content with Vite and create the docs server:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
// src/lib/docs.server.ts
|
|
36
|
+
import { createDocsServer } from "@farming-labs/svelte/server";
|
|
37
|
+
import config from "./docs.config";
|
|
38
|
+
|
|
39
|
+
const contentFiles = import.meta.glob("/docs/**/*.{md,mdx,svx}", {
|
|
40
|
+
query: "?raw",
|
|
41
|
+
import: "default",
|
|
42
|
+
eager: true,
|
|
43
|
+
}) as Record<string, string>;
|
|
44
|
+
|
|
45
|
+
export const { load, GET, POST, MCP } = createDocsServer({
|
|
46
|
+
...config,
|
|
47
|
+
_preloadedContent: contentFiles,
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Re-export `load` from the docs `+layout.server.ts` and `GET`/`POST` from the docs API route. Use
|
|
52
|
+
`DocsLayout` and `DocsContent` from `@farming-labs/svelte-theme` for presentation. The CLI
|
|
53
|
+
generates all of these files, including public agent and MCP forwarding.
|
|
54
|
+
|
|
55
|
+
## Main entrypoints
|
|
56
|
+
|
|
57
|
+
| Entrypoint | Purpose |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `@farming-labs/svelte/server` | Docs server, loaders, API/MCP handlers, and API-reference helper |
|
|
60
|
+
| `@farming-labs/svelte/content` | Content discovery and navigation utilities |
|
|
61
|
+
| `@farming-labs/svelte/markdown` | Server-side Markdown rendering |
|
|
62
|
+
| `@farming-labs/svelte/config` | Optional mdsvex configuration helper |
|
|
63
|
+
| `@farming-labs/svelte/api-reference` | API-reference route handler |
|
|
64
|
+
|
|
65
|
+
## Learn more
|
|
66
|
+
|
|
67
|
+
- [Documentation](https://docs.farming-labs.dev/docs)
|
|
68
|
+
- [SvelteKit example](https://github.com/farming-labs/docs/tree/main/examples/sveltekit)
|
|
69
|
+
- [GitHub repository](https://github.com/farming-labs/docs)
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
MIT
|
package/dist/content.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* extracts frontmatter, and builds a navigation tree compatible
|
|
6
6
|
* with @farming-labs/docs DocsConfig.
|
|
7
7
|
*/
|
|
8
|
-
import { type OrderingItem, type ResolvedDocsRelatedLink, type SidebarFolderIndexBehavior } from "@farming-labs/docs";
|
|
8
|
+
import { type OrderingItem, type PageAgentFrontmatter, type ResolvedDocsRelatedLink, type SidebarFolderIndexBehavior } from "@farming-labs/docs";
|
|
9
9
|
export interface PageNode {
|
|
10
10
|
type: "page";
|
|
11
11
|
name: string;
|
|
@@ -32,9 +32,14 @@ export interface ContentPage {
|
|
|
32
32
|
title: string;
|
|
33
33
|
description?: string;
|
|
34
34
|
related?: ResolvedDocsRelatedLink[];
|
|
35
|
+
agent?: PageAgentFrontmatter;
|
|
35
36
|
icon?: string;
|
|
36
37
|
sourcePath?: string;
|
|
37
38
|
lastModified?: string;
|
|
39
|
+
locale?: string;
|
|
40
|
+
framework?: string;
|
|
41
|
+
version?: string;
|
|
42
|
+
tags?: string[];
|
|
38
43
|
content: string;
|
|
39
44
|
rawContent: string;
|
|
40
45
|
agentContent?: string;
|
package/dist/content.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import fs from "node:fs";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import matter from "gray-matter";
|
|
11
|
-
import { normalizeDocsRelated, resolveDocsAgentMdxContent, resolvePageSidebarFolderIndexBehavior, } from "@farming-labs/docs";
|
|
11
|
+
import { normalizeDocsRelated, normalizePageAgentFrontmatter, resolveDocsAgentMdxContent, resolvePageSidebarFolderIndexBehavior, } from "@farming-labs/docs";
|
|
12
12
|
/**
|
|
13
13
|
* Scan a content directory and return all docs pages.
|
|
14
14
|
* Expects a flat or nested structure of `.md` files:
|
|
@@ -52,9 +52,16 @@ export function loadDocsContent(contentDir, entry = "docs") {
|
|
|
52
52
|
title,
|
|
53
53
|
description: data.description,
|
|
54
54
|
...(related.length > 0 ? { related } : {}),
|
|
55
|
+
agent: normalizePageAgentFrontmatter(data.agent),
|
|
55
56
|
icon: data.icon,
|
|
56
57
|
sourcePath: full.replace(/\\/g, "/"),
|
|
57
58
|
lastModified: stat.mtime.toISOString(),
|
|
59
|
+
locale: typeof data.locale === "string" ? data.locale : undefined,
|
|
60
|
+
framework: typeof data.framework === "string" ? data.framework : undefined,
|
|
61
|
+
version: typeof data.version === "string" ? data.version : undefined,
|
|
62
|
+
tags: Array.isArray(data.tags)
|
|
63
|
+
? data.tags.filter((tag) => typeof tag === "string")
|
|
64
|
+
: undefined,
|
|
58
65
|
content: stripMarkdown(humanRawContent),
|
|
59
66
|
rawContent: humanRawContent,
|
|
60
67
|
...(pageAgentRawContent !== humanRawContent
|
package/dist/server.js
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
import fs from "node:fs";
|
|
31
31
|
import path from "node:path";
|
|
32
32
|
import matter from "gray-matter";
|
|
33
|
-
import { applySidebarFolderIndexBehavior, buildDocsAskAIContext, buildDocsAgentDiscoverySpec, buildDocsConfigMap, buildDocsDiagnostics, createDocsRobotsResponse, createDocsSitemapResponse, createDocsAgentTraceContext, createDocsAgentTraceId, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, findDocsMarkdownPage, getDocsLlmsTxtMaxCharsIssue,
|
|
33
|
+
import { applySidebarFolderIndexBehavior, buildDocsAskAIContext, buildDocsAgentDiscoverySpec, buildDocsConfigMap, buildDocsDiagnostics, createDocsMarkdownResponse, createDocsRobotsResponse, createDocsSitemapResponse, createDocsAgentTraceContext, createDocsAgentTraceId, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, findDocsMarkdownPage, getDocsLlmsTxtMaxCharsIssue, isDocsAgentDiscoveryRequest, isDocsAgentsRequest, isDocsConfigRequest, isDocsDiagnosticsRequest, isDocsSkillRequest, normalizeDocsRelated, normalizePageAgentFrontmatter, parseDocsAgentFeedbackData, performDocsSearch, renderDocsMarkdownDocument, renderDocsLlmsTxt, renderDocsAgentsDocument, renderDocsSkillDocument, readDocsSitemapManifestFromContentMap, stripGeneratedAgentProvenance, resolveDocsAgentMdxContent, resolveDocsAgentFeedbackConfig, resolveDocsAgentFeedbackRequest, resolvePageSidebarFolderIndexBehavior, resolveAskAISearchRequestConfig, resolveSearchRequestConfig, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLocale, resolveDocsMarkdownRequest, resolveDocsMetadataBaseUrl, resolveDocsPath, resolvePageReadingTime, resolveReadingTimeOptions, resolveDocsSitemapPageLastmod, resolveDocsAgentsFormat, resolveDocsSkillFormat, inferDocsTelemetryAgentSurface, renderDocsPageStructuredDataJson, selectDocsLlmsTxtContent, validateDocsAgentFeedbackPayload, } from "@farming-labs/docs";
|
|
34
34
|
import { buildApiReferenceOpenApiDocumentAsync, createDocsCloudAskAIResponse, createDocsMcpHttpHandler, isDocsCloudAskAIProvider, readDocsSitemapManifest, resolveApiReferenceConfig, resolveDocsMcpConfig, serializeDocsIconRegistry, serializeOpenDocsProviders, } from "@farming-labs/docs/server";
|
|
35
35
|
import { loadDocsNavTree, loadDocsContent, flattenNavTree } from "./content.js";
|
|
36
36
|
import { renderMarkdown } from "./markdown.js";
|
|
@@ -336,7 +336,14 @@ function searchIndexFromMap(contentMap, dirPrefix, entry) {
|
|
|
336
336
|
title,
|
|
337
337
|
description: data.description,
|
|
338
338
|
...(related.length > 0 ? { related } : {}),
|
|
339
|
+
agent: normalizePageAgentFrontmatter(data.agent),
|
|
339
340
|
icon: data.icon,
|
|
341
|
+
locale: typeof data.locale === "string" ? data.locale : undefined,
|
|
342
|
+
framework: typeof data.framework === "string" ? data.framework : undefined,
|
|
343
|
+
version: typeof data.version === "string" ? data.version : undefined,
|
|
344
|
+
tags: Array.isArray(data.tags)
|
|
345
|
+
? data.tags.filter((tag) => typeof tag === "string")
|
|
346
|
+
: undefined,
|
|
340
347
|
content: stripMarkdownText(humanRawContent),
|
|
341
348
|
rawContent: humanRawContent,
|
|
342
349
|
...(pageAgentRawContent !== humanRawContent
|
|
@@ -585,6 +592,7 @@ export function createDocsServer(config = {}) {
|
|
|
585
592
|
baseUrl: resolveDocsMetadataBaseUrl(config),
|
|
586
593
|
entry,
|
|
587
594
|
dateModified: lastModifiedIso,
|
|
595
|
+
agent: normalizePageAgentFrontmatter(data.agent),
|
|
588
596
|
});
|
|
589
597
|
return {
|
|
590
598
|
tree,
|
|
@@ -682,9 +690,14 @@ export function createDocsServer(config = {}) {
|
|
|
682
690
|
return locale;
|
|
683
691
|
return i18n.defaultLocale;
|
|
684
692
|
}
|
|
685
|
-
function
|
|
693
|
+
function getMarkdownRepresentation(ctx, requestedPath, origin) {
|
|
686
694
|
const page = findDocsMarkdownPage(entry, getSearchIndex(ctx), requestedPath);
|
|
687
|
-
return page
|
|
695
|
+
return page
|
|
696
|
+
? {
|
|
697
|
+
document: renderDocsMarkdownDocument(page, { origin, sitemap: config.sitemap }),
|
|
698
|
+
lastModified: page.agentRawContent === undefined ? page.lastModified : undefined,
|
|
699
|
+
}
|
|
700
|
+
: null;
|
|
688
701
|
}
|
|
689
702
|
// ─── GET /api/docs?query=… | ?format=llms | ?format=llms-full ──
|
|
690
703
|
async function GET(event) {
|
|
@@ -870,54 +883,17 @@ export function createDocsServer(config = {}) {
|
|
|
870
883
|
const markdownRequest = resolveDocsMarkdownRequest(entry, event.url, event.request);
|
|
871
884
|
if (markdownRequest) {
|
|
872
885
|
const markdownOrigin = markdownMetadataBaseUrl || event.url.origin;
|
|
873
|
-
const
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
886
|
+
const representation = getMarkdownRepresentation(ctx, markdownRequest.requestedPath, markdownOrigin);
|
|
887
|
+
return createDocsMarkdownResponse({
|
|
888
|
+
request: event.request,
|
|
889
|
+
document: representation?.document ?? null,
|
|
877
890
|
entry,
|
|
878
891
|
requestedPath: markdownRequest.requestedPath,
|
|
892
|
+
origin: markdownOrigin,
|
|
879
893
|
locale: ctx.locale,
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
entry,
|
|
884
|
-
requestedPath: markdownRequest.requestedPath,
|
|
885
|
-
pages: getSearchIndex(ctx),
|
|
886
|
-
sitemap: config.sitemap,
|
|
887
|
-
});
|
|
888
|
-
if (recovery.redirect) {
|
|
889
|
-
return new Response(null, {
|
|
890
|
-
status: 307,
|
|
891
|
-
headers: {
|
|
892
|
-
Location: new URL(recovery.redirect.markdownUrl, event.url.origin).toString(),
|
|
893
|
-
...(varyHeader ? { Vary: varyHeader } : {}),
|
|
894
|
-
"X-Robots-Tag": "noindex",
|
|
895
|
-
},
|
|
896
|
-
});
|
|
897
|
-
}
|
|
898
|
-
return new Response(renderDocsMarkdownNotFound({
|
|
899
|
-
entry,
|
|
900
|
-
requestedPath: markdownRequest.requestedPath,
|
|
901
|
-
origin: markdownOrigin,
|
|
902
|
-
pages: getSearchIndex(ctx),
|
|
903
|
-
sitemap: config.sitemap,
|
|
904
|
-
}), {
|
|
905
|
-
status: 200,
|
|
906
|
-
headers: {
|
|
907
|
-
"Content-Type": "text/markdown; charset=utf-8",
|
|
908
|
-
...(varyHeader ? { Vary: varyHeader } : {}),
|
|
909
|
-
"X-Robots-Tag": "noindex",
|
|
910
|
-
},
|
|
911
|
-
});
|
|
912
|
-
}
|
|
913
|
-
return new Response(document, {
|
|
914
|
-
headers: {
|
|
915
|
-
"Content-Type": "text/markdown; charset=utf-8",
|
|
916
|
-
"Cache-Control": "public, max-age=0, s-maxage=3600",
|
|
917
|
-
Link: canonicalLinkHeader,
|
|
918
|
-
...(varyHeader ? { Vary: varyHeader } : {}),
|
|
919
|
-
"X-Robots-Tag": "noindex",
|
|
920
|
-
},
|
|
894
|
+
lastModified: representation?.lastModified,
|
|
895
|
+
pages: getSearchIndex(ctx),
|
|
896
|
+
sitemap: config.sitemap,
|
|
921
897
|
});
|
|
922
898
|
}
|
|
923
899
|
const llmsRequest = resolveDocsLlmsTxtRequest(event.url, llmsTxtConfig, entry);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/svelte",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.53",
|
|
4
4
|
"description": "SvelteKit adapter for @farming-labs/docs — content loading and navigation utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/node": "^22.10.0",
|
|
58
58
|
"typescript": "^5.9.3",
|
|
59
|
-
"@farming-labs/docs": "0.2.
|
|
59
|
+
"@farming-labs/docs": "0.2.53"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@farming-labs/docs": "*"
|