@farming-labs/theme 0.2.120 → 0.2.122

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.
@@ -1,3 +1,5 @@
1
+ import { DocsStructuredDataPages } from "./page-structured-data.mjs";
2
+ import { DocsPageMetadata } from "./page-metadata.mjs";
1
3
  import { ReactNode } from "react";
2
4
  import { CopyMarkdownFormat, DocsFeedbackData, DocsTelemetryConfig, DocsTelemetryFramework, PageActionConnectMcpConfig, PageActionInstallSkillsConfig, ReadingTimeFormat } from "@farming-labs/docs";
3
5
  import * as react_jsx_runtime0 from "react/jsx-runtime";
@@ -16,6 +18,8 @@ interface SerializedProvider {
16
18
  prompt?: string;
17
19
  }
18
20
  interface DocsPageClientProps {
21
+ /** Internal packed layout metadata. Direct values and legacy maps retain precedence. */
22
+ pageMetadata?: DocsPageMetadata;
19
23
  tocEnabled: boolean;
20
24
  /** Expose the llms.txt action in a runtime-owned header slot. */
21
25
  showLlmsInHeader?: boolean;
@@ -67,6 +71,8 @@ interface DocsPageClientProps {
67
71
  nextPage?: PageNavigationItem | null;
68
72
  /** Map of pathname → serialized Schema.org JSON-LD. */
69
73
  structuredDataMap?: Record<string, string>;
74
+ /** Compact page fields; shared schema and breadcrumbs expand only for the active page. */
75
+ structuredDataPages?: DocsStructuredDataPages;
70
76
  /** Direct serialized Schema.org JSON-LD override for the current page. */
71
77
  structuredData?: string;
72
78
  /**
@@ -107,6 +113,7 @@ interface DocsPageClientProps {
107
113
  children: ReactNode;
108
114
  }
109
115
  declare function DocsPageClient({
116
+ pageMetadata,
110
117
  tocEnabled,
111
118
  showLlmsInHeader,
112
119
  tocStyle,
@@ -141,6 +148,7 @@ declare function DocsPageClient({
141
148
  previousPage,
142
149
  nextPage,
143
150
  structuredDataMap,
151
+ structuredDataPages,
144
152
  structuredData: structuredDataProp,
145
153
  readingTimeEnabled,
146
154
  lastUpdatedEnabled,
@@ -6,6 +6,8 @@ import { useWindowPathname, useWindowSearchParams } from "./client-location.mjs"
6
6
  import { DocsFeedback } from "./docs-feedback.mjs";
7
7
  import { resolveClientLocale, withLangInUrl } from "./i18n.mjs";
8
8
  import { escapeJsonLdForScript } from "./json-ld.mjs";
9
+ import { renderPageStructuredData } from "./page-structured-data.mjs";
10
+ import { resolvePageMetadata } from "./page-metadata.mjs";
9
11
  import { Children, Fragment, useEffect, useLayoutEffect, useState } from "react";
10
12
  import { DocsBody, DocsPage, EditOnGitHub } from "fumadocs-ui/layouts/docs/page";
11
13
  import { createPortal } from "react-dom";
@@ -25,6 +27,14 @@ const agentLlmsDirectiveStyle = {
25
27
  whiteSpace: "nowrap",
26
28
  border: 0
27
29
  };
30
+ /** Read authored heading text without changing its anchor controls or accessible names. */
31
+ function getTocHeadingText(node) {
32
+ if (node.nodeType === Node.TEXT_NODE) return node.textContent ?? "";
33
+ if (node instanceof Element && node.matches("button, [role=\"button\"]")) return "";
34
+ let text = "";
35
+ for (const child of node.childNodes) text += getTocHeadingText(child);
36
+ return text;
37
+ }
28
38
  /**
29
39
  * Path-based breadcrumb that shows only parent / current folder.
30
40
  * Skips the entry segment (e.g. "docs"). Parent is clickable.
@@ -256,7 +266,7 @@ function findThreadlineTocActionsContainer() {
256
266
  }
257
267
  return toc.parentElement ?? toc;
258
268
  }
259
- function DocsPageClient({ tocEnabled, showLlmsInHeader = false, tocStyle = "default", breadcrumbEnabled = true, changelogBasePath, entry = "docs", publicPath, locale, copyMarkdown = false, copyMarkdownFormat, copyMarkdownIncludeTitle, copyMarkdownLabel, copyMarkdownCopiedLabel, openDocs = false, openDocsProviders, openDocsTarget, openDocsPrompt, connectMcp, installSkills, pageActionsPosition = "below-title", pageActionsAlignment = "left", githubUrl, contentDir, githubBranch = "main", githubDirectory, editOnGithubUrl, lastModifiedMap, lastModified: lastModifiedProp, readingTimeMap, readingTime: readingTimeProp, readingTimeFormat = "long", previousPage, nextPage, structuredDataMap, structuredData: structuredDataProp, readingTimeEnabled = false, lastUpdatedEnabled = true, lastUpdatedLabel = "Last updated", lastUpdatedPosition = "footer", llmsTxtEnabled = false, generatedTitleMap, descriptionMap, description, descriptionInBody = false, feedbackEnabled = false, feedbackQuestion, feedbackPlaceholder, feedbackRequireComment, feedbackPositiveLabel, feedbackNegativeLabel, feedbackSubmitLabel, feedbackSuccessMessage, feedbackErrorMessage, feedbackOnFeedback, analytics = false, telemetry, telemetryFramework, children }) {
269
+ function DocsPageClient({ pageMetadata, tocEnabled, showLlmsInHeader = false, tocStyle = "default", breadcrumbEnabled = true, changelogBasePath, entry = "docs", publicPath, locale, copyMarkdown = false, copyMarkdownFormat, copyMarkdownIncludeTitle, copyMarkdownLabel, copyMarkdownCopiedLabel, openDocs = false, openDocsProviders, openDocsTarget, openDocsPrompt, connectMcp, installSkills, pageActionsPosition = "below-title", pageActionsAlignment = "left", githubUrl, contentDir, githubBranch = "main", githubDirectory, editOnGithubUrl, lastModifiedMap, lastModified: lastModifiedProp, readingTimeMap, readingTime: readingTimeProp, readingTimeFormat = "long", previousPage, nextPage, structuredDataMap, structuredDataPages, structuredData: structuredDataProp, readingTimeEnabled = false, lastUpdatedEnabled = true, lastUpdatedLabel = "Last updated", lastUpdatedPosition = "footer", llmsTxtEnabled = false, generatedTitleMap, descriptionMap, description, descriptionInBody = false, feedbackEnabled = false, feedbackQuestion, feedbackPlaceholder, feedbackRequireComment, feedbackPositiveLabel, feedbackNegativeLabel, feedbackSubmitLabel, feedbackSuccessMessage, feedbackErrorMessage, feedbackOnFeedback, analytics = false, telemetry, telemetryFramework, children }) {
260
270
  const router = useRouter();
261
271
  const fdTocStyle = tocStyle === "directional" ? "clerk" : void 0;
262
272
  const [toc, setToc] = useState([]);
@@ -272,11 +282,12 @@ function DocsPageClient({ tocEnabled, showLlmsInHeader = false, tocStyle = "defa
272
282
  const llmsLangQuery = activeLocale ? `?lang=${encodeURIComponent(activeLocale)}` : "";
273
283
  const shouldShowLlmsInHeader = llmsTxtEnabled && showLlmsInHeader;
274
284
  const normalizedPath = (browserPathname || pathname).replace(/\/$/, "") || "/";
275
- const pageTitle = generatedTitleMap?.[normalizedPath];
276
- const pageDescription = description ?? descriptionMap?.[normalizedPath];
285
+ const page = resolvePageMetadata(pageMetadata, normalizedPath);
286
+ const pageTitle = generatedTitleMap?.[normalizedPath] ?? page?.generatedTitle;
287
+ const pageDescription = description ?? descriptionMap?.[normalizedPath] ?? page?.description;
277
288
  const isChangelogRoute = !!(changelogBasePath && (normalizedPath === changelogBasePath || normalizedPath.startsWith(`${changelogBasePath}/`)));
278
- const matchedReadingTime = readingTimeMap?.[normalizedPath];
279
- const structuredDataJson = !isChangelogRoute ? structuredDataProp ?? structuredDataMap?.[normalizedPath] : void 0;
289
+ const matchedReadingTime = readingTimeMap?.[normalizedPath] ?? page?.readingTime;
290
+ const structuredDataJson = !isChangelogRoute ? structuredDataProp ?? structuredDataMap?.[normalizedPath] ?? renderPageStructuredData(structuredDataPages, normalizedPath) ?? renderPageStructuredData(page?.structuredDataPages, normalizedPath) : void 0;
280
291
  useEffect(() => {
281
292
  if (!analytics) return;
282
293
  emitClientAnalyticsEvent({
@@ -326,7 +337,7 @@ function DocsPageClient({ tocEnabled, showLlmsInHeader = false, tocStyle = "defa
326
337
  if (!container) return;
327
338
  const headings = container.querySelectorAll("h2[id], h3[id], h4[id]");
328
339
  setToc(Array.from(headings).map((el) => ({
329
- title: el.textContent?.replace(/^#\s*/, "") || "",
340
+ title: getTocHeadingText(el).replace(/^#\s*/, ""),
330
341
  url: `#${el.id}`,
331
342
  depth: parseInt(el.tagName[1], 10)
332
343
  })));
@@ -453,7 +464,7 @@ function DocsPageClient({ tocEnabled, showLlmsInHeader = false, tocStyle = "defa
453
464
  setTitleControlsPortalHost(null);
454
465
  };
455
466
  }, [pathname, showActionsInToc]);
456
- const lastModified = !isChangelogRoute && lastUpdatedEnabled ? lastModifiedProp ?? lastModifiedMap?.[normalizedPath] : void 0;
467
+ const lastModified = !isChangelogRoute && lastUpdatedEnabled ? lastModifiedProp ?? lastModifiedMap?.[normalizedPath] ?? page?.lastModified : void 0;
457
468
  const showLastUpdatedBelowTitle = !!lastModified && lastUpdatedPosition === "below-title";
458
469
  const showLastUpdatedInFooter = !!lastModified && lastUpdatedPosition === "footer";
459
470
  const lastUpdatedLabelText = lastUpdatedLabel.trim();
@@ -0,0 +1,10 @@
1
+ import "./page-structured-data.mjs";
2
+ import "@farming-labs/docs";
3
+
4
+ //#region src/page-metadata.d.ts
5
+ /** Internal transport shared by the layout and its client component. */
6
+ interface DocsPageMetadata {
7
+ json: string;
8
+ }
9
+ //#endregion
10
+ export { DocsPageMetadata };
@@ -0,0 +1,81 @@
1
+ //#region src/page-metadata.ts
2
+ /**
3
+ * Pack once per content snapshot. RSC can send one string instead of traversing
4
+ * several overlapping maps for every prerendered page. Keep all routes so a
5
+ * persistent layout still has metadata after client navigation.
6
+ */
7
+ function serializePageMetadata(maps) {
8
+ const dates = [];
9
+ const dateIndexes = /* @__PURE__ */ new Map();
10
+ const dateIndex = (value) => {
11
+ if (value === void 0) return null;
12
+ const cached = dateIndexes.get(value);
13
+ if (cached !== void 0) return cached;
14
+ const index = dates.push(value) - 1;
15
+ dateIndexes.set(value, index);
16
+ return index;
17
+ };
18
+ const pages = {};
19
+ for (const [route, page] of Object.entries(maps.structuredDataPages.pages)) {
20
+ const generatedTitle = maps.generatedTitleMap[route];
21
+ const description = maps.descriptionMap[route];
22
+ const row = [
23
+ page.title,
24
+ page.description ?? null,
25
+ dateIndex(page.dateModified),
26
+ dateIndex(maps.lastModifiedMap[route]),
27
+ generatedTitle === void 0 ? null : generatedTitle === page.title ? 1 : generatedTitle,
28
+ maps.readingTimeMap[route] ?? null,
29
+ description === void 0 ? null : description === page.description ? 1 : description
30
+ ];
31
+ if (page.url !== route || page.breadcrumbs !== void 0 || page.mainEntity !== void 0) row.push({
32
+ url: page.url !== route ? page.url : void 0,
33
+ breadcrumbs: page.breadcrumbs,
34
+ mainEntity: page.mainEntity
35
+ });
36
+ pages[route] = row;
37
+ }
38
+ return { json: JSON.stringify({
39
+ baseUrl: maps.structuredDataPages.baseUrl,
40
+ entry: maps.structuredDataPages.entry,
41
+ dates,
42
+ pages
43
+ }) };
44
+ }
45
+ const decoded = /* @__PURE__ */ new WeakMap();
46
+ function resolvePageMetadata(data, route) {
47
+ if (!data) return void 0;
48
+ let cached = decoded.get(data);
49
+ if (!cached || cached.json !== data.json) {
50
+ cached = {
51
+ json: data.json,
52
+ pages: JSON.parse(data.json)
53
+ };
54
+ decoded.set(data, cached);
55
+ }
56
+ const packed = cached.pages;
57
+ const row = Object.hasOwn(packed.pages, route) ? packed.pages[route] : void 0;
58
+ if (!row) return void 0;
59
+ const [title, description, modified, lastModified, generatedTitle, readingTime, visible, extra] = row;
60
+ return {
61
+ generatedTitle: generatedTitle === 1 ? title : generatedTitle ?? void 0,
62
+ description: visible === 1 ? description ?? void 0 : visible ?? void 0,
63
+ lastModified: lastModified === null ? void 0 : packed.dates[lastModified],
64
+ readingTime: readingTime ?? void 0,
65
+ structuredDataPages: {
66
+ baseUrl: packed.baseUrl,
67
+ entry: packed.entry,
68
+ pages: { [route]: {
69
+ title,
70
+ description: description ?? void 0,
71
+ dateModified: modified === null ? void 0 : packed.dates[modified],
72
+ url: extra?.url ?? route,
73
+ breadcrumbs: extra?.breadcrumbs,
74
+ mainEntity: extra?.mainEntity
75
+ } }
76
+ }
77
+ };
78
+ }
79
+
80
+ //#endregion
81
+ export { resolvePageMetadata, serializePageMetadata };
@@ -0,0 +1,13 @@
1
+ import { DocsPageStructuredDataInput } from "@farming-labs/docs";
2
+
3
+ //#region src/page-structured-data.d.ts
4
+ type Page = Pick<DocsPageStructuredDataInput, "title" | "description" | "url" | "dateModified" | "breadcrumbs"> & {
5
+ mainEntity?: unknown;
6
+ };
7
+ interface DocsStructuredDataPages {
8
+ baseUrl?: string;
9
+ entry?: string;
10
+ pages: Record<string, Page>;
11
+ }
12
+ //#endregion
13
+ export { DocsStructuredDataPages };
@@ -0,0 +1,30 @@
1
+ import { buildDocsPageStructuredData } from "@farming-labs/docs/browser";
2
+
3
+ //#region src/page-structured-data.ts
4
+ /** Retain only fields that contribute to the public JSON-LD, never raw agent frontmatter. */
5
+ function compactPageStructuredData(input) {
6
+ return {
7
+ title: input.title,
8
+ description: input.description,
9
+ url: input.url,
10
+ dateModified: input.dateModified,
11
+ breadcrumbs: input.breadcrumbs,
12
+ mainEntity: input.agent ? buildDocsPageStructuredData(input).mainEntity : void 0
13
+ };
14
+ }
15
+ /** Expand only the active page, during both server rendering and client navigation. */
16
+ function renderPageStructuredData(data, pathname) {
17
+ const page = data?.pages[pathname];
18
+ if (!page) return void 0;
19
+ const { mainEntity, ...input } = page;
20
+ const value = buildDocsPageStructuredData({
21
+ ...input,
22
+ baseUrl: data?.baseUrl,
23
+ entry: data?.entry
24
+ });
25
+ if (mainEntity !== void 0) value.mainEntity = mainEntity;
26
+ return JSON.stringify(value).replace(/</g, "\\u003c");
27
+ }
28
+
29
+ //#endregion
30
+ export { compactPageStructuredData, renderPageStructuredData };
@@ -16,7 +16,7 @@ function resolveReadingTimeOptions(readingTime) {
16
16
  includeCode: false
17
17
  };
18
18
  return {
19
- enabled: readingTime.enabled !== false,
19
+ enabled: readingTime.enabled === true,
20
20
  wordsPerMinute: typeof readingTime.wordsPerMinute === "number" && Number.isFinite(readingTime.wordsPerMinute) ? readingTime.wordsPerMinute : void 0,
21
21
  format: readingTime.format === "short" ? "short" : "long",
22
22
  includeCode: readingTime.includeCode === true
@@ -2,12 +2,12 @@ import { resolveOpenDocsProviders } from "./open-docs-providers.mjs";
2
2
  import { withLangInUrl } from "./i18n.mjs";
3
3
  import { escapeJsonLdForScript } from "./json-ld.mjs";
4
4
  import { DocsPageClient } from "./docs-page-client.mjs";
5
- import { DocsAIFeatures } from "./docs-ai-features.mjs";
6
5
  import { resolveDocsCloudAIClientRequest } from "./docs-cloud-ai-client.mjs";
7
6
  import { DocsCommandSearch } from "./docs-command-search.mjs";
8
7
  import { resolveReadingTimeOptions } from "./reading-time-options.mjs";
9
8
  import { SidebarSearchWithAI } from "./sidebar-search-ai.mjs";
10
9
  import { LocaleThemeControl } from "./locale-theme-control.mjs";
10
+ import { DocsAIFeatures } from "./docs-ai-features.mjs";
11
11
  import { TabletSidebarBridge } from "./tablet-sidebar-bridge.mjs";
12
12
  import { DocsLayout } from "fumadocs-ui/layouts/docs";
13
13
  import { Suspense } from "react";
@@ -287,6 +287,7 @@ function TanstackDocsLayout({ config, tree, browserRuntime = false, telemetryFra
287
287
  const aiConfig = config.ai;
288
288
  const aiEnabled = !staticExport && !!aiConfig?.enabled;
289
289
  const aiMode = aiConfig?.mode ?? "search";
290
+ const aiHandlesSearch = aiEnabled && (aiMode === "search" || aiMode === "sidebar-icon");
290
291
  const aiPosition = aiConfig?.position ?? "bottom-right";
291
292
  const aiFloatingStyle = aiConfig?.floatingStyle ?? "panel";
292
293
  const aiSuggestedQuestions = aiConfig?.suggestedQuestions;
@@ -350,7 +351,7 @@ function TanstackDocsLayout({ config, tree, browserRuntime = false, telemetryFra
350
351
  /* @__PURE__ */ jsx(LayoutStyle, { layout: layoutDimensions }),
351
352
  forcedTheme && /* @__PURE__ */ jsx(ForcedThemeScript, { theme: forcedTheme }),
352
353
  browserRuntime && config.theme?.name === "fumadocs-pixel-border" && /* @__PURE__ */ jsx(TabletSidebarBridge, {}),
353
- !staticExport && /* @__PURE__ */ jsx(Suspense, {
354
+ !staticExport && !aiHandlesSearch && /* @__PURE__ */ jsx(Suspense, {
354
355
  fallback: null,
355
356
  children: /* @__PURE__ */ jsx(DocsCommandSearch, {
356
357
  api: docsApiUrl,
@@ -381,7 +382,6 @@ function TanstackDocsLayout({ config, tree, browserRuntime = false, telemetryFra
381
382
  fallback: children,
382
383
  children: /* @__PURE__ */ jsx(DocsPageClient, {
383
384
  tocEnabled,
384
- showLlmsInHeader: browserRuntime && config.theme?.name === "fumadocs-pixel-border",
385
385
  tocStyle,
386
386
  breadcrumbEnabled,
387
387
  entry: config.entry ?? "docs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/theme",
3
- "version": "0.2.120",
3
+ "version": "0.2.122",
4
4
  "description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
5
5
  "keywords": [
6
6
  "docs",
@@ -161,7 +161,7 @@
161
161
  "tsdown": "^0.20.3",
162
162
  "typescript": "^5.9.3",
163
163
  "vitest": "^4.1.8",
164
- "@farming-labs/docs": "0.2.120"
164
+ "@farming-labs/docs": "0.2.122"
165
165
  },
166
166
  "peerDependencies": {
167
167
  "@farming-labs/docs": ">=0.0.1",
@@ -3658,3 +3658,4 @@ html.dark #nd-docs-layout[data-fd-framework] pre.shiki {
3658
3658
  #nd-docs-layout[data-fd-framework] .fd-ai-fm-trigger-btn:active {
3659
3659
  transform: scale(0.97);
3660
3660
  }
3661
+