@farming-labs/svelte 0.2.73 → 0.2.75
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.d.ts +3 -0
- package/dist/content.js +9 -0
- package/dist/server.js +25 -21
- package/package.json +2 -2
package/dist/content.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export interface ContentPage {
|
|
|
35
35
|
agent?: PageAgentFrontmatter;
|
|
36
36
|
icon?: string;
|
|
37
37
|
sourcePath?: string;
|
|
38
|
+
lastmod?: string;
|
|
38
39
|
lastModified?: string;
|
|
39
40
|
locale?: string;
|
|
40
41
|
framework?: string;
|
|
@@ -44,9 +45,11 @@ export interface ContentPage {
|
|
|
44
45
|
rawContent: string;
|
|
45
46
|
agentContent?: string;
|
|
46
47
|
agentRawContent?: string;
|
|
48
|
+
agentLastModified?: string;
|
|
47
49
|
agentFallbackContent?: string;
|
|
48
50
|
agentFallbackRawContent?: string;
|
|
49
51
|
}
|
|
52
|
+
export declare function normalizeDocsFrontmatterLastmod(value: unknown): string | undefined;
|
|
50
53
|
/**
|
|
51
54
|
* Scan a content directory and return all docs pages.
|
|
52
55
|
* Expects a flat or nested structure of `.md` files:
|
package/dist/content.js
CHANGED
|
@@ -9,6 +9,13 @@ import fs from "node:fs";
|
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import matter from "gray-matter";
|
|
11
11
|
import { normalizeDocsRelated, normalizePageAgentFrontmatter, resolveDocsAudienceMdxContent, resolvePageSidebarFolderIndexBehavior, } from "@farming-labs/docs";
|
|
12
|
+
export function normalizeDocsFrontmatterLastmod(value) {
|
|
13
|
+
if (typeof value === "string")
|
|
14
|
+
return value;
|
|
15
|
+
if (value instanceof Date && !Number.isNaN(value.getTime()))
|
|
16
|
+
return value.toISOString();
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
12
19
|
/**
|
|
13
20
|
* Scan a content directory and return all docs pages.
|
|
14
21
|
* Expects a flat or nested structure of `.md` files:
|
|
@@ -55,6 +62,7 @@ export function loadDocsContent(contentDir, entry = "docs") {
|
|
|
55
62
|
agent: normalizePageAgentFrontmatter(data.agent),
|
|
56
63
|
icon: data.icon,
|
|
57
64
|
sourcePath: full.replace(/\\/g, "/"),
|
|
65
|
+
lastmod: normalizeDocsFrontmatterLastmod(data.lastmod),
|
|
58
66
|
lastModified: stat.mtime.toISOString(),
|
|
59
67
|
locale: typeof data.locale === "string" ? data.locale : undefined,
|
|
60
68
|
framework: typeof data.framework === "string" ? data.framework : undefined,
|
|
@@ -87,6 +95,7 @@ function readAgentDoc(dir) {
|
|
|
87
95
|
return {
|
|
88
96
|
agentContent: stripMarkdown(agentRawContent),
|
|
89
97
|
agentRawContent,
|
|
98
|
+
agentLastModified: fs.statSync(agentPath).mtime.toISOString(),
|
|
90
99
|
};
|
|
91
100
|
}
|
|
92
101
|
/**
|
package/dist/server.js
CHANGED
|
@@ -30,9 +30,9 @@
|
|
|
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, createDocsStandardsDiscoveryResponse, createDocsMarkdownResponse, createDocsRobotsResponse, createDocsSitemapResponse, createDocsAgentTraceContext, createDocsAgentTraceId, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, findDocsMarkdownPage, getDocsLlmsTxtMaxCharsIssue, getDocsAgentManifestLinkHeader, getDocsDiscoveryLinkHeader, isDocsAgentDiscoveryRequest, isDocsAgentsRequest, isDocsConfigRequest, isDocsDiagnosticsRequest, isDocsSkillRequest, normalizeDocsRelated, normalizePageAgentFrontmatter, parseDocsAgentFeedbackData, performDocsSearch, performDocsSearchWithMetadata, renderDocsMarkdownDocument, renderDocsLlmsTxt, renderDocsAgentsDocument, renderDocsSkillDocument, readDocsSitemapManifestFromContentMap, stripGeneratedAgentProvenance, resolveDocsAudienceMdxContent, resolveDocsAgentFeedbackConfig, resolveDocsAgentFeedbackRequest, resolvePageSidebarFolderIndexBehavior, resolveAskAISearchRequestConfig, resolveDocsSearchAudience, resolveDocsSearchFilters, resolveSearchRequestConfig, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLocale, resolveDocsMarkdownRequest, resolveDocsMetadataBaseUrl, resolveDocsRequestApiRoute, resolveDocsPublishedAgentSkill, resolveDocsStandardsDiscoveryRequest, resolveDocsPath, resolvePageReadingTime, resolveReadingTimeOptions, resolveDocsSitemapPageLastmod, resolveDocsAgentsFormat, resolveDocsSkillFormat, inferDocsTelemetryAgentSurface, renderDocsPageStructuredDataJson, selectDocsLlmsTxtContent, validateDocsAgentFeedbackPayload, } from "@farming-labs/docs";
|
|
33
|
+
import { applySidebarFolderIndexBehavior, buildDocsAskAIContext, buildDocsAgentDiscoverySpec, buildDocsConfigMap, buildDocsDiagnostics, createDocsStandardsDiscoveryResponse, createDocsMarkdownResponse, createDocsRobotsResponse, createDocsSitemapResponse, createDocsAgentTraceContext, createDocsAgentTraceId, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, findDocsMarkdownPage, getDocsLlmsTxtMaxCharsIssue, getDocsAgentManifestLinkHeader, getDocsDiscoveryLinkHeader, isDocsAgentDiscoveryRequest, isDocsAgentsRequest, isDocsConfigRequest, isDocsDiagnosticsRequest, isDocsSkillRequest, normalizeDocsRelated, normalizePageAgentFrontmatter, parseDocsAgentFeedbackData, performDocsSearch, performDocsSearchWithMetadata, renderDocsMarkdownDocument, renderDocsLlmsTxt, renderDocsAgentsDocument, renderDocsSkillDocument, readDocsSitemapManifestFromContentMap, stripGeneratedAgentProvenance, resolveDocsAudienceMdxContent, resolveDocsAgentFeedbackConfig, resolveDocsAgentFeedbackRequest, resolvePageSidebarFolderIndexBehavior, resolveAskAISearchRequestConfig, resolveDocsSearchAudience, resolveDocsSearchFilters, resolveSearchRequestConfig, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLocale, resolveDocsMarkdownRequest, resolveDocsMetadataBaseUrl, resolveDocsRequestApiRoute, resolveDocsRetrievalLastModified, resolveDocsPublishedAgentSkill, resolveDocsStandardsDiscoveryRequest, resolveDocsPath, resolvePageReadingTime, resolveReadingTimeOptions, resolveDocsSitemapPageLastmod, resolveDocsAgentsFormat, resolveDocsSkillFormat, inferDocsTelemetryAgentSurface, renderDocsPageStructuredDataJson, selectDocsLlmsTxtContent, validateDocsAgentFeedbackPayload, } from "@farming-labs/docs";
|
|
34
34
|
import { buildApiReferenceOpenApiDocumentAsync, createDocsCloudAskAIResponse, createDocsMcpHttpHandler, isDocsCloudAskAIProvider, readDocsSitemapManifest, resolveApiReferenceConfig, resolveDocsMcpConfig, resolveConfiguredAgentSkills, serializeDocsIconRegistry, serializeOpenDocsProviders, } from "@farming-labs/docs/server";
|
|
35
|
-
import { loadDocsNavTree, loadDocsContent, flattenNavTree } from "./content.js";
|
|
35
|
+
import { loadDocsNavTree, loadDocsContent, flattenNavTree, normalizeDocsFrontmatterLastmod, } from "./content.js";
|
|
36
36
|
import { renderMarkdown } from "./markdown.js";
|
|
37
37
|
export { createSvelteApiReference } from "./api-reference.js";
|
|
38
38
|
function isApiReferenceOpenApiRequest(url) {
|
|
@@ -311,7 +311,7 @@ function navTreeFromMap(contentMap, dirPrefix, entry, ordering) {
|
|
|
311
311
|
children.push(...buildLevel([]));
|
|
312
312
|
return { name: "Docs", children };
|
|
313
313
|
}
|
|
314
|
-
function searchIndexFromMap(contentMap, dirPrefix, entry) {
|
|
314
|
+
function searchIndexFromMap(contentMap, dirPrefix, entry, locale, sitemapManifest) {
|
|
315
315
|
const pages = [];
|
|
316
316
|
for (const [key, raw] of Object.entries(contentMap)) {
|
|
317
317
|
if (!key.startsWith(dirPrefix))
|
|
@@ -325,6 +325,9 @@ function searchIndexFromMap(contentMap, dirPrefix, entry) {
|
|
|
325
325
|
const isIdx = base === "page" || base === "index" || base === "+page";
|
|
326
326
|
const slug = isIdx ? segments.join("/") : [...segments, base].join("/");
|
|
327
327
|
const url = slug ? `/${entry}/${slug}` : `/${entry}`;
|
|
328
|
+
const manifestLastmod = (locale
|
|
329
|
+
? resolveDocsSitemapPageLastmod(sitemapManifest, `${url}?lang=${encodeURIComponent(locale)}`)
|
|
330
|
+
: undefined) ?? resolveDocsSitemapPageLastmod(sitemapManifest, url);
|
|
328
331
|
const { data, content } = matter(raw);
|
|
329
332
|
const humanRawContent = resolveDocsAudienceMdxContent(content, "human");
|
|
330
333
|
const pageAgentRawContent = resolveDocsAudienceMdxContent(content, "agent");
|
|
@@ -339,6 +342,7 @@ function searchIndexFromMap(contentMap, dirPrefix, entry) {
|
|
|
339
342
|
...(related.length > 0 ? { related } : {}),
|
|
340
343
|
agent: normalizePageAgentFrontmatter(data.agent),
|
|
341
344
|
icon: data.icon,
|
|
345
|
+
lastmod: normalizeDocsFrontmatterLastmod(data.lastmod),
|
|
342
346
|
locale: typeof data.locale === "string" ? data.locale : undefined,
|
|
343
347
|
framework: typeof data.framework === "string" ? data.framework : undefined,
|
|
344
348
|
version: typeof data.version === "string" ? data.version : undefined,
|
|
@@ -347,6 +351,7 @@ function searchIndexFromMap(contentMap, dirPrefix, entry) {
|
|
|
347
351
|
: undefined,
|
|
348
352
|
content: stripMarkdownText(humanRawContent),
|
|
349
353
|
rawContent: humanRawContent,
|
|
354
|
+
...(manifestLastmod ? { lastModified: `${manifestLastmod}T00:00:00.000Z` } : {}),
|
|
350
355
|
...(pageAgentRawContent !== humanRawContent
|
|
351
356
|
? {
|
|
352
357
|
agentFallbackContent: stripMarkdownText(pageAgentRawContent),
|
|
@@ -630,7 +635,7 @@ export function createDocsServer(config = {}) {
|
|
|
630
635
|
if (cached)
|
|
631
636
|
return cached;
|
|
632
637
|
const index = preloaded
|
|
633
|
-
? searchIndexFromMap(preloaded, ctx.dirPrefix, entry)
|
|
638
|
+
? searchIndexFromMap(preloaded, ctx.dirPrefix, entry, ctx.locale, preloadedSitemapManifest)
|
|
634
639
|
: loadDocsContent(ctx.contentDirAbs, entry);
|
|
635
640
|
searchIndexByEntry.set(key, index);
|
|
636
641
|
return index;
|
|
@@ -714,7 +719,7 @@ export function createDocsServer(config = {}) {
|
|
|
714
719
|
return page
|
|
715
720
|
? {
|
|
716
721
|
document: renderDocsMarkdownDocument(page, { origin, sitemap: config.sitemap }),
|
|
717
|
-
lastModified: page
|
|
722
|
+
lastModified: resolveDocsRetrievalLastModified(page, "agent"),
|
|
718
723
|
}
|
|
719
724
|
: null;
|
|
720
725
|
}
|
|
@@ -990,26 +995,14 @@ export function createDocsServer(config = {}) {
|
|
|
990
995
|
const audience = resolveDocsSearchAudience(event.url.searchParams.get("audience"));
|
|
991
996
|
const filters = resolveDocsSearchFilters(event.url.searchParams);
|
|
992
997
|
const structured = event.url.searchParams.get("response") === "structured";
|
|
993
|
-
if (!query) {
|
|
994
|
-
|
|
995
|
-
? {
|
|
996
|
-
format: "docs-search.v1",
|
|
997
|
-
query: "",
|
|
998
|
-
audience,
|
|
999
|
-
filters,
|
|
1000
|
-
resultCount: 0,
|
|
1001
|
-
results: [],
|
|
1002
|
-
warnings: [],
|
|
1003
|
-
}
|
|
1004
|
-
: [];
|
|
1005
|
-
return new Response(JSON.stringify(searchResponse), {
|
|
998
|
+
if (!query && !structured) {
|
|
999
|
+
return new Response("[]", {
|
|
1006
1000
|
headers: { "Content-Type": "application/json" },
|
|
1007
1001
|
});
|
|
1008
1002
|
}
|
|
1009
|
-
const searchStartedAt = Date.now();
|
|
1010
1003
|
const searchOptions = {
|
|
1011
1004
|
pages: getSearchIndex(ctx),
|
|
1012
|
-
query,
|
|
1005
|
+
query: query ?? "",
|
|
1013
1006
|
search: resolveSearchRequestConfig(config.search, event.request.url),
|
|
1014
1007
|
audience,
|
|
1015
1008
|
filters,
|
|
@@ -1017,7 +1010,15 @@ export function createDocsServer(config = {}) {
|
|
|
1017
1010
|
pathname: event.url.searchParams.get("pathname") ?? undefined,
|
|
1018
1011
|
siteTitle: llmsTitle,
|
|
1019
1012
|
baseUrl: markdownMetadataBaseUrl || event.url.origin,
|
|
1013
|
+
syncBaseUrl: markdownMetadataBaseUrl ?? null,
|
|
1020
1014
|
};
|
|
1015
|
+
if (!query) {
|
|
1016
|
+
const searchResponse = structured ? await performDocsSearchWithMetadata(searchOptions) : [];
|
|
1017
|
+
return new Response(JSON.stringify(searchResponse), {
|
|
1018
|
+
headers: { "Content-Type": "application/json" },
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
const searchStartedAt = Date.now();
|
|
1021
1022
|
const searchResponse = structured
|
|
1022
1023
|
? await performDocsSearchWithMetadata(searchOptions)
|
|
1023
1024
|
: await performDocsSearch(searchOptions);
|
|
@@ -1297,7 +1298,8 @@ export function createDocsServer(config = {}) {
|
|
|
1297
1298
|
locale: ctx.locale,
|
|
1298
1299
|
pathname: requestUrl.searchParams.get("pathname") ?? undefined,
|
|
1299
1300
|
siteTitle: llmsTitle,
|
|
1300
|
-
baseUrl: requestUrl.origin,
|
|
1301
|
+
baseUrl: markdownMetadataBaseUrl || requestUrl.origin,
|
|
1302
|
+
syncBaseUrl: markdownMetadataBaseUrl ?? null,
|
|
1301
1303
|
limit: maxResults,
|
|
1302
1304
|
});
|
|
1303
1305
|
const scored = retrieval.results;
|
|
@@ -1581,6 +1583,8 @@ export function createDocsServer(config = {}) {
|
|
|
1581
1583
|
source: {
|
|
1582
1584
|
entry,
|
|
1583
1585
|
siteTitle: mcpSiteTitle,
|
|
1586
|
+
baseUrl: markdownMetadataBaseUrl || undefined,
|
|
1587
|
+
resolveLocale: resolveLocaleForMcp,
|
|
1584
1588
|
getPages(locale) {
|
|
1585
1589
|
const ctx = resolveContextFromPath(`/${entry}`, resolveLocaleForMcp(locale));
|
|
1586
1590
|
return getSearchIndex(ctx);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/svelte",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.75",
|
|
4
4
|
"description": "SvelteKit adapter for @farming-labs/docs — content loading and navigation utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@types/node": "^22.10.0",
|
|
58
58
|
"typescript": "^5.9.3",
|
|
59
59
|
"vitest": "^4.1.8",
|
|
60
|
-
"@farming-labs/docs": "0.2.
|
|
60
|
+
"@farming-labs/docs": "0.2.75"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"@farming-labs/docs": ">=0.2.73"
|