@farming-labs/theme 0.2.121 → 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.
package/dist/docs-layout.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { serializeIcon } from "./serialize-icon.mjs";
|
|
|
2
2
|
import { resolveOpenDocsProviders } from "./open-docs-providers.mjs";
|
|
3
3
|
import { withLangInUrl } from "./i18n.mjs";
|
|
4
4
|
import { compactPageStructuredData } from "./page-structured-data.mjs";
|
|
5
|
+
import { serializePageMetadata } from "./page-metadata.mjs";
|
|
5
6
|
import { DocsPageClient } from "./docs-page-client.mjs";
|
|
6
7
|
import { DocsAIFeatures } from "./docs-ai-features-lazy.mjs";
|
|
7
8
|
import { resolveDocsCloudAIClientRequest } from "./docs-cloud-ai-client.mjs";
|
|
@@ -780,15 +781,15 @@ function createDocsLayout(config, options) {
|
|
|
780
781
|
defaultBehavior: config.theme?.name === "shadcn" ? "hidden" : "link"
|
|
781
782
|
});
|
|
782
783
|
return {
|
|
783
|
-
|
|
784
|
+
pageMetadata: serializePageMetadata(maps),
|
|
785
|
+
readingTimeEnabled: readingTimeEnabledByDefault || Object.keys(maps.readingTimeMap).length > 0,
|
|
784
786
|
localizedTree: i18n ? localizeTreeUrls(tree, activeLocale) : tree
|
|
785
787
|
};
|
|
786
788
|
}
|
|
787
789
|
let productionContent;
|
|
788
790
|
return function DocsLayoutWrapper({ children }) {
|
|
789
|
-
const {
|
|
791
|
+
const { pageMetadata, readingTimeEnabled, localizedTree: preparedTree } = process.env.NODE_ENV === "production" ? productionContent ??= prepareContent() : prepareContent();
|
|
790
792
|
const localizedTree = cloneTree(preparedTree);
|
|
791
|
-
const readingTimeEnabled = readingTimeEnabledByDefault || Object.keys(readingTimeMap).length > 0;
|
|
792
793
|
const finalSidebarProps = { ...sidebarProps };
|
|
793
794
|
const sidebarFooter = withStableReactKey(sidebarProps.footer, "docs-sidebar-footer");
|
|
794
795
|
finalSidebarProps.banner = withStableReactKey(sidebarProps.banner, "docs-sidebar-banner");
|
|
@@ -889,17 +890,13 @@ function createDocsLayout(config, options) {
|
|
|
889
890
|
contentDir,
|
|
890
891
|
githubBranch,
|
|
891
892
|
githubDirectory,
|
|
892
|
-
|
|
893
|
+
pageMetadata,
|
|
893
894
|
lastUpdatedEnabled,
|
|
894
895
|
lastUpdatedLabel,
|
|
895
896
|
lastUpdatedPosition,
|
|
896
897
|
readingTimeEnabled,
|
|
897
898
|
readingTimeFormat,
|
|
898
|
-
readingTimeMap,
|
|
899
|
-
structuredDataPages,
|
|
900
899
|
llmsTxtEnabled,
|
|
901
|
-
generatedTitleMap,
|
|
902
|
-
descriptionMap,
|
|
903
900
|
feedbackEnabled: feedbackConfig.enabled,
|
|
904
901
|
feedbackQuestion: feedbackConfig.question,
|
|
905
902
|
feedbackPlaceholder: feedbackConfig.placeholder,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DocsStructuredDataPages } from "./page-structured-data.mjs";
|
|
2
|
+
import { DocsPageMetadata } from "./page-metadata.mjs";
|
|
2
3
|
import { ReactNode } from "react";
|
|
3
4
|
import { CopyMarkdownFormat, DocsFeedbackData, DocsTelemetryConfig, DocsTelemetryFramework, PageActionConnectMcpConfig, PageActionInstallSkillsConfig, ReadingTimeFormat } from "@farming-labs/docs";
|
|
4
5
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
@@ -17,6 +18,8 @@ interface SerializedProvider {
|
|
|
17
18
|
prompt?: string;
|
|
18
19
|
}
|
|
19
20
|
interface DocsPageClientProps {
|
|
21
|
+
/** Internal packed layout metadata. Direct values and legacy maps retain precedence. */
|
|
22
|
+
pageMetadata?: DocsPageMetadata;
|
|
20
23
|
tocEnabled: boolean;
|
|
21
24
|
/** Expose the llms.txt action in a runtime-owned header slot. */
|
|
22
25
|
showLlmsInHeader?: boolean;
|
|
@@ -110,6 +113,7 @@ interface DocsPageClientProps {
|
|
|
110
113
|
children: ReactNode;
|
|
111
114
|
}
|
|
112
115
|
declare function DocsPageClient({
|
|
116
|
+
pageMetadata,
|
|
113
117
|
tocEnabled,
|
|
114
118
|
showLlmsInHeader,
|
|
115
119
|
tocStyle,
|
|
@@ -7,6 +7,7 @@ import { DocsFeedback } from "./docs-feedback.mjs";
|
|
|
7
7
|
import { resolveClientLocale, withLangInUrl } from "./i18n.mjs";
|
|
8
8
|
import { escapeJsonLdForScript } from "./json-ld.mjs";
|
|
9
9
|
import { renderPageStructuredData } from "./page-structured-data.mjs";
|
|
10
|
+
import { resolvePageMetadata } from "./page-metadata.mjs";
|
|
10
11
|
import { Children, Fragment, useEffect, useLayoutEffect, useState } from "react";
|
|
11
12
|
import { DocsBody, DocsPage, EditOnGitHub } from "fumadocs-ui/layouts/docs/page";
|
|
12
13
|
import { createPortal } from "react-dom";
|
|
@@ -265,7 +266,7 @@ function findThreadlineTocActionsContainer() {
|
|
|
265
266
|
}
|
|
266
267
|
return toc.parentElement ?? toc;
|
|
267
268
|
}
|
|
268
|
-
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, 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 }) {
|
|
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 }) {
|
|
269
270
|
const router = useRouter();
|
|
270
271
|
const fdTocStyle = tocStyle === "directional" ? "clerk" : void 0;
|
|
271
272
|
const [toc, setToc] = useState([]);
|
|
@@ -281,11 +282,12 @@ function DocsPageClient({ tocEnabled, showLlmsInHeader = false, tocStyle = "defa
|
|
|
281
282
|
const llmsLangQuery = activeLocale ? `?lang=${encodeURIComponent(activeLocale)}` : "";
|
|
282
283
|
const shouldShowLlmsInHeader = llmsTxtEnabled && showLlmsInHeader;
|
|
283
284
|
const normalizedPath = (browserPathname || pathname).replace(/\/$/, "") || "/";
|
|
284
|
-
const
|
|
285
|
-
const
|
|
285
|
+
const page = resolvePageMetadata(pageMetadata, normalizedPath);
|
|
286
|
+
const pageTitle = generatedTitleMap?.[normalizedPath] ?? page?.generatedTitle;
|
|
287
|
+
const pageDescription = description ?? descriptionMap?.[normalizedPath] ?? page?.description;
|
|
286
288
|
const isChangelogRoute = !!(changelogBasePath && (normalizedPath === changelogBasePath || normalizedPath.startsWith(`${changelogBasePath}/`)));
|
|
287
|
-
const matchedReadingTime = readingTimeMap?.[normalizedPath];
|
|
288
|
-
const structuredDataJson = !isChangelogRoute ? structuredDataProp ?? structuredDataMap?.[normalizedPath] ?? renderPageStructuredData(structuredDataPages, 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;
|
|
289
291
|
useEffect(() => {
|
|
290
292
|
if (!analytics) return;
|
|
291
293
|
emitClientAnalyticsEvent({
|
|
@@ -462,7 +464,7 @@ function DocsPageClient({ tocEnabled, showLlmsInHeader = false, tocStyle = "defa
|
|
|
462
464
|
setTitleControlsPortalHost(null);
|
|
463
465
|
};
|
|
464
466
|
}, [pathname, showActionsInToc]);
|
|
465
|
-
const lastModified = !isChangelogRoute && lastUpdatedEnabled ? lastModifiedProp ?? lastModifiedMap?.[normalizedPath] : void 0;
|
|
467
|
+
const lastModified = !isChangelogRoute && lastUpdatedEnabled ? lastModifiedProp ?? lastModifiedMap?.[normalizedPath] ?? page?.lastModified : void 0;
|
|
466
468
|
const showLastUpdatedBelowTitle = !!lastModified && lastUpdatedPosition === "below-title";
|
|
467
469
|
const showLastUpdatedInFooter = !!lastModified && lastUpdatedPosition === "footer";
|
|
468
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/theme",
|
|
3
|
-
"version": "0.2.
|
|
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.
|
|
164
|
+
"@farming-labs/docs": "0.2.122"
|
|
165
165
|
},
|
|
166
166
|
"peerDependencies": {
|
|
167
167
|
"@farming-labs/docs": ">=0.0.1",
|