@takazudo/zudo-doc 11.0.0 → 12.0.0

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 +19 -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
@@ -1,4 +1,92 @@
1
- function normalizeAgentMarkdown(source, pageUrl, resolveSourceLink) {
1
+ function dynamicContentPlaceholder(name) {
2
+ return `[Dynamic content unavailable in text export: ${name}]`;
3
+ }
4
+ function skipBraces(text, start) {
5
+ let depth = 0;
6
+ for (let i = start; i < text.length; i++) {
7
+ const ch = text[i];
8
+ if (ch === '"' || ch === "'" || ch === "`") {
9
+ for (i++; i < text.length && text[i] !== ch; i++) if (text[i] === "\\") i++;
10
+ } else if (ch === "{") depth++;
11
+ else if (ch === "}" && --depth === 0) return i + 1;
12
+ }
13
+ return -1;
14
+ }
15
+ function literalExpression(expression) {
16
+ const trimmed = expression.trim();
17
+ const template = trimmed.match(/^`([^`$\\]*)`$/);
18
+ if (template) return { value: template[1] };
19
+ try {
20
+ return { value: JSON.parse(trimmed.replace(/,(\s*[\]}])/g, "$1")) };
21
+ } catch {
22
+ return void 0;
23
+ }
24
+ }
25
+ function parseOpeningTag(text, start) {
26
+ const name = text.slice(start + 1).match(/^[A-Z][\w.]*/)?.[0];
27
+ if (!name) return void 0;
28
+ let i = start + 1 + name.length;
29
+ if (i < text.length && !/[\s/>]/.test(text[i])) return void 0;
30
+ let props = {};
31
+ while (i < text.length) {
32
+ while (/\s/.test(text[i] ?? "")) i++;
33
+ if (text[i] === ">") return { name, props, selfClosing: false, end: i + 1 };
34
+ if (text.startsWith("/>", i)) return { name, props, selfClosing: true, end: i + 2 };
35
+ if (text[i] === "{") {
36
+ const end = skipBraces(text, i);
37
+ if (end < 0) return void 0;
38
+ props = void 0;
39
+ i = end;
40
+ continue;
41
+ }
42
+ const attr = text.slice(i).match(/^[A-Za-z_:][\w:.-]*/)?.[0];
43
+ if (!attr) return void 0;
44
+ i += attr.length;
45
+ while (/[ \t]/.test(text[i] ?? "")) i++;
46
+ if (text[i] !== "=") {
47
+ if (props) props[attr] = true;
48
+ continue;
49
+ }
50
+ i++;
51
+ while (/\s/.test(text[i] ?? "")) i++;
52
+ const quote = text[i];
53
+ if (quote === '"' || quote === "'") {
54
+ const end = text.indexOf(quote, i + 1);
55
+ if (end < 0) return void 0;
56
+ if (props) props[attr] = text.slice(i + 1, end);
57
+ i = end + 1;
58
+ } else if (quote === "{") {
59
+ const end = skipBraces(text, i);
60
+ if (end < 0) return void 0;
61
+ const literal = literalExpression(text.slice(i + 1, end - 1));
62
+ if (!literal) props = void 0;
63
+ else if (props) props[attr] = literal.value;
64
+ i = end;
65
+ } else return void 0;
66
+ }
67
+ return void 0;
68
+ }
69
+ function replaceComponentTags(text, render) {
70
+ let unsupported = false;
71
+ let out = "";
72
+ let offset = 0;
73
+ for (let i = text.indexOf("<"); i >= 0; i = text.indexOf("<", i + 1)) {
74
+ if (i < offset || !/[A-Z]/.test(text[i + 1] ?? "")) continue;
75
+ let tag = parseOpeningTag(text, i);
76
+ if (!tag) {
77
+ const loose = text.slice(i).match(/^<([A-Z][\w.]*)\b[^>]*>/);
78
+ if (!loose) continue;
79
+ tag = { name: loose[1], props: void 0, selfClosing: loose[0].endsWith("/>"), end: i + loose[0].length };
80
+ }
81
+ const rendered = render?.(tag);
82
+ if (!rendered || rendered.unsupported) unsupported = true;
83
+ const gap = rendered?.text && /\S/.test(text[tag.end] ?? "") ? "\n\n" : "";
84
+ out += text.slice(offset, i) + (rendered ? rendered.text + gap : dynamicContentPlaceholder(tag.name));
85
+ offset = tag.end;
86
+ }
87
+ return { text: out + text.slice(offset), unsupported };
88
+ }
89
+ function normalizeAgentMarkdown(source, pageUrl, resolveSourceLink, renderComponent) {
2
90
  let unsupportedDynamicContent = false;
3
91
  const literals = [];
4
92
  let marker = "\0agent-code:";
@@ -59,15 +147,13 @@ function normalizeAgentMarkdown(source, pageUrl, resolveSourceLink) {
59
147
  /^( {0,3}\[[^\]]+\]:[ \t]*)(?:<([^>]+)>|([^\s]+))/gm,
60
148
  (_all, before, angled, plain) => shield(before + (angled !== void 0 ? `<${resolveLink(angled)}>` : resolveLink(plain)))
61
149
  );
62
- text = text.replace(/<([A-Z][\w.]*)\b[^>]*>/g, () => {
63
- unsupportedDynamicContent = true;
64
- return "[Dynamic content unavailable in text export]";
65
- });
150
+ ({ text, unsupported: unsupportedDynamicContent } = replaceComponentTags(text, renderComponent));
66
151
  text = text.replace(/<\/([A-Z][\w.]*)\s*>/g, "");
67
152
  text = text.replace(/<\/?[a-z][\w-]*(?=[\s/>])[^>]*>/g, "");
68
153
  for (let i = literals.length - 1; i >= 0; i--) text = text.replaceAll(`${marker}${i}\0`, () => literals[i]);
69
154
  return { text: text.trim(), unsupportedDynamicContent };
70
155
  }
71
156
  export {
157
+ dynamicContentPlaceholder,
72
158
  normalizeAgentMarkdown
73
159
  };
@@ -19,6 +19,8 @@ export interface LlmsTxtDevMiddlewareOptions extends LlmsTxtSiteMeta {
19
19
  base: string;
20
20
  /** Optional absolute site URL; see `LlmsTxtLoadOptions.siteUrl`. */
21
21
  siteUrl?: string;
22
+ /** Append `/` to page URLs, matching the route layer's `trailingSlash` setting. Omitted means `false`. */
23
+ trailingSlash?: boolean;
22
24
  /** Actual default locale code; needed to match agent-export page IDs. */
23
25
  defaultLocale?: string;
24
26
  /** Link slim-index docs to agent-export Markdown artifacts when enabled. */
@@ -47,6 +47,7 @@ function createLlmsTxtDevMiddleware(options, logger) {
47
47
  locale: match.locale,
48
48
  base,
49
49
  siteUrl,
50
+ trailingSlash: options.trailingSlash === true,
50
51
  ...options.agentExport === true ? { agentExportLocale: match.locale ?? options.defaultLocale ?? "en" } : {}
51
52
  });
52
53
  const assets = loadLlmsAssetEntries({
@@ -14,6 +14,7 @@ function emitLlmsTxt(options) {
14
14
  outDir,
15
15
  base,
16
16
  siteUrl,
17
+ trailingSlash,
17
18
  siteName,
18
19
  siteDescription,
19
20
  defaultLocaleDir,
@@ -40,6 +41,7 @@ function emitLlmsTxt(options) {
40
41
  locale: null,
41
42
  base,
42
43
  siteUrl,
44
+ trailingSlash: trailingSlash === true,
43
45
  ...agentExport === true ? { agentExportLocale: defaultLocale ?? "en" } : {}
44
46
  });
45
47
  mkdirSync(outDir, { recursive: true });
@@ -68,6 +70,7 @@ function emitLlmsTxt(options) {
68
70
  locale: code,
69
71
  base,
70
72
  siteUrl,
73
+ trailingSlash: trailingSlash === true,
71
74
  ...agentExport === true ? { agentExportLocale: code } : {}
72
75
  });
73
76
  const localeDir = join(outDir, code);
@@ -20,7 +20,7 @@ import {
20
20
  slugToUrl as slugToUrl2
21
21
  } from "../../../md-utils/index.js";
22
22
  function loadDocEntries(options) {
23
- const { contentDir, locale, base, siteUrl, agentExportLocale } = options;
23
+ const { contentDir, locale, base, siteUrl, trailingSlash, agentExportLocale } = options;
24
24
  const absDir = resolve(contentDir);
25
25
  const files = collectMdFiles(absDir);
26
26
  const entries = [];
@@ -38,7 +38,7 @@ function loadDocEntries(options) {
38
38
  const entry = {
39
39
  title: data.title ?? slug,
40
40
  description,
41
- url: slugToUrl(slug, locale, base, siteUrl),
41
+ url: slugToUrl(slug, locale, base, siteUrl, trailingSlash === true),
42
42
  content: stripImportsAndJsx(content),
43
43
  sidebarPosition: data.sidebar_position
44
44
  };
@@ -103,6 +103,8 @@ export interface LlmsTxtLoadOptions {
103
103
  * empty, URLs are returned path-only for projects that omit `siteUrl`.
104
104
  */
105
105
  siteUrl?: string;
106
+ /** Append `/` to page URLs, matching the route layer's `trailingSlash` setting. Omitted means `false`. */
107
+ trailingSlash?: boolean;
106
108
  /** Actual locale code used by the agent export page identity, including for the default locale. */
107
109
  agentExportLocale?: string;
108
110
  }
@@ -117,6 +119,8 @@ export interface LlmsTxtEmitOptions extends LlmsTxtSiteMeta {
117
119
  base: string;
118
120
  /** Optional absolute site URL; see {@link LlmsTxtLoadOptions}. */
119
121
  siteUrl?: string;
122
+ /** Append `/` to page URLs, matching the route layer's `trailingSlash` setting. Omitted means `false`. */
123
+ trailingSlash?: boolean;
120
124
  /** Actual default locale code; needed to match agent-export page IDs. */
121
125
  defaultLocale?: string;
122
126
  /** Link slim-index docs to agent-export Markdown artifacts when enabled. */
@@ -36,7 +36,7 @@ function readAssetExcerpt(filePath, maxBodyLength) {
36
36
  closeSync(fd);
37
37
  }
38
38
  }
39
- function buildEntries(contentDir, locale, base, maxBodyLength) {
39
+ function buildEntries(contentDir, locale, base, maxBodyLength, trailingSlash) {
40
40
  const absDir = resolve(contentDir);
41
41
  const files = collectMdFiles(absDir);
42
42
  const entries = [];
@@ -51,7 +51,7 @@ function buildEntries(contentDir, locale, base, maxBodyLength) {
51
51
  id,
52
52
  title: data.title ?? slug,
53
53
  body: truncateBody(stripMarkdown(content), maxBodyLength),
54
- url: slugToUrl(slug, locale, base),
54
+ url: slugToUrl(slug, locale, base, void 0, trailingSlash),
55
55
  description: data.description ?? ""
56
56
  });
57
57
  }
@@ -82,11 +82,12 @@ function collectSearchEntries(config) {
82
82
  assertValidSearchMaxBodyLength(config.maxBodyLength);
83
83
  const maxBodyLength = config.maxBodyLength ?? MAX_BODY_LENGTH;
84
84
  const base = config.base ?? "";
85
+ const trailingSlash = config.trailingSlash === true;
85
86
  const entries = [];
86
- entries.push(...buildEntries(config.docsDir, null, base, maxBodyLength));
87
+ entries.push(...buildEntries(config.docsDir, null, base, maxBodyLength, trailingSlash));
87
88
  if (config.locales) {
88
89
  for (const [code, locale] of Object.entries(config.locales)) {
89
- entries.push(...buildEntries(locale.dir, code, base, maxBodyLength));
90
+ entries.push(...buildEntries(locale.dir, code, base, maxBodyLength, trailingSlash));
90
91
  }
91
92
  }
92
93
  entries.push(...buildAssetEntries(config, maxBodyLength));
@@ -36,6 +36,8 @@ export interface SearchIndexConfig {
36
36
  locales?: Record<string, SearchIndexLocaleConfig>;
37
37
  /** Site base path (e.g. `""`, `"/docs"`); trailing slash is normalised away. */
38
38
  base?: string;
39
+ /** Append `/` to page URLs, matching the route layer's `trailingSlash` setting. Omitted means `false`. */
40
+ trailingSlash?: boolean;
39
41
  /** Runtime project root for asset scans; injected by the zfb plugin wrapper, never serialized in the preset. */
40
42
  projectRoot?: string;
41
43
  /** Shared asset-viewer projection; consumed by the asset indexing wave. */
package/dist/preset.d.ts CHANGED
@@ -131,6 +131,8 @@ export interface PresetSettings {
131
131
  agentExport?: boolean;
132
132
  /** Enable the stateless read-only MCP endpoint; requires `agentExport: true`. */
133
133
  mcp?: boolean;
134
+ /** Top-level categories left out of `<SiteTreeNav />`; the agent export mirrors it. */
135
+ siteTreeNavIgnore?: string[];
134
136
  changelogs?: PresetChangelogConfig[] | false;
135
137
  /** Metadata fields shown in the doc metadata area. */
136
138
  docMetainfoFields?: Array<"created" | "updated" | "author">;
package/dist/preset.js CHANGED
@@ -282,6 +282,7 @@ function buildPlugins(settings, routeContext) {
282
282
  docsDir: settings.docsDir,
283
283
  locales: localeRecord,
284
284
  base: settings.base,
285
+ trailingSlash: settings.trailingSlash,
285
286
  assetScan,
286
287
  maxBodyLength: settings.searchMaxBodyLength
287
288
  }
@@ -310,6 +311,7 @@ function buildPlugins(settings, routeContext) {
310
311
  siteDescription: settings.siteDescription,
311
312
  base: settings.base,
312
313
  siteUrl: settings.siteUrl,
314
+ trailingSlash: settings.trailingSlash,
313
315
  defaultLocale: settings.defaultLocale ?? "en",
314
316
  agentExport: settings.agentExport === true,
315
317
  mcp: settings.mcp === true,
@@ -325,9 +327,11 @@ function buildPlugins(settings, routeContext) {
325
327
  siteName: settings.siteName,
326
328
  siteUrl: settings.siteUrl,
327
329
  base: settings.base,
330
+ trailingSlash: settings.trailingSlash,
328
331
  defaultLocale: settings.defaultLocale ?? "en",
329
332
  defaultLocaleDir: settings.docsDir,
330
- locales: localeArray
333
+ locales: localeArray,
334
+ siteTreeNavIgnore: settings.siteTreeNavIgnore ?? []
331
335
  }
332
336
  }] : [],
333
337
  ...Array.isArray(settings.changelogs) && settings.changelogs.length > 0 ? [
@@ -23,6 +23,44 @@ export interface TagInfoForEnum {
23
23
  tag: string;
24
24
  count: number;
25
25
  }
26
+ /**
27
+ * Minimal doc-history manifest entry read by {@link RouteEnumeratorsAPI.enumerateSitemapEntries}
28
+ * — a structural subset of `.zfb/doc-history-meta.json` values.
29
+ */
30
+ export interface DocHistoryDateEntry {
31
+ /** ISO date or git `%aI` timestamp of the page's most recent commit. */
32
+ updatedDate?: string;
33
+ }
34
+ /** Doc-history manifest keyed like the visible Created/Updated block. */
35
+ export type DocHistoryDateManifest = Readonly<Record<string, unknown>>;
36
+ /** Options for {@link RouteEnumeratorsAPI.enumerateSitemapEntries}. */
37
+ export interface SitemapEntriesOptions {
38
+ /**
39
+ * The build's doc-history manifest. Absent, `null`, or `{}` means no page
40
+ * has a known date, so every entry omits `lastmod`.
41
+ */
42
+ docHistoryMeta?: DocHistoryDateManifest | null;
43
+ }
44
+ /**
45
+ * One locale variant of a page, for `hreflang` alternates. `url` is the
46
+ * base-prefixed path (callers make it absolute with `siteUrl`). `hreflang` is
47
+ * the locale code (the same value as the page's `<html lang>`) or `x-default`.
48
+ */
49
+ export interface LocaleAlternate {
50
+ hreflang: string;
51
+ url: string;
52
+ }
53
+ /** One sitemap URL with its last-modified date, when one is known. */
54
+ export interface SitemapEntry {
55
+ url: string;
56
+ /** `YYYY-MM-DD` (UTC), or absent when the page has no known date. */
57
+ lastmod?: string;
58
+ /**
59
+ * Locale variants of this page, including itself and `x-default`. Present
60
+ * only for pages that exist as real content in more than one locale.
61
+ */
62
+ alternates?: LocaleAlternate[];
63
+ }
26
64
  /**
27
65
  * Context slice `createRouteEnumerators` derives its bag from (epic Collapse
28
66
  * Wiring Shells #2420, FACTORIES #2424 — breaking signature). STRUCTURAL SUBSET
@@ -103,12 +141,35 @@ export interface RouteEnumeratorsAPI {
103
141
  */
104
142
  enumerateVersionedRoutes: (version: VersionConfigForEnum, locale: string) => string[];
105
143
  /**
106
- * Compose all route enumerators into a deduped Map<url, lastmod>.
144
+ * Compose all route enumerators into a deduped Map<url, buildDate>.
107
145
  *
108
146
  * Covers site root, default-locale docs + tags, per-locale docs + tags,
109
- * asset-viewer routes, versioned EN docs, and versioned locale docs.
147
+ * asset-viewer routes, versioned EN docs, and versioned locale docs. Every
148
+ * value is the current build date; the sitemap uses
149
+ * {@link RouteEnumeratorsAPI.enumerateSitemapEntries} instead.
110
150
  */
111
151
  enumerateAllRoutes: () => Map<string, string>;
152
+ /**
153
+ * The same deduped route set as `enumerateAllRoutes()`, in the same order,
154
+ * with each latest (unversioned) doc page's `lastmod` taken from the
155
+ * doc-history manifest — the date the page's visible "Updated" label shows.
156
+ * Routes with no known date (site roots, tags, assets, versioned pages,
157
+ * pages missing from the manifest) carry no `lastmod`.
158
+ */
159
+ enumerateSitemapEntries: (options?: SitemapEntriesOptions) => SitemapEntry[];
160
+ /**
161
+ * `hreflang` alternates for a latest (unversioned) doc page. Non-empty only
162
+ * when the page in `locale` is real content (its own locale file, not an
163
+ * EN fallback or auto-index) and at least one other locale also has real
164
+ * content at the same slug. Lists every such locale, then `x-default` (the
165
+ * default locale's URL) when the default locale is one of them.
166
+ */
167
+ getDocLocaleAlternates: (slug: string, locale: string) => LocaleAlternate[];
168
+ /**
169
+ * `hreflang` alternates for the home pages: every configured locale's home,
170
+ * then `x-default`. Empty for single-locale sites.
171
+ */
172
+ getHomeLocaleAlternates: () => LocaleAlternate[];
112
173
  }
113
174
  /**
114
175
  * Create the route-enumeration functions bound to the host's injected context.
@@ -1,5 +1,13 @@
1
1
  import { assetViewerHref } from "../asset-path/index.js";
2
2
  import { mergeLocaleDocs } from "../locale-merge/index.js";
3
+ import { toHistorySlug } from "../slug/index.js";
4
+ function toSitemapDate(value) {
5
+ if (typeof value !== "string") return void 0;
6
+ if (/^\d{4}-\d{2}-\d{2}$/.test(value)) return value;
7
+ if (!/^\d{4}-\d{2}-\d{2}T/.test(value)) return void 0;
8
+ const time = new Date(value).getTime();
9
+ return Number.isNaN(time) ? void 0 : new Date(time).toISOString().slice(0, 10);
10
+ }
3
11
  function createRouteEnumerators(ctx) {
4
12
  const defaultLocale = ctx.defaultLocale;
5
13
  const getLocaleKeys = () => Object.keys(ctx.settings.locales);
@@ -17,22 +25,92 @@ function createRouteEnumerators(ctx) {
17
25
  const collectAutoIndexNodes = ctx.collectAutoIndexNodes;
18
26
  const resolveNavSource = ctx.resolveNavSource;
19
27
  const resolveVersionedLocaleSource = ctx.resolveVersionedLocaleSource;
20
- function enumerateDocsRoutes(locale) {
21
- const urls = [];
22
- const { docs: allDocs, navDocs, categoryMeta } = resolveNavSource(
28
+ function enumerateKeyedDocsRoutes(locale) {
29
+ const entries = [];
30
+ const seen = /* @__PURE__ */ new Set();
31
+ const isDefault = locale === defaultLocale;
32
+ const { docs: allDocs, navDocs, categoryMeta, localeSlugSet } = resolveNavSource(
23
33
  locale,
24
34
  void 0,
25
35
  { applyDefaultLocaleOnlyFilter: true, keepUnlisted: true }
26
36
  );
27
37
  const tree = buildNavTree(navDocs, locale, categoryMeta);
38
+ function push(slug, isFallback, autoIndex) {
39
+ const url = docsUrl(slug, locale);
40
+ if (seen.has(url)) return;
41
+ seen.add(url);
42
+ const historySlug = toHistorySlug(slug);
43
+ entries.push({
44
+ url,
45
+ historyKey: isDefault || isFallback ? historySlug : `${locale}/${historySlug}`,
46
+ slug,
47
+ autoIndex
48
+ });
49
+ }
28
50
  for (const doc of allDocs) {
29
51
  if (doc.data.category_no_page === true) continue;
30
- urls.push(docsUrl(doc.data.slug ?? toRouteSlug(doc.slug), locale));
52
+ const slug = doc.data.slug ?? toRouteSlug(doc.slug);
53
+ push(slug, !isDefault && !localeSlugSet.has(slug), false);
31
54
  }
32
55
  for (const node of collectAutoIndexNodes(tree)) {
33
- urls.push(docsUrl(node.slug, locale));
56
+ push(node.slug, false, true);
34
57
  }
35
- return [...new Set(urls)];
58
+ return entries;
59
+ }
60
+ function enumerateDocsRoutes(locale) {
61
+ return enumerateKeyedDocsRoutes(locale).map((entry) => entry.url);
62
+ }
63
+ const realSlugCache = /* @__PURE__ */ new WeakMap();
64
+ function realContentSlugs(locale) {
65
+ const source = resolveNavSource(locale, void 0, {
66
+ applyDefaultLocaleOnlyFilter: true,
67
+ keepUnlisted: true
68
+ });
69
+ const cached = realSlugCache.get(source.docs);
70
+ if (cached) return cached;
71
+ const isDefault = locale === defaultLocale;
72
+ const slugs = /* @__PURE__ */ new Set();
73
+ for (const doc of source.docs) {
74
+ if (doc.data.category_no_page === true) continue;
75
+ const slug = doc.data.slug ?? toRouteSlug(doc.slug);
76
+ if (!isDefault) {
77
+ if (!source.localeSlugSet.has(slug)) continue;
78
+ if (isDefaultLocaleOnlyPath(`/docs/${slug}`)) continue;
79
+ }
80
+ slugs.add(slug);
81
+ }
82
+ realSlugCache.set(source.docs, slugs);
83
+ return slugs;
84
+ }
85
+ function getDocLocaleAlternates(slug, locale) {
86
+ const localeKeys = getLocaleKeys();
87
+ if (localeKeys.length === 0) return [];
88
+ if (!realContentSlugs(locale).has(slug)) return [];
89
+ const candidates = [defaultLocale, ...localeKeys.filter((code) => code !== defaultLocale)];
90
+ const alternates = [];
91
+ for (const code of candidates) {
92
+ if (realContentSlugs(code).has(slug)) {
93
+ alternates.push({ hreflang: code, url: docsUrl(slug, code) });
94
+ }
95
+ }
96
+ if (alternates.length < 2) return [];
97
+ if (alternates[0]?.hreflang === defaultLocale) {
98
+ alternates.push({ hreflang: "x-default", url: alternates[0].url });
99
+ }
100
+ return alternates;
101
+ }
102
+ function homeUrl(locale) {
103
+ return locale === defaultLocale ? withBase("/") : withBase(`/${locale}`);
104
+ }
105
+ function getHomeLocaleAlternates() {
106
+ const localeKeys = getLocaleKeys().filter((code) => code !== defaultLocale);
107
+ if (localeKeys.length === 0) return [];
108
+ const alternates = [
109
+ { hreflang: defaultLocale, url: homeUrl(defaultLocale) },
110
+ ...localeKeys.map((code) => ({ hreflang: code, url: homeUrl(code) }))
111
+ ];
112
+ alternates.push({ hreflang: "x-default", url: homeUrl(defaultLocale) });
113
+ return alternates;
36
114
  }
37
115
  function enumerateTagsRoutes(locale) {
38
116
  if (!getDocTags()) return [];
@@ -130,20 +208,27 @@ function createRouteEnumerators(ctx) {
130
208
  }
131
209
  return [...new Set(urls)];
132
210
  }
133
- function enumerateAllRoutes() {
134
- const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "";
135
- const routes = /* @__PURE__ */ new Map();
211
+ function collectAllRoutes() {
212
+ const seen = /* @__PURE__ */ new Set();
213
+ const routes = [];
136
214
  const localeKeys = getLocaleKeys();
137
215
  const versions = getVersions();
138
- function add(url) {
139
- if (!routes.has(url)) {
140
- routes.set(url, today);
141
- }
216
+ const homeAlternates = getHomeLocaleAlternates();
217
+ function add(url, historyKey, alternates) {
218
+ if (seen.has(url)) return;
219
+ seen.add(url);
220
+ const route = { url };
221
+ if (historyKey !== void 0) route.historyKey = historyKey;
222
+ if (alternates !== void 0 && alternates.length > 0) route.alternates = alternates;
223
+ routes.push(route);
142
224
  }
143
- add(withBase("/"));
144
- for (const url of enumerateDocsRoutes(defaultLocale)) {
145
- add(url);
225
+ function addDocs(locale) {
226
+ for (const { url, historyKey, slug, autoIndex } of enumerateKeyedDocsRoutes(locale)) {
227
+ add(url, historyKey, autoIndex ? void 0 : getDocLocaleAlternates(slug, locale));
228
+ }
146
229
  }
230
+ add(withBase("/"), void 0, homeAlternates);
231
+ addDocs(defaultLocale);
147
232
  for (const url of enumerateTagsRoutes(defaultLocale)) {
148
233
  add(url);
149
234
  }
@@ -151,10 +236,8 @@ function createRouteEnumerators(ctx) {
151
236
  add(url);
152
237
  }
153
238
  for (const locale of localeKeys) {
154
- add(withBase(`/${locale}`));
155
- for (const url of enumerateDocsRoutes(locale)) {
156
- add(url);
157
- }
239
+ add(withBase(`/${locale}`), void 0, homeAlternates);
240
+ addDocs(locale);
158
241
  for (const url of enumerateTagsRoutes(locale)) {
159
242
  add(url);
160
243
  }
@@ -182,12 +265,32 @@ function createRouteEnumerators(ctx) {
182
265
  }
183
266
  return routes;
184
267
  }
268
+ function enumerateAllRoutes() {
269
+ const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "";
270
+ return new Map(collectAllRoutes().map(({ url }) => [url, today]));
271
+ }
272
+ function enumerateSitemapEntries(options = {}) {
273
+ const meta = options.docHistoryMeta ?? {};
274
+ return collectAllRoutes().map(({ url, historyKey, alternates }) => {
275
+ const sitemapEntry = { url };
276
+ if (historyKey !== void 0 && Object.hasOwn(meta, historyKey)) {
277
+ const entry = meta[historyKey];
278
+ const lastmod = toSitemapDate(entry?.updatedDate);
279
+ if (lastmod !== void 0) sitemapEntry.lastmod = lastmod;
280
+ }
281
+ if (alternates !== void 0) sitemapEntry.alternates = alternates;
282
+ return sitemapEntry;
283
+ });
284
+ }
185
285
  return {
186
286
  enumerateDocsRoutes,
187
287
  enumerateTagsRoutes,
188
288
  enumerateAssetRoutes,
189
289
  enumerateVersionedRoutes,
190
- enumerateAllRoutes
290
+ enumerateAllRoutes,
291
+ enumerateSitemapEntries,
292
+ getDocLocaleAlternates,
293
+ getHomeLocaleAlternates
191
294
  };
192
295
  }
193
296
  export {
@@ -26,6 +26,6 @@ export declare const i18n: import("../index.js").FactoryI18n, defaultLocale: str
26
26
  };
27
27
  }>, slugFn: (entrySlug: string, data: {
28
28
  slug?: string;
29
- }) => string) => Map<string, import("./_context.js").TagInfo>, resolveNavSource: (lang: string, currentVersion: string | undefined, options?: import("../nav-source-docs/index.js").NavSourceOptions) => import("../nav-source-docs/index.js").NavSourceDocs, resolveVersionedLocaleSource: (versionSlug: string, versionDocsDir: string | undefined, lang: string, localeDir: string | undefined, options?: import("../nav-source-docs/index.js").NavSourceOptions) => import("../nav-source-docs/index.js").NavSourceDocs, loadNavSourceDocs: (lang: string, currentVersion: string | undefined) => import("../nav-source-docs/index.js").NavSourceDocs, buildDocRouteEntries: (args: import("../site-schema/doc-route-entries.js").BuildDocRouteEntriesArgs<import("../doc-page-props/index.js").DocPageEntry>) => import("../site-schema/doc-route-entries.js").DocRouteEntry<import("../doc-page-props/index.js").DocPageEntry>[], enumerateDocsRoutes: (locale: string) => string[], enumerateTagsRoutes: (locale: string) => string[], enumerateVersionedRoutes: (version: import("../route-enumerators/index.js").VersionConfigForEnum, locale: string) => string[], enumerateAllRoutes: () => Map<string, string>, buildNavTree: (docs: import("../doc-page-props/index.js").DocPageEntry[], locale: string, categoryMeta: Map<string, import("../sidebar-tree/types.js").CategoryMeta> | undefined, buildHref: import("../index.js").RouteHrefBuilder, options?: {
29
+ }) => string) => Map<string, import("./_context.js").TagInfo>, resolveNavSource: (lang: string, currentVersion: string | undefined, options?: import("../nav-source-docs/index.js").NavSourceOptions) => import("../nav-source-docs/index.js").NavSourceDocs, resolveVersionedLocaleSource: (versionSlug: string, versionDocsDir: string | undefined, lang: string, localeDir: string | undefined, options?: import("../nav-source-docs/index.js").NavSourceOptions) => import("../nav-source-docs/index.js").NavSourceDocs, loadNavSourceDocs: (lang: string, currentVersion: string | undefined) => import("../nav-source-docs/index.js").NavSourceDocs, buildDocRouteEntries: (args: import("../site-schema/doc-route-entries.js").BuildDocRouteEntriesArgs<import("../doc-page-props/index.js").DocPageEntry>) => import("../site-schema/doc-route-entries.js").DocRouteEntry<import("../doc-page-props/index.js").DocPageEntry>[], enumerateDocsRoutes: (locale: string) => string[], enumerateTagsRoutes: (locale: string) => string[], enumerateVersionedRoutes: (version: import("../route-enumerators/index.js").VersionConfigForEnum, locale: string) => string[], enumerateAllRoutes: () => Map<string, string>, enumerateSitemapEntries: (options?: import("../route-enumerators/index.js").SitemapEntriesOptions) => import("../route-enumerators/index.js").SitemapEntry[], getDocLocaleAlternates: (slug: string, locale: string) => import("../route-enumerators/index.js").LocaleAlternate[], getHomeLocaleAlternates: () => import("../route-enumerators/index.js").LocaleAlternate[], buildNavTree: (docs: import("../doc-page-props/index.js").DocPageEntry[], locale: string, categoryMeta: Map<string, import("../sidebar-tree/types.js").CategoryMeta> | undefined, buildHref: import("../index.js").RouteHrefBuilder, options?: {
30
30
  buildHref?: import("../index.js").RouteHrefBuilder;
31
31
  }) => import("./_chrome.js").DocNavNode[], groupSatelliteNodes: (tree: import("./_chrome.js").DocNavNode[], prefixes: string[]) => import("./_chrome.js").DocNavNode[], findNode: (nodes: import("./_chrome.js").DocNavNode[], slug: string) => import("./_chrome.js").DocNavNode | undefined, firstRoutedHref: (node: import("./_chrome.js").DocNavNode) => string | undefined, collectAutoIndexNodes: (nodes: import("./_chrome.js").DocNavNode[]) => import("./_chrome.js").DocNavNode[], isNavVisible: (doc: import("../doc-page-props/index.js").DocPageEntry) => boolean, stableDocs: (collectionName: string) => import("../doc-page-props/index.js").DocPageEntry[], toRouteSlug: (entrySlug: string) => string, toSlugParams: (routeSlug: string) => string[];
@@ -40,6 +40,9 @@ const {
40
40
  enumerateTagsRoutes,
41
41
  enumerateVersionedRoutes,
42
42
  enumerateAllRoutes,
43
+ enumerateSitemapEntries,
44
+ getDocLocaleAlternates,
45
+ getHomeLocaleAlternates,
43
46
  buildNavTree,
44
47
  groupSatelliteNodes,
45
48
  findNode,
@@ -64,12 +67,15 @@ export {
64
67
  docsUrl,
65
68
  enumerateAllRoutes,
66
69
  enumerateDocsRoutes,
70
+ enumerateSitemapEntries,
67
71
  enumerateTagsRoutes,
68
72
  enumerateVersionedRoutes,
69
73
  extractHeadings,
70
74
  findNode,
71
75
  firstRoutedHref,
72
76
  getCategoryOrder,
77
+ getDocLocaleAlternates,
78
+ getHomeLocaleAlternates,
73
79
  getLocaleConfig,
74
80
  getLocaleLabel,
75
81
  getNavSectionForSlug,
@@ -1,4 +1,5 @@
1
- import { settings, enumerateAllRoutes } from "./_context.js";
1
+ import { chromeBindings } from "virtual:zudo-doc-chrome-bindings";
2
+ import { settings, enumerateSitemapEntries } from "./_context.js";
2
3
  const frontmatter = { title: "Sitemap" };
3
4
  const contentType = "application/xml";
4
5
  function escapeXml(str) {
@@ -13,16 +14,25 @@ function Sitemap() {
13
14
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
14
15
  </urlset>`;
15
16
  }
16
- const routeMap = enumerateAllRoutes();
17
+ const entries = enumerateSitemapEntries({
18
+ docHistoryMeta: settings.docHistory ? chromeBindings.docHistoryMeta : void 0
19
+ });
17
20
  const siteUrlBase = (settings.siteUrl ?? "").replace(/\/$/, "");
18
- const urlEntries = [...routeMap.entries()].sort(([a], [b]) => a.localeCompare(b)).map(
19
- ([url, lastmod]) => ` <url>
20
- <loc>${escapeXml(siteUrlBase + url)}</loc>
21
- <lastmod>${lastmod}</lastmod>
22
- </url>`
23
- ).join("\n");
21
+ const withAlternates = siteUrlBase !== "" && entries.some((e) => e.alternates);
22
+ const urlEntries = entries.sort((a, b) => a.url.localeCompare(b.url)).map(({ url, lastmod, alternates }) => {
23
+ const lastmodLine = lastmod ? `
24
+ <lastmod>${lastmod}</lastmod>` : "";
25
+ const alternateLines = withAlternates && alternates ? alternates.map(
26
+ (a) => `
27
+ <xhtml:link rel="alternate" hreflang="${escapeXml(a.hreflang)}" href="${escapeXml(siteUrlBase + a.url)}"/>`
28
+ ).join("") : "";
29
+ return ` <url>
30
+ <loc>${escapeXml(siteUrlBase + url)}</loc>${lastmodLine}${alternateLines}
31
+ </url>`;
32
+ }).join("\n");
33
+ const urlsetOpen = withAlternates ? '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">' : '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
24
34
  return `<?xml version="1.0" encoding="UTF-8"?>
25
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
35
+ ${urlsetOpen}
26
36
  ${urlEntries}
27
37
  </urlset>
28
38
  `;