@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.
- package/README.md +6 -0
- package/dist/deferred-dialog.mjs +72 -0
- package/dist/docs-ai-features-lazy.mjs +13 -0
- package/dist/docs-ai-features.mjs +75 -57
- package/dist/docs-api.mjs +1 -1
- package/dist/docs-cloud-ai-client.mjs +2 -1
- package/dist/docs-content-reader.mjs +65 -0
- package/dist/docs-layout.mjs +106 -350
- package/dist/docs-page-client.d.mts +8 -0
- package/dist/docs-page-client.mjs +18 -7
- package/dist/page-metadata.d.mts +10 -0
- package/dist/page-metadata.mjs +81 -0
- package/dist/page-structured-data.d.mts +13 -0
- package/dist/page-structured-data.mjs +30 -0
- package/dist/reading-time-options.mjs +1 -1
- package/dist/tanstack-layout.mjs +3 -3
- package/package.json +2 -2
- package/styles/framework.css +1 -0
package/dist/docs-layout.mjs
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { serializeIcon } from "./serialize-icon.mjs";
|
|
2
2
|
import { resolveOpenDocsProviders } from "./open-docs-providers.mjs";
|
|
3
3
|
import { withLangInUrl } from "./i18n.mjs";
|
|
4
|
+
import { compactPageStructuredData } from "./page-structured-data.mjs";
|
|
5
|
+
import { serializePageMetadata } from "./page-metadata.mjs";
|
|
4
6
|
import { DocsPageClient } from "./docs-page-client.mjs";
|
|
5
|
-
import { DocsAIFeatures } from "./docs-ai-features.mjs";
|
|
7
|
+
import { DocsAIFeatures } from "./docs-ai-features-lazy.mjs";
|
|
6
8
|
import { resolveDocsCloudAIClientRequest } from "./docs-cloud-ai-client.mjs";
|
|
7
9
|
import { DocsCommandSearch } from "./docs-command-search.mjs";
|
|
8
10
|
import { resolveReadingTimeOptions } from "./reading-time-options.mjs";
|
|
9
11
|
import { resolvePageReadingTime } from "./reading-time.mjs";
|
|
10
12
|
import { SidebarSearchWithAI } from "./sidebar-search-ai.mjs";
|
|
11
13
|
import { LocaleThemeControl } from "./locale-theme-control.mjs";
|
|
14
|
+
import { createDocsContentReader } from "./docs-content-reader.mjs";
|
|
12
15
|
import fs from "node:fs";
|
|
13
16
|
import path from "node:path";
|
|
14
|
-
import matter from "gray-matter";
|
|
15
17
|
import { DocsLayout } from "fumadocs-ui/layouts/docs";
|
|
16
18
|
import { Suspense, cloneElement, isValidElement } from "react";
|
|
17
|
-
import { applySidebarFolderIndexBehavior, buildPageOpenGraph, buildPageTwitter, normalizePageAgentFrontmatter,
|
|
19
|
+
import { applySidebarFolderIndexBehavior, buildPageOpenGraph, buildPageTwitter, normalizePageAgentFrontmatter, resolveChangelogConfig, resolveDocsAnalyticsConfig, resolveDocsAudienceMdxContent, resolveDocsMetadataBaseUrl, resolveDocsSitemapPageLastmod, resolvePageSidebarFolderIndexBehavior, toDocsMarkdownUrl } from "@farming-labs/docs";
|
|
18
20
|
import { readDocsSitemapManifest } from "@farming-labs/docs/runtime";
|
|
19
21
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
20
22
|
|
|
@@ -40,20 +42,14 @@ function resolveIcon(iconKey, registry) {
|
|
|
40
42
|
return withStableReactKey(registry[iconKey] ?? void 0, iconKey);
|
|
41
43
|
}
|
|
42
44
|
/** Read frontmatter from a page.mdx file. */
|
|
43
|
-
function readFrontmatter(filePath) {
|
|
45
|
+
function readFrontmatter(reader, filePath) {
|
|
44
46
|
try {
|
|
45
|
-
|
|
46
|
-
/* turbopackIgnore: true */
|
|
47
|
-
filePath,
|
|
48
|
-
"utf-8"
|
|
49
|
-
));
|
|
50
|
-
return data;
|
|
47
|
+
return reader.page(filePath).data;
|
|
51
48
|
} catch {
|
|
52
49
|
return {};
|
|
53
50
|
}
|
|
54
51
|
}
|
|
55
|
-
function hasAuthoredPageTitle(
|
|
56
|
-
const { content } = matter(source);
|
|
52
|
+
function hasAuthoredPageTitle(content) {
|
|
57
53
|
const lines = content.split(/\r?\n/);
|
|
58
54
|
let fence;
|
|
59
55
|
let previousTextLine = "";
|
|
@@ -88,32 +84,15 @@ function isExcludedDir(dir, excludedDirs) {
|
|
|
88
84
|
);
|
|
89
85
|
return excludedDirs.some((excluded) => isWithinDir(resolved, excluded));
|
|
90
86
|
}
|
|
91
|
-
function hasChildPages(dir, excludedDirs) {
|
|
92
|
-
|
|
93
|
-
/* turbopackIgnore: true */
|
|
94
|
-
dir
|
|
95
|
-
)) return false;
|
|
96
|
-
for (const name of fs.readdirSync(
|
|
97
|
-
/* turbopackIgnore: true */
|
|
98
|
-
dir
|
|
99
|
-
)) {
|
|
87
|
+
function hasChildPages(reader, dir, excludedDirs) {
|
|
88
|
+
for (const name of reader.directory(dir).directories) {
|
|
100
89
|
const full = path.join(
|
|
101
90
|
/* turbopackIgnore: true */
|
|
102
91
|
dir,
|
|
103
92
|
name
|
|
104
93
|
);
|
|
105
94
|
if (isExcludedDir(full, excludedDirs)) continue;
|
|
106
|
-
if (
|
|
107
|
-
/* turbopackIgnore: true */
|
|
108
|
-
full
|
|
109
|
-
).isDirectory() && fs.existsSync(
|
|
110
|
-
/* turbopackIgnore: true */
|
|
111
|
-
path.join(
|
|
112
|
-
/* turbopackIgnore: true */
|
|
113
|
-
full,
|
|
114
|
-
"page.mdx"
|
|
115
|
-
)
|
|
116
|
-
)) return true;
|
|
95
|
+
if (reader.directory(full).files.has("page.mdx")) return true;
|
|
117
96
|
}
|
|
118
97
|
return false;
|
|
119
98
|
}
|
|
@@ -201,7 +180,7 @@ function getExcludedDocsDirs(config, ctx) {
|
|
|
201
180
|
dir
|
|
202
181
|
)];
|
|
203
182
|
}
|
|
204
|
-
function readChangelogTreeEntries(config, ctx) {
|
|
183
|
+
function readChangelogTreeEntries(config, ctx, reader) {
|
|
205
184
|
const changelog = resolveChangelogConfig(config.changelog);
|
|
206
185
|
if (!changelog.enabled) return [];
|
|
207
186
|
const changelogDir = path.isAbsolute(changelog.contentDir) ? changelog.contentDir : path.join(
|
|
@@ -209,38 +188,21 @@ function readChangelogTreeEntries(config, ctx) {
|
|
|
209
188
|
ctx.docsDir,
|
|
210
189
|
changelog.contentDir
|
|
211
190
|
);
|
|
212
|
-
if (!fs.existsSync(
|
|
213
|
-
/* turbopackIgnore: true */
|
|
214
|
-
changelogDir
|
|
215
|
-
)) return [];
|
|
216
191
|
const entries = [];
|
|
217
|
-
for (const name of
|
|
218
|
-
/* turbopackIgnore: true */
|
|
219
|
-
changelogDir
|
|
220
|
-
)) {
|
|
192
|
+
for (const name of reader.directory(changelogDir).directories) {
|
|
221
193
|
if (!/^\d{4}-\d{2}-\d{2}$/.test(name)) continue;
|
|
222
194
|
const entryDir = path.join(
|
|
223
195
|
/* turbopackIgnore: true */
|
|
224
196
|
changelogDir,
|
|
225
197
|
name
|
|
226
198
|
);
|
|
227
|
-
if (!fs.existsSync(
|
|
228
|
-
/* turbopackIgnore: true */
|
|
229
|
-
entryDir
|
|
230
|
-
) || !fs.statSync(
|
|
231
|
-
/* turbopackIgnore: true */
|
|
232
|
-
entryDir
|
|
233
|
-
).isDirectory()) continue;
|
|
234
199
|
const pagePath = path.join(
|
|
235
200
|
/* turbopackIgnore: true */
|
|
236
201
|
entryDir,
|
|
237
202
|
"page.mdx"
|
|
238
203
|
);
|
|
239
|
-
if (!
|
|
240
|
-
|
|
241
|
-
pagePath
|
|
242
|
-
)) continue;
|
|
243
|
-
const data = readFrontmatter(pagePath);
|
|
204
|
+
if (!reader.directory(entryDir).files.has("page.mdx")) continue;
|
|
205
|
+
const data = readFrontmatter(reader, pagePath);
|
|
244
206
|
if (data.draft === true) continue;
|
|
245
207
|
entries.push({
|
|
246
208
|
slug: name,
|
|
@@ -254,10 +216,10 @@ function readChangelogTreeEntries(config, ctx) {
|
|
|
254
216
|
return right.date.localeCompare(left.date);
|
|
255
217
|
});
|
|
256
218
|
}
|
|
257
|
-
function buildChangelogTree(config, ctx, flat = false) {
|
|
219
|
+
function buildChangelogTree(config, ctx, reader, flat = false) {
|
|
258
220
|
const changelog = resolveChangelogConfig(config.changelog);
|
|
259
221
|
if (!changelog.enabled) return null;
|
|
260
|
-
const entries = readChangelogTreeEntries(config, ctx);
|
|
222
|
+
const entries = readChangelogTreeEntries(config, ctx, reader);
|
|
261
223
|
if (entries.length === 0) return null;
|
|
262
224
|
const url = publicDocsRoute(ctx, [changelog.path]);
|
|
263
225
|
const children = entries.map((entry) => ({
|
|
@@ -280,21 +242,14 @@ function buildChangelogTree(config, ctx, flat = false) {
|
|
|
280
242
|
} : {}
|
|
281
243
|
};
|
|
282
244
|
}
|
|
283
|
-
function buildTree(config, ctx, flat = false) {
|
|
245
|
+
function buildTree(config, ctx, reader, flat = false) {
|
|
284
246
|
const docsDir = ctx.docsDir;
|
|
285
247
|
const icons = config.icons;
|
|
286
248
|
const ordering = config.ordering;
|
|
287
249
|
const rootChildren = [];
|
|
288
250
|
const excludedDirs = getExcludedDocsDirs(config, ctx);
|
|
289
|
-
if (
|
|
290
|
-
|
|
291
|
-
path.join(
|
|
292
|
-
/* turbopackIgnore: true */
|
|
293
|
-
docsDir,
|
|
294
|
-
"page.mdx"
|
|
295
|
-
)
|
|
296
|
-
)) {
|
|
297
|
-
const data = readFrontmatter(path.join(
|
|
251
|
+
if (reader.directory(docsDir).files.has("page.mdx")) {
|
|
252
|
+
const data = readFrontmatter(reader, path.join(
|
|
298
253
|
/* turbopackIgnore: true */
|
|
299
254
|
docsDir,
|
|
300
255
|
"page.mdx"
|
|
@@ -313,26 +268,19 @@ function buildTree(config, ctx, flat = false) {
|
|
|
313
268
|
name
|
|
314
269
|
);
|
|
315
270
|
if (isExcludedDir(full, excludedDirs)) return null;
|
|
316
|
-
if (!fs.statSync(
|
|
317
|
-
/* turbopackIgnore: true */
|
|
318
|
-
full
|
|
319
|
-
).isDirectory()) return null;
|
|
320
271
|
const pagePath = path.join(
|
|
321
272
|
/* turbopackIgnore: true */
|
|
322
273
|
full,
|
|
323
274
|
"page.mdx"
|
|
324
275
|
);
|
|
325
|
-
if (!
|
|
326
|
-
|
|
327
|
-
pagePath
|
|
328
|
-
)) return null;
|
|
329
|
-
const data = readFrontmatter(pagePath);
|
|
276
|
+
if (!reader.directory(full).files.has("page.mdx")) return null;
|
|
277
|
+
const data = readFrontmatter(reader, pagePath);
|
|
330
278
|
const slug = [...baseSlug, name];
|
|
331
279
|
const url = publicDocsRoute(ctx, slug);
|
|
332
280
|
const icon = resolveIcon(data.icon, icons);
|
|
333
281
|
const displayName = data.title ?? name.replace(/-/g, " ");
|
|
334
282
|
const folderName = resolveSidebarFolderName(config.theme?.name, name, displayName);
|
|
335
|
-
const hasChildren = hasChildPages(full, excludedDirs);
|
|
283
|
+
const hasChildren = hasChildPages(reader, full, excludedDirs);
|
|
336
284
|
if (data.hidden === true) {
|
|
337
285
|
if (!hasChildren) return null;
|
|
338
286
|
return {
|
|
@@ -374,14 +322,7 @@ function buildTree(config, ctx, flat = false) {
|
|
|
374
322
|
};
|
|
375
323
|
}
|
|
376
324
|
function scanDir(dir, baseSlug, slugOrder) {
|
|
377
|
-
|
|
378
|
-
/* turbopackIgnore: true */
|
|
379
|
-
dir
|
|
380
|
-
)) return [];
|
|
381
|
-
const entries = fs.readdirSync(
|
|
382
|
-
/* turbopackIgnore: true */
|
|
383
|
-
dir
|
|
384
|
-
).sort();
|
|
325
|
+
const entries = reader.directory(dir).directories;
|
|
385
326
|
if (slugOrder) {
|
|
386
327
|
const nodes = [];
|
|
387
328
|
const slugMap = /* @__PURE__ */ new Map();
|
|
@@ -417,20 +358,13 @@ function buildTree(config, ctx, flat = false) {
|
|
|
417
358
|
name
|
|
418
359
|
);
|
|
419
360
|
if (isExcludedDir(full, excludedDirs)) continue;
|
|
420
|
-
if (!fs.statSync(
|
|
421
|
-
/* turbopackIgnore: true */
|
|
422
|
-
full
|
|
423
|
-
).isDirectory()) continue;
|
|
424
361
|
const pagePath = path.join(
|
|
425
362
|
/* turbopackIgnore: true */
|
|
426
363
|
full,
|
|
427
364
|
"page.mdx"
|
|
428
365
|
);
|
|
429
|
-
if (!
|
|
430
|
-
|
|
431
|
-
pagePath
|
|
432
|
-
)) continue;
|
|
433
|
-
const data = readFrontmatter(pagePath);
|
|
366
|
+
if (!reader.directory(full).files.has("page.mdx")) continue;
|
|
367
|
+
const data = readFrontmatter(reader, pagePath);
|
|
434
368
|
const order = typeof data.order === "number" ? data.order : Infinity;
|
|
435
369
|
const node = buildNode(dir, name, baseSlug);
|
|
436
370
|
if (node) nodes.push({
|
|
@@ -458,7 +392,7 @@ function buildTree(config, ctx, flat = false) {
|
|
|
458
392
|
}
|
|
459
393
|
const rootSlugOrder = Array.isArray(ordering) ? ordering : void 0;
|
|
460
394
|
rootChildren.push(...scanDir(docsDir, [], rootSlugOrder));
|
|
461
|
-
const changelogTree = buildChangelogTree(config, ctx, flat);
|
|
395
|
+
const changelogTree = buildChangelogTree(config, ctx, reader, flat);
|
|
462
396
|
if (changelogTree) {
|
|
463
397
|
if (rootChildren.length > 0) rootChildren.push({
|
|
464
398
|
type: "separator",
|
|
@@ -492,264 +426,84 @@ function localizeTreeUrls(tree, locale) {
|
|
|
492
426
|
children: tree.children.map(mapNode)
|
|
493
427
|
};
|
|
494
428
|
}
|
|
495
|
-
/**
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
const map = {};
|
|
505
|
-
const excludedDirs = getExcludedDocsDirs(config, ctx);
|
|
506
|
-
function formatDate(date) {
|
|
507
|
-
return date.toLocaleDateString("en-US", {
|
|
508
|
-
year: "numeric",
|
|
509
|
-
month: "long",
|
|
510
|
-
day: "numeric"
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
function scan(dir, slugParts) {
|
|
514
|
-
if (!fs.existsSync(
|
|
515
|
-
/* turbopackIgnore: true */
|
|
516
|
-
dir
|
|
517
|
-
)) return;
|
|
518
|
-
if (isExcludedDir(dir, excludedDirs)) return;
|
|
519
|
-
const pagePath = path.join(
|
|
520
|
-
/* turbopackIgnore: true */
|
|
521
|
-
dir,
|
|
522
|
-
"page.mdx"
|
|
523
|
-
);
|
|
524
|
-
if (fs.existsSync(
|
|
525
|
-
/* turbopackIgnore: true */
|
|
526
|
-
pagePath
|
|
527
|
-
)) {
|
|
528
|
-
const url = publicDocsRoute(ctx, slugParts);
|
|
529
|
-
const manifestLastmod = resolveManifestLastmod(manifest, ctx, url);
|
|
530
|
-
map[url] = formatDate(manifestLastmod ? /* @__PURE__ */ new Date(`${manifestLastmod}T00:00:00`) : fs.statSync(
|
|
531
|
-
/* turbopackIgnore: true */
|
|
532
|
-
pagePath
|
|
533
|
-
).mtime);
|
|
534
|
-
}
|
|
535
|
-
for (const name of fs.readdirSync(
|
|
536
|
-
/* turbopackIgnore: true */
|
|
537
|
-
dir
|
|
538
|
-
)) {
|
|
539
|
-
const full = path.join(
|
|
540
|
-
/* turbopackIgnore: true */
|
|
541
|
-
dir,
|
|
542
|
-
name
|
|
543
|
-
);
|
|
544
|
-
if (fs.statSync(
|
|
545
|
-
/* turbopackIgnore: true */
|
|
546
|
-
full
|
|
547
|
-
).isDirectory()) scan(full, [...slugParts, name]);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
scan(docsDir, []);
|
|
551
|
-
return map;
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* Scan all page.mdx files and build a map of URL pathname → description
|
|
555
|
-
* from the frontmatter `description` field.
|
|
556
|
-
*/
|
|
557
|
-
function buildDescriptionMap(config, ctx) {
|
|
558
|
-
const docsDir = ctx.docsDir;
|
|
559
|
-
const map = {};
|
|
560
|
-
const excludedDirs = getExcludedDocsDirs(config, ctx);
|
|
561
|
-
function scan(dir, slugParts) {
|
|
562
|
-
if (!fs.existsSync(
|
|
563
|
-
/* turbopackIgnore: true */
|
|
564
|
-
dir
|
|
565
|
-
)) return;
|
|
566
|
-
if (isExcludedDir(dir, excludedDirs)) return;
|
|
567
|
-
const pagePath = path.join(
|
|
568
|
-
/* turbopackIgnore: true */
|
|
569
|
-
dir,
|
|
570
|
-
"page.mdx"
|
|
571
|
-
);
|
|
572
|
-
if (fs.existsSync(
|
|
573
|
-
/* turbopackIgnore: true */
|
|
574
|
-
pagePath
|
|
575
|
-
)) {
|
|
576
|
-
const desc = readFrontmatter(pagePath).description;
|
|
577
|
-
if (desc) {
|
|
578
|
-
const url = publicDocsRoute(ctx, slugParts);
|
|
579
|
-
map[url] = desc;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
for (const name of fs.readdirSync(
|
|
583
|
-
/* turbopackIgnore: true */
|
|
584
|
-
dir
|
|
585
|
-
)) {
|
|
586
|
-
const full = path.join(
|
|
587
|
-
/* turbopackIgnore: true */
|
|
588
|
-
dir,
|
|
589
|
-
name
|
|
590
|
-
);
|
|
591
|
-
if (fs.statSync(
|
|
592
|
-
/* turbopackIgnore: true */
|
|
593
|
-
full
|
|
594
|
-
).isDirectory()) scan(full, [...slugParts, name]);
|
|
595
|
-
}
|
|
429
|
+
/** Keep consumer sidebar mutations local to the current render. */
|
|
430
|
+
function cloneTree(tree) {
|
|
431
|
+
function cloneNode(node) {
|
|
432
|
+
if (node.type !== "folder") return { ...node };
|
|
433
|
+
return {
|
|
434
|
+
...node,
|
|
435
|
+
index: node.index ? { ...node.index } : void 0,
|
|
436
|
+
children: node.children.map(cloneNode)
|
|
437
|
+
};
|
|
596
438
|
}
|
|
597
|
-
|
|
598
|
-
|
|
439
|
+
return {
|
|
440
|
+
...tree,
|
|
441
|
+
children: tree.children.map(cloneNode)
|
|
442
|
+
};
|
|
599
443
|
}
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
* This lets the page frame render the frontmatter title exactly once.
|
|
603
|
-
*/
|
|
604
|
-
function buildGeneratedTitleMap(config, ctx) {
|
|
605
|
-
const docsDir = ctx.docsDir;
|
|
606
|
-
const map = {};
|
|
607
|
-
const excludedDirs = getExcludedDocsDirs(config, ctx);
|
|
608
|
-
function scan(dir, slugParts) {
|
|
609
|
-
if (!fs.existsSync(
|
|
610
|
-
/* turbopackIgnore: true */
|
|
611
|
-
dir
|
|
612
|
-
)) return;
|
|
613
|
-
if (isExcludedDir(dir, excludedDirs)) return;
|
|
614
|
-
const pagePath = findDocsPageFile(dir);
|
|
615
|
-
if (pagePath) {
|
|
616
|
-
const source = fs.readFileSync(
|
|
617
|
-
/* turbopackIgnore: true */
|
|
618
|
-
pagePath,
|
|
619
|
-
"utf-8"
|
|
620
|
-
);
|
|
621
|
-
const { data } = matter(source);
|
|
622
|
-
if (typeof data.title === "string" && !hasAuthoredPageTitle(source)) map[publicDocsRoute(ctx, slugParts)] = data.title;
|
|
623
|
-
}
|
|
624
|
-
for (const name of fs.readdirSync(
|
|
625
|
-
/* turbopackIgnore: true */
|
|
626
|
-
dir
|
|
627
|
-
)) {
|
|
628
|
-
const full = path.join(
|
|
629
|
-
/* turbopackIgnore: true */
|
|
630
|
-
dir,
|
|
631
|
-
name
|
|
632
|
-
);
|
|
633
|
-
if (fs.statSync(
|
|
634
|
-
/* turbopackIgnore: true */
|
|
635
|
-
full
|
|
636
|
-
).isDirectory()) scan(full, [...slugParts, name]);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
scan(docsDir, []);
|
|
640
|
-
return map;
|
|
444
|
+
function resolveManifestLastmod(manifest, ctx, url) {
|
|
445
|
+
return (ctx.locale ? resolveDocsSitemapPageLastmod(manifest, `${url}?lang=${encodeURIComponent(ctx.locale)}`) : void 0) ?? resolveDocsSitemapPageLastmod(manifest, url);
|
|
641
446
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
const
|
|
447
|
+
/** Read each page once for all metadata, sharing the reader with navigation. */
|
|
448
|
+
function buildPageMaps(config, ctx, reader, manifest, options) {
|
|
449
|
+
const lastModifiedMap = {};
|
|
450
|
+
const descriptionMap = {};
|
|
451
|
+
const generatedTitleMap = {};
|
|
452
|
+
const readingTimeMap = {};
|
|
645
453
|
const excludedDirs = getExcludedDocsDirs(config, ctx);
|
|
454
|
+
const structuredDataPages = {
|
|
455
|
+
baseUrl: resolveDocsMetadataBaseUrl(config),
|
|
456
|
+
entry: ctx.entryPath,
|
|
457
|
+
pages: {}
|
|
458
|
+
};
|
|
459
|
+
const dateFormatter = options.lastUpdated ? new Intl.DateTimeFormat("en-US", {
|
|
460
|
+
year: "numeric",
|
|
461
|
+
month: "long",
|
|
462
|
+
day: "numeric"
|
|
463
|
+
}) : void 0;
|
|
646
464
|
function scan(dir, slugParts) {
|
|
647
|
-
if (!fs.existsSync(
|
|
648
|
-
/* turbopackIgnore: true */
|
|
649
|
-
dir
|
|
650
|
-
)) return;
|
|
651
465
|
if (isExcludedDir(dir, excludedDirs)) return;
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
);
|
|
657
|
-
if (fs.existsSync(
|
|
658
|
-
/* turbopackIgnore: true */
|
|
659
|
-
pagePath
|
|
660
|
-
)) {
|
|
661
|
-
const { data, content } = matter(fs.readFileSync(
|
|
662
|
-
/* turbopackIgnore: true */
|
|
663
|
-
pagePath,
|
|
664
|
-
"utf-8"
|
|
665
|
-
));
|
|
666
|
-
const minutes = resolvePageReadingTime(data, resolveDocsAudienceMdxContent(content, "human"), options);
|
|
667
|
-
if (typeof minutes === "number") {
|
|
668
|
-
const url = publicDocsRoute(ctx, slugParts);
|
|
669
|
-
map[url] = minutes;
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
for (const name of fs.readdirSync(
|
|
673
|
-
/* turbopackIgnore: true */
|
|
674
|
-
dir
|
|
675
|
-
)) {
|
|
676
|
-
const full = path.join(
|
|
466
|
+
const { directories, files } = reader.directory(dir);
|
|
467
|
+
const fileName = files.has("page.mdx") ? "page.mdx" : files.has("page.md") ? "page.md" : void 0;
|
|
468
|
+
if (fileName) {
|
|
469
|
+
const { data, content, modifiedAt } = reader.page(path.join(
|
|
677
470
|
/* turbopackIgnore: true */
|
|
678
471
|
dir,
|
|
679
|
-
|
|
680
|
-
);
|
|
681
|
-
if (fs.statSync(
|
|
682
|
-
/* turbopackIgnore: true */
|
|
683
|
-
full
|
|
684
|
-
).isDirectory()) scan(full, [...slugParts, name]);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
scan(docsDir, []);
|
|
688
|
-
return map;
|
|
689
|
-
}
|
|
690
|
-
function findDocsPageFile(dir) {
|
|
691
|
-
return ["page.mdx", "page.md"].map((fileName) => path.join(
|
|
692
|
-
/* turbopackIgnore: true */
|
|
693
|
-
dir,
|
|
694
|
-
fileName
|
|
695
|
-
)).find((candidate) => fs.existsSync(
|
|
696
|
-
/* turbopackIgnore: true */
|
|
697
|
-
candidate
|
|
698
|
-
));
|
|
699
|
-
}
|
|
700
|
-
function buildStructuredDataMap(config, ctx, manifest) {
|
|
701
|
-
const docsDir = ctx.docsDir;
|
|
702
|
-
const map = {};
|
|
703
|
-
const excludedDirs = getExcludedDocsDirs(config, ctx);
|
|
704
|
-
const baseUrl = resolveDocsMetadataBaseUrl(config);
|
|
705
|
-
function scan(dir, slugParts) {
|
|
706
|
-
if (!fs.existsSync(
|
|
707
|
-
/* turbopackIgnore: true */
|
|
708
|
-
dir
|
|
709
|
-
)) return;
|
|
710
|
-
if (isExcludedDir(dir, excludedDirs)) return;
|
|
711
|
-
const pagePath = findDocsPageFile(dir);
|
|
712
|
-
if (pagePath) {
|
|
713
|
-
const { data } = matter(fs.readFileSync(
|
|
714
|
-
/* turbopackIgnore: true */
|
|
715
|
-
pagePath,
|
|
716
|
-
"utf-8"
|
|
472
|
+
fileName
|
|
717
473
|
));
|
|
718
474
|
const route = publicDocsRoute(ctx, slugParts);
|
|
719
475
|
const title = typeof data.title === "string" ? data.title : slugParts.at(-1)?.replace(/-/g, " ") || "Documentation";
|
|
720
476
|
const description = typeof data.description === "string" ? data.description : void 0;
|
|
721
477
|
const manifestLastmod = resolveManifestLastmod(manifest, ctx, route);
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
478
|
+
if (config.theme?.name === "shadcn" && typeof data.title === "string" && !hasAuthoredPageTitle(content)) generatedTitleMap[route] = data.title;
|
|
479
|
+
if (fileName === "page.mdx") {
|
|
480
|
+
if (dateFormatter) lastModifiedMap[route] = dateFormatter.format(manifestLastmod ? /* @__PURE__ */ new Date(`${manifestLastmod}T00:00:00`) : modifiedAt);
|
|
481
|
+
if (description) descriptionMap[route] = description;
|
|
482
|
+
const minutes = resolvePageReadingTime(data, (options.enabledByDefault || Object.hasOwn(data, "readingTime")) && data.readingTime !== false && !(typeof data.readingTime === "number" && Number.isFinite(data.readingTime)) ? resolveDocsAudienceMdxContent(content, "human") : "", options);
|
|
483
|
+
if (typeof minutes === "number") readingTimeMap[route] = minutes;
|
|
484
|
+
}
|
|
485
|
+
structuredDataPages.pages[route] = compactPageStructuredData({
|
|
727
486
|
title,
|
|
728
487
|
description,
|
|
729
488
|
url: withLangInUrl(route, ctx.locale),
|
|
730
|
-
|
|
731
|
-
entry: ctx.entryPath,
|
|
732
|
-
dateModified,
|
|
489
|
+
dateModified: manifestLastmod ? `${manifestLastmod}T00:00:00.000Z` : modifiedAt.toISOString(),
|
|
733
490
|
agent: normalizePageAgentFrontmatter(data.agent)
|
|
734
491
|
});
|
|
735
492
|
}
|
|
736
|
-
for (const name of
|
|
493
|
+
for (const name of directories) scan(path.join(
|
|
737
494
|
/* turbopackIgnore: true */
|
|
738
|
-
dir
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
/* turbopackIgnore: true */
|
|
742
|
-
dir,
|
|
743
|
-
name
|
|
744
|
-
);
|
|
745
|
-
if (fs.statSync(
|
|
746
|
-
/* turbopackIgnore: true */
|
|
747
|
-
full
|
|
748
|
-
).isDirectory()) scan(full, [...slugParts, name]);
|
|
749
|
-
}
|
|
495
|
+
dir,
|
|
496
|
+
name
|
|
497
|
+
), [...slugParts, name]);
|
|
750
498
|
}
|
|
751
|
-
scan(docsDir, []);
|
|
752
|
-
return
|
|
499
|
+
scan(ctx.docsDir, []);
|
|
500
|
+
return {
|
|
501
|
+
lastModifiedMap,
|
|
502
|
+
descriptionMap,
|
|
503
|
+
generatedTitleMap,
|
|
504
|
+
readingTimeMap,
|
|
505
|
+
structuredDataPages
|
|
506
|
+
};
|
|
753
507
|
}
|
|
754
508
|
/**
|
|
755
509
|
* Build a Next.js Metadata object from the docs config.
|
|
@@ -944,7 +698,6 @@ function createDocsLayout(config, options) {
|
|
|
944
698
|
const tocStyle = tocConfig?.style;
|
|
945
699
|
const analyticsEnabled = resolveDocsAnalyticsConfig(config.analytics).enabled;
|
|
946
700
|
const localeContext = resolveDocsLocaleContext(config, options?.locale);
|
|
947
|
-
const sitemapManifest = readDocsSitemapManifest(process.cwd(), config.sitemap);
|
|
948
701
|
const i18n = resolveDocsI18nConfig(getDocsI18n(config));
|
|
949
702
|
const activeLocale = localeContext.locale ?? i18n?.defaultLocale;
|
|
950
703
|
const docsApiUrl = withLangInUrl("/api/docs", activeLocale);
|
|
@@ -999,6 +752,7 @@ function createDocsLayout(config, options) {
|
|
|
999
752
|
const aiConfig = config.ai;
|
|
1000
753
|
const aiEnabled = !staticExport && !!aiConfig?.enabled;
|
|
1001
754
|
const aiMode = aiConfig?.mode ?? "search";
|
|
755
|
+
const aiHandlesSearch = aiEnabled && (aiMode === "search" || aiMode === "sidebar-icon");
|
|
1002
756
|
const aiPosition = aiConfig?.position ?? "bottom-right";
|
|
1003
757
|
const aiFloatingStyle = aiConfig?.floatingStyle ?? "panel";
|
|
1004
758
|
const aiTriggerComponentHtml = aiConfig?.triggerComponent ? serializeIcon(aiConfig.triggerComponent) : void 0;
|
|
@@ -1014,22 +768,28 @@ function createDocsLayout(config, options) {
|
|
|
1014
768
|
aiModels = rawModelConfig.models ?? aiModels;
|
|
1015
769
|
aiDefaultModelId = rawModelConfig.defaultModel ?? rawModelConfig.models?.[0]?.id ?? aiDefaultModelId;
|
|
1016
770
|
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
const readingTimeEnabled = readingTimeEnabledByDefault || Object.keys(readingTimeMap).length > 0;
|
|
1027
|
-
return function DocsLayoutWrapper({ children }) {
|
|
1028
|
-
const tree = applySidebarFolderIndexBehavior(buildTree(config, localeContext, !!sidebarFlat), {
|
|
771
|
+
function prepareContent() {
|
|
772
|
+
const reader = createDocsContentReader();
|
|
773
|
+
const maps = buildPageMaps(config, localeContext, reader, readDocsSitemapManifest(process.cwd(), config.sitemap), {
|
|
774
|
+
lastUpdated: lastUpdatedEnabled,
|
|
775
|
+
enabledByDefault: readingTimeEnabledByDefault,
|
|
776
|
+
wordsPerMinute: readingTimeWordsPerMinute,
|
|
777
|
+
includeCode: readingTimeIncludeCode
|
|
778
|
+
});
|
|
779
|
+
const tree = applySidebarFolderIndexBehavior(buildTree(config, localeContext, reader, !!sidebarFlat), {
|
|
1029
780
|
sidebar: config.sidebar,
|
|
1030
781
|
defaultBehavior: config.theme?.name === "shadcn" ? "hidden" : "link"
|
|
1031
782
|
});
|
|
1032
|
-
|
|
783
|
+
return {
|
|
784
|
+
pageMetadata: serializePageMetadata(maps),
|
|
785
|
+
readingTimeEnabled: readingTimeEnabledByDefault || Object.keys(maps.readingTimeMap).length > 0,
|
|
786
|
+
localizedTree: i18n ? localizeTreeUrls(tree, activeLocale) : tree
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
let productionContent;
|
|
790
|
+
return function DocsLayoutWrapper({ children }) {
|
|
791
|
+
const { pageMetadata, readingTimeEnabled, localizedTree: preparedTree } = process.env.NODE_ENV === "production" ? productionContent ??= prepareContent() : prepareContent();
|
|
792
|
+
const localizedTree = cloneTree(preparedTree);
|
|
1033
793
|
const finalSidebarProps = { ...sidebarProps };
|
|
1034
794
|
const sidebarFooter = withStableReactKey(sidebarProps.footer, "docs-sidebar-footer");
|
|
1035
795
|
finalSidebarProps.banner = withStableReactKey(sidebarProps.banner, "docs-sidebar-banner");
|
|
@@ -1073,7 +833,7 @@ function createDocsLayout(config, options) {
|
|
|
1073
833
|
/* @__PURE__ */ jsx(TypographyStyle, { typography }),
|
|
1074
834
|
/* @__PURE__ */ jsx(LayoutStyle, { layout: layoutDimensions }),
|
|
1075
835
|
forcedTheme && /* @__PURE__ */ jsx(ForcedThemeScript, { theme: forcedTheme }),
|
|
1076
|
-
!staticExport && /* @__PURE__ */ jsx(Suspense, {
|
|
836
|
+
!staticExport && !aiHandlesSearch && /* @__PURE__ */ jsx(Suspense, {
|
|
1077
837
|
fallback: null,
|
|
1078
838
|
children: /* @__PURE__ */ jsx(DocsCommandSearch, {
|
|
1079
839
|
api: docsApiUrl,
|
|
@@ -1130,17 +890,13 @@ function createDocsLayout(config, options) {
|
|
|
1130
890
|
contentDir,
|
|
1131
891
|
githubBranch,
|
|
1132
892
|
githubDirectory,
|
|
1133
|
-
|
|
893
|
+
pageMetadata,
|
|
1134
894
|
lastUpdatedEnabled,
|
|
1135
895
|
lastUpdatedLabel,
|
|
1136
896
|
lastUpdatedPosition,
|
|
1137
897
|
readingTimeEnabled,
|
|
1138
898
|
readingTimeFormat,
|
|
1139
|
-
readingTimeMap,
|
|
1140
|
-
structuredDataMap,
|
|
1141
899
|
llmsTxtEnabled,
|
|
1142
|
-
generatedTitleMap,
|
|
1143
|
-
descriptionMap,
|
|
1144
900
|
feedbackEnabled: feedbackConfig.enabled,
|
|
1145
901
|
feedbackQuestion: feedbackConfig.question,
|
|
1146
902
|
feedbackPlaceholder: feedbackConfig.placeholder,
|