@takazudo/zudo-doc 11.0.0 → 12.0.1

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/agent-docs/search.js +6 -3
  3. package/dist/config.js +5 -0
  4. package/dist/content-admonition/index.d.ts +2 -1
  5. package/dist/content-admonition/index.js +2 -1
  6. package/dist/doc-page-renderer/index.d.ts +4 -0
  7. package/dist/doc-page-renderer/index.js +5 -0
  8. package/dist/doc-page-shell/index.d.ts +9 -0
  9. package/dist/doc-page-shell/index.js +2 -0
  10. package/dist/head-with-defaults/index.d.ts +9 -0
  11. package/dist/head-with-defaults/index.js +10 -0
  12. package/dist/home-page/index.js +8 -0
  13. package/dist/mcp/handler.js +1 -7
  14. package/dist/md-utils/index.d.ts +6 -1
  15. package/dist/md-utils/index.js +3 -2
  16. package/dist/mdx-components/index.js +4 -7
  17. package/dist/mdx-components/vocabulary.d.ts +19 -0
  18. package/dist/mdx-components/vocabulary.js +32 -0
  19. package/dist/plugins/internal/agent-export/components.d.ts +27 -0
  20. package/dist/plugins/internal/agent-export/components.js +125 -0
  21. package/dist/plugins/internal/agent-export/index.d.ts +4 -0
  22. package/dist/plugins/internal/agent-export/index.js +29 -8
  23. package/dist/plugins/internal/agent-export/normalize.d.ts +18 -1
  24. package/dist/plugins/internal/agent-export/normalize.js +91 -5
  25. package/dist/plugins/internal/llms-txt/dev-middleware.d.ts +2 -0
  26. package/dist/plugins/internal/llms-txt/dev-middleware.js +1 -0
  27. package/dist/plugins/internal/llms-txt/emit.js +3 -0
  28. package/dist/plugins/internal/llms-txt/load.js +2 -2
  29. package/dist/plugins/internal/llms-txt/types.d.ts +4 -0
  30. package/dist/plugins/internal/search-index/collect.js +5 -4
  31. package/dist/plugins/internal/search-index/types.d.ts +2 -0
  32. package/dist/preset.d.ts +2 -0
  33. package/dist/preset.js +5 -1
  34. package/dist/route-enumerators/index.d.ts +63 -2
  35. package/dist/route-enumerators/index.js +124 -21
  36. package/dist/routes/_context.d.ts +1 -1
  37. package/dist/routes/_context.js +6 -0
  38. package/dist/routes/sitemap.xml.js +19 -9
  39. package/eject/content-admonition/index.tsx +4 -9
  40. package/package.json +3 -3
  41. package/routes-src/_context.ts +3 -0
  42. package/routes-src/sitemap.xml.tsx +36 -12
package/CHANGELOG.md CHANGED
@@ -6,6 +6,29 @@ The format is based on Keep a Changelog, and release notes are generated from th
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [12.0.1] - 2026-11-14
10
+
11
+ - No package-specific changes.
12
+
13
+ ## [12.0.0] - 2026-11-13
14
+
15
+ ### Breaking Changes
16
+
17
+ - `zudoDoc()` now throws a `TypeError` when the settings still contain `findInPage`, the key that 11.0.0 removed, instead of ignoring it. The message tells you to remove the key. Configs without `findInPage` are unaffected. (#4763)
18
+ - The `@takazudo/zudo-doc-history-server` peer floor moves from `^11.0.0` to `^12.0.0`. Projects that enable document history need history-server 12.x.
19
+
20
+ ### Features
21
+
22
+ - Pages that exist as real content in more than one locale now link each other with `<link rel="alternate" hreflang>` after the canonical link, including a self-reference and `x-default` for the default-locale page, and the sitemap lists the same pairs as `xhtml:link` alternates. This covers the home pages and latest document pages; fallback-only, versioned and tag pages stay unpaired. Nothing changes without `siteUrl` or on single-locale sites. `@takazudo/zudo-doc/route-enumerators` adds `getDocLocaleAlternates` and `getHomeLocaleAlternates`, and sitemap entries gain an optional `alternates` field. (#4787)
23
+
24
+ ### Bug Fixes
25
+
26
+ - The sitemap's `<lastmod>` is now each document page's last-updated date from document history, the same date as its "Updated" label, instead of the build date on every URL. Routes with no known date (home and locale roots, tag, asset and versioned pages, or any page while `docHistory` is off or document history generation is skipped) have no `<lastmod>`. `@takazudo/zudo-doc/route-enumerators` adds `enumerateSitemapEntries`; `enumerateAllRoutes` is unchanged. (#4784)
27
+ - Page URLs in `llms.txt`, `llms-full.txt`, the browser search index (`search-index.json`), the agent export (manifest, items, search index) and MCP `search`/`fetch` results now follow the `trailingSlash` setting, the same as the built routes. With `trailingSlash: true` they end with `/` and no longer cite a URL that redirects; with `trailingSlash: false` output is unchanged. The schemas are unchanged and agent page IDs stay the same, but the `url` values, the `llms.txt` bytes and the agent corpus fingerprint change for sites with `trailingSlash: true`. (#4783)
28
+ - MCP `search` result titles name the part of a multi-part page once, for example `Read-only MCP server (en · part 1/2)` instead of `Read-only MCP server (part 1/2) (en · part 1/2)`. Stored item titles and `fetch` results are unchanged. (#4783)
29
+ - `/mcp` no longer approves the opaque `Origin: null` when `siteUrl` has no `http:` or `https:` scheme (for example `docs.example.com:8443`). Only an `http(s)` `siteUrl` adds an approved origin; requests without `Origin` and requests from the endpoint's own origin behave as before. (#4783)
30
+ - The agent export (`/agent/v1/` pages, items and search index) now turns admonitions, `` and `` into a bold label such as `**Note: Title**` followed by their body, and renders ``, ``, ``, `` and `` as Markdown link lists of the same locale's exported pages. These pages are no longer marked `unsupportedDynamicContent`. Other components, and components whose props are not plain literals, still become a placeholder that now names the component, for example `[Dynamic content unavailable in text export: MathBlock]`, and keep the flag. Item text and the corpus fingerprint change for pages that use these components. `llms-full.txt` is unchanged. (#4786)
31
+
9
32
  ## [11.0.0] - 2026-11-13
10
33
 
11
34
  ### Breaking Changes
@@ -31,11 +31,14 @@ function buildAgentSearchIndex(source) {
31
31
  }
32
32
  function displayTitle(item, duplicateTitle, duplicateQualifier) {
33
33
  const { locale, section, part, partCount } = item.metadata;
34
+ const partLabel = `part ${part}/${partCount}`;
35
+ const suffix = ` (${partLabel})`;
36
+ const title = partCount > 1 && item.title.endsWith(suffix) ? item.title.slice(0, -suffix.length) : item.title;
34
37
  const qualifiers = [locale];
35
- if (section && section !== item.title) qualifiers.push(section);
36
- if (partCount > 1) qualifiers.push(`part ${part}/${partCount}`);
38
+ if (section && section !== title) qualifiers.push(section);
39
+ if (partCount > 1) qualifiers.push(partLabel);
37
40
  if (duplicateQualifier) qualifiers.push(item.id);
38
- return duplicateTitle || qualifiers.length > 1 ? `${item.title} (${qualifiers.join(" \xB7 ")})` : item.title;
41
+ return duplicateTitle || qualifiers.length > 1 ? `${title} (${qualifiers.join(" \xB7 ")})` : title;
39
42
  }
40
43
  function searchAgentIndex(index, query, topK = AGENT_MAX_SEARCH_RESULTS) {
41
44
  if (query.length > AGENT_MAX_QUERY_UNITS) {
package/dist/config.js CHANGED
@@ -65,6 +65,11 @@ function zudoDoc(user = {}) {
65
65
  "githubAutolinksRepo is no longer supported; the githubAutolinks markdown feature was removed"
66
66
  );
67
67
  }
68
+ if ("findInPage" in user) {
69
+ throw new TypeError(
70
+ "findInPage is no longer supported; the find-in-page bar was removed in 11.0.0, so remove the findInPage key from your zudoDoc() settings"
71
+ );
72
+ }
68
73
  const {
69
74
  port,
70
75
  adapter,
@@ -1,6 +1,7 @@
1
1
  /** @jsxRuntime automatic */
2
2
  import type { Child } from "@takazudo/zfb/zudo-react";
3
- export type AdmonitionVariant = "note" | "tip" | "info" | "warning" | "danger" | "caution" | "important";
3
+ import { type AdmonitionVariant } from "../mdx-components/vocabulary.js";
4
+ export type { AdmonitionVariant };
4
5
  export interface AdmonitionProps {
5
6
  /** Custom title; falls back to the capitalized variant name (e.g. "Note"). */
6
7
  title?: string;
@@ -1,6 +1,7 @@
1
1
  import { jsx, jsxs } from "@takazudo/zfb/zudo-react/jsx-runtime";
2
+ import { admonitionComponentName } from "../mdx-components/vocabulary.js";
2
3
  function makeAdmonition(variant) {
3
- const defaultTitle = variant.charAt(0).toUpperCase() + variant.slice(1);
4
+ const defaultTitle = admonitionComponentName(variant);
4
5
  return function Admonition({ title, children }) {
5
6
  const heading = title && title.length > 0 ? title : defaultTitle;
6
7
  return /* @__PURE__ */ jsxs("div", { "data-admonition": variant, class: `admonition-${variant}`, children: [
@@ -77,6 +77,10 @@ export interface DocPageRendererDeps {
77
77
  type?: string;
78
78
  title?: string;
79
79
  }>;
80
+ localeAlternates?: ReadonlyArray<{
81
+ hreflang: string;
82
+ href: string;
83
+ }>;
80
84
  breadcrumbs: Array<{
81
85
  label: string;
82
86
  href?: string;
@@ -64,6 +64,10 @@ function createRenderDocPage(ctx) {
64
64
  type: "text/markdown",
65
65
  href: ctx.withBase(`/agent/v1/pages/${agentPageKey(locale, slug)}.md`)
66
66
  }] : void 0;
67
+ const localeAlternates = !version && props.kind === "entry" && !isFallback && canonical !== void 0 ? ctx.getDocLocaleAlternates(slug, locale).flatMap(({ hreflang, url }) => {
68
+ const href = absoluteUrl(url);
69
+ return href === void 0 ? [] : [{ hreflang, href }];
70
+ }) : [];
67
71
  const ContentComponent = props.kind === "entry" ? props.entry.Content : null;
68
72
  return /* @__PURE__ */ jsx(
69
73
  DocPageShell,
@@ -76,6 +80,7 @@ function createRenderDocPage(ctx) {
76
80
  canonical,
77
81
  ogImage: typeof entryData?.og_image === "string" && isRootAbsoluteSitePath(entryData.og_image) ? entryData.og_image : void 0,
78
82
  alternateLinks: agentMarkdownAlternates,
83
+ localeAlternates: localeAlternates.length > 0 ? localeAlternates : void 0,
79
84
  breadcrumbs,
80
85
  prev,
81
86
  next,
@@ -52,6 +52,11 @@ export interface DocPageShellProps {
52
52
  type?: string;
53
53
  title?: string;
54
54
  }>;
55
+ /** Absolute `hreflang` alternates passed through to the head defaults. */
56
+ localeAlternates?: ReadonlyArray<{
57
+ hreflang: string;
58
+ href: string;
59
+ }>;
55
60
  /** Pre-resolved breadcrumb trail (hrefs already remapped per route). */
56
61
  breadcrumbs: DocPageBreadcrumbItem[];
57
62
  /** Pre-resolved prev/next nav nodes (hrefs already remapped per route). */
@@ -139,6 +144,10 @@ export interface DocPageShellDeps {
139
144
  type?: string;
140
145
  title?: string;
141
146
  }>;
147
+ localeAlternates?: ReadonlyArray<{
148
+ hreflang: string;
149
+ href: string;
150
+ }>;
142
151
  lang?: string;
143
152
  }) => JSX.Element;
144
153
  SidebarWithDefaults: (props: {
@@ -63,6 +63,7 @@ function createDocPageShell(ctx) {
63
63
  canonical,
64
64
  ogImage,
65
65
  alternateLinks,
66
+ localeAlternates,
66
67
  breadcrumbs,
67
68
  prev,
68
69
  next,
@@ -135,6 +136,7 @@ function createDocPageShell(ctx) {
135
136
  description,
136
137
  canonical,
137
138
  alternateLinks,
139
+ localeAlternates,
138
140
  locale,
139
141
  ogImage
140
142
  }
@@ -16,6 +16,15 @@ export interface HeadWithDefaultsProps {
16
16
  canonical?: string;
17
17
  /** Page-specific alternate links, such as an exported Markdown version. */
18
18
  alternateLinks?: HeadProps["alternateLinks"];
19
+ /**
20
+ * Absolute `hreflang` alternates for this page's locale variants (including
21
+ * itself and `x-default`), emitted right after the canonical link. Omitted
22
+ * or empty emits nothing.
23
+ */
24
+ localeAlternates?: ReadonlyArray<{
25
+ hreflang: string;
26
+ href: string;
27
+ }>;
19
28
  /** Active locale: selects `locales[locale].ogImage` when set, and a configured non-default
20
29
  * locale links its own `llms.txt`. */
21
30
  locale?: string;
@@ -114,6 +114,7 @@ function createHeadWithDefaults(ctx) {
114
114
  description,
115
115
  canonical,
116
116
  alternateLinks,
117
+ localeAlternates,
117
118
  locale,
118
119
  ogImage
119
120
  }) {
@@ -162,6 +163,15 @@ function createHeadWithDefaults(ctx) {
162
163
  settings.sidebarResizer && /* @__PURE__ */ jsx("script", { rawHtml: SIDEBAR_RESIZER_RESTORE_SCRIPT }),
163
164
  faviconLinks.map((attrs, i) => /* @__PURE__ */ jsx("link", { ...attrs }, i)),
164
165
  canonical !== void 0 && /* @__PURE__ */ jsx("link", { rel: "canonical", href: canonical }),
166
+ localeAlternates?.map((alternate) => /* @__PURE__ */ jsx(
167
+ "link",
168
+ {
169
+ rel: "alternate",
170
+ hreflang: alternate.hreflang,
171
+ href: alternate.href
172
+ },
173
+ `hreflang:${alternate.hreflang}`
174
+ )),
165
175
  alternateLinks?.map((alternate, i) => /* @__PURE__ */ jsx(
166
176
  "link",
167
177
  {
@@ -95,6 +95,13 @@ function createHomePageView(ctx) {
95
95
  ctx.themePackRegistry,
96
96
  ctx.settings
97
97
  );
98
+ function homeLocaleAlternates() {
99
+ const alternates = ctx.getHomeLocaleAlternates().flatMap(({ hreflang, url }) => {
100
+ const href = ctx.absoluteUrl(url);
101
+ return href === void 0 ? [] : [{ hreflang, href }];
102
+ });
103
+ return alternates.length > 0 ? alternates : void 0;
104
+ }
98
105
  function HomePageView({
99
106
  locale,
100
107
  extras,
@@ -252,6 +259,7 @@ function createHomePageView(ctx) {
252
259
  title: settings.siteName,
253
260
  description,
254
261
  canonical: ctx.absoluteUrl(homePath),
262
+ localeAlternates: homeLocaleAlternates(),
255
263
  locale
256
264
  }
257
265
  ),
@@ -49,13 +49,7 @@ function createMcpHandler(options) {
49
49
  return async (request) => {
50
50
  const requestOrigin = new URL(request.url).origin;
51
51
  const origin = request.headers.get("origin");
52
- const allowed = /* @__PURE__ */ new Set([requestOrigin]);
53
- if (options.siteUrl) {
54
- try {
55
- allowed.add(new URL(options.siteUrl).origin);
56
- } catch {
57
- }
58
- }
52
+ const allowed = /* @__PURE__ */ new Set([requestOrigin, mcpPublicOrigin(options.siteUrl, request.url)]);
59
53
  const cors = origin && allowed.has(origin) ? origin : void 0;
60
54
  const finish = (response) => {
61
55
  const headers = new Headers(response.headers);
@@ -62,10 +62,15 @@ export declare function collectMdFiles(dir: string): Array<{
62
62
  * qualified URL is produced (matching the legacy llms-txt emitter's
63
63
  * `slugToUrl(slug, locale, true)` call site exactly).
64
64
  *
65
+ * `trailingSlash` mirrors the route layer's rule (`applyTrailingSlash` in
66
+ * `plugins/routes.ts`): when true, a slash is appended unless the path
67
+ * already ends with one, so the emitted URL is the served page rather than
68
+ * a redirect to it. Omitted means `false` (slash-less output).
69
+ *
65
70
  * Callers must pass the EFFECTIVE slug (`data.slug ?? filesystem slug`) —
66
71
  * the frontmatter override is resolved at the call site, not here.
67
72
  */
68
- export declare function slugToUrl(slug: string, locale: string | null, base: string, siteUrl?: string): string;
73
+ export declare function slugToUrl(slug: string, locale: string | null, base: string, siteUrl?: string, trailingSlash?: boolean): string;
69
74
  /**
70
75
  * Parse a markdown file into frontmatter + body. Returns `null` when
71
76
  * the file is unreadable so callers can simply skip it.
@@ -67,9 +67,10 @@ function collectMdFiles(dir) {
67
67
  walk(dir, dir);
68
68
  return results;
69
69
  }
70
- function slugToUrl(slug, locale, base, siteUrl) {
70
+ function slugToUrl(slug, locale, base, siteUrl, trailingSlash = false) {
71
71
  const trimmedBase = base.replace(/\/$/, "");
72
- const path = locale ? `${trimmedBase}/${locale}/docs/${slug}` : `${trimmedBase}/docs/${slug}`;
72
+ const rawPath = locale ? `${trimmedBase}/${locale}/docs/${slug}` : `${trimmedBase}/docs/${slug}`;
73
+ const path = trailingSlash && !rawPath.endsWith("/") ? `${rawPath}/` : rawPath;
73
74
  if (siteUrl) {
74
75
  return `${siteUrl.replace(/\/$/, "")}${path}`;
75
76
  }
@@ -3,6 +3,7 @@ import { defaultComponents } from "../content/index.js";
3
3
  import { createContentLink } from "../content/content-link.js";
4
4
  import { decodeAuthoredHref, assetViewerHref } from "../asset-path/index.js";
5
5
  import { makeAdmonition } from "../content-admonition/index.js";
6
+ import { ADMONITION_COMPONENTS } from "./vocabulary.js";
6
7
  import { CodeGroup } from "../code-group/index.js";
7
8
  import { Tabs } from "../code-syntax/index.js";
8
9
  import { TabItem } from "../tab-item/index.js";
@@ -149,13 +150,9 @@ function createMdxComponents(options) {
149
150
  // targets. `:::note` directives emit <Note>; `<Note title="…">` JSX is
150
151
  // also authored directly. github-alerts [!IMPORTANT]/[!CAUTION] map to
151
152
  // Important/Caution — omitting those two 500s their SSR render.
152
- Note: makeAdmonition("note"),
153
- Tip: makeAdmonition("tip"),
154
- Info: makeAdmonition("info"),
155
- Warning: makeAdmonition("warning"),
156
- Danger: makeAdmonition("danger"),
157
- Important: makeAdmonition("important"),
158
- Caution: makeAdmonition("caution"),
153
+ ...Object.fromEntries(
154
+ [...ADMONITION_COMPONENTS].map(([name, variant]) => [name, makeAdmonition(variant)])
155
+ ),
159
156
  // codeTabs Option A: zfb emits <CodeGroup tabs={[...]}> for :::code-group.
160
157
  CodeGroup,
161
158
  Tabs,
@@ -0,0 +1,19 @@
1
+ import type { DirectiveSpec } from "@takazudo/zfb/config";
2
+ /** The JSX component a directive vocabulary entry resolves to. */
3
+ export declare function directiveComponentName(spec: DirectiveSpec): string;
4
+ /** Admonition variants, in registration order. */
5
+ export declare const ADMONITION_VARIANTS: readonly ["note", "tip", "info", "warning", "danger", "important", "caution"];
6
+ export type AdmonitionVariant = (typeof ADMONITION_VARIANTS)[number];
7
+ /** `"note"` → `"Note"`: both the MDX tag name and the default visible title. */
8
+ export declare function admonitionComponentName(variant: AdmonitionVariant): string;
9
+ /** MDX tag name → admonition variant. */
10
+ export declare const ADMONITION_COMPONENTS: ReadonlyMap<string, AdmonitionVariant>;
11
+ /** The collapsible the `:::details` directive resolves to. Its default title is "Details". */
12
+ export declare const DETAILS_COMPONENT: string;
13
+ /** Tab containers whose body is ordinary Markdown. */
14
+ export declare const TAB_GROUP_COMPONENTS: readonly ["Tabs", "CodeGroup"];
15
+ /** One labelled tab inside a tab container (`label` prop). */
16
+ export declare const TAB_ITEM_COMPONENT = "TabItem";
17
+ /** Navigation tags that list documents from the docs collection. */
18
+ export declare const NAV_COMPONENTS: readonly ["CategoryNav", "CategoryTreeNav", "SiteTreeNav", "SiteTreeNavDemo", "DocCardNav", "NoteTrayIndex"];
19
+ export type NavComponentName = (typeof NAV_COMPONENTS)[number];
@@ -0,0 +1,32 @@
1
+ import { defaultDirectiveVocabulary } from "../directive-vocabulary-defaults/index.js";
2
+ function directiveComponentName(spec) {
3
+ return typeof spec === "string" ? spec : spec.component;
4
+ }
5
+ const ADMONITION_VARIANTS = ["note", "tip", "info", "warning", "danger", "important", "caution"];
6
+ function admonitionComponentName(variant) {
7
+ return variant.charAt(0).toUpperCase() + variant.slice(1);
8
+ }
9
+ const ADMONITION_COMPONENTS = new Map(
10
+ ADMONITION_VARIANTS.map((variant) => [admonitionComponentName(variant), variant])
11
+ );
12
+ const DETAILS_COMPONENT = defaultDirectiveVocabulary.details ? directiveComponentName(defaultDirectiveVocabulary.details) : "Details";
13
+ const TAB_GROUP_COMPONENTS = ["Tabs", "CodeGroup"];
14
+ const TAB_ITEM_COMPONENT = "TabItem";
15
+ const NAV_COMPONENTS = [
16
+ "CategoryNav",
17
+ "CategoryTreeNav",
18
+ "SiteTreeNav",
19
+ "SiteTreeNavDemo",
20
+ "DocCardNav",
21
+ "NoteTrayIndex"
22
+ ];
23
+ export {
24
+ ADMONITION_COMPONENTS,
25
+ ADMONITION_VARIANTS,
26
+ DETAILS_COMPONENT,
27
+ NAV_COMPONENTS,
28
+ TAB_GROUP_COMPONENTS,
29
+ TAB_ITEM_COMPONENT,
30
+ admonitionComponentName,
31
+ directiveComponentName
32
+ };
@@ -0,0 +1,27 @@
1
+ import type { MdDocFrontmatter } from "../../../md-utils/index.js";
2
+ import type { CategoryMeta } from "../../../sidebar-tree/types.js";
3
+ import type { AgentComponentRenderer } from "./normalize.js";
4
+ /** One locale's docs as the export sees them, before export exclusions. */
5
+ export interface AgentNavLocale {
6
+ locale: string;
7
+ /** Every parsed file of the locale: `slug` is the filesystem route slug. */
8
+ entries: Array<{
9
+ slug: string;
10
+ data: MdDocFrontmatter;
11
+ }>;
12
+ categoryMeta?: Map<string, CategoryMeta>;
13
+ /** Effective route slug → published page URL, for documents in the export only. */
14
+ published: Map<string, {
15
+ url: string;
16
+ title: string;
17
+ description?: string;
18
+ }>;
19
+ siteTreeNavIgnore?: readonly string[];
20
+ }
21
+ /**
22
+ * Build the per-locale renderer for content wrappers and navigation tags. Nav
23
+ * output lists only documents in the published export, so draft, unlisted and
24
+ * search-excluded pages never appear; a group whose own page is excluded is
25
+ * dissolved and its published descendants move up a level.
26
+ */
27
+ export declare function createAgentComponentRenderer(source: AgentNavLocale): (currentSlug: string) => AgentComponentRenderer;
@@ -0,0 +1,125 @@
1
+ import { isCanonicalDocSlug } from "../../../doc-card-nav/slug.js";
2
+ import {
3
+ ADMONITION_COMPONENTS,
4
+ admonitionComponentName,
5
+ DETAILS_COMPONENT,
6
+ TAB_GROUP_COMPONENTS,
7
+ TAB_ITEM_COMPONENT
8
+ } from "../../../mdx-components/vocabulary.js";
9
+ import { findContainingNoteTray, findNoteTray, getNoteTrayItems } from "../../../note-tray-model/index.js";
10
+ import { buildSidebarTree, findSidebarNode } from "../../../sidebar-tree/build-tree.js";
11
+ const isoDate = (value) => value instanceof Date ? value.toISOString().slice(0, 10) : value;
12
+ const linkLabel = (label) => label.replace(/[\\[\]]/g, (ch) => `\\${ch}`);
13
+ function line(node, depth, withDescription, suffix = "") {
14
+ const label = node.url === void 0 ? node.label : `[${linkLabel(node.label)}](${node.url})`;
15
+ const description = withDescription && node.description ? `: ${node.description}` : "";
16
+ return `${" ".repeat(depth)}- ${label}${suffix}${description}`;
17
+ }
18
+ function nestedList(nodes, withDescription, depth = 0) {
19
+ return nodes.flatMap((node) => [line(node, depth, withDescription), ...nestedList(node.children, withDescription, depth + 1)]);
20
+ }
21
+ const asString = (value) => typeof value === "string" ? value : void 0;
22
+ function wrapperLabel(kind, title, props) {
23
+ if (props === void 0 || title !== void 0 && typeof title !== "string") return { text: `**${kind}**`, unsupported: true };
24
+ return { text: title ? `**${kind}: ${title}**` : `**${kind}**` };
25
+ }
26
+ function createAgentComponentRenderer(source) {
27
+ const entries = source.entries.map(({ slug, data }) => ({
28
+ slug,
29
+ data: { ...data, date: isoDate(data.date), updated: isoDate(data.updated) }
30
+ }));
31
+ const hidden = new Set(entries.filter(({ data }) => data.search_exclude).map(({ slug, data }) => data.slug ?? slug));
32
+ const tree = buildSidebarTree(entries, source.locale, {
33
+ ...source.categoryMeta ? { categoryMeta: source.categoryMeta } : {},
34
+ buildHref: (slug) => slug,
35
+ isNavVisible: ({ data }) => !data.draft && !data.unlisted && !data.standalone
36
+ });
37
+ const publish = (nodes) => nodes.flatMap((node) => {
38
+ const children = publish(node.children);
39
+ const page = source.published.get(node.id);
40
+ if (!page && (hidden.has(node.id) || children.length === 0)) return children;
41
+ return [{
42
+ slug: node.id,
43
+ label: node.label,
44
+ ...node.description !== void 0 ? { description: node.description } : {},
45
+ ...page ? { url: page.url } : {},
46
+ ...node.date !== void 0 ? { date: node.date } : {},
47
+ ...node.shape !== void 0 ? { shape: node.shape } : {},
48
+ hasPage: page !== void 0,
49
+ children
50
+ }];
51
+ });
52
+ const published = publish(tree);
53
+ const findPublished = (nodes, slug) => {
54
+ for (const node of nodes) {
55
+ if (node.slug === slug) return node;
56
+ const found = findPublished(node.children, slug);
57
+ if (found) return found;
58
+ }
59
+ return void 0;
60
+ };
61
+ const firstUrl = (node) => node.url ?? node.children.map(firstUrl).find((url) => url !== void 0);
62
+ const list = (lines) => lines.join("\n");
63
+ const nav = (name, props, currentSlug) => {
64
+ switch (name) {
65
+ case "CategoryNav": {
66
+ if (props.categories !== void 0) {
67
+ if (!Array.isArray(props.categories) || !props.categories.every((slug) => typeof slug === "string")) return void 0;
68
+ return list(props.categories.flatMap((slug) => {
69
+ const node = findSidebarNode(tree, slug);
70
+ const target = findPublished(published, slug);
71
+ const url = target && firstUrl(target);
72
+ if (!node || hidden.has(slug) || url === void 0) return [];
73
+ return [line({ label: node.label, url, ...node.description !== void 0 ? { description: node.description } : {} }, 0, true)];
74
+ }));
75
+ }
76
+ if (props.category === void 0) return "";
77
+ const category = asString(props.category);
78
+ if (category === void 0) return void 0;
79
+ return list((findPublished(published, category)?.children ?? []).filter((node) => node.hasPage).map((node) => line(node, 0, true)));
80
+ }
81
+ case "CategoryTreeNav": {
82
+ const category = asString(props.category);
83
+ if (category === void 0) return void 0;
84
+ return list(nestedList(findPublished(published, category)?.children ?? [], false));
85
+ }
86
+ case "SiteTreeNav":
87
+ case "SiteTreeNavDemo": {
88
+ if (props.variant !== void 0 && props.variant !== "default" && props.variant !== "described") return void 0;
89
+ const ignore = new Set(source.siteTreeNavIgnore ?? []);
90
+ return list(nestedList(published.filter((node) => !ignore.has(node.slug)), props.variant === "described"));
91
+ }
92
+ case "NoteTrayIndex": {
93
+ if (props.category !== void 0 && typeof props.category !== "string") return void 0;
94
+ const tray = typeof props.category === "string" ? findNoteTray(published, props.category) : findContainingNoteTray(published, currentSlug);
95
+ if (!tray) return "";
96
+ return list(getNoteTrayItems(tray).filter((item) => item.url !== void 0).map((item) => line(item, 0, true, props.showDate === true && item.date ? ` (${item.date})` : "")));
97
+ }
98
+ case "DocCardNav": {
99
+ if (!Array.isArray(props.docs)) return void 0;
100
+ const seen = /* @__PURE__ */ new Set();
101
+ return list(props.docs.flatMap((slug) => {
102
+ if (!isCanonicalDocSlug(slug) || seen.has(slug)) return [];
103
+ seen.add(slug);
104
+ const page = source.published.get(slug);
105
+ return page ? [line({ label: page.title, url: page.url, ...page.description ? { description: page.description } : {} }, 0, true)] : [];
106
+ }));
107
+ }
108
+ default:
109
+ return void 0;
110
+ }
111
+ };
112
+ return (currentSlug) => (tag) => {
113
+ const variant = ADMONITION_COMPONENTS.get(tag.name);
114
+ if (variant) return wrapperLabel(admonitionComponentName(variant), tag.props?.title, tag.props);
115
+ if (tag.name === DETAILS_COMPONENT) return wrapperLabel(DETAILS_COMPONENT, tag.props?.title, tag.props);
116
+ if (tag.name === TAB_ITEM_COMPONENT) return wrapperLabel("Tab", tag.props?.label, tag.props);
117
+ if (TAB_GROUP_COMPONENTS.includes(tag.name)) return { text: "" };
118
+ if (!tag.props) return void 0;
119
+ const text = nav(tag.name, tag.props, currentSlug);
120
+ return text === void 0 ? void 0 : { text };
121
+ };
122
+ }
123
+ export {
124
+ createAgentComponentRenderer
125
+ };
@@ -3,6 +3,8 @@ export interface AgentExportOptions {
3
3
  outDir?: string;
4
4
  base: string;
5
5
  siteUrl?: string;
6
+ /** Append `/` to page URLs, matching the route layer's `trailingSlash` setting. Omitted means `false`. */
7
+ trailingSlash?: boolean;
6
8
  siteName: string;
7
9
  defaultLocale: string;
8
10
  defaultLocaleDir: string;
@@ -10,6 +12,8 @@ export interface AgentExportOptions {
10
12
  code: string;
11
13
  dir: string;
12
14
  }>;
15
+ /** Top-level category slugs left out of `<SiteTreeNav />` link lists, as in the rendered page. */
16
+ siteTreeNavIgnore?: string[];
13
17
  }
14
18
  export declare function projectAgentCorpus(options: AgentExportOptions): {
15
19
  manifest: AgentManifest;
@@ -5,7 +5,9 @@ import { fileURLToPath, pathToFileURL } from "node:url";
5
5
  import { agentItemKey, agentPageKey } from "../../../agent-docs/identity.js";
6
6
  import { AGENT_MAX_ITEMS, AGENT_MAX_MANIFEST_BYTES, AGENT_MAX_SEARCH_INDEX_BYTES } from "../../../agent-docs/limits.js";
7
7
  import { collectMdFiles, isExcluded, parseMarkdownFile, slugToUrl, stripMarkdown } from "../../../md-utils/index.js";
8
+ import { loadCategoryMeta } from "../../../sidebar-tree/category-meta.js";
8
9
  import { chunkAgentText } from "./chunk.js";
10
+ import { createAgentComponentRenderer } from "./components.js";
9
11
  import { normalizeAgentMarkdown } from "./normalize.js";
10
12
  const hash = (value) => createHash("sha256").update(value).digest("hex");
11
13
  const json = (value) => JSON.stringify(value);
@@ -25,19 +27,38 @@ function artifactUrl(options, path) {
25
27
  function projectAgentCorpus(options) {
26
28
  const roots = [{ code: options.defaultLocale, dir: options.defaultLocaleDir, default: true }, ...(options.locales ?? []).map(({ code, dir }) => ({ code, dir, default: false }))];
27
29
  const seen = /* @__PURE__ */ new Set();
28
- const sources = roots.flatMap((root) => collectMdFiles(resolve(root.dir)).flatMap(({ filePath, slug: fileSlug }) => {
29
- const parsed = parseMarkdownFile(filePath);
30
- if (!parsed || isExcluded(parsed.data)) return [];
30
+ const parsedRoots = roots.map((root) => ({
31
+ root,
32
+ files: collectMdFiles(resolve(root.dir)).flatMap(({ filePath, slug: fileSlug }) => {
33
+ const parsed = parseMarkdownFile(filePath);
34
+ return parsed ? [{ filePath, fileSlug, parsed }] : [];
35
+ })
36
+ }));
37
+ const sources = parsedRoots.flatMap(({ root, files }) => files.flatMap(({ filePath, fileSlug, parsed }) => {
38
+ if (isExcluded(parsed.data)) return [];
31
39
  const slug = parsed.data.slug ?? fileSlug;
32
- const url = slugToUrl(slug, root.default ? null : root.code, options.base, options.siteUrl);
33
- return [{ root, filePath, parsed, slug, url }];
40
+ const locale = root.default ? null : root.code;
41
+ const url = slugToUrl(slug, locale, options.base, options.siteUrl, options.trailingSlash === true);
42
+ const linkBase = slugToUrl(slug, locale, options.base, options.siteUrl);
43
+ return [{ root, filePath, parsed, slug, url, linkBase }];
34
44
  }));
45
+ const renderers = new Map(parsedRoots.map(({ root, files }) => [root.code, createAgentComponentRenderer({
46
+ locale: root.code,
47
+ entries: files.map(({ fileSlug, parsed }) => ({ slug: fileSlug, data: parsed.data })),
48
+ categoryMeta: loadCategoryMeta(resolve(root.dir)),
49
+ published: new Map(sources.filter((source) => source.root === root).map(({ slug, url, parsed }) => [slug, {
50
+ url,
51
+ title: parsed.data.title ?? slug,
52
+ ...typeof parsed.data.description === "string" ? { description: parsed.data.description } : {}
53
+ }])),
54
+ ...options.siteTreeNavIgnore ? { siteTreeNavIgnore: options.siteTreeNavIgnore } : {}
55
+ })]));
35
56
  const sourceUrls = new Map(sources.map((source) => [source.filePath, source.url]));
36
- const documents = sources.map(({ root, filePath, parsed, slug, url }) => {
57
+ const documents = sources.map(({ root, filePath, parsed, slug, url, linkBase }) => {
37
58
  const id = agentPageKey(root.code, slug);
38
59
  if (seen.has(id)) throw new Error(`Duplicate agent page ID: ${id}`);
39
60
  seen.add(id);
40
- const normalized = normalizeAgentMarkdown(parsed.content, url, (target) => {
61
+ const normalized = normalizeAgentMarkdown(parsed.content, linkBase, (target) => {
41
62
  try {
42
63
  const source = new URL(target, pathToFileURL(filePath));
43
64
  if (!/\.mdx?$/.test(source.pathname)) return void 0;
@@ -46,7 +67,7 @@ function projectAgentCorpus(options) {
46
67
  } catch {
47
68
  return void 0;
48
69
  }
49
- });
70
+ }, renderers.get(root.code)(slug));
50
71
  const title = parsed.data.title ?? slug;
51
72
  const description = parsed.data.description ?? stripMarkdown(parsed.content).split("\n").find(Boolean) ?? "";
52
73
  const metadata = {
@@ -1,5 +1,22 @@
1
+ /** Literal JSX attribute values; `true` stands for a bare boolean attribute. */
2
+ export type AgentTagProps = Record<string, string | number | boolean | null | unknown[] | Record<string, unknown>>;
3
+ export interface AgentComponentTag {
4
+ name: string;
5
+ /** Undefined when any attribute is a non-literal expression or a spread. */
6
+ props: AgentTagProps | undefined;
7
+ selfClosing: boolean;
8
+ }
9
+ /**
10
+ * Text that replaces a capitalised JSX opening tag, or undefined to keep the
11
+ * named placeholder. `unsupported` flags the page even when text is returned.
12
+ */
13
+ export type AgentComponentRenderer = (tag: AgentComponentTag) => {
14
+ text: string;
15
+ unsupported?: boolean;
16
+ } | undefined;
17
+ export declare function dynamicContentPlaceholder(name: string): string;
1
18
  /** Normalize MDX for a published text corpus without evaluating its modules. */
2
- export declare function normalizeAgentMarkdown(source: string, pageUrl: string, resolveSourceLink?: (target: string) => string | undefined): {
19
+ export declare function normalizeAgentMarkdown(source: string, pageUrl: string, resolveSourceLink?: (target: string) => string | undefined, renderComponent?: AgentComponentRenderer): {
3
20
  text: string;
4
21
  unsupportedDynamicContent: boolean;
5
22
  };