@writedocs/generator 0.14.0 → 0.16.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 (120) hide show
  1. package/astro.config.mjs +31 -69
  2. package/package.json +4 -2
  3. package/packages/components/package.json +53 -0
  4. package/{src → packages/components/src}/components/Accordion.astro +2 -2
  5. package/{src → packages/components/src}/components/AppIcon.astro +3 -3
  6. package/{src → packages/components/src}/components/Callout.astro +3 -3
  7. package/{src → packages/components/src}/components/CodeBlock.astro +8 -27
  8. package/{src → packages/components/src}/components/CodeGroup.astro +9 -9
  9. package/{src → packages/components/src}/components/Image.astro +7 -9
  10. package/{src → packages/components/src}/components/compound.ts +1 -1
  11. package/packages/components/src/host.js +24 -0
  12. package/packages/components/src/index.ts +59 -0
  13. package/packages/components/src/integration.js +151 -0
  14. package/packages/components/src/lib/base-path.js +39 -0
  15. package/{src → packages/components/src}/lib/code-line-numbers.js +1 -1
  16. package/packages/components/src/lib/code-transformers.js +45 -0
  17. package/{src → packages/components/src}/lib/icons.js +13 -7
  18. package/{src → packages/components/src}/lib/shiki-code-block.js +9 -9
  19. package/{src → packages/components/src}/lib/site-base.ts +9 -6
  20. package/packages/components/src/scripts/code-block.ts +62 -0
  21. package/packages/components/src/styles/components.css +373 -0
  22. package/packages/components/src/styles/theme.css +63 -0
  23. package/src/cli/build.js +1 -1
  24. package/src/cli/rewrite-redirect-pages.js +8 -6
  25. package/src/cli/run-astro.js +1 -1
  26. package/src/cli/write-mcp-files.js +4 -1
  27. package/src/cli/write-redirects-file.js +4 -3
  28. package/src/components/ApiPlayground.astro +2 -2
  29. package/src/components/ApiSchemaField.astro +1 -1
  30. package/src/components/CopyPageMenu.astro +2 -2
  31. package/src/content.config.ts +21 -1
  32. package/src/icons/README.md +1 -1
  33. package/src/layout/BaseLayout.astro +45 -51
  34. package/src/layout/components/AnalyticsScripts.astro +2 -2
  35. package/src/layout/components/Breadcrumbs.astro +1 -1
  36. package/src/layout/components/ConsentBanner.astro +1 -1
  37. package/src/layout/components/MobileMenu.astro +11 -7
  38. package/src/layout/components/NavTree.astro +2 -2
  39. package/src/layout/components/Sidebar.astro +2 -2
  40. package/src/layout/components/SiteFooter.astro +2 -2
  41. package/src/layout/components/TopBar.astro +10 -6
  42. package/src/layout/styles/base.css +4 -37
  43. package/src/lib/a11y-check.js +1 -1
  44. package/src/lib/appearance.js +64 -0
  45. package/src/lib/asset-dimensions.js +2 -1
  46. package/src/lib/base-path.js +4 -25
  47. package/src/lib/bom.js +20 -0
  48. package/src/lib/color.js +1 -1
  49. package/src/lib/components-host.ts +21 -0
  50. package/src/lib/config-file.js +21 -8
  51. package/src/lib/config-schema.js +14 -7
  52. package/src/lib/config-schema.ts +19 -12
  53. package/src/lib/config.ts +4 -3
  54. package/src/lib/content-check.js +38 -3
  55. package/src/lib/content-store-prune.js +44 -0
  56. package/src/lib/json-schema-descriptions.js +4 -1
  57. package/src/lib/link-check.js +2 -2
  58. package/src/lib/mdx-inject-builtins.js +2 -2
  59. package/src/lib/mdx-inline-react.js +1 -1
  60. package/src/lib/mdx-title-anchor-ids.js +2 -2
  61. package/src/lib/mdx-unknown-components.js +1 -1
  62. package/src/lib/mintlify-convert.js +13 -3
  63. package/src/lib/openapi-reload-integration.js +1 -1
  64. package/src/lib/pages.js +6 -4
  65. package/src/lib/project-files-integration.js +1 -1
  66. package/src/lib/rehype-base-path.js +1 -1
  67. package/src/lib/wdignore-cases.json +9 -2
  68. package/src/lib/wdignore.js +5 -0
  69. package/src/lib/writedocs-legacy-convert.js +2 -2
  70. package/src/pages/404.astro +1 -1
  71. package/src/pages/[...slug].astro +53 -416
  72. package/src/pages/llms-full.txt.ts +6 -3
  73. package/src/pages/llms.txt.ts +4 -4
  74. package/writedocs.schema.json +23 -0
  75. package/src/components/index.ts +0 -62
  76. /package/{src → packages/components/src}/components/AccordionGroup.astro +0 -0
  77. /package/{src → packages/components/src}/components/Badge.astro +0 -0
  78. /package/{src → packages/components/src}/components/Card.astro +0 -0
  79. /package/{src → packages/components/src}/components/CardGroup.astro +0 -0
  80. /package/{src → packages/components/src}/components/Check.astro +0 -0
  81. /package/{src → packages/components/src}/components/Color.astro +0 -0
  82. /package/{src → packages/components/src}/components/ColorItem.astro +0 -0
  83. /package/{src → packages/components/src}/components/ColorRow.astro +0 -0
  84. /package/{src → packages/components/src}/components/Column.astro +0 -0
  85. /package/{src → packages/components/src}/components/Columns.astro +0 -0
  86. /package/{src → packages/components/src}/components/Danger.astro +0 -0
  87. /package/{src → packages/components/src}/components/Expandable.astro +0 -0
  88. /package/{src → packages/components/src}/components/Frame.astro +0 -0
  89. /package/{src → packages/components/src}/components/GitHubRepo.astro +0 -0
  90. /package/{src → packages/components/src}/components/Hint.astro +0 -0
  91. /package/{src → packages/components/src}/components/Icon.astro +0 -0
  92. /package/{src → packages/components/src}/components/Info.astro +0 -0
  93. /package/{src → packages/components/src}/components/Note.astro +0 -0
  94. /package/{src → packages/components/src}/components/Panel.astro +0 -0
  95. /package/{src → packages/components/src}/components/ParamField.astro +0 -0
  96. /package/{src → packages/components/src}/components/Parameter.astro +0 -0
  97. /package/{src → packages/components/src}/components/Prompt.astro +0 -0
  98. /package/{src → packages/components/src}/components/RequestExample.astro +0 -0
  99. /package/{src → packages/components/src}/components/ResponseExample.astro +0 -0
  100. /package/{src → packages/components/src}/components/ResponseField.astro +0 -0
  101. /package/{src → packages/components/src}/components/Searchbar.astro +0 -0
  102. /package/{src → packages/components/src}/components/Step.astro +0 -0
  103. /package/{src → packages/components/src}/components/Steps.astro +0 -0
  104. /package/{src → packages/components/src}/components/Tab.astro +0 -0
  105. /package/{src → packages/components/src}/components/Tabs.astro +0 -0
  106. /package/{src → packages/components/src}/components/Tile.astro +0 -0
  107. /package/{src → packages/components/src}/components/Tip.astro +0 -0
  108. /package/{src → packages/components/src}/components/Tooltip.astro +0 -0
  109. /package/{src → packages/components/src}/components/Tree.astro +0 -0
  110. /package/{src → packages/components/src}/components/TreeFile.astro +0 -0
  111. /package/{src → packages/components/src}/components/TreeFolder.astro +0 -0
  112. /package/{src → packages/components/src}/components/Update.astro +0 -0
  113. /package/{src → packages/components/src}/components/Video.astro +0 -0
  114. /package/{src → packages/components/src}/components/View.astro +0 -0
  115. /package/{src → packages/components/src}/components/Visibility.astro +0 -0
  116. /package/{src → packages/components/src}/components/Warning.astro +0 -0
  117. /package/{src → packages/components/src}/components/class-names.ts +0 -0
  118. /package/{src → packages/components/src}/lib/cli-report.js +0 -0
  119. /package/{src → packages/components/src}/lib/inline-markdown.js +0 -0
  120. /package/{src → packages/components/src}/lib/plain-text.js +0 -0
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { findNodeAtLocation, parseTree, visit } from "jsonc-parser";
3
3
  import { BASE_PATH_FIELD_PATTERN } from "./base-path.js";
4
+ import { stripBom } from "./bom.js";
4
5
  const navPageSchema = z.string();
5
6
  const navGroupPagesSchema = z.lazy(
6
7
  () => z.object({
@@ -270,6 +271,15 @@ const stylesSchema = z.object({
270
271
  light: z.string().optional(),
271
272
  dark: z.string().optional()
272
273
  }).strict().optional()
274
+ }).strict().optional(),
275
+ // Which color mode a page opens in (`default`: the reader's OS setting,
276
+ // or always light/dark) and whether readers can switch (`strict` hides
277
+ // the theme toggle). Same shape as Mintlify's top-level `appearance`.
278
+ // Both fields optional here: resolveAppearance() (src/lib/appearance.js)
279
+ // fills in "system"/false, and is what everything reads it through.
280
+ appearance: z.object({
281
+ default: z.enum(["system", "light", "dark"]).optional(),
282
+ strict: z.boolean().optional()
273
283
  }).strict().optional()
274
284
  }).default({ colors: { primary: DEFAULT_PRIMARY } });
275
285
  const topbarLinkSchema = z.object({
@@ -1082,7 +1092,7 @@ instalarCorte(
1082
1092
  /* @__PURE__ */ new Set([navGroupPagesSchema._zod.innerType, navGroupOpenApiSchema, navLinkSchema])
1083
1093
  );
1084
1094
  function localizarCaminhos(rawText, caminhos) {
1085
- rawText = semBom(rawText);
1095
+ rawText = stripBom(rawText);
1086
1096
  const raiz = { filhos: /* @__PURE__ */ new Map(), alvo: false };
1087
1097
  for (const caminho of caminhos) {
1088
1098
  if (caminho.length === 0) continue;
@@ -1145,7 +1155,7 @@ function createJsonLocator(rawText) {
1145
1155
  return criarLocalizador(rawText);
1146
1156
  }
1147
1157
  function criarLocalizador(rawText) {
1148
- rawText = semBom(rawText);
1158
+ rawText = stripBom(rawText);
1149
1159
  let arvore = null;
1150
1160
  let inicios;
1151
1161
  return (caminho) => {
@@ -1286,7 +1296,7 @@ function unknownRootKeyIssues(rawText) {
1286
1296
  return unknownRootKeyWarnings(rawText).issues;
1287
1297
  }
1288
1298
  function unknownRootKeyWarnings(rawText, { all = false } = {}) {
1289
- rawText = semBom(rawText);
1299
+ rawText = stripBom(rawText);
1290
1300
  let raiz;
1291
1301
  try {
1292
1302
  raiz = JSON.parse(rawText);
@@ -1318,11 +1328,8 @@ function unknownRootKeyWarnings(rawText, { all = false } = {}) {
1318
1328
  });
1319
1329
  return { issues, issuesTotal: desconhecidas.length };
1320
1330
  }
1321
- function semBom(texto) {
1322
- return texto.charCodeAt(0) === 65279 ? texto.slice(1) : texto;
1323
- }
1324
1331
  function validateDocsConfig(rawText, { all = false } = {}) {
1325
- rawText = semBom(rawText);
1332
+ rawText = stripBom(rawText);
1326
1333
  let raw;
1327
1334
  try {
1328
1335
  raw = JSON.parse(rawText);
@@ -36,6 +36,9 @@ import { z } from 'zod';
36
36
  import { findNodeAtLocation, parseTree, visit } from 'jsonc-parser';
37
37
  // The form of `basePath`. Plain JS with no `node:` import, like this file.
38
38
  import { BASE_PATH_FIELD_PATTERN } from './base-path.js';
39
+ // A leading UTF-8 byte order mark off the text - the one copy, lib/bom.js.
40
+ // Plain JS with no `node:` import too.
41
+ import { stripBom } from './bom.js';
39
42
 
40
43
  // ---------------------------------------------------------------------
41
44
  // Pages & groups - the leaf content any container ultimately bottoms out
@@ -551,6 +554,18 @@ const stylesSchema = z
551
554
  })
552
555
  .strict()
553
556
  .optional(),
557
+ // Which color mode a page opens in (`default`: the reader's OS setting,
558
+ // or always light/dark) and whether readers can switch (`strict` hides
559
+ // the theme toggle). Same shape as Mintlify's top-level `appearance`.
560
+ // Both fields optional here: resolveAppearance() (src/lib/appearance.js)
561
+ // fills in "system"/false, and is what everything reads it through.
562
+ appearance: z
563
+ .object({
564
+ default: z.enum(['system', 'light', 'dark']).optional(),
565
+ strict: z.boolean().optional(),
566
+ })
567
+ .strict()
568
+ .optional(),
554
569
  })
555
570
  .default({ colors: { primary: DEFAULT_PRIMARY } });
556
571
 
@@ -2066,7 +2081,7 @@ instalarCorte(
2066
2081
  * findNodeAtLocation), inclusive com chave repetida num objeto, onde vale a
2067
2082
  * primeira; o que nao leva a nenhum caminho pedido e pulado sem callbacks. */
2068
2083
  function localizarCaminhos(rawText: string, caminhos: (string | number)[][]): (caminho: (string | number)[]) => { line: number; column: number } | null {
2069
- rawText = semBom(rawText);
2084
+ rawText = stripBom(rawText);
2070
2085
  type No = { filhos: Map<string | number, No>; alvo: boolean; offset?: number };
2071
2086
  const raiz: No = { filhos: new Map(), alvo: false };
2072
2087
  for (const caminho of caminhos) {
@@ -2150,7 +2165,7 @@ export function createJsonLocator(rawText: string): (path: (string | number)[])
2150
2165
  * '\n' (um `\r\n` e um '\n' com o '\r' no fim da linha anterior), e a coluna e
2151
2166
  * em unidades UTF-16, como o offset do jsonc-parser - um emoji conta 2. */
2152
2167
  function criarLocalizador(rawText: string): (caminho: (string | number)[]) => { line: number; column: number } | null {
2153
- rawText = semBom(rawText);
2168
+ rawText = stripBom(rawText);
2154
2169
  let arvore: ReturnType<typeof parseTree> | undefined | null = null;
2155
2170
  let inicios: number[] | undefined;
2156
2171
  return (caminho) => {
@@ -2356,7 +2371,7 @@ export function unknownRootKeyWarnings(
2356
2371
  rawText: string,
2357
2372
  { all = false }: ValidationOptions = {}
2358
2373
  ): { issues: ValidationIssue[]; issuesTotal: number } {
2359
- rawText = semBom(rawText);
2374
+ rawText = stripBom(rawText);
2360
2375
  let raiz: unknown;
2361
2376
  try {
2362
2377
  raiz = JSON.parse(rawText);
@@ -2390,16 +2405,8 @@ export function unknownRootKeyWarnings(
2390
2405
  return { issues, issuesTotal: desconhecidas.length };
2391
2406
  }
2392
2407
 
2393
- /** Texto sem o BOM do UTF-8 no inicio. Editores do Windows (Bloco de Notas, o
2394
- * `Out-File` do PowerShell 5.1) gravam um, e o JSON.parse o rejeita com uma
2395
- * mensagem que culpa virgulas e colchetes. Copia local, e nao import de
2396
- * lib/config-file.js: este modulo so importa zod e jsonc-parser (ver o topo). */
2397
- function semBom(texto: string): string {
2398
- return texto.charCodeAt(0) === 0xfeff ? texto.slice(1) : texto;
2399
- }
2400
-
2401
2408
  export function validateDocsConfig(rawText: string, { all = false }: ValidationOptions = {}): ValidationResult {
2402
- rawText = semBom(rawText);
2409
+ rawText = stripBom(rawText);
2403
2410
  let raw: unknown;
2404
2411
  try {
2405
2412
  raw = JSON.parse(rawText);
package/src/lib/config.ts CHANGED
@@ -289,9 +289,10 @@ export type IconResolution =
289
289
  | { kind: 'image'; src: string } // an image URL or site path, rendered as <img>
290
290
  | { kind: 'text'; value: string }; // literal text/emoji, rendered as-is
291
291
 
292
- // The implementation lives in lib/icons.js - plain JavaScript, because
293
- // `writedocs validate` loads it with plain Node (see that file's comment).
294
- export { resolveIcon, iconExists, iconSvg } from './icons.js';
292
+ // The implementation lives in the components package's lib/icons.js -
293
+ // plain JavaScript, because `writedocs validate` loads it with plain Node
294
+ // (see that file's comment).
295
+ export { resolveIcon, iconExists, iconSvg } from '../../packages/components/src/lib/icons.js';
295
296
 
296
297
  // ---------------------------------------------------------------------
297
298
  // OpenAPI navigation expansion - turns a group's `openapi: { src, path }`
@@ -1,7 +1,7 @@
1
1
  // `writedocs validate`'s content pass: everything in a site's pages that
2
2
  // would break the build or silently degrade it, found in one run instead of
3
3
  // one build failure at a time. Plain JavaScript, loaded by plain Node from
4
- // an installed package (see lib/icons.js's comment on why not TypeScript).
4
+ // an installed package (see packages/components/src/lib/icons.js's comment on why not TypeScript).
5
5
  //
6
6
  // Errors - the build would fail:
7
7
  // - a page's frontmatter doesn't match the page schema (the same
@@ -31,11 +31,13 @@ import path from 'node:path';
31
31
  import matter from 'gray-matter';
32
32
  import { visit } from 'unist-util-visit';
33
33
  import { findAllPages, fileIdForPath, titleFromPath, navPageId } from './pages.js';
34
- import { iconExists } from './icons.js';
34
+ import { projectIgnore } from './project-ignore.js';
35
+ import { iconExists } from '../../packages/components/src/lib/icons.js';
35
36
  import { findUnknownComponents } from './mdx-unknown-components.js';
36
37
  import { findInteractiveComponents, simplifiedBuiltinMessage } from './mdx-inline-react.js';
37
38
  import { pageFrontmatterSchema, createJsonLocator } from './config-schema.js';
38
39
  import { parseOpenApiRef } from './openapi-ref.js';
40
+ import { readText } from './config-file.js';
39
41
  import { collectOpenApiGroups, operationKeys } from './openapi-spec.js';
40
42
 
41
43
  /** An issue: { file, line?, message, suggestion? } - `file` relative to the
@@ -70,7 +72,9 @@ async function parseMdx(text) {
70
72
  }
71
73
 
72
74
  async function checkPage(contentDir, rel, errors, warnings, openapiRefs) {
73
- const raw = fs.readFileSync(path.join(contentDir, rel), 'utf-8').replace(/\r\n/g, '\n');
75
+ // Without a byte order mark, so the frontmatter's line numbers below are
76
+ // the same as in the same file without one (lib/bom.js).
77
+ const raw = readText(path.join(contentDir, rel)).replace(/\r\n/g, '\n');
74
78
  let parsed;
75
79
  try {
76
80
  // An options object bypasses gray-matter's cache, which keeps an empty
@@ -381,6 +385,22 @@ async function checkOpenApi(contentDir, config, locate, openapiRefs, errors, war
381
385
  * null when it isn't valid JSON (then only the pages themselves are
382
386
  * checked). Returns { pages, errors, warnings }.
383
387
  */
388
+ /** The file a navigation id names (`<id>.mdx`, `<id>.md`, or the same as a
389
+ * folder's index), when it exists but the project's ignore rules
390
+ * (projectIgnore() - the default exclusions and `.wdignore`) leave it out.
391
+ * Its project-relative path, or null. */
392
+ function ignoredPageFile(contentDir, id) {
393
+ const rules = projectIgnore(contentDir);
394
+ for (const rel of [`${id}.mdx`, `${id}.md`, `${id}/index.mdx`, `${id}/index.md`]) {
395
+ let isFile = false;
396
+ try {
397
+ isFile = fs.statSync(path.join(contentDir, rel)).isFile();
398
+ } catch {}
399
+ if (isFile && rules.ignores(rel)) return rel;
400
+ }
401
+ return null;
402
+ }
403
+
384
404
  export async function checkContent(contentDir, configText) {
385
405
  const errors = [];
386
406
  const warnings = [];
@@ -405,6 +425,21 @@ export async function checkContent(contentDir, configText) {
405
425
  for (const ref of navigationReferences(config.navigation)) {
406
426
  // "guides/index" and "guides" both name guides/index.mdx (navPageId()).
407
427
  if (ids.has(navPageId(ref.id))) continue;
428
+ // The file is there but an ignore rule leaves it out - README.md is a
429
+ // default exclusion (lib/wdignore.js), and a Mintlify project may list
430
+ // its README. "Create README.mdx" would send the author in circles.
431
+ const ignoredFile = ignoredPageFile(contentDir, ref.id);
432
+ if (ignoredFile) {
433
+ errors.push(
434
+ issue(
435
+ 'writedocs.json',
436
+ locate(ref.path)?.line,
437
+ `The navigation lists page "${ref.id}", but ${ignoredFile} is left out of the site by the ignore rules.`,
438
+ `Rename the file, or bring it back with a line "!${ignoredFile}" at the end of .wdignore.`
439
+ )
440
+ );
441
+ continue;
442
+ }
408
443
  errors.push(
409
444
  issue(
410
445
  'writedocs.json',
@@ -0,0 +1,44 @@
1
+ // Which entries of Astro's content store point at a file that's no longer
2
+ // one of the project's pages - so the content loaders (src/content.config.ts)
3
+ // can delete them before each sync.
4
+ //
5
+ // Why: Astro's glob() loader keeps a page's stored entry when one with the
6
+ // same id has the same digest - a hash of the file's text, not of where it
7
+ // is (astro/dist/content/loaders/glob.js, syncData()). A page with a `slug`
8
+ // in its frontmatter takes that slug as its id, so a page moved to another
9
+ // folder keeps its id and its text, and the store keeps its old `filePath`.
10
+ // The store is saved between runs (writedocsTempDir()'s cache/), so from
11
+ // then on:
12
+ // - `writedocs build` fails: content-modules.mjs, which Astro writes from
13
+ // the stored entries, imports the page from where it was;
14
+ // - `writedocs dev` fails on every page: writedocs reads a page's file id
15
+ // from its `filePath` (fileIdForEntry() in lib/config.ts), and the
16
+ // navigation names the page where it is now.
17
+ // Deleting the entry makes glob() read the page again, from its new path. A
18
+ // page without `slug` takes its id from its path, so moving it already
19
+ // makes a new entry - deleting is harmless there too.
20
+ //
21
+ // Plain JavaScript, so scripts/content-store-prune.test.js can run it.
22
+ import path from 'node:path';
23
+
24
+ // Windows paths aren't case-sensitive, and the same folder can reach here
25
+ // spelled two ways (lib/canonical-path.js).
26
+ const key = (p) => {
27
+ const resolved = path.resolve(p);
28
+ return process.platform === 'win32' ? resolved.toLowerCase() : resolved;
29
+ };
30
+
31
+ /** The ids of the stored entries whose file isn't one of `files`.
32
+ * `entries`: the store's [id, entry] pairs - an entry's `filePath` is
33
+ * relative to `root`, Astro's project root. `files`: the absolute paths of
34
+ * the pages the loader is about to sync. An entry with no `filePath` isn't
35
+ * a file's, and is left alone. */
36
+ export function staleEntryIds(entries, root, files) {
37
+ const current = new Set(files.map(key));
38
+ const stale = [];
39
+ for (const [id, entry] of entries) {
40
+ if (typeof entry?.filePath !== 'string' || entry.filePath === '') continue;
41
+ if (!current.has(key(path.resolve(root, entry.filePath)))) stale.push(id);
42
+ }
43
+ return stale;
44
+ }
@@ -125,7 +125,10 @@ export const DESCRIPTIONS = {
125
125
  'styles.navbar.dark.accent': 'Color of the underline under the active tab in the topbar, in dark mode.',
126
126
  'styles.background': 'Background color of the site, and an optional background image.',
127
127
  'styles.background.colors': 'Background colors.',
128
- 'styles.background.colors.light': 'Background color in light mode. Default "#ffffff".',
128
+ 'styles.appearance': 'Light and dark mode: which one pages open in, and whether readers can switch.',
129
+ 'styles.appearance.default': 'The mode pages open in: "system" follows the reader\'s device setting; "light" or "dark" always starts there. Default "system". A reader who picks a mode with the theme toggle keeps their choice.',
130
+ 'styles.appearance.strict': 'Hide the theme toggle, so every reader sees the `default` mode and can\'t switch. Default false.',
131
+ 'styles.background.colors.light':'Background color in light mode. Default "#ffffff".',
129
132
  'styles.background.colors.dark': 'Background color in dark mode. Default "#0b1120".',
130
133
  'styles.background.images': 'Background images, shown behind the content and sidebar.',
131
134
  'styles.background.images.light': 'Background image in light mode.',
@@ -1,7 +1,7 @@
1
1
  // `writedocs broken-links`: every internal link in the content - page
2
2
  // bodies, the snippets they import, and writedocs.json - checked against the
3
3
  // site the build would produce, without building it. Plain JavaScript,
4
- // loaded by plain Node from an installed package (see lib/icons.js's
4
+ // loaded by plain Node from an installed package (see packages/components/src/lib/icons.js's
5
5
  // comment on why not TypeScript).
6
6
  //
7
7
  // A link is broken when, on the built site:
@@ -30,7 +30,7 @@
30
30
  //
31
31
  // External links (http:, mailto:, ...) aren't checked.
32
32
  import fs from 'node:fs';
33
- import { estreeText } from './plain-text.js';
33
+ import { estreeText } from '../../packages/components/src/lib/plain-text.js';
34
34
  import path from 'node:path';
35
35
  import { createRequire } from 'node:module';
36
36
  import { pathToFileURL } from 'node:url';
@@ -3,7 +3,7 @@ import { parse as acornParse } from 'acorn';
3
3
 
4
4
  // The exact same set [...slug].astro passes as the `components` prop to
5
5
  // every page's own <Content components={components} /> call (see
6
- // src/components/index.ts, the barrel this imports from) - kept as one
6
+ // packages/components/src/index.ts, the barrel this imports from) - kept as one
7
7
  // literal list rather than importing that map here, since this runs inside
8
8
  // astro.config.mjs's markdown pipeline, a different module graph than
9
9
  // [...slug].astro's own.
@@ -58,7 +58,7 @@ const PACKAGE_SPECIFIER = 'writedocs/components';
58
58
  /**
59
59
  * A remark plugin that auto-imports any of Writedocs' built-in components
60
60
  * (`Callout`, `Card`, ...) a `.mdx` file uses but never itself imported -
61
- * from `writedocs/components` (see src/components/index.ts) - so a snippet
61
+ * from `writedocs/components` (see packages/components/src/index.ts) - so a snippet
62
62
  * (see docs/dev/docs/snippets.mdx) gets the exact same zero-import
63
63
  * experience a page under docs/ already has via [...slug].astro's own
64
64
  * `components` prop. Runs on every `.mdx` file, pages included - harmless
@@ -2,7 +2,7 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import crypto from 'node:crypto';
4
4
  import { parse as acornParse } from 'acorn';
5
- import { report } from './cli-report.js';
5
+ import { report } from '../../packages/components/src/lib/cli-report.js';
6
6
  import { writedocsTempDir } from './writedocs-temp-dir.js';
7
7
  import { MINTLIFY_HOOKS } from './mdx-mintlify.js';
8
8
  import { BUILTIN_COMPONENT_NAMES } from './mdx-inject-builtins.js';
@@ -1,5 +1,5 @@
1
1
  import { visit } from 'unist-util-visit';
2
- import { estreeText } from './plain-text.js';
2
+ import { estreeText } from '../../packages/components/src/lib/plain-text.js';
3
3
 
4
4
  // Every JSX tag name that can carry a `title` prop and render a linkable
5
5
  // heading of its own - the 6 Callout variants remarkInjectBuiltinComponents
@@ -20,7 +20,7 @@ const ANCHOR_ATTRIBUTE = { Update: 'label' };
20
20
  // rather than a shared import, since this file runs inside
21
21
  // astro.config.mjs's markdown pipeline, a different module graph than
22
22
  // either component's own (same reasoning mdx-inject-builtins.js gives for
23
- // not importing src/components/index.ts).
23
+ // not importing packages/components/src/index.ts).
24
24
  function slugify(value) {
25
25
  return value
26
26
  .toLowerCase()
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import { visit } from 'unist-util-visit';
3
3
  import { parse as acornParse } from 'acorn';
4
4
  import { BUILTIN_COMPONENT_NAMES } from './mdx-inject-builtins.js';
5
- import { report } from './cli-report.js';
5
+ import { report } from '../../packages/components/src/lib/cli-report.js';
6
6
 
7
7
  // Which JSX elements in an MDX file are components writedocs can't resolve
8
8
  // - neither a built-in nor something the file imports or defines itself.
@@ -1,6 +1,6 @@
1
1
  // Converts a Mintlify docs.json into a writedocs.json - `writedocs convert
2
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).
3
+ // from an installed package (see packages/components/src/lib/icons.js's comment).
4
4
  //
5
5
  // convertMintlifyConfig() is a pure function: Mintlify config in, writedocs
6
6
  // config plus a list of notes out. A note is anything that couldn't be
@@ -10,7 +10,7 @@
10
10
  // its `$ref`s first.
11
11
  import fs from 'node:fs';
12
12
  import path from 'node:path';
13
- import { iconExists } from './icons.js';
13
+ import { iconExists } from '../../packages/components/src/lib/icons.js';
14
14
  import { readJsonText } from './config-file.js';
15
15
 
16
16
  // ---------------------------------------------------------------------
@@ -418,6 +418,17 @@ export function convertMintlifyConfig(docs) {
418
418
  if (Object.keys(background).length) styles.background = background;
419
419
  if (bg.decoration) notes.add('background.decoration', ['background', 'decoration'], `\`background.decoration\` ("${bg.decoration}") isn't supported - dropped.`);
420
420
  }
421
+ // `appearance` is the same shape in writedocs, under `styles`.
422
+ if (docs.appearance && typeof docs.appearance === 'object') {
423
+ const appearance = {};
424
+ const mode = docs.appearance.default;
425
+ if (['system', 'light', 'dark'].includes(mode)) appearance.default = mode;
426
+ else if (mode !== undefined) {
427
+ notes.add('appearance.default', ['appearance', 'default'], `\`appearance.default: ${JSON.stringify(mode)}\` isn't "system", "light" or "dark" - dropped, so pages follow the reader's device setting.`);
428
+ }
429
+ if (typeof docs.appearance.strict === 'boolean') appearance.strict = docs.appearance.strict;
430
+ if (Object.keys(appearance).length) styles.appearance = appearance;
431
+ }
421
432
  if (Object.keys(styles).length) out.styles = styles;
422
433
 
423
434
  // navigation (also collects topbar links from `global`)
@@ -576,7 +587,6 @@ export function convertMintlifyConfig(docs) {
576
587
 
577
588
  // Settings with no equivalent at all
578
589
  const unsupported = {
579
- appearance: 'Light/dark mode defaults (`appearance`) aren\'t configurable - readers choose with the theme toggle.',
580
590
  interaction: '`interaction` settings aren\'t supported.',
581
591
  thumbnails: 'Social thumbnails (`thumbnails`) aren\'t generated - set `seo.ogImage` for a social preview image.',
582
592
  metadata: '`metadata` (last-modified timestamps) isn\'t supported.',
@@ -32,7 +32,7 @@ import { planApiPages, writeGeneratedFiles } from '../cli/generate-api-pages.js'
32
32
  import { collectOpenApiGroups } from './openapi-spec.js';
33
33
  import { readConfigText } from './config-file.js';
34
34
  import { writedocsTempDir } from './writedocs-temp-dir.js';
35
- import { report } from './cli-report.js';
35
+ import { report } from '../../packages/components/src/lib/cli-report.js';
36
36
  import { readDevOpenApiState, writeDevOpenApiState, specProblem } from './openapi-dev-status.js';
37
37
  import { contentStoreChanged } from './content-store-reload-integration.js';
38
38
 
package/src/lib/pages.js CHANGED
@@ -1,11 +1,11 @@
1
1
  // Which files in a content directory are pages. Plain JavaScript, not
2
2
  // TypeScript, so `writedocs validate` can load it with plain Node (Node
3
- // refuses to strip types under node_modules - see lib/icons.js's comment);
3
+ // refuses to strip types under node_modules - see packages/components/src/lib/icons.js's comment);
4
4
  // lib/config.ts re-exports findAllPages() for everything inside Astro.
5
5
  import fs from 'node:fs';
6
6
  import path from 'node:path';
7
7
  import matter from 'gray-matter';
8
- import { readConfigText } from './config-file.js';
8
+ import { readConfigText, readText } from './config-file.js';
9
9
  import { oncePerBuild } from './build-memo.js';
10
10
  import { projectIgnore } from './project-ignore.js';
11
11
 
@@ -41,7 +41,7 @@ export function titleFromPath(filePath) {
41
41
  function readIgnoreFile(contentDir) {
42
42
  let text;
43
43
  try {
44
- text = fs.readFileSync(path.join(contentDir, '.mintignore'), 'utf-8');
44
+ text = readText(path.join(contentDir, '.mintignore'));
45
45
  } catch {
46
46
  return () => false;
47
47
  }
@@ -184,7 +184,9 @@ function scanAllPages(contentDir) {
184
184
  if (ignored(rel, false) || rules.ignores(rel)) continue;
185
185
  let raw;
186
186
  try {
187
- raw = fs.readFileSync(abs, 'utf-8');
187
+ // Without its byte order mark: the `^---` below has to see the
188
+ // frontmatter of a page saved by a Windows editor (lib/bom.js).
189
+ raw = readText(abs);
188
190
  } catch {
189
191
  continue;
190
192
  }
@@ -25,7 +25,7 @@ import { findPublishedFiles, readSpecPaths } from './project-files.js';
25
25
  import { projectIgnore } from './project-ignore.js';
26
26
  import { robotsTxt } from './robots-txt.js';
27
27
  import { isNoindex } from './seo-tags.js';
28
- import { report } from './cli-report.js';
28
+ import { report } from '../../packages/components/src/lib/cli-report.js';
29
29
 
30
30
  /** Every file under `dir`, as POSIX paths from it. */
31
31
  function listFiles(dir, relBase = '') {
@@ -9,7 +9,7 @@
9
9
  // .md page (`raw`), and HTML tags written in MDX (`mdxJsx*` with a lowercase
10
10
  // name) - their href, src, srcset, poster and action. Not a component's
11
11
  // props (`<Card href="/a">`): a component writes its own addresses, with
12
- // siteHref() (lib/site-base.ts), so prefixing here too would give them the
12
+ // siteHref() (the components package's lib/site-base.ts), so prefixing here too would give them the
13
13
  // base twice. Not a value written as an expression (`href={link}`), which
14
14
  // isn't known until the page runs.
15
15
  //
@@ -34,6 +34,11 @@
34
34
  { "path": "bun.lock", "ignored": true },
35
35
  { "path": "composer.json", "ignored": true },
36
36
  { "path": "composer.lock", "ignored": true },
37
+ { "path": "README.md", "ignored": true },
38
+ { "path": "readme.md", "ignored": true },
39
+ { "path": "docs/Readme.MD", "ignored": true },
40
+ { "path": "docs/README.mdx", "ignored": false },
41
+ { "path": "docs/readme-first.md", "ignored": false },
37
42
  { "path": "node_modules/pkg/index.js", "ignored": true },
38
43
  { "path": "node_modules", "directory": true, "ignored": true },
39
44
  { "path": "examples/app/node_modules/x/a.json", "ignored": true },
@@ -138,7 +143,7 @@
138
143
  },
139
144
  {
140
145
  "name": "default exclusions brought back with !",
141
- "wdignore": "!.well-known/\n!examples/package.json\n!*.sql\n!examples/dist/\n",
146
+ "wdignore": "!.well-known/\n!examples/package.json\n!*.sql\n!examples/dist/\n!docs/README.md\n",
142
147
  "paths": [
143
148
  { "path": ".well-known/security.txt", "ignored": false },
144
149
  { "path": ".well-known", "directory": true, "ignored": false },
@@ -151,7 +156,9 @@
151
156
  { "path": "data/app.db", "ignored": true },
152
157
  { "path": "examples/dist/bundle.zip", "ignored": false },
153
158
  { "path": "dist/bundle.zip", "ignored": true },
154
- { "path": "other/dist/bundle.zip", "ignored": true }
159
+ { "path": "other/dist/bundle.zip", "ignored": true },
160
+ { "path": "docs/README.md", "ignored": false },
161
+ { "path": "README.md", "ignored": true }
155
162
  ]
156
163
  },
157
164
  {
@@ -66,6 +66,11 @@ export const DEFAULT_PATTERNS = [
66
66
  'bun.lock',
67
67
  'composer.json',
68
68
  'composer.lock',
69
+ // The repository's README, at any depth and in any case (README.md,
70
+ // readme.md, docs/Readme.md): it describes the repository, not the
71
+ // site. Without frontmatter it was never a page, but with frontmatter it
72
+ // became one, at /readme/.
73
+ 'README.md',
69
74
  // Dependencies and build output, at any depth.
70
75
  'node_modules/',
71
76
  'dist/',
@@ -17,7 +17,7 @@
17
17
  import fs from 'node:fs';
18
18
  import path from 'node:path';
19
19
  import matter from 'gray-matter';
20
- import { iconExists } from './icons.js';
20
+ import { iconExists } from '../../packages/components/src/lib/icons.js';
21
21
  import { readJsonText } from './config-file.js';
22
22
  import { fileIdForPath } from './pages.js';
23
23
  import { Notes, LANGUAGE_NAMES } from './mintlify-convert.js';
@@ -490,7 +490,7 @@ export async function convertLegacyConfig(old, contentDir) {
490
490
  * navbar labels and category/group names. */
491
491
  function readTranslations(contentDir) {
492
492
  try {
493
- return JSON.parse(fs.readFileSync(path.join(contentDir, 'translations.json'), 'utf-8')) ?? {};
493
+ return JSON.parse(readJsonText(path.join(contentDir, 'translations.json'))) ?? {};
494
494
  } catch {
495
495
  return {};
496
496
  }
@@ -9,7 +9,7 @@
9
9
  // non-dynamic page at its literal path).
10
10
  import { loadDocsConfig } from '../lib/config';
11
11
  import BaseLayout from '../layout/BaseLayout.astro';
12
- import { siteHref } from '../lib/site-base';
12
+ import { siteHref } from '../../packages/components/src/lib/site-base';
13
13
 
14
14
  const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
15
15
  const config = loadDocsConfig(contentDir);