@writedocs/generator 0.13.3 → 0.13.5

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 (87) hide show
  1. package/README.md +28 -28
  2. package/astro.config.mjs +645 -645
  3. package/bin/writedocs.js +43 -12
  4. package/package.json +99 -99
  5. package/src/cli/base-path-layout.js +44 -44
  6. package/src/cli/build-auth.js +135 -135
  7. package/src/cli/build.js +203 -203
  8. package/src/cli/check-built-styles.js +41 -41
  9. package/src/cli/convert.js +1 -1
  10. package/src/cli/dev.js +268 -268
  11. package/src/cli/exit-when-flushed.js +4 -0
  12. package/src/cli/generate-api-pages.js +507 -507
  13. package/src/cli/og-image-worker.js +20 -20
  14. package/src/cli/og-images.js +70 -70
  15. package/src/cli/page-list-watch.js +69 -69
  16. package/src/cli/run-astro.js +97 -97
  17. package/src/cli/run-pagefind.js +154 -154
  18. package/src/cli/write-mcp-files.js +103 -103
  19. package/src/cli/write-redirects-file.js +158 -158
  20. package/src/components/ApiReferencePanel.astro +1792 -1792
  21. package/src/components/AppIcon.astro +51 -51
  22. package/src/components/Card.astro +193 -193
  23. package/src/components/CodeGroup.astro +63 -39
  24. package/src/components/CopyPageMenu.astro +374 -374
  25. package/src/components/Hint.astro +188 -188
  26. package/src/components/Icon.astro +72 -72
  27. package/src/components/Image.astro +165 -165
  28. package/src/components/Tile.astro +67 -67
  29. package/src/components/Video.astro +137 -137
  30. package/src/content.config.ts +203 -203
  31. package/src/layout/BaseLayout.astro +908 -908
  32. package/src/layout/components/AnalyticsScripts.astro +49 -49
  33. package/src/layout/components/Breadcrumbs.astro +98 -98
  34. package/src/layout/components/ConsentBanner.astro +119 -119
  35. package/src/layout/components/MobileMenu.astro +225 -225
  36. package/src/layout/components/NavTree.astro +408 -408
  37. package/src/layout/components/Sidebar.astro +232 -232
  38. package/src/layout/components/SiteFooter.astro +87 -87
  39. package/src/layout/components/TopBar.astro +386 -386
  40. package/src/layout/styles/base.css +332 -326
  41. package/src/layout/styles/mobile-menu.css +285 -285
  42. package/src/lib/agent-markdown.js +164 -164
  43. package/src/lib/asset-dimensions.js +89 -89
  44. package/src/lib/base-path.js +90 -90
  45. package/src/lib/cli-report.js +22 -22
  46. package/src/lib/code-line-numbers.js +13 -0
  47. package/src/lib/config-schema.js +414 -75
  48. package/src/lib/config-schema.ts +2509 -1905
  49. package/src/lib/config.ts +1316 -1314
  50. package/src/lib/consent.js +108 -108
  51. package/src/lib/content-store-reload-integration.js +101 -101
  52. package/src/lib/icon-data-dev.js +53 -53
  53. package/src/lib/image-size.js +152 -152
  54. package/src/lib/json-schema-descriptions.js +228 -228
  55. package/src/lib/link-check.js +544 -544
  56. package/src/lib/llms-index.ts +90 -90
  57. package/src/lib/mcp-dev-integration.js +65 -65
  58. package/src/lib/mcp-index.ts +102 -102
  59. package/src/lib/mintlify-convert.js +605 -605
  60. package/src/lib/moved-api-pages.js +49 -49
  61. package/src/lib/og-cards.js +33 -33
  62. package/src/lib/og-image.js +235 -235
  63. package/src/lib/openapi-dev-status.js +80 -80
  64. package/src/lib/openapi-reload-integration.js +193 -193
  65. package/src/lib/pages.js +312 -312
  66. package/src/lib/project-files-integration.js +116 -116
  67. package/src/lib/project-files.js +137 -137
  68. package/src/lib/rehype-base-path.js +62 -62
  69. package/src/lib/rehype-image-loading.js +71 -71
  70. package/src/lib/robots-txt.js +21 -21
  71. package/src/lib/search-scope.js +44 -44
  72. package/src/lib/selector-placement.js +50 -50
  73. package/src/lib/seo-tags.js +155 -155
  74. package/src/lib/shiki-code-block.js +7 -1
  75. package/src/lib/site-base.ts +27 -27
  76. package/src/lib/styles-asset-integration.js +291 -291
  77. package/src/lib/wdignore-cases.json +195 -195
  78. package/src/lib/wdignore.js +177 -177
  79. package/src/pages/404.astro +63 -63
  80. package/src/pages/[...slug].astro +1762 -1608
  81. package/src/pages/[...slug].md.ts +93 -93
  82. package/src/pages/llms-full.txt.ts +88 -88
  83. package/src/pages/og/[...slug].png.ts +63 -63
  84. package/src/scripts/mobile-menu.ts +80 -80
  85. package/src/scripts/search.ts +245 -245
  86. package/src/scripts/sidebar-scroll.ts +61 -61
  87. package/src/styles/global.css +40 -40
@@ -1,605 +1,605 @@
1
- // Converts a Mintlify docs.json into a writedocs.json - `writedocs convert
2
- // --mintlify` (src/cli/convert.js). Plain JavaScript so the CLI can load it
3
- // from an installed package (see lib/icons.js's comment).
4
- //
5
- // convertMintlifyConfig() is a pure function: Mintlify config in, writedocs
6
- // config plus a list of notes out. A note is anything that couldn't be
7
- // carried over as-is - dropped, approximated, or needing a manual step - so
8
- // the author gets one complete list instead of discovering each difference
9
- // on their own. loadMintlifyConfig() reads docs.json from disk and resolves
10
- // its `$ref`s first.
11
- import fs from 'node:fs';
12
- import path from 'node:path';
13
- import { iconExists } from './icons.js';
14
- import { readJsonText } from './config-file.js';
15
-
16
- // ---------------------------------------------------------------------
17
- // Reading docs.json
18
- // ---------------------------------------------------------------------
19
-
20
- /** Reads a Mintlify docs.json and resolves every `$ref` in it, the way
21
- * Mintlify does: a `$ref` is a path to another JSON file, relative to the
22
- * file it's in; an object reference is merged under any sibling keys (the
23
- * siblings win); a non-object reference replaces the whole value. */
24
- export function loadMintlifyConfig(file) {
25
- const root = path.dirname(path.resolve(file));
26
- const seen = new Set();
27
- function readJson(p) {
28
- const abs = path.resolve(p);
29
- if (seen.has(abs)) throw new Error(`Circular $ref: ${path.relative(root, abs)}`);
30
- seen.add(abs);
31
- try {
32
- return resolve(JSON.parse(readJsonText(abs)), path.dirname(abs));
33
- } finally {
34
- seen.delete(abs);
35
- }
36
- }
37
- function resolve(value, dir) {
38
- if (Array.isArray(value)) return value.map((v) => resolve(v, dir));
39
- if (!value || typeof value !== 'object') return value;
40
- if (typeof value.$ref === 'string') {
41
- const target = readJson(path.join(dir, value.$ref));
42
- const { $ref, ...siblings } = value;
43
- if (target && typeof target === 'object' && !Array.isArray(target)) {
44
- return { ...target, ...resolve(siblings, dir) };
45
- }
46
- return target;
47
- }
48
- return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, resolve(v, dir)]));
49
- }
50
- return readJson(file);
51
- }
52
-
53
- // ---------------------------------------------------------------------
54
- // Notes
55
- // ---------------------------------------------------------------------
56
-
57
- function pathString(trail) {
58
- return trail.reduce((s, part) => (typeof part === 'number' ? `${s}[${part}]` : s ? `${s}.${part}` : part), '');
59
- }
60
-
61
- export class Notes {
62
- constructor() {
63
- this.byKey = new Map();
64
- }
65
- /** `key` groups repeats of the same kind of note into one entry. */
66
- add(key, trail, message, suggestion) {
67
- const where = pathString(trail);
68
- const existing = this.byKey.get(key);
69
- if (existing) existing.where.push(where);
70
- else this.byKey.set(key, { where: [where], message, suggestion });
71
- }
72
- list() {
73
- return [...this.byKey.values()];
74
- }
75
- }
76
-
77
- // ---------------------------------------------------------------------
78
- // Navigation
79
- // ---------------------------------------------------------------------
80
-
81
- const ENDPOINT_RE = /^(?:(\S+?\.(?:json|ya?ml))\s+)?(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|TRACE|WEBHOOK)\s+\S+/i;
82
-
83
- // Structural keys, handled for every navigation item - anything else on an
84
- // item that isn't in that item type's own list below is reported.
85
- const STRUCTURAL = ['pages', 'groups', 'tabs', 'anchors', 'dropdowns', 'products', 'versions', 'languages', 'menu', 'href', 'openapi', 'hidden'];
86
-
87
- export const LANGUAGE_NAMES = {
88
- ar: 'العربية', ca: 'Català', cn: '简体中文', 'zh-Hant': '繁體中文', cs: 'Čeština', da: 'Dansk', de: 'Deutsch',
89
- en: 'English', es: 'Español', fi: 'Suomi', fr: 'Français', 'fr-CA': 'Français (Canada)', he: 'עברית',
90
- hi: 'हिन्दी', hu: 'Magyar', id: 'Bahasa Indonesia', it: 'Italiano', ja: '日本語', 'ja-JP': '日本語', jp: '日本語',
91
- ko: '한국어', lv: 'Latviešu', nl: 'Nederlands', no: 'Norsk', pl: 'Polski', pt: 'Português', 'pt-BR': 'Português (Brasil)',
92
- ro: 'Română', ru: 'Русский', sv: 'Svenska', tr: 'Türkçe', uk: 'Українська', uz: 'Oʻzbek', vi: 'Tiếng Việt', zh: '中文',
93
- };
94
-
95
- function slugify(value) {
96
- return String(value)
97
- .toLowerCase()
98
- .normalize('NFKD')
99
- .replace(/[̀-ͯ]/g, '')
100
- .replace(/[^a-z0-9]+/g, '-')
101
- .replace(/^-+|-+$/g, '') || 'api';
102
- }
103
-
104
- /** A Mintlify page reference as a writedocs page id: no leading slash, no
105
- * extension, and a folder's index page by the folder's path ("cli/index"
106
- * -> "cli") - which is how writedocs ids index pages (fileIdForPath() in
107
- * lib/pages.js). */
108
- function pagePath(ref) {
109
- return String(ref).trim().replace(/^\.?\//, '').replace(/\.mdx?$/i, '').replace(/\/index$/, '');
110
- }
111
-
112
- class NavConverter {
113
- constructor(notes, defaultSpec) {
114
- this.notes = notes;
115
- this.defaultSpec = defaultSpec;
116
- this.usedApiPaths = new Set();
117
- }
118
-
119
- /** An OpenAPI reference as writedocs can use it: a local file path, or
120
- * null (with a note) when it's a URL or missing. */
121
- spec(value, trail) {
122
- let src = value;
123
- if (Array.isArray(src)) {
124
- if (src.length > 1) {
125
- this.notes.add('openapi-multi', trail, 'More than one OpenAPI spec on one navigation item - only the first is used.', 'Split the item so each spec has its own group.');
126
- }
127
- src = src[0];
128
- }
129
- if (src && typeof src === 'object') src = src.source;
130
- if (typeof src !== 'string' || !src.trim()) return null;
131
- if (/^https?:\/\//i.test(src)) {
132
- this.notes.add('openapi-url', trail, `OpenAPI spec is a URL (${src}) - writedocs reads specs from files in the project.`, 'Download the spec into the project, then add an openapi group for it: { "group": "...", "openapi": { "src": "spec.json", "path": "/api" } }.');
133
- return null;
134
- }
135
- return src.trim().replace(/^\.?\//, '');
136
- }
137
-
138
- apiPath(name) {
139
- const base = `/${slugify(name)}`;
140
- let candidate = base;
141
- for (let n = 2; this.usedApiPaths.has(candidate); n++) candidate = `${base}-${n}`;
142
- this.usedApiPaths.add(candidate);
143
- return candidate;
144
- }
145
-
146
- openapiGroup(name, src) {
147
- return { group: name, openapi: { src, path: this.apiPath(name) } };
148
- }
149
-
150
- reportExtraKeys(item, own, kind, trail) {
151
- for (const key of Object.keys(item)) {
152
- if (own.includes(key) || STRUCTURAL.includes(key)) continue;
153
- this.notes.add(`nav-key:${kind}:${key}`, [...trail, key], `\`${key}\` on ${kind}s has no writedocs equivalent - dropped.`);
154
- }
155
- }
156
-
157
- /** A Mintlify navigation node's children, as writedocs children
158
- * ({ pages } | { tabs } | ... | { href }), or null if it has none. */
159
- children(node, trail, spec) {
160
- const ownSpec = node.openapi !== undefined ? this.spec(node.openapi, [...trail, 'openapi']) : spec;
161
- if (node.pages || node.groups) {
162
- const pages = [
163
- ...this.items(node.pages ?? [], [...trail, 'pages'], ownSpec),
164
- ...this.items(node.groups ?? [], [...trail, 'groups'], ownSpec),
165
- ];
166
- return { pages };
167
- }
168
- if (node.tabs) return this.list('tabs', node.tabs, [...trail, 'tabs'], ownSpec, (t, tr) => this.container(t, tr, ownSpec, 'tab', 'tab', ['tab', 'icon']));
169
- if (node.anchors) {
170
- this.notes.add('anchors', [...trail, 'anchors'], "Anchors became tabs - writedocs has no sidebar anchors.", 'For a plain external link, a global dropdown or a topbar link may fit better.');
171
- return this.list('tabs', node.anchors, [...trail, 'anchors'], ownSpec, (a, tr) => this.container({ ...a, tab: a.anchor, anchor: undefined }, tr, ownSpec, 'tab', 'anchor', ['tab', 'anchor', 'icon']));
172
- }
173
- if (node.menu) {
174
- this.notes.add('menu', [...trail, 'menu'], "A tab's or product's menu became a list of dropdowns inside it.");
175
- return this.list('dropdowns', node.menu, [...trail, 'menu'], ownSpec, (m, tr) => this.container({ ...m, dropdown: m.item, item: undefined }, tr, ownSpec, 'dropdown', 'menu item', ['dropdown', 'item', 'icon']));
176
- }
177
- if (node.dropdowns) return this.list('dropdowns', node.dropdowns, [...trail, 'dropdowns'], ownSpec, (d, tr) => this.container(d, tr, ownSpec, 'dropdown', 'dropdown', ['dropdown', 'icon']));
178
- if (node.products) return this.list('products', node.products, [...trail, 'products'], ownSpec, (p, tr) => this.container(p, tr, ownSpec, 'product', 'product', ['product', 'icon', 'description']));
179
- if (node.versions) return this.list('versions', node.versions, [...trail, 'versions'], ownSpec, (v, tr) => this.container(v, tr, ownSpec, 'version', 'version', ['version', 'tag', 'default']));
180
- if (node.languages) return this.list('languages', node.languages, [...trail, 'languages'], ownSpec, (l, tr) => this.language(l, tr, ownSpec));
181
- if (typeof node.href === 'string') return { href: node.href };
182
- // An item with only an OpenAPI spec: Mintlify generates every endpoint.
183
- if (node.openapi !== undefined && ownSpec) {
184
- const label = node.tab ?? node.anchor ?? node.dropdown ?? node.product ?? node.item ?? node.version ?? node.language ?? 'API reference';
185
- return { pages: [this.openapiGroup(label, ownSpec)] };
186
- }
187
- return null;
188
- }
189
-
190
- list(key, items, trail, spec, convert) {
191
- const converted = items.map((item, i) => convert(item, [...trail, i])).filter(Boolean);
192
- return converted.length ? { [key]: converted } : null;
193
- }
194
-
195
- /** A tab/anchor/dropdown/menu item/product/version. */
196
- container(item, trail, spec, nameKey, kind, own) {
197
- const name = item[nameKey];
198
- if (item.hidden) {
199
- this.notes.add(`hidden:${kind}`, trail, `Hidden ${kind}s were left out of the navigation - writedocs has no hidden ${kind}s.`, "Their pages still build and are reachable by URL, like a page that isn't in the navigation.");
200
- return null;
201
- }
202
- this.reportExtraKeys(item, own, kind, trail);
203
- const children = this.children(item, trail, spec);
204
- if (!children) {
205
- this.notes.add(`empty:${kind}`, trail, `A ${kind} with no pages, groups or link was left out.`);
206
- return null;
207
- }
208
- const out = { [nameKey]: name };
209
- if (item.icon && typeof item.icon === 'string') out.icon = item.icon;
210
- if (nameKey === 'product' && item.description) out.description = item.description;
211
- if (nameKey === 'version') {
212
- if (item.tag) out.tag = item.tag;
213
- if (item.default) out.default = true;
214
- }
215
- return { ...out, ...children };
216
- }
217
-
218
- language(item, trail, spec) {
219
- if (item.hidden) {
220
- this.notes.add('hidden:language', trail, 'Hidden languages were left out of the navigation.', 'Their pages still build and are reachable by URL.');
221
- return null;
222
- }
223
- for (const key of ['banner', 'footer', 'navbar']) {
224
- if (item[key]) {
225
- this.notes.add(`language:${key}`, [...trail, key], `A per-language \`${key}\` isn't supported - writedocs has one ${key} for the whole site.`, `Only the top-level \`${key}\` was converted.`);
226
- }
227
- }
228
- this.reportExtraKeys(item, ['language', 'default', 'banner', 'footer', 'navbar'], 'language', trail);
229
- const children = this.children(item, trail, spec);
230
- if (!children) {
231
- this.notes.add('empty:language', trail, 'A language with no pages was left out.');
232
- return null;
233
- }
234
- const out = { language: item.language };
235
- if (LANGUAGE_NAMES[item.language]) out.label = LANGUAGE_NAMES[item.language];
236
- return { ...out, ...children };
237
- }
238
-
239
- /** A `pages`/`groups` array: page paths and groups. */
240
- items(list, trail, spec) {
241
- const out = [];
242
- list.forEach((item, i) => {
243
- const tr = [...trail, i];
244
- if (typeof item === 'string') {
245
- if (ENDPOINT_RE.test(item.trim())) {
246
- this.notes.add('endpoint-outside-group', tr, 'An API endpoint listed outside a group was left out.', 'Put the endpoints in a group with an `openapi` spec - writedocs generates a page for every endpoint in it.');
247
- return;
248
- }
249
- out.push(pagePath(item));
250
- } else if (item && typeof item === 'object' && typeof item.group === 'string') {
251
- const group = this.group(item, tr, spec);
252
- if (group) out.push(group);
253
- } else if (item && typeof item === 'object' && typeof item.href === 'string') {
254
- out.push({ label: item.label ?? item.title ?? item.href, href: item.href });
255
- } else {
256
- this.notes.add('unknown-page-entry', tr, 'A navigation entry that is neither a page path nor a group was left out.');
257
- }
258
- });
259
- return out;
260
- }
261
-
262
- group(g, trail, spec) {
263
- if (g.hidden) {
264
- this.notes.add('hidden:group', trail, 'Hidden groups were left out of the navigation.', 'Their pages still build and are reachable by URL.');
265
- return null;
266
- }
267
- this.reportExtraKeys(g, ['group', 'root', 'pages'], 'group', trail);
268
- const ownSpec = g.openapi !== undefined ? this.spec(g.openapi, [...trail, 'openapi']) : spec;
269
- const pages = [];
270
- let endpoints = 0;
271
- (g.pages ?? []).forEach((item, i) => {
272
- if (typeof item === 'string' && ENDPOINT_RE.test(item.trim())) {
273
- endpoints++;
274
- return;
275
- }
276
- pages.push(...this.items([item], [...trail, 'pages', i], ownSpec));
277
- });
278
- const wantsApi = endpoints > 0 || (g.openapi !== undefined && (g.pages ?? []).length === 0);
279
- if (wantsApi) {
280
- if (ownSpec) {
281
- if (endpoints > 0) {
282
- this.notes.add('endpoint-selection', [...trail, 'pages'], 'Groups that listed individual API endpoints now generate a page for every endpoint in their OpenAPI spec - writedocs has no per-endpoint selection.', 'To show only some endpoints, split the spec, or write those pages by hand with `openapi: "METHOD /path"` frontmatter.');
283
- }
284
- if (pages.length === 0 && !g.root) return this.openapiGroup(g.group, ownSpec);
285
- pages.push(this.openapiGroup('Endpoints', ownSpec));
286
- } else if (endpoints > 0) {
287
- this.notes.add('endpoint-no-spec', [...trail, 'pages'], 'API endpoints listed without a usable OpenAPI spec were left out.', 'Add an `openapi` group with a spec file in the project.');
288
- }
289
- }
290
- if (pages.length === 0 && !g.root) {
291
- this.notes.add('empty:group', trail, 'A group with no pages was left out.');
292
- return null;
293
- }
294
- const out = { group: g.group };
295
- if (g.root) out.page = pagePath(g.root);
296
- out.pages = pages;
297
- return out;
298
- }
299
- }
300
-
301
- function convertNavigation(nav, notes, topbarLinks, defaultSpec) {
302
- const trail = ['navigation'];
303
- const conv = new NavConverter(notes, defaultSpec);
304
- if (Array.isArray(nav)) {
305
- notes.add('legacy-navigation', trail, 'docs.json navigation is an array - that is the older mint.json shape.', 'Run `npx mint upgrade` in the Mintlify project first, then convert again.');
306
- return { navigation: [], api: conv };
307
- }
308
- const children = nav ? conv.children(nav, trail, defaultSpec) : null;
309
- let navigation = children ?? { pages: [] };
310
- if (!children) notes.add('empty-navigation', trail, 'No navigation could be converted.');
311
-
312
- // `global` links: writedocs' global dropdowns are its equivalent of
313
- // Mintlify's global anchors (config-schema.ts), but they only exist
314
- // alongside a root division, not a plain page list - there they become
315
- // topbar links instead.
316
- const globalLinks = [];
317
- const g = nav?.global ?? {};
318
- for (const [key, nameKey] of [['anchors', 'anchor'], ['tabs', 'tab'], ['dropdowns', 'dropdown'], ['products', 'product']]) {
319
- (g[key] ?? []).forEach((item, i) => {
320
- if (item.hidden) return;
321
- if (typeof item.href !== 'string') {
322
- notes.add('global-no-href', ['navigation', 'global', key, i], 'Global navigation items without an `href` were left out.');
323
- return;
324
- }
325
- globalLinks.push({ label: item[nameKey], href: item.href, icon: item.icon });
326
- });
327
- }
328
- for (const key of ['languages', 'versions']) {
329
- if (g[key]?.length) notes.add(`global-${key}`, ['navigation', 'global', key], `Global ${key} (links to other sites) aren't supported - left out.`);
330
- }
331
- if (children?.pages) {
332
- navigation = children.pages;
333
- for (const link of globalLinks) topbarLinks.push(link.icon ? link : { label: link.label, href: link.href });
334
- if (globalLinks.length) {
335
- notes.add('global-to-topbar', ['navigation', 'global'], 'Global anchors became topbar links - writedocs only has global dropdowns alongside tabs, versions, languages, dropdowns or products.');
336
- }
337
- } else if (globalLinks.length) {
338
- navigation = {
339
- global: { dropdowns: globalLinks.map((l) => ({ dropdown: l.label, ...(l.icon ? { icon: l.icon } : {}), href: l.href })) },
340
- ...navigation,
341
- };
342
- }
343
- return { navigation, api: conv };
344
- }
345
-
346
- // ---------------------------------------------------------------------
347
- // Everything else
348
- // ---------------------------------------------------------------------
349
-
350
- const SOCIAL_ICONS = { x: 'x-twitter', website: 'globe' };
351
-
352
- function lightDark(value) {
353
- if (typeof value === 'string') return { light: value, dark: value };
354
- if (value && typeof value === 'object') return { light: value.light, dark: value.dark };
355
- return null;
356
- }
357
-
358
- /**
359
- * Mintlify docs.json (with `$ref`s already resolved) -> { config, notes }.
360
- * `config` is a writedocs.json object; `notes` is a list of
361
- * { where: string[], message, suggestion? }.
362
- */
363
- export function convertMintlifyConfig(docs) {
364
- const notes = new Notes();
365
- const out = { name: docs.name ?? 'Documentation' };
366
- if (!docs.name) notes.add('name', ['name'], 'docs.json has no `name` - used "Documentation".');
367
- if (docs.description) out.description = docs.description;
368
-
369
- // styles
370
- const styles = {};
371
- const colors = {};
372
- if (docs.colors?.primary) colors.primary = docs.colors.primary;
373
- if (docs.colors?.light) colors.dark = { primary: docs.colors.light };
374
- if (docs.colors?.dark) notes.add('colors.dark', ['colors', 'dark'], '`colors.dark` (buttons and hover states) has no writedocs equivalent - dropped.', 'writedocs uses `colors.primary` for those.');
375
- if (Object.keys(colors).length) styles.colors = colors;
376
- if (typeof docs.logo === 'string') styles.logo = docs.logo;
377
- else if (docs.logo && typeof docs.logo === 'object') {
378
- styles.logo = {};
379
- if (docs.logo.light) styles.logo.light = docs.logo.light;
380
- if (docs.logo.dark) styles.logo.dark = docs.logo.dark;
381
- if (docs.logo.href) notes.add('logo.href', ['logo', 'href'], '`logo.href` isn\'t supported - the logo always links to the home page.');
382
- }
383
- if (typeof docs.favicon === 'string') styles.favicon = docs.favicon;
384
- else if (docs.favicon?.light) {
385
- styles.favicon = docs.favicon.light;
386
- if (docs.favicon.dark) notes.add('favicon.dark', ['favicon', 'dark'], 'writedocs has one favicon - used `favicon.light`, dropped `favicon.dark`.');
387
- }
388
- if (docs.fonts && typeof docs.fonts === 'object') {
389
- const font = (f) => {
390
- const o = { family: f.family };
391
- for (const k of ['weight', 'source', 'format']) if (f[k] !== undefined) o[k] = f[k];
392
- return o;
393
- };
394
- if (docs.fonts.family) {
395
- styles.fonts = font(docs.fonts);
396
- if (docs.fonts.heading?.family) styles.fonts.heading = font(docs.fonts.heading);
397
- if (docs.fonts.body?.family) styles.fonts.body = font(docs.fonts.body);
398
- } else if (docs.fonts.body?.family || docs.fonts.heading?.family) {
399
- styles.fonts = font(docs.fonts.body ?? docs.fonts.heading);
400
- if (docs.fonts.heading?.family && docs.fonts.body?.family) styles.fonts.heading = font(docs.fonts.heading);
401
- }
402
- }
403
- const cb = docs.styling?.codeblocks;
404
- if (cb !== undefined && cb !== 'system') {
405
- const theme = typeof cb === 'string' ? cb : cb?.theme;
406
- if (theme === 'dark') styles.codeblocks = { light: 'github-dark', dark: 'github-dark' };
407
- else if (typeof theme === 'string') styles.codeblocks = { light: theme, dark: theme };
408
- else if (theme && typeof theme === 'object') styles.codeblocks = { light: theme.light, dark: theme.dark };
409
- if (cb?.languages) notes.add('codeblock-languages', ['styling', 'codeblocks', 'languages'], 'Custom code block languages aren\'t supported - dropped.');
410
- }
411
- const bg = docs.background;
412
- if (bg) {
413
- const background = {};
414
- const c = lightDark(bg.color);
415
- if (c) background.colors = c;
416
- const img = lightDark(bg.image);
417
- if (img) background.images = img;
418
- if (Object.keys(background).length) styles.background = background;
419
- if (bg.decoration) notes.add('background.decoration', ['background', 'decoration'], `\`background.decoration\` ("${bg.decoration}") isn't supported - dropped.`);
420
- }
421
- if (Object.keys(styles).length) out.styles = styles;
422
-
423
- // navigation (also collects topbar links from `global`)
424
- const topbarLinks = [];
425
- const defaultSpec = docs.api?.openapi;
426
- const navNotesSpec = defaultSpec !== undefined ? new NavConverter(notes).spec(defaultSpec, ['api', 'openapi']) : null;
427
- const { navigation } = convertNavigation(docs.navigation, notes, topbarLinks, navNotesSpec);
428
- out.navigation = navigation;
429
-
430
- // topbar
431
- const navbar = docs.navbar ?? {};
432
- const linkFor = (l) => {
433
- if (l.type === 'github' || l.type === 'discord') {
434
- return { label: l.label ?? (l.type === 'github' ? 'GitHub' : 'Discord'), href: l.href, icon: l.type };
435
- }
436
- const link = { label: l.label, href: l.href };
437
- if (typeof l.icon === 'string') link.icon = l.icon;
438
- return link;
439
- };
440
- for (const l of navbar.links ?? []) if (l?.href && (l.label || l.type || l.icon)) topbarLinks.push(linkFor(l));
441
- if (navbar.primary?.href) {
442
- topbarLinks.push(linkFor(navbar.primary));
443
- notes.add('navbar.primary', ['navbar', 'primary'], 'The navbar\'s primary button became a regular topbar link - writedocs has no call-to-action button style.');
444
- }
445
- if (topbarLinks.length) out.topbar = { links: topbarLinks };
446
-
447
- // footer + socials
448
- const socials = docs.footer?.socials;
449
- if (socials && typeof socials === 'object') {
450
- out.socials = {};
451
- for (const [key, url] of Object.entries(socials)) {
452
- const icon = iconExists(key) && !SOCIAL_ICONS[key] ? key : SOCIAL_ICONS[key] ?? key;
453
- if (!iconExists(icon)) notes.add(`social:${key}`, ['footer', 'socials', key], `No icon for the "${key}" social link - it shows without one.`);
454
- out.socials[icon] = url;
455
- }
456
- }
457
- if (Array.isArray(docs.footer?.links) && docs.footer.links.length) {
458
- out.footer = {
459
- columns: docs.footer.links.map((col) => ({
460
- ...(col.header ? { title: col.header } : {}),
461
- links: (col.items ?? []).filter((i) => i?.href && i.label).map((i) => ({ label: i.label, href: i.href })),
462
- })),
463
- };
464
- }
465
-
466
- // banner
467
- if (docs.banner?.content) {
468
- out.banner = { content: docs.banner.content };
469
- if (docs.banner.dismissible) out.banner.dismissible = true;
470
- if (['info', 'warning', 'critical'].includes(docs.banner.type)) out.banner.type = docs.banner.type;
471
- if (docs.banner.color) notes.add('banner.color', ['banner', 'color'], '`banner.color` isn\'t supported - the banner uses its `type`\'s color.');
472
- }
473
-
474
- // 404
475
- const e404 = docs.errors?.['404'];
476
- if (e404?.title || e404?.description) {
477
- out.notFound = {};
478
- if (e404.title) out.notFound.title = e404.title;
479
- if (e404.description) out.notFound.description = e404.description;
480
- }
481
- if (e404 && e404.redirect !== false) {
482
- notes.add('404-redirect', ['errors', '404', 'redirect'], 'Mintlify redirects a missing page to the home page; writedocs shows a 404 page instead.');
483
- }
484
-
485
- // redirects
486
- if (Array.isArray(docs.redirects) && docs.redirects.length) {
487
- // Mintlify redirects can match a path pattern (`/old/:slug`, `/old/*`);
488
- // writedocs redirects are exact paths - a pattern would become a
489
- // literal page path (and `:` can't even be a folder name on Windows).
490
- const isPattern = (p) => /(^|\/):[A-Za-z_]|\*/.test(p);
491
- const patterns = docs.redirects.filter((r) => r?.source && r?.destination && (isPattern(r.source) || isPattern(r.destination)));
492
- out.redirects = docs.redirects
493
- .filter((r) => r?.source && r?.destination && !patterns.includes(r))
494
- .map((r) => ({ source: r.source, destination: r.destination }));
495
- if (out.redirects.length === 0) delete out.redirects;
496
- if (patterns.length) {
497
- const examples = patterns.slice(0, 2).map((r) => `${r.source} -> ${r.destination}`).join('; ');
498
- notes.add('redirect-patterns', ['redirects'], `${patterns.length} redirect${patterns.length === 1 ? '' : 's'} with a path parameter or wildcard (e.g. ${examples}) ${patterns.length === 1 ? 'was' : 'were'} left out - writedocs redirects match one exact path.`, 'Add an exact redirect for each old page that still gets traffic.');
499
- }
500
- if (docs.redirects.some((r) => r?.permanent === false)) {
501
- notes.add('redirect-permanent', ['redirects'], '`permanent: false` on redirects has no effect - every writedocs redirect is the same kind.');
502
- }
503
- }
504
-
505
- // variables
506
- if (docs.variables && typeof docs.variables === 'object' && Object.keys(docs.variables).length) {
507
- out.variables = { ...docs.variables };
508
- const hyphenated = Object.keys(docs.variables).filter((k) => k.includes('-'));
509
- if (hyphenated.length) {
510
- notes.add('variables-hyphen', ['variables'], `Variables with a hyphen (${hyphenated.join(', ')}) can't be written as {{name}} in writedocs pages.`, 'Write them as [[name]] in your pages instead.');
511
- }
512
- }
513
-
514
- // SEO
515
- const meta = docs.seo?.metatags ?? {};
516
- const seo = {};
517
- const ignoredMeta = [];
518
- for (const [k, v] of Object.entries(meta)) {
519
- if (k === 'og:image') seo.ogImage = v;
520
- else if (k === 'og:type') seo.ogType = v;
521
- else if (k === 'twitter:card' && ['summary', 'summary_large_image'].includes(v)) seo.twitterCard = v;
522
- else if (k === 'keywords') seo.keywords = String(v).split(',').map((s) => s.trim()).filter(Boolean);
523
- else if (k === 'robots') seo.robots = String(v);
524
- // The site's address for canonical URLs is writedocs' `domain`.
525
- else if (k === 'canonical') ignoredMeta.push(k);
526
- else (seo.metatags ??= {})[k] = String(v);
527
- }
528
- if (Object.keys(seo).length) out.seo = seo;
529
- if (ignoredMeta.length) {
530
- notes.add('metatags', ['seo', 'metatags'], 'The `canonical` meta tag was dropped: writedocs builds the canonical URL of every page from `domain`.', 'Set "domain" to the address of the site; a single page can set its own with `seo.canonical` in its frontmatter.');
531
- }
532
- if (docs.seo?.indexing === 'all') notes.add('seo.indexing', ['seo', 'indexing'], '`seo.indexing: "all"` has no equivalent - writedocs indexes every page that isn\'t marked noindex.');
533
-
534
- // context menu
535
- // Mintlify's option names are writedocs' own for the eight both have, so
536
- // the list carries over as is. No `contextual` leaves the field out - the
537
- // menu is on by default, with every option.
538
- const options = docs.contextual?.options;
539
- if (Array.isArray(options) && options.length) {
540
- const known = ['copy', 'view', 'chatgpt', 'claude', 'perplexity', 'mcp', 'cursor', 'vscode'];
541
- out.contextMenu = known.filter((o) => options.includes(o));
542
- const other = options.filter((o) => typeof o !== 'string' || !known.includes(o));
543
- if (other.length) {
544
- notes.add('contextual', ['contextual', 'options'], `Context menu options writedocs doesn't have were dropped: ${other.map((o) => (typeof o === 'string' ? o : o.title ?? 'custom')).join(', ')}.`, 'writedocs\' page menu offers copy, view as Markdown, open in ChatGPT, Claude and Perplexity, and the MCP server: copy its URL, connect to Cursor or VS Code.');
545
- }
546
- }
547
-
548
- // API playground
549
- if (docs.api?.playground?.proxy === false) out.api = { proxy: false };
550
- if (docs.api?.playground?.display && docs.api.playground.display !== 'interactive') {
551
- notes.add('api.playground.display', ['api', 'playground', 'display'], `\`api.playground.display: "${docs.api.playground.display}"\` isn't supported - the playground is always interactive.`);
552
- }
553
- for (const key of ['params', 'url', 'examples', 'mdx', 'asyncapi']) {
554
- if (docs.api?.[key] !== undefined) notes.add(`api.${key}`, ['api', key], `\`api.${key}\` has no writedocs equivalent - dropped.`);
555
- }
556
-
557
- // integrations
558
- const integrations = {};
559
- const ig = docs.integrations ?? {};
560
- if (ig.ga4?.measurementId) integrations.ga4 = { measurementId: ig.ga4.measurementId };
561
- if (ig.gtm?.tagId) integrations.googleTagManager = { containerId: ig.gtm.tagId };
562
- if (ig.plausible?.domain) {
563
- integrations.plausible = { domain: ig.plausible.domain };
564
- if (ig.plausible.server) integrations.plausible.src = `${ig.plausible.server.replace(/\/+$/, '')}/js/script.js`;
565
- }
566
- if (ig.fathom?.siteId) integrations.fathom = { siteId: ig.fathom.siteId };
567
- if (ig.posthog?.apiKey) {
568
- integrations.posthog = { apiKey: ig.posthog.apiKey };
569
- if (ig.posthog.apiHost) integrations.posthog.apiHost = ig.posthog.apiHost;
570
- }
571
- if (Object.keys(integrations).length) out.integrations = integrations;
572
- const otherIntegrations = Object.keys(ig).filter((k) => !['ga4', 'gtm', 'plausible', 'fathom', 'posthog', 'telemetry', 'cookies'].includes(k));
573
- if (otherIntegrations.length) {
574
- notes.add('integrations', ['integrations'], `These integrations have no writedocs equivalent and were dropped: ${otherIntegrations.join(', ')}.`, 'Most can be added as a custom script in writedocs.json\'s `scripts.head`.');
575
- }
576
-
577
- // Settings with no equivalent at all
578
- const unsupported = {
579
- appearance: 'Light/dark mode defaults (`appearance`) aren\'t configurable - readers choose with the theme toggle.',
580
- interaction: '`interaction` settings aren\'t supported.',
581
- thumbnails: 'Social thumbnails (`thumbnails`) aren\'t generated - set `seo.ogImage` for a social preview image.',
582
- metadata: '`metadata` (last-modified timestamps) isn\'t supported.',
583
- markdown: '`markdown` export settings aren\'t supported.',
584
- search: '`search` settings aren\'t supported.',
585
- };
586
- for (const [key, message] of Object.entries(unsupported)) if (docs[key] !== undefined) notes.add(key, [key], message);
587
- if (docs.styling?.eyebrows) notes.add('styling.eyebrows', ['styling', 'eyebrows'], '`styling.eyebrows` isn\'t supported - writedocs shows breadcrumbs.');
588
- if (docs.icons?.library === 'tabler') {
589
- notes.add('icons.library', ['icons', 'library'], 'Icon names are looked up in Lucide, then Font Awesome - not Tabler.', 'Tabler names that don\'t exist there can be written as "tabler:name".');
590
- }
591
-
592
- return { config: out, notes: notes.list() };
593
- }
594
-
595
- /** Formats notes for the terminal - same layout as `writedocs validate`. */
596
- export function formatNotes(notes) {
597
- return notes
598
- .map((n) => {
599
- const where = n.where.length > 3 ? `${n.where.slice(0, 3).join(', ')} and ${n.where.length - 3} more` : n.where.join(', ');
600
- const lines = [` ${where}`, ` ${n.message}`];
601
- if (n.suggestion) lines.push(` ${n.suggestion}`);
602
- return lines.join('\n');
603
- })
604
- .join('\n\n');
605
- }
1
+ // Converts a Mintlify docs.json into a writedocs.json - `writedocs convert
2
+ // --mintlify` (src/cli/convert.js). Plain JavaScript so the CLI can load it
3
+ // from an installed package (see lib/icons.js's comment).
4
+ //
5
+ // convertMintlifyConfig() is a pure function: Mintlify config in, writedocs
6
+ // config plus a list of notes out. A note is anything that couldn't be
7
+ // carried over as-is - dropped, approximated, or needing a manual step - so
8
+ // the author gets one complete list instead of discovering each difference
9
+ // on their own. loadMintlifyConfig() reads docs.json from disk and resolves
10
+ // its `$ref`s first.
11
+ import fs from 'node:fs';
12
+ import path from 'node:path';
13
+ import { iconExists } from './icons.js';
14
+ import { readJsonText } from './config-file.js';
15
+
16
+ // ---------------------------------------------------------------------
17
+ // Reading docs.json
18
+ // ---------------------------------------------------------------------
19
+
20
+ /** Reads a Mintlify docs.json and resolves every `$ref` in it, the way
21
+ * Mintlify does: a `$ref` is a path to another JSON file, relative to the
22
+ * file it's in; an object reference is merged under any sibling keys (the
23
+ * siblings win); a non-object reference replaces the whole value. */
24
+ export function loadMintlifyConfig(file) {
25
+ const root = path.dirname(path.resolve(file));
26
+ const seen = new Set();
27
+ function readJson(p) {
28
+ const abs = path.resolve(p);
29
+ if (seen.has(abs)) throw new Error(`Circular $ref: ${path.relative(root, abs)}`);
30
+ seen.add(abs);
31
+ try {
32
+ return resolve(JSON.parse(readJsonText(abs)), path.dirname(abs));
33
+ } finally {
34
+ seen.delete(abs);
35
+ }
36
+ }
37
+ function resolve(value, dir) {
38
+ if (Array.isArray(value)) return value.map((v) => resolve(v, dir));
39
+ if (!value || typeof value !== 'object') return value;
40
+ if (typeof value.$ref === 'string') {
41
+ const target = readJson(path.join(dir, value.$ref));
42
+ const { $ref, ...siblings } = value;
43
+ if (target && typeof target === 'object' && !Array.isArray(target)) {
44
+ return { ...target, ...resolve(siblings, dir) };
45
+ }
46
+ return target;
47
+ }
48
+ return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, resolve(v, dir)]));
49
+ }
50
+ return readJson(file);
51
+ }
52
+
53
+ // ---------------------------------------------------------------------
54
+ // Notes
55
+ // ---------------------------------------------------------------------
56
+
57
+ function pathString(trail) {
58
+ return trail.reduce((s, part) => (typeof part === 'number' ? `${s}[${part}]` : s ? `${s}.${part}` : part), '');
59
+ }
60
+
61
+ export class Notes {
62
+ constructor() {
63
+ this.byKey = new Map();
64
+ }
65
+ /** `key` groups repeats of the same kind of note into one entry. */
66
+ add(key, trail, message, suggestion) {
67
+ const where = pathString(trail);
68
+ const existing = this.byKey.get(key);
69
+ if (existing) existing.where.push(where);
70
+ else this.byKey.set(key, { where: [where], message, suggestion });
71
+ }
72
+ list() {
73
+ return [...this.byKey.values()];
74
+ }
75
+ }
76
+
77
+ // ---------------------------------------------------------------------
78
+ // Navigation
79
+ // ---------------------------------------------------------------------
80
+
81
+ const ENDPOINT_RE = /^(?:(\S+?\.(?:json|ya?ml))\s+)?(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|TRACE|WEBHOOK)\s+\S+/i;
82
+
83
+ // Structural keys, handled for every navigation item - anything else on an
84
+ // item that isn't in that item type's own list below is reported.
85
+ const STRUCTURAL = ['pages', 'groups', 'tabs', 'anchors', 'dropdowns', 'products', 'versions', 'languages', 'menu', 'href', 'openapi', 'hidden'];
86
+
87
+ export const LANGUAGE_NAMES = {
88
+ ar: 'العربية', ca: 'Català', cn: '简体中文', 'zh-Hant': '繁體中文', cs: 'Čeština', da: 'Dansk', de: 'Deutsch',
89
+ en: 'English', es: 'Español', fi: 'Suomi', fr: 'Français', 'fr-CA': 'Français (Canada)', he: 'עברית',
90
+ hi: 'हिन्दी', hu: 'Magyar', id: 'Bahasa Indonesia', it: 'Italiano', ja: '日本語', 'ja-JP': '日本語', jp: '日本語',
91
+ ko: '한국어', lv: 'Latviešu', nl: 'Nederlands', no: 'Norsk', pl: 'Polski', pt: 'Português', 'pt-BR': 'Português (Brasil)',
92
+ ro: 'Română', ru: 'Русский', sv: 'Svenska', tr: 'Türkçe', uk: 'Українська', uz: 'Oʻzbek', vi: 'Tiếng Việt', zh: '中文',
93
+ };
94
+
95
+ function slugify(value) {
96
+ return String(value)
97
+ .toLowerCase()
98
+ .normalize('NFKD')
99
+ .replace(/[̀-ͯ]/g, '')
100
+ .replace(/[^a-z0-9]+/g, '-')
101
+ .replace(/^-+|-+$/g, '') || 'api';
102
+ }
103
+
104
+ /** A Mintlify page reference as a writedocs page id: no leading slash, no
105
+ * extension, and a folder's index page by the folder's path ("cli/index"
106
+ * -> "cli") - which is how writedocs ids index pages (fileIdForPath() in
107
+ * lib/pages.js). */
108
+ function pagePath(ref) {
109
+ return String(ref).trim().replace(/^\.?\//, '').replace(/\.mdx?$/i, '').replace(/\/index$/, '');
110
+ }
111
+
112
+ class NavConverter {
113
+ constructor(notes, defaultSpec) {
114
+ this.notes = notes;
115
+ this.defaultSpec = defaultSpec;
116
+ this.usedApiPaths = new Set();
117
+ }
118
+
119
+ /** An OpenAPI reference as writedocs can use it: a local file path, or
120
+ * null (with a note) when it's a URL or missing. */
121
+ spec(value, trail) {
122
+ let src = value;
123
+ if (Array.isArray(src)) {
124
+ if (src.length > 1) {
125
+ this.notes.add('openapi-multi', trail, 'More than one OpenAPI spec on one navigation item - only the first is used.', 'Split the item so each spec has its own group.');
126
+ }
127
+ src = src[0];
128
+ }
129
+ if (src && typeof src === 'object') src = src.source;
130
+ if (typeof src !== 'string' || !src.trim()) return null;
131
+ if (/^https?:\/\//i.test(src)) {
132
+ this.notes.add('openapi-url', trail, `OpenAPI spec is a URL (${src}) - writedocs reads specs from files in the project.`, 'Download the spec into the project, then add an openapi group for it: { "group": "...", "openapi": { "src": "spec.json", "path": "/api" } }.');
133
+ return null;
134
+ }
135
+ return src.trim().replace(/^\.?\//, '');
136
+ }
137
+
138
+ apiPath(name) {
139
+ const base = `/${slugify(name)}`;
140
+ let candidate = base;
141
+ for (let n = 2; this.usedApiPaths.has(candidate); n++) candidate = `${base}-${n}`;
142
+ this.usedApiPaths.add(candidate);
143
+ return candidate;
144
+ }
145
+
146
+ openapiGroup(name, src) {
147
+ return { group: name, openapi: { src, path: this.apiPath(name) } };
148
+ }
149
+
150
+ reportExtraKeys(item, own, kind, trail) {
151
+ for (const key of Object.keys(item)) {
152
+ if (own.includes(key) || STRUCTURAL.includes(key)) continue;
153
+ this.notes.add(`nav-key:${kind}:${key}`, [...trail, key], `\`${key}\` on ${kind}s has no writedocs equivalent - dropped.`);
154
+ }
155
+ }
156
+
157
+ /** A Mintlify navigation node's children, as writedocs children
158
+ * ({ pages } | { tabs } | ... | { href }), or null if it has none. */
159
+ children(node, trail, spec) {
160
+ const ownSpec = node.openapi !== undefined ? this.spec(node.openapi, [...trail, 'openapi']) : spec;
161
+ if (node.pages || node.groups) {
162
+ const pages = [
163
+ ...this.items(node.pages ?? [], [...trail, 'pages'], ownSpec),
164
+ ...this.items(node.groups ?? [], [...trail, 'groups'], ownSpec),
165
+ ];
166
+ return { pages };
167
+ }
168
+ if (node.tabs) return this.list('tabs', node.tabs, [...trail, 'tabs'], ownSpec, (t, tr) => this.container(t, tr, ownSpec, 'tab', 'tab', ['tab', 'icon']));
169
+ if (node.anchors) {
170
+ this.notes.add('anchors', [...trail, 'anchors'], "Anchors became tabs - writedocs has no sidebar anchors.", 'For a plain external link, a global dropdown or a topbar link may fit better.');
171
+ return this.list('tabs', node.anchors, [...trail, 'anchors'], ownSpec, (a, tr) => this.container({ ...a, tab: a.anchor, anchor: undefined }, tr, ownSpec, 'tab', 'anchor', ['tab', 'anchor', 'icon']));
172
+ }
173
+ if (node.menu) {
174
+ this.notes.add('menu', [...trail, 'menu'], "A tab's or product's menu became a list of dropdowns inside it.");
175
+ return this.list('dropdowns', node.menu, [...trail, 'menu'], ownSpec, (m, tr) => this.container({ ...m, dropdown: m.item, item: undefined }, tr, ownSpec, 'dropdown', 'menu item', ['dropdown', 'item', 'icon']));
176
+ }
177
+ if (node.dropdowns) return this.list('dropdowns', node.dropdowns, [...trail, 'dropdowns'], ownSpec, (d, tr) => this.container(d, tr, ownSpec, 'dropdown', 'dropdown', ['dropdown', 'icon']));
178
+ if (node.products) return this.list('products', node.products, [...trail, 'products'], ownSpec, (p, tr) => this.container(p, tr, ownSpec, 'product', 'product', ['product', 'icon', 'description']));
179
+ if (node.versions) return this.list('versions', node.versions, [...trail, 'versions'], ownSpec, (v, tr) => this.container(v, tr, ownSpec, 'version', 'version', ['version', 'tag', 'default']));
180
+ if (node.languages) return this.list('languages', node.languages, [...trail, 'languages'], ownSpec, (l, tr) => this.language(l, tr, ownSpec));
181
+ if (typeof node.href === 'string') return { href: node.href };
182
+ // An item with only an OpenAPI spec: Mintlify generates every endpoint.
183
+ if (node.openapi !== undefined && ownSpec) {
184
+ const label = node.tab ?? node.anchor ?? node.dropdown ?? node.product ?? node.item ?? node.version ?? node.language ?? 'API reference';
185
+ return { pages: [this.openapiGroup(label, ownSpec)] };
186
+ }
187
+ return null;
188
+ }
189
+
190
+ list(key, items, trail, spec, convert) {
191
+ const converted = items.map((item, i) => convert(item, [...trail, i])).filter(Boolean);
192
+ return converted.length ? { [key]: converted } : null;
193
+ }
194
+
195
+ /** A tab/anchor/dropdown/menu item/product/version. */
196
+ container(item, trail, spec, nameKey, kind, own) {
197
+ const name = item[nameKey];
198
+ if (item.hidden) {
199
+ this.notes.add(`hidden:${kind}`, trail, `Hidden ${kind}s were left out of the navigation - writedocs has no hidden ${kind}s.`, "Their pages still build and are reachable by URL, like a page that isn't in the navigation.");
200
+ return null;
201
+ }
202
+ this.reportExtraKeys(item, own, kind, trail);
203
+ const children = this.children(item, trail, spec);
204
+ if (!children) {
205
+ this.notes.add(`empty:${kind}`, trail, `A ${kind} with no pages, groups or link was left out.`);
206
+ return null;
207
+ }
208
+ const out = { [nameKey]: name };
209
+ if (item.icon && typeof item.icon === 'string') out.icon = item.icon;
210
+ if (nameKey === 'product' && item.description) out.description = item.description;
211
+ if (nameKey === 'version') {
212
+ if (item.tag) out.tag = item.tag;
213
+ if (item.default) out.default = true;
214
+ }
215
+ return { ...out, ...children };
216
+ }
217
+
218
+ language(item, trail, spec) {
219
+ if (item.hidden) {
220
+ this.notes.add('hidden:language', trail, 'Hidden languages were left out of the navigation.', 'Their pages still build and are reachable by URL.');
221
+ return null;
222
+ }
223
+ for (const key of ['banner', 'footer', 'navbar']) {
224
+ if (item[key]) {
225
+ this.notes.add(`language:${key}`, [...trail, key], `A per-language \`${key}\` isn't supported - writedocs has one ${key} for the whole site.`, `Only the top-level \`${key}\` was converted.`);
226
+ }
227
+ }
228
+ this.reportExtraKeys(item, ['language', 'default', 'banner', 'footer', 'navbar'], 'language', trail);
229
+ const children = this.children(item, trail, spec);
230
+ if (!children) {
231
+ this.notes.add('empty:language', trail, 'A language with no pages was left out.');
232
+ return null;
233
+ }
234
+ const out = { language: item.language };
235
+ if (LANGUAGE_NAMES[item.language]) out.label = LANGUAGE_NAMES[item.language];
236
+ return { ...out, ...children };
237
+ }
238
+
239
+ /** A `pages`/`groups` array: page paths and groups. */
240
+ items(list, trail, spec) {
241
+ const out = [];
242
+ list.forEach((item, i) => {
243
+ const tr = [...trail, i];
244
+ if (typeof item === 'string') {
245
+ if (ENDPOINT_RE.test(item.trim())) {
246
+ this.notes.add('endpoint-outside-group', tr, 'An API endpoint listed outside a group was left out.', 'Put the endpoints in a group with an `openapi` spec - writedocs generates a page for every endpoint in it.');
247
+ return;
248
+ }
249
+ out.push(pagePath(item));
250
+ } else if (item && typeof item === 'object' && typeof item.group === 'string') {
251
+ const group = this.group(item, tr, spec);
252
+ if (group) out.push(group);
253
+ } else if (item && typeof item === 'object' && typeof item.href === 'string') {
254
+ out.push({ label: item.label ?? item.title ?? item.href, href: item.href });
255
+ } else {
256
+ this.notes.add('unknown-page-entry', tr, 'A navigation entry that is neither a page path nor a group was left out.');
257
+ }
258
+ });
259
+ return out;
260
+ }
261
+
262
+ group(g, trail, spec) {
263
+ if (g.hidden) {
264
+ this.notes.add('hidden:group', trail, 'Hidden groups were left out of the navigation.', 'Their pages still build and are reachable by URL.');
265
+ return null;
266
+ }
267
+ this.reportExtraKeys(g, ['group', 'root', 'pages'], 'group', trail);
268
+ const ownSpec = g.openapi !== undefined ? this.spec(g.openapi, [...trail, 'openapi']) : spec;
269
+ const pages = [];
270
+ let endpoints = 0;
271
+ (g.pages ?? []).forEach((item, i) => {
272
+ if (typeof item === 'string' && ENDPOINT_RE.test(item.trim())) {
273
+ endpoints++;
274
+ return;
275
+ }
276
+ pages.push(...this.items([item], [...trail, 'pages', i], ownSpec));
277
+ });
278
+ const wantsApi = endpoints > 0 || (g.openapi !== undefined && (g.pages ?? []).length === 0);
279
+ if (wantsApi) {
280
+ if (ownSpec) {
281
+ if (endpoints > 0) {
282
+ this.notes.add('endpoint-selection', [...trail, 'pages'], 'Groups that listed individual API endpoints now generate a page for every endpoint in their OpenAPI spec - writedocs has no per-endpoint selection.', 'To show only some endpoints, split the spec, or write those pages by hand with `openapi: "METHOD /path"` frontmatter.');
283
+ }
284
+ if (pages.length === 0 && !g.root) return this.openapiGroup(g.group, ownSpec);
285
+ pages.push(this.openapiGroup('Endpoints', ownSpec));
286
+ } else if (endpoints > 0) {
287
+ this.notes.add('endpoint-no-spec', [...trail, 'pages'], 'API endpoints listed without a usable OpenAPI spec were left out.', 'Add an `openapi` group with a spec file in the project.');
288
+ }
289
+ }
290
+ if (pages.length === 0 && !g.root) {
291
+ this.notes.add('empty:group', trail, 'A group with no pages was left out.');
292
+ return null;
293
+ }
294
+ const out = { group: g.group };
295
+ if (g.root) out.page = pagePath(g.root);
296
+ out.pages = pages;
297
+ return out;
298
+ }
299
+ }
300
+
301
+ function convertNavigation(nav, notes, topbarLinks, defaultSpec) {
302
+ const trail = ['navigation'];
303
+ const conv = new NavConverter(notes, defaultSpec);
304
+ if (Array.isArray(nav)) {
305
+ notes.add('legacy-navigation', trail, 'docs.json navigation is an array - that is the older mint.json shape.', 'Run `npx mint upgrade` in the Mintlify project first, then convert again.');
306
+ return { navigation: [], api: conv };
307
+ }
308
+ const children = nav ? conv.children(nav, trail, defaultSpec) : null;
309
+ let navigation = children ?? { pages: [] };
310
+ if (!children) notes.add('empty-navigation', trail, 'No navigation could be converted.');
311
+
312
+ // `global` links: writedocs' global dropdowns are its equivalent of
313
+ // Mintlify's global anchors (config-schema.ts), but they only exist
314
+ // alongside a root division, not a plain page list - there they become
315
+ // topbar links instead.
316
+ const globalLinks = [];
317
+ const g = nav?.global ?? {};
318
+ for (const [key, nameKey] of [['anchors', 'anchor'], ['tabs', 'tab'], ['dropdowns', 'dropdown'], ['products', 'product']]) {
319
+ (g[key] ?? []).forEach((item, i) => {
320
+ if (item.hidden) return;
321
+ if (typeof item.href !== 'string') {
322
+ notes.add('global-no-href', ['navigation', 'global', key, i], 'Global navigation items without an `href` were left out.');
323
+ return;
324
+ }
325
+ globalLinks.push({ label: item[nameKey], href: item.href, icon: item.icon });
326
+ });
327
+ }
328
+ for (const key of ['languages', 'versions']) {
329
+ if (g[key]?.length) notes.add(`global-${key}`, ['navigation', 'global', key], `Global ${key} (links to other sites) aren't supported - left out.`);
330
+ }
331
+ if (children?.pages) {
332
+ navigation = children.pages;
333
+ for (const link of globalLinks) topbarLinks.push(link.icon ? link : { label: link.label, href: link.href });
334
+ if (globalLinks.length) {
335
+ notes.add('global-to-topbar', ['navigation', 'global'], 'Global anchors became topbar links - writedocs only has global dropdowns alongside tabs, versions, languages, dropdowns or products.');
336
+ }
337
+ } else if (globalLinks.length) {
338
+ navigation = {
339
+ global: { dropdowns: globalLinks.map((l) => ({ dropdown: l.label, ...(l.icon ? { icon: l.icon } : {}), href: l.href })) },
340
+ ...navigation,
341
+ };
342
+ }
343
+ return { navigation, api: conv };
344
+ }
345
+
346
+ // ---------------------------------------------------------------------
347
+ // Everything else
348
+ // ---------------------------------------------------------------------
349
+
350
+ const SOCIAL_ICONS = { x: 'x-twitter', website: 'globe' };
351
+
352
+ function lightDark(value) {
353
+ if (typeof value === 'string') return { light: value, dark: value };
354
+ if (value && typeof value === 'object') return { light: value.light, dark: value.dark };
355
+ return null;
356
+ }
357
+
358
+ /**
359
+ * Mintlify docs.json (with `$ref`s already resolved) -> { config, notes }.
360
+ * `config` is a writedocs.json object; `notes` is a list of
361
+ * { where: string[], message, suggestion? }.
362
+ */
363
+ export function convertMintlifyConfig(docs) {
364
+ const notes = new Notes();
365
+ const out = { name: docs.name ?? 'Documentation' };
366
+ if (!docs.name) notes.add('name', ['name'], 'docs.json has no `name` - used "Documentation".');
367
+ if (docs.description) out.description = docs.description;
368
+
369
+ // styles
370
+ const styles = {};
371
+ const colors = {};
372
+ if (docs.colors?.primary) colors.primary = docs.colors.primary;
373
+ if (docs.colors?.light) colors.dark = { primary: docs.colors.light };
374
+ if (docs.colors?.dark) notes.add('colors.dark', ['colors', 'dark'], '`colors.dark` (buttons and hover states) has no writedocs equivalent - dropped.', 'writedocs uses `colors.primary` for those.');
375
+ if (Object.keys(colors).length) styles.colors = colors;
376
+ if (typeof docs.logo === 'string') styles.logo = docs.logo;
377
+ else if (docs.logo && typeof docs.logo === 'object') {
378
+ styles.logo = {};
379
+ if (docs.logo.light) styles.logo.light = docs.logo.light;
380
+ if (docs.logo.dark) styles.logo.dark = docs.logo.dark;
381
+ if (docs.logo.href) notes.add('logo.href', ['logo', 'href'], '`logo.href` isn\'t supported - the logo always links to the home page.');
382
+ }
383
+ if (typeof docs.favicon === 'string') styles.favicon = docs.favicon;
384
+ else if (docs.favicon?.light) {
385
+ styles.favicon = docs.favicon.light;
386
+ if (docs.favicon.dark) notes.add('favicon.dark', ['favicon', 'dark'], 'writedocs has one favicon - used `favicon.light`, dropped `favicon.dark`.');
387
+ }
388
+ if (docs.fonts && typeof docs.fonts === 'object') {
389
+ const font = (f) => {
390
+ const o = { family: f.family };
391
+ for (const k of ['weight', 'source', 'format']) if (f[k] !== undefined) o[k] = f[k];
392
+ return o;
393
+ };
394
+ if (docs.fonts.family) {
395
+ styles.fonts = font(docs.fonts);
396
+ if (docs.fonts.heading?.family) styles.fonts.heading = font(docs.fonts.heading);
397
+ if (docs.fonts.body?.family) styles.fonts.body = font(docs.fonts.body);
398
+ } else if (docs.fonts.body?.family || docs.fonts.heading?.family) {
399
+ styles.fonts = font(docs.fonts.body ?? docs.fonts.heading);
400
+ if (docs.fonts.heading?.family && docs.fonts.body?.family) styles.fonts.heading = font(docs.fonts.heading);
401
+ }
402
+ }
403
+ const cb = docs.styling?.codeblocks;
404
+ if (cb !== undefined && cb !== 'system') {
405
+ const theme = typeof cb === 'string' ? cb : cb?.theme;
406
+ if (theme === 'dark') styles.codeblocks = { light: 'github-dark', dark: 'github-dark' };
407
+ else if (typeof theme === 'string') styles.codeblocks = { light: theme, dark: theme };
408
+ else if (theme && typeof theme === 'object') styles.codeblocks = { light: theme.light, dark: theme.dark };
409
+ if (cb?.languages) notes.add('codeblock-languages', ['styling', 'codeblocks', 'languages'], 'Custom code block languages aren\'t supported - dropped.');
410
+ }
411
+ const bg = docs.background;
412
+ if (bg) {
413
+ const background = {};
414
+ const c = lightDark(bg.color);
415
+ if (c) background.colors = c;
416
+ const img = lightDark(bg.image);
417
+ if (img) background.images = img;
418
+ if (Object.keys(background).length) styles.background = background;
419
+ if (bg.decoration) notes.add('background.decoration', ['background', 'decoration'], `\`background.decoration\` ("${bg.decoration}") isn't supported - dropped.`);
420
+ }
421
+ if (Object.keys(styles).length) out.styles = styles;
422
+
423
+ // navigation (also collects topbar links from `global`)
424
+ const topbarLinks = [];
425
+ const defaultSpec = docs.api?.openapi;
426
+ const navNotesSpec = defaultSpec !== undefined ? new NavConverter(notes).spec(defaultSpec, ['api', 'openapi']) : null;
427
+ const { navigation } = convertNavigation(docs.navigation, notes, topbarLinks, navNotesSpec);
428
+ out.navigation = navigation;
429
+
430
+ // topbar
431
+ const navbar = docs.navbar ?? {};
432
+ const linkFor = (l) => {
433
+ if (l.type === 'github' || l.type === 'discord') {
434
+ return { label: l.label ?? (l.type === 'github' ? 'GitHub' : 'Discord'), href: l.href, icon: l.type };
435
+ }
436
+ const link = { label: l.label, href: l.href };
437
+ if (typeof l.icon === 'string') link.icon = l.icon;
438
+ return link;
439
+ };
440
+ for (const l of navbar.links ?? []) if (l?.href && (l.label || l.type || l.icon)) topbarLinks.push(linkFor(l));
441
+ if (navbar.primary?.href) {
442
+ topbarLinks.push(linkFor(navbar.primary));
443
+ notes.add('navbar.primary', ['navbar', 'primary'], 'The navbar\'s primary button became a regular topbar link - writedocs has no call-to-action button style.');
444
+ }
445
+ if (topbarLinks.length) out.topbar = { links: topbarLinks };
446
+
447
+ // footer + socials
448
+ const socials = docs.footer?.socials;
449
+ if (socials && typeof socials === 'object') {
450
+ out.socials = {};
451
+ for (const [key, url] of Object.entries(socials)) {
452
+ const icon = iconExists(key) && !SOCIAL_ICONS[key] ? key : SOCIAL_ICONS[key] ?? key;
453
+ if (!iconExists(icon)) notes.add(`social:${key}`, ['footer', 'socials', key], `No icon for the "${key}" social link - it shows without one.`);
454
+ out.socials[icon] = url;
455
+ }
456
+ }
457
+ if (Array.isArray(docs.footer?.links) && docs.footer.links.length) {
458
+ out.footer = {
459
+ columns: docs.footer.links.map((col) => ({
460
+ ...(col.header ? { title: col.header } : {}),
461
+ links: (col.items ?? []).filter((i) => i?.href && i.label).map((i) => ({ label: i.label, href: i.href })),
462
+ })),
463
+ };
464
+ }
465
+
466
+ // banner
467
+ if (docs.banner?.content) {
468
+ out.banner = { content: docs.banner.content };
469
+ if (docs.banner.dismissible) out.banner.dismissible = true;
470
+ if (['info', 'warning', 'critical'].includes(docs.banner.type)) out.banner.type = docs.banner.type;
471
+ if (docs.banner.color) notes.add('banner.color', ['banner', 'color'], '`banner.color` isn\'t supported - the banner uses its `type`\'s color.');
472
+ }
473
+
474
+ // 404
475
+ const e404 = docs.errors?.['404'];
476
+ if (e404?.title || e404?.description) {
477
+ out.notFound = {};
478
+ if (e404.title) out.notFound.title = e404.title;
479
+ if (e404.description) out.notFound.description = e404.description;
480
+ }
481
+ if (e404 && e404.redirect !== false) {
482
+ notes.add('404-redirect', ['errors', '404', 'redirect'], 'Mintlify redirects a missing page to the home page; writedocs shows a 404 page instead.');
483
+ }
484
+
485
+ // redirects
486
+ if (Array.isArray(docs.redirects) && docs.redirects.length) {
487
+ // Mintlify redirects can match a path pattern (`/old/:slug`, `/old/*`);
488
+ // writedocs redirects are exact paths - a pattern would become a
489
+ // literal page path (and `:` can't even be a folder name on Windows).
490
+ const isPattern = (p) => /(^|\/):[A-Za-z_]|\*/.test(p);
491
+ const patterns = docs.redirects.filter((r) => r?.source && r?.destination && (isPattern(r.source) || isPattern(r.destination)));
492
+ out.redirects = docs.redirects
493
+ .filter((r) => r?.source && r?.destination && !patterns.includes(r))
494
+ .map((r) => ({ source: r.source, destination: r.destination }));
495
+ if (out.redirects.length === 0) delete out.redirects;
496
+ if (patterns.length) {
497
+ const examples = patterns.slice(0, 2).map((r) => `${r.source} -> ${r.destination}`).join('; ');
498
+ notes.add('redirect-patterns', ['redirects'], `${patterns.length} redirect${patterns.length === 1 ? '' : 's'} with a path parameter or wildcard (e.g. ${examples}) ${patterns.length === 1 ? 'was' : 'were'} left out - writedocs redirects match one exact path.`, 'Add an exact redirect for each old page that still gets traffic.');
499
+ }
500
+ if (docs.redirects.some((r) => r?.permanent === false)) {
501
+ notes.add('redirect-permanent', ['redirects'], '`permanent: false` on redirects has no effect - every writedocs redirect is the same kind.');
502
+ }
503
+ }
504
+
505
+ // variables
506
+ if (docs.variables && typeof docs.variables === 'object' && Object.keys(docs.variables).length) {
507
+ out.variables = { ...docs.variables };
508
+ const hyphenated = Object.keys(docs.variables).filter((k) => k.includes('-'));
509
+ if (hyphenated.length) {
510
+ notes.add('variables-hyphen', ['variables'], `Variables with a hyphen (${hyphenated.join(', ')}) can't be written as {{name}} in writedocs pages.`, 'Write them as [[name]] in your pages instead.');
511
+ }
512
+ }
513
+
514
+ // SEO
515
+ const meta = docs.seo?.metatags ?? {};
516
+ const seo = {};
517
+ const ignoredMeta = [];
518
+ for (const [k, v] of Object.entries(meta)) {
519
+ if (k === 'og:image') seo.ogImage = v;
520
+ else if (k === 'og:type') seo.ogType = v;
521
+ else if (k === 'twitter:card' && ['summary', 'summary_large_image'].includes(v)) seo.twitterCard = v;
522
+ else if (k === 'keywords') seo.keywords = String(v).split(',').map((s) => s.trim()).filter(Boolean);
523
+ else if (k === 'robots') seo.robots = String(v);
524
+ // The site's address for canonical URLs is writedocs' `domain`.
525
+ else if (k === 'canonical') ignoredMeta.push(k);
526
+ else (seo.metatags ??= {})[k] = String(v);
527
+ }
528
+ if (Object.keys(seo).length) out.seo = seo;
529
+ if (ignoredMeta.length) {
530
+ notes.add('metatags', ['seo', 'metatags'], 'The `canonical` meta tag was dropped: writedocs builds the canonical URL of every page from `domain`.', 'Set "domain" to the address of the site; a single page can set its own with `seo.canonical` in its frontmatter.');
531
+ }
532
+ if (docs.seo?.indexing === 'all') notes.add('seo.indexing', ['seo', 'indexing'], '`seo.indexing: "all"` has no equivalent - writedocs indexes every page that isn\'t marked noindex.');
533
+
534
+ // context menu
535
+ // Mintlify's option names are writedocs' own for the eight both have, so
536
+ // the list carries over as is. No `contextual` leaves the field out - the
537
+ // menu is on by default, with every option.
538
+ const options = docs.contextual?.options;
539
+ if (Array.isArray(options) && options.length) {
540
+ const known = ['copy', 'view', 'chatgpt', 'claude', 'perplexity', 'mcp', 'cursor', 'vscode'];
541
+ out.contextMenu = known.filter((o) => options.includes(o));
542
+ const other = options.filter((o) => typeof o !== 'string' || !known.includes(o));
543
+ if (other.length) {
544
+ notes.add('contextual', ['contextual', 'options'], `Context menu options writedocs doesn't have were dropped: ${other.map((o) => (typeof o === 'string' ? o : o.title ?? 'custom')).join(', ')}.`, 'writedocs\' page menu offers copy, view as Markdown, open in ChatGPT, Claude and Perplexity, and the MCP server: copy its URL, connect to Cursor or VS Code.');
545
+ }
546
+ }
547
+
548
+ // API playground
549
+ if (docs.api?.playground?.proxy === false) out.api = { proxy: false };
550
+ if (docs.api?.playground?.display && docs.api.playground.display !== 'interactive') {
551
+ notes.add('api.playground.display', ['api', 'playground', 'display'], `\`api.playground.display: "${docs.api.playground.display}"\` isn't supported - the playground is always interactive.`);
552
+ }
553
+ for (const key of ['params', 'url', 'examples', 'mdx', 'asyncapi']) {
554
+ if (docs.api?.[key] !== undefined) notes.add(`api.${key}`, ['api', key], `\`api.${key}\` has no writedocs equivalent - dropped.`);
555
+ }
556
+
557
+ // integrations
558
+ const integrations = {};
559
+ const ig = docs.integrations ?? {};
560
+ if (ig.ga4?.measurementId) integrations.ga4 = { measurementId: ig.ga4.measurementId };
561
+ if (ig.gtm?.tagId) integrations.googleTagManager = { containerId: ig.gtm.tagId };
562
+ if (ig.plausible?.domain) {
563
+ integrations.plausible = { domain: ig.plausible.domain };
564
+ if (ig.plausible.server) integrations.plausible.src = `${ig.plausible.server.replace(/\/+$/, '')}/js/script.js`;
565
+ }
566
+ if (ig.fathom?.siteId) integrations.fathom = { siteId: ig.fathom.siteId };
567
+ if (ig.posthog?.apiKey) {
568
+ integrations.posthog = { apiKey: ig.posthog.apiKey };
569
+ if (ig.posthog.apiHost) integrations.posthog.apiHost = ig.posthog.apiHost;
570
+ }
571
+ if (Object.keys(integrations).length) out.integrations = integrations;
572
+ const otherIntegrations = Object.keys(ig).filter((k) => !['ga4', 'gtm', 'plausible', 'fathom', 'posthog', 'telemetry', 'cookies'].includes(k));
573
+ if (otherIntegrations.length) {
574
+ notes.add('integrations', ['integrations'], `These integrations have no writedocs equivalent and were dropped: ${otherIntegrations.join(', ')}.`, 'Most can be added as a custom script in writedocs.json\'s `scripts.head`.');
575
+ }
576
+
577
+ // Settings with no equivalent at all
578
+ const unsupported = {
579
+ appearance: 'Light/dark mode defaults (`appearance`) aren\'t configurable - readers choose with the theme toggle.',
580
+ interaction: '`interaction` settings aren\'t supported.',
581
+ thumbnails: 'Social thumbnails (`thumbnails`) aren\'t generated - set `seo.ogImage` for a social preview image.',
582
+ metadata: '`metadata` (last-modified timestamps) isn\'t supported.',
583
+ markdown: '`markdown` export settings aren\'t supported.',
584
+ search: '`search` settings aren\'t supported.',
585
+ };
586
+ for (const [key, message] of Object.entries(unsupported)) if (docs[key] !== undefined) notes.add(key, [key], message);
587
+ if (docs.styling?.eyebrows) notes.add('styling.eyebrows', ['styling', 'eyebrows'], '`styling.eyebrows` isn\'t supported - writedocs shows breadcrumbs.');
588
+ if (docs.icons?.library === 'tabler') {
589
+ notes.add('icons.library', ['icons', 'library'], 'Icon names are looked up in Lucide, then Font Awesome - not Tabler.', 'Tabler names that don\'t exist there can be written as "tabler:name".');
590
+ }
591
+
592
+ return { config: out, notes: notes.list() };
593
+ }
594
+
595
+ /** Formats notes for the terminal - same layout as `writedocs validate`. */
596
+ export function formatNotes(notes) {
597
+ return notes
598
+ .map((n) => {
599
+ const where = n.where.length > 3 ? `${n.where.slice(0, 3).join(', ')} and ${n.where.length - 3} more` : n.where.join(', ');
600
+ const lines = [` ${where}`, ` ${n.message}`];
601
+ if (n.suggestion) lines.push(` ${n.suggestion}`);
602
+ return lines.join('\n');
603
+ })
604
+ .join('\n\n');
605
+ }