@writedocs/generator 0.13.5 → 0.15.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 (113) hide show
  1. package/astro.config.mjs +31 -69
  2. package/bin/writedocs.js +4 -1
  3. package/package.json +4 -2
  4. package/packages/components/package.json +53 -0
  5. package/{src → packages/components/src}/components/Accordion.astro +2 -2
  6. package/{src → packages/components/src}/components/AppIcon.astro +3 -3
  7. package/{src → packages/components/src}/components/Callout.astro +3 -3
  8. package/{src → packages/components/src}/components/CodeBlock.astro +8 -27
  9. package/{src → packages/components/src}/components/CodeGroup.astro +3 -3
  10. package/{src → packages/components/src}/components/Image.astro +7 -9
  11. package/{src → packages/components/src}/components/compound.ts +1 -1
  12. package/packages/components/src/host.js +24 -0
  13. package/packages/components/src/index.ts +59 -0
  14. package/packages/components/src/integration.js +151 -0
  15. package/packages/components/src/lib/base-path.js +39 -0
  16. package/{src → packages/components/src}/lib/code-line-numbers.js +1 -1
  17. package/packages/components/src/lib/code-transformers.js +45 -0
  18. package/{src → packages/components/src}/lib/icons.js +13 -7
  19. package/{src → packages/components/src}/lib/shiki-code-block.js +9 -9
  20. package/{src → packages/components/src}/lib/site-base.ts +9 -6
  21. package/packages/components/src/scripts/code-block.ts +62 -0
  22. package/packages/components/src/styles/components.css +373 -0
  23. package/packages/components/src/styles/theme.css +63 -0
  24. package/src/cli/build.js +23 -3
  25. package/src/cli/dev.js +2 -1
  26. package/src/cli/generate-api-pages.js +9 -7
  27. package/src/cli/page-list-watch.js +4 -2
  28. package/src/cli/run-astro.js +2 -2
  29. package/src/components/ApiPlayground.astro +2 -2
  30. package/src/components/ApiSchemaField.astro +1 -1
  31. package/src/components/CopyPageMenu.astro +2 -2
  32. package/src/content.config.ts +16 -0
  33. package/src/icons/README.md +1 -1
  34. package/src/layout/BaseLayout.astro +7 -2
  35. package/src/layout/components/AnalyticsScripts.astro +2 -2
  36. package/src/layout/components/Breadcrumbs.astro +1 -1
  37. package/src/layout/components/ConsentBanner.astro +1 -1
  38. package/src/layout/components/MobileMenu.astro +2 -2
  39. package/src/layout/components/NavTree.astro +16 -2
  40. package/src/layout/components/Sidebar.astro +2 -2
  41. package/src/layout/components/SiteFooter.astro +2 -2
  42. package/src/layout/components/TopBar.astro +2 -2
  43. package/src/layout/styles/base.css +4 -37
  44. package/src/lib/a11y-check.js +1 -1
  45. package/src/lib/base-path.js +4 -25
  46. package/src/lib/color.js +1 -1
  47. package/src/lib/components-host.ts +21 -0
  48. package/src/lib/config-file.js +1 -1
  49. package/src/lib/config-schema.js +12 -1
  50. package/src/lib/config-schema.ts +14 -0
  51. package/src/lib/config.ts +22 -6
  52. package/src/lib/content-check.js +6 -3
  53. package/src/lib/drafts.js +186 -0
  54. package/src/lib/link-check.js +13 -4
  55. package/src/lib/mdx-inject-builtins.js +2 -2
  56. package/src/lib/mdx-inline-react.js +1 -1
  57. package/src/lib/mdx-title-anchor-ids.js +2 -2
  58. package/src/lib/mdx-unknown-components.js +1 -1
  59. package/src/lib/mintlify-convert.js +2 -2
  60. package/src/lib/openapi-reload-integration.js +1 -1
  61. package/src/lib/pages.js +41 -7
  62. package/src/lib/project-files-integration.js +1 -1
  63. package/src/lib/rehype-base-path.js +1 -1
  64. package/src/lib/seo-tags.js +3 -1
  65. package/src/lib/writedocs-legacy-convert.js +1 -1
  66. package/src/pages/404.astro +1 -1
  67. package/src/pages/[...slug].astro +65 -417
  68. package/src/components/index.ts +0 -62
  69. /package/{src → packages/components/src}/components/AccordionGroup.astro +0 -0
  70. /package/{src → packages/components/src}/components/Badge.astro +0 -0
  71. /package/{src → packages/components/src}/components/Card.astro +0 -0
  72. /package/{src → packages/components/src}/components/CardGroup.astro +0 -0
  73. /package/{src → packages/components/src}/components/Check.astro +0 -0
  74. /package/{src → packages/components/src}/components/Color.astro +0 -0
  75. /package/{src → packages/components/src}/components/ColorItem.astro +0 -0
  76. /package/{src → packages/components/src}/components/ColorRow.astro +0 -0
  77. /package/{src → packages/components/src}/components/Column.astro +0 -0
  78. /package/{src → packages/components/src}/components/Columns.astro +0 -0
  79. /package/{src → packages/components/src}/components/Danger.astro +0 -0
  80. /package/{src → packages/components/src}/components/Expandable.astro +0 -0
  81. /package/{src → packages/components/src}/components/Frame.astro +0 -0
  82. /package/{src → packages/components/src}/components/GitHubRepo.astro +0 -0
  83. /package/{src → packages/components/src}/components/Hint.astro +0 -0
  84. /package/{src → packages/components/src}/components/Icon.astro +0 -0
  85. /package/{src → packages/components/src}/components/Info.astro +0 -0
  86. /package/{src → packages/components/src}/components/Note.astro +0 -0
  87. /package/{src → packages/components/src}/components/Panel.astro +0 -0
  88. /package/{src → packages/components/src}/components/ParamField.astro +0 -0
  89. /package/{src → packages/components/src}/components/Parameter.astro +0 -0
  90. /package/{src → packages/components/src}/components/Prompt.astro +0 -0
  91. /package/{src → packages/components/src}/components/RequestExample.astro +0 -0
  92. /package/{src → packages/components/src}/components/ResponseExample.astro +0 -0
  93. /package/{src → packages/components/src}/components/ResponseField.astro +0 -0
  94. /package/{src → packages/components/src}/components/Searchbar.astro +0 -0
  95. /package/{src → packages/components/src}/components/Step.astro +0 -0
  96. /package/{src → packages/components/src}/components/Steps.astro +0 -0
  97. /package/{src → packages/components/src}/components/Tab.astro +0 -0
  98. /package/{src → packages/components/src}/components/Tabs.astro +0 -0
  99. /package/{src → packages/components/src}/components/Tile.astro +0 -0
  100. /package/{src → packages/components/src}/components/Tip.astro +0 -0
  101. /package/{src → packages/components/src}/components/Tooltip.astro +0 -0
  102. /package/{src → packages/components/src}/components/Tree.astro +0 -0
  103. /package/{src → packages/components/src}/components/TreeFile.astro +0 -0
  104. /package/{src → packages/components/src}/components/TreeFolder.astro +0 -0
  105. /package/{src → packages/components/src}/components/Update.astro +0 -0
  106. /package/{src → packages/components/src}/components/Video.astro +0 -0
  107. /package/{src → packages/components/src}/components/View.astro +0 -0
  108. /package/{src → packages/components/src}/components/Visibility.astro +0 -0
  109. /package/{src → packages/components/src}/components/Warning.astro +0 -0
  110. /package/{src → packages/components/src}/components/class-names.ts +0 -0
  111. /package/{src → packages/components/src}/lib/cli-report.js +0 -0
  112. /package/{src → packages/components/src}/lib/inline-markdown.js +0 -0
  113. /package/{src → packages/components/src}/lib/plain-text.js +0 -0
package/astro.config.mjs CHANGED
@@ -9,16 +9,8 @@ import fs from 'node:fs';
9
9
  import { fileURLToPath } from 'node:url';
10
10
  import matter from 'gray-matter';
11
11
  import { unified } from '@astrojs/markdown-remark';
12
- import {
13
- transformerMetaHighlight,
14
- transformerMetaWordHighlight,
15
- transformerNotationHighlight,
16
- transformerNotationWordHighlight,
17
- transformerNotationFocus,
18
- transformerNotationDiff,
19
- transformerNotationErrorLevel,
20
- } from '@shikijs/transformers';
21
- import { codeBlockTransformer } from './src/lib/shiki-code-block.js';
12
+ import { codeTransformers } from './packages/components/src/lib/code-transformers.js';
13
+ import writedocsComponents from './packages/components/src/integration.js';
22
14
  import { rehypeMermaid } from './src/lib/mermaid-rehype.js';
23
15
  import remarkMath from 'remark-math';
24
16
  import rehypeKatex from 'rehype-katex';
@@ -44,7 +36,7 @@ import { iconDataFromFile } from './src/lib/icon-data-dev.js';
44
36
  import { canonicalPath } from './src/lib/canonical-path.js';
45
37
  import { withBase, withoutBase } from './src/lib/base-path.js';
46
38
  import { folderAddresses } from './src/lib/folder-redirects.js';
47
- import { report } from './src/lib/cli-report.js';
39
+ import { report } from './packages/components/src/lib/cli-report.js';
48
40
  import { publishProjectFiles, generatedRobotsTxt } from './src/lib/project-files-integration.js';
49
41
  import { frontmatterNoindex, canonicalIsElsewhere } from './src/lib/seo-tags.js';
50
42
  import { readMovedApiPages } from './src/lib/moved-api-pages.js';
@@ -340,6 +332,20 @@ export default defineConfig({
340
332
  // purely for snippets a site author writes themselves.
341
333
  react(),
342
334
  icon(),
335
+ // The components package (packages/components): its integration puts
336
+ // the generator's answers (src/lib/components-host.ts - writedocs.json's
337
+ // code themes, the project's image sizes) in place of the package's
338
+ // defaults. What it adds to any other project - astro-icon, its
339
+ // stylesheets, the code-block script, Shiki's setup for ``` fences - the
340
+ // generator has already: icon() above, BaseLayout.astro's imports,
341
+ // [...slug].astro's page script, markdown.shikiConfig below.
342
+ writedocsComponents({
343
+ host: path.join(packageRoot, 'src/lib/components-host.ts'),
344
+ icons: false,
345
+ styles: false,
346
+ scripts: false,
347
+ markdown: false,
348
+ }),
343
349
  // A project's own files, published as they are (robots.txt, sitemap.xml,
344
350
  // a PDF...) - before the sitemap integration, see
345
351
  // lib/project-files-integration.js.
@@ -514,36 +520,11 @@ export default defineConfig({
514
520
  shikiConfig: {
515
521
  themes: codeblockTheme,
516
522
  langAlias: codeblockLangAlias,
517
- // The official @shikijs/transformers annotation transformers -
518
- // enabled sitewide so any fenced code block can use their meta-
519
- // string/comment syntax without per-page opt-in:
520
- // ```js {1,3-5} -> transformerMetaHighlight
521
- // ```js /someWord/ -> transformerMetaWordHighlight
522
- // // [!code highlight] -> transformerNotationHighlight
523
- // // [!code word:someWord] -> transformerNotationWordHighlight
524
- // // [!code focus] -> transformerNotationFocus
525
- // // [!code ++] / // [!code --] -> transformerNotationDiff
526
- // // [!code error] / [!code warning] -> transformerNotationErrorLevel
527
- // (comment syntax adapts to the language - # for Python/bash, //
528
- // for JS/etc - see each transformer's own docs at shiki.style).
529
- // Plus codeBlockTransformer, writedocs' own transformer for the
530
- // copy button, an optional title bar, and wrap/lines/expandable
531
- // meta flags - see src/lib/shiki-code-block.js. It runs last so
532
- // its `root` hook wraps the <pre> only after every class the
533
- // transformers above added to it is already in place - though in
534
- // practice this doesn't matter, since all `pre`/`line` hooks
535
- // across every transformer run to completion before any `root`
536
- // hook runs at all (two separate passes, not interleaved).
537
- transformers: [
538
- transformerMetaHighlight(),
539
- transformerMetaWordHighlight(),
540
- transformerNotationHighlight(),
541
- transformerNotationWordHighlight(),
542
- transformerNotationFocus(),
543
- transformerNotationDiff(),
544
- transformerNotationErrorLevel(),
545
- codeBlockTransformer(),
546
- ],
523
+ // The official @shikijs/transformers annotation transformers plus
524
+ // writedocs' own (copy button, title bar, wrap/lines/expandable) -
525
+ // the same list <CodeBlock> uses, from the components package (see
526
+ // its lib/code-transformers.js for what each one does).
527
+ transformers: codeTransformers(),
547
528
  },
548
529
  },
549
530
  // Tailwind is available for future/custom content (e.g. hand-authored
@@ -608,36 +589,17 @@ export default defineConfig({
608
589
  // injects `import { Callout, ... } from 'writedocs/components'`
609
590
  // into any .mdx file that uses a built-in component tag without
610
591
  // importing it itself - a real bare specifier Vite has to resolve
611
- // as if the .mdx file had written it. package.json's own
612
- // `exports: { "./components": "./src/components/index.ts" }`
613
- // makes that specifier valid *in principle* (Node's package
614
- // self-reference feature - a package importing its own name), but
615
- // self-reference only resolves when the importing file is a
616
- // descendant of this package's own package.json - true for every
617
- // existing fixture (always built from inside this repo/package
618
- // tree) but never true for a real consumer's content, which lives
619
- // in a completely separate directory in the actual product
620
- // architecture (see docs/dev/docs/architecture.mdx) - walking up
621
- // from such a file never finds a package.json named "writedocs",
622
- // so self-reference fails and Vite reports the bare specifier as
623
- // unresolvable ("Rolldown failed to resolve import
624
- // 'writedocs/components'").
625
- // This alias bypasses self-reference resolution entirely for
626
- // that one specifier - Vite's alias matching is a plain string
627
- // match against the specifier itself, independent of which file
628
- // imported it, so it resolves correctly regardless of where the
629
- // content directory actually lives. WRITEDOCS_PACKAGE_ROOT is the
630
- // same packageRoot value already set by run-astro.js for
631
- // lib/config.ts's fileIdForEntry() to consume - reusing it here
632
- // instead of recomputing via import.meta.url keeps there being
633
- // exactly one source of truth for "where this package lives" per
634
- // astro subprocess. Falls back to this file's own directory
635
- // (astro.config.mjs always lives at packageRoot) for anything
636
- // that ever imports this config outside that subprocess, e.g. a
637
- // future test harness.
592
+ // as if the .mdx file had written it. No package is named
593
+ // "writedocs" (this one is @writedocs/generator, and the
594
+ // components' own is @writedocs/components, inside it rather than
595
+ // installed - packages/components), and a site's content lives
596
+ // outside this package anyway, so nothing would resolve it by
597
+ // name: this alias points it at the components package's barrel.
598
+ // Vite's alias matching is a plain string match against the
599
+ // specifier itself, independent of which file imported it.
638
600
  {
639
601
  find: 'writedocs/components',
640
- replacement: path.join(packageRoot, 'src/components/index.ts'),
602
+ replacement: path.join(packageRoot, 'packages/components/src/index.ts'),
641
603
  },
642
604
  ],
643
605
  },
package/bin/writedocs.js CHANGED
@@ -90,6 +90,9 @@ program
90
90
  .argument('[dir]', 'content directory (contains writedocs.json and docs/)', '.')
91
91
  .option('-k, --key <key>', 'build authorization key (or set WRITEDOCS_API_KEY)')
92
92
  .option('--verbose', "also print Astro's and Vite's own output")
93
+ // A preview of the drafts (src/lib/drafts.js): included, marked and
94
+ // noindex, out of the sitemap, llms.txt and the MCP index.
95
+ .option('--drafts', 'include draft pages (draft: true), marked and noindex')
93
96
  .action(async (dir, opts) => {
94
97
  const contentDir = canonicalPath(path.resolve(process.cwd(), dir));
95
98
  // Project-scoped, not global: a .env sitting next to this project's own
@@ -99,7 +102,7 @@ program
99
102
  // environment - an explicit `export`/CI secret still wins over the file.
100
103
  dotenv.config({ path: path.join(contentDir, '.env'), quiet: true });
101
104
  await requireBuildKey(opts.key || process.env.WRITEDOCS_API_KEY);
102
- await runBuild({ contentDir, packageRoot, verbose: Boolean(opts.verbose) });
105
+ await runBuild({ contentDir, packageRoot, verbose: Boolean(opts.verbose), drafts: Boolean(opts.drafts) });
103
106
  });
104
107
 
105
108
  program
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@writedocs/generator",
3
- "version": "0.13.5",
3
+ "version": "0.15.0",
4
4
  "description": "Static site generator for docs — a writedocs.json + MDX folder in, a static site out.",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "writedocs": "./bin/writedocs.js"
8
8
  },
9
9
  "exports": {
10
- "./components": "./src/components/index.ts",
10
+ "./components": "./packages/components/src/index.ts",
11
11
  "./config-schema": "./src/lib/config-schema.js",
12
12
  "./writedocs.schema.json": "./writedocs.schema.json",
13
13
  "./mcp": "./src/mcp/server.js",
@@ -17,6 +17,8 @@
17
17
  "files": [
18
18
  "bin",
19
19
  "src",
20
+ "packages/components/src",
21
+ "packages/components/package.json",
20
22
  "astro.config.mjs",
21
23
  "writedocs.schema.json"
22
24
  ],
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@writedocs/components",
3
+ "version": "0.1.0",
4
+ "description": "The writedocs documentation components (Callout, Card, Tabs, CodeBlock, ...) as Astro components, for any Astro project",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./src/index.ts",
8
+ "./integration": "./src/integration.js",
9
+ "./host": "./src/host.js",
10
+ "./styles/*": "./src/styles/*",
11
+ "./scripts/*": "./src/scripts/*.ts"
12
+ },
13
+ "files": [
14
+ "src",
15
+ "README.md"
16
+ ],
17
+ "keywords": [
18
+ "astro-component",
19
+ "withastro",
20
+ "writedocs",
21
+ "documentation"
22
+ ],
23
+ "peerDependencies": {
24
+ "astro": "^7.2.9"
25
+ },
26
+ "dependencies": {
27
+ "@iconify-json/bi": "1.2.7",
28
+ "@iconify-json/fa6-brands": "1.2.6",
29
+ "@iconify-json/fa6-solid": "1.2.4",
30
+ "@iconify-json/heroicons": "1.2.3",
31
+ "@iconify-json/ion": "1.2.7",
32
+ "@iconify-json/lucide": "1.2.123",
33
+ "@iconify-json/mdi": "1.2.3",
34
+ "@iconify-json/ri": "1.2.10",
35
+ "@iconify-json/simple-icons": "1.2.93",
36
+ "@iconify-json/tabler": "1.2.38",
37
+ "@shikijs/transformers": "4.4.3",
38
+ "astro-icon": "1.1.5"
39
+ },
40
+ "engines": {
41
+ "node": ">=22.12.0"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "author": "Gabriel Raeder Gonçalves",
47
+ "license": "ISC",
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/writedocs/writedocs.git",
51
+ "directory": "packages/components"
52
+ }
53
+ }
@@ -11,7 +11,7 @@ interface Props {
11
11
  // `defaultOpen` renders the accordion already expanded.
12
12
  description?: string;
13
13
  defaultOpen?: boolean;
14
- // Set automatically by remarkTitleAnchorIds (src/lib/mdx-title-anchor-ids.js)
14
+ // Set automatically by the generator's remarkTitleAnchorIds (src/lib/mdx-title-anchor-ids.js)
15
15
  // for every <Accordion title="..."> it finds in an .mdx file's own JSX,
16
16
  // already deduped (-2, -3, ...) against every other Accordion/Callout
17
17
  // title on that same page - see that plugin's own comment for why the
@@ -155,7 +155,7 @@ const titleId = _titleId ?? slugify(plainText(title));
155
155
  scroll-margin-top: calc(var(--wd-topbar-offset, 5rem) + 1rem);
156
156
  }
157
157
  /* .wd-heading-anchor's base look (color, opacity: 0, transition) comes
158
- from [...slug].astro's own <style is:global> block - see
158
+ from styles/components.css - see
159
159
  Callout.astro's identical comment on its own title anchor. Only the
160
160
  hover trigger needs to live here, and - since both
161
161
  .wd-accordion-title and the anchor inside it are rendered directly
@@ -1,13 +1,13 @@
1
1
  ---
2
2
  // Renders any writedocs.json `icon` string, whichever of the two forms it
3
- // takes (see resolveIcon() in lib/config.ts): an Iconify icon id (looked
3
+ // takes (see resolveIcon() in lib/icons.js): an Iconify icon id (looked
4
4
  // up against whatever @iconify-json/* collections are installed - see
5
5
  // astro.config.mjs) rendered as a real <svg>, or literal text/emoji
6
6
  // rendered as-is. Centralizes the icon/text branch so BaseLayout.astro
7
7
  // and Card.astro (the two places writedocs.json icon strings get rendered)
8
8
  // don't each need their own copy of the resolveIcon() call + branch.
9
9
  import { Icon } from 'astro-icon/components';
10
- import { resolveIcon, iconExists } from '../lib/config';
10
+ import { resolveIcon, iconExists } from '../lib/icons.js';
11
11
  import { report } from '../lib/cli-report.js';
12
12
  import { siteHref } from '../lib/site-base';
13
13
 
@@ -43,7 +43,7 @@ if (icon && resolved?.kind === 'iconify' && !iconExists(icon)) {
43
43
  ) : resolved.kind === 'image' ? (
44
44
  // Wrapped in the same <span> text icons use, so each caller's own
45
45
  // span.<class> rule (font-size, spacing) sizes it; the image fills
46
- // 1em of that (img.wd-icon-img in layout/styles/base.css).
46
+ // 1em of that (img.wd-icon-img in styles/components.css).
47
47
  <span class={className} style={style}><img src={siteHref(resolved.src)} alt="" class="wd-icon-img" /></span>
48
48
  ) : (
49
49
  <span class={className} style={style}>{resolved.value}</span>
@@ -11,7 +11,7 @@ import { plainText } from "../lib/plain-text.js";
11
11
  interface Props {
12
12
  type?: "note" | "tip" | "warning" | "danger" | "info" | "check";
13
13
  title?: string | object;
14
- // Set automatically by remarkCalloutAnchorIds (src/lib/mdx-callout-anchor-ids.js)
14
+ // Set automatically by the generator's remarkTitleAnchorIds (src/lib/mdx-title-anchor-ids.js)
15
15
  // for every <Callout title="...">/<Note title="...">/etc. it finds in an
16
16
  // .mdx file's own JSX, already deduped (-2, -3, ...) against every other
17
17
  // callout title on that same page - see that plugin's own comment for
@@ -138,8 +138,8 @@ const titleId = title ? (_titleId ?? slugify(plainText(title))) : undefined;
138
138
  scroll-margin-top: calc(var(--wd-topbar-offset, 5rem) + 1rem);
139
139
  }
140
140
  /* .wd-heading-anchor's base look (color, opacity: 0, transition) comes
141
- from [...slug].astro's own <style is:global> block - it already
142
- applies anywhere that class shows up, headings or not. Only the
141
+ from styles/components.css - it already applies anywhere that class
142
+ shows up, headings or not. Only the
143
143
  hover trigger needs to live here, and unlike the icon rules above,
144
144
  no :global() is needed for it: both .wd-callout-title and the
145
145
  anchor inside it are rendered directly by this component's own
@@ -1,27 +1,18 @@
1
1
  ---
2
2
  // Mintlify's <CodeBlock> - a code block from props instead of a ``` fence,
3
3
  // for code a page builds up in a component. Renders through the same Shiki
4
- // setup and the same writedocs:code-block transformer as a fenced block
5
- // (see astro.config.mjs's markdown.shikiConfig), so title, icon, line
6
- // numbers, wrap, copy button, expandable, highlight and focus all look and
7
- // behave the same.
4
+ // transformers as a fenced block in the generator (codeTransformers(), which
5
+ // its astro.config.mjs's markdown.shikiConfig uses too), so title, icon,
6
+ // line numbers, wrap, copy button, expandable, highlight and focus all look
7
+ // and behave the same. The themes come from the host (../host.js).
8
8
  //
9
9
  // The code is the component's children (or a `code` prop). Mintlify's
10
10
  // `highlight`/`focus` are stringified arrays ("[1,3,4]"); ranges like
11
11
  // "1-3" work too.
12
12
  import { Code } from 'astro:components';
13
13
  import { extraClasses } from './class-names';
14
- import {
15
- transformerMetaHighlight,
16
- transformerMetaWordHighlight,
17
- transformerNotationHighlight,
18
- transformerNotationWordHighlight,
19
- transformerNotationFocus,
20
- transformerNotationDiff,
21
- transformerNotationErrorLevel,
22
- } from '@shikijs/transformers';
23
- import { codeBlockTransformer } from '../lib/shiki-code-block.js';
24
- import { loadDocsConfig, resolveCodeblockTheme } from '../lib/config';
14
+ import { codeTransformers } from '../lib/code-transformers.js';
15
+ import { codeblockTheme } from '../host.js';
25
16
 
26
17
  interface Props {
27
18
  language?: string;
@@ -66,18 +57,8 @@ const meta = [
66
57
  .filter(Boolean)
67
58
  .join(' ');
68
59
 
69
- const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
70
- const themes = resolveCodeblockTheme(loadDocsConfig(contentDir));
71
- const transformers = [
72
- transformerMetaHighlight(),
73
- transformerMetaWordHighlight(),
74
- transformerNotationHighlight(),
75
- transformerNotationWordHighlight(),
76
- transformerNotationFocus(),
77
- transformerNotationDiff(),
78
- transformerNotationErrorLevel(),
79
- codeBlockTransformer(),
80
- ];
60
+ const themes = codeblockTheme();
61
+ const transformers = codeTransformers();
81
62
  const extras = extraClasses(Astro.props);
82
63
  ---
83
64
  {
@@ -100,7 +100,7 @@ const { dropdown = false } = Astro.props as Props;
100
100
  </script>
101
101
  <style is:global>
102
102
  /* The group is one frame, like a single block's (see .wd-code-block in
103
- [...slug].astro): border, surface background and a 0.125rem inset,
103
+ styles/components.css): border, surface background and a 0.125rem inset,
104
104
  with the tab strip (or dropdown) on the frame and the code panel
105
105
  inside. The blocks inside lose their own frame below, so it isn't
106
106
  drawn twice. */
@@ -113,8 +113,8 @@ const { dropdown = false } = Astro.props as Props;
113
113
  background: var(--wd-surface);
114
114
  }
115
115
  /* Each fenced code block inside a <CodeGroup> is wrapped in a
116
- .wd-code-block div by codeBlockTransformer (see astro.config.mjs /
117
- src/lib/shiki-code-block.js) rather than being a bare <pre> - this
116
+ .wd-code-block div by codeBlockTransformer (see lib/code-transformers.js /
117
+ lib/shiki-code-block.js) rather than being a bare <pre> - this
118
118
  drops that wrapper's own frame (margin, inset, border, radius,
119
119
  background), leaving its title bar and code panel on the group's. */
120
120
  .wd-codegroup > .wd-code-block {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  import { extraClasses } from './class-names';
3
- import { imageFileFor, imageSize } from '../lib/image-size.js';
3
+ import { imageSize } from '../host.js';
4
4
  import { siteHref } from '../lib/site-base';
5
5
  // Block-level (own line, centered) - unlike Hint (inline/text-level),
6
6
  // this is meant to be dropped in on its own the way Callout/Card are.
@@ -69,14 +69,12 @@ interface Props {
69
69
  loading?: "lazy" | "eager";
70
70
  }
71
71
  const { src, srcDark, size, alt = "", caption, noZoom, loading = "lazy" } = Astro.props as Props;
72
- // Each file's own pixel size, as width/height: the browser keeps the
73
- // image's place before it arrives, so the text below doesn't jump. The
74
- // CSS below already has height: auto, so the image still scales.
75
- const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
76
- const sizeOf = (address?: string) => {
77
- const file = address ? imageFileFor(address, contentDir) : null;
78
- return (file && imageSize(file, contentDir)) || { width: undefined, height: undefined };
79
- };
72
+ // Each file's own pixel size, as width/height, when the host knows it (in
73
+ // the generator, read from the project's file - see ../host.js): the
74
+ // browser keeps the image's place before it arrives, so the text below
75
+ // doesn't jump. The CSS below already has height: auto, so the image still
76
+ // scales.
77
+ const sizeOf = (address?: string) => (address && imageSize(address)) || { width: undefined, height: undefined };
80
78
  const light = sizeOf(src);
81
79
  const dark = sizeOf(srcDark);
82
80
  const sizeStyle = size ? `--wd-image-size:${size}` : undefined;
@@ -2,7 +2,7 @@
2
2
  // <GitHub.Repo>, ... MDX compiles <Tree.Folder> to a property lookup on
3
3
  // whatever `Tree` resolves to, so the parts are attached as properties of
4
4
  // their parent here, once, and everything that hands components to MDX (the
5
- // src/components/index.ts barrel and [...slug].astro's `components` map)
5
+ // package barrel, src/index.ts, and the generator's [...slug].astro's `components` map)
6
6
  // takes these three from this module rather than importing the .astro files
7
7
  // directly. `FileTree` is Mintlify's other name for `Tree`.
8
8
  import TreeRoot from './Tree.astro';
@@ -0,0 +1,24 @@
1
+ // What the components ask of the site they render in - the "host". This file
2
+ // is the default, for a project that renders them on its own pages. The
3
+ // integration (integration.js) swaps it for the project's own module when
4
+ // given `host`: the writedocs generator's is src/lib/components-host.ts,
5
+ // which answers from the site's writedocs.json and its files. A replacement
6
+ // exports the same functions. They run on the server, while a page renders.
7
+
8
+ /** The Shiki themes <CodeBlock> highlights with, by name - see
9
+ * https://shiki.style/themes. ``` fences in a project's own Markdown use
10
+ * its markdown.shikiConfig instead.
11
+ * @returns {{ light: string, dark: string }} */
12
+ export function codeblockTheme() {
13
+ return { light: 'github-light', dark: 'github-dark' };
14
+ }
15
+
16
+ /** The pixel size of the image at `src` (an address as written in the
17
+ * page - "/images/a.png", "https://..."), as { width, height }, or null when
18
+ * it isn't known. <Image> writes it on the <img>, so the page keeps the
19
+ * image's place while it loads.
20
+ * @param {string} src
21
+ * @returns {{ width: number, height: number } | null} */
22
+ export function imageSize(src) {
23
+ return null;
24
+ }
@@ -0,0 +1,59 @@
1
+ // The package's entry point: `import { Callout, Tabs } from
2
+ // '@writedocs/components'`. Every component a writedocs page's own MDX gets
3
+ // for free (the `components` map the generator passes to
4
+ // `<Content components={components} />` in src/pages/[...slug].astro).
5
+ //
6
+ // Inside the generator this is also what an MDX *snippet* imports: a page's
7
+ // own MDX never needs an import - Callout, Card, etc. are already in scope -
8
+ // but a snippet, imported and rendered as `<MySnippet />` from inside that
9
+ // page, is its own independently-compiled MDX component with its own (empty,
10
+ // unless passed explicitly) components map, so a `<Callout>` in its body has
11
+ // nothing to resolve against without an import of its own.
12
+ // remarkInjectBuiltinComponents (src/lib/mdx-inject-builtins.js) adds
13
+ // `import { Callout } from 'writedocs/components'`, which the generator's
14
+ // astro.config.mjs aliases to this file (see docs/dev/docs/snippets.mdx).
15
+ //
16
+ // Deliberately the same set passed into <Content components={...}> and no
17
+ // more - AppIcon is a building block the components use, and the
18
+ // generator's ApiPlayground, ApiReferencePanel, CopyPageMenu etc. aren't in
19
+ // this package at all.
20
+ export { default as Callout } from './components/Callout.astro';
21
+ export { default as Note } from './components/Note.astro';
22
+ export { default as Info } from './components/Info.astro';
23
+ export { default as Tip } from './components/Tip.astro';
24
+ export { default as Warning } from './components/Warning.astro';
25
+ export { default as Danger } from './components/Danger.astro';
26
+ export { default as Card } from './components/Card.astro';
27
+ export { default as CardGroup } from './components/CardGroup.astro';
28
+ export { default as Tabs } from './components/Tabs.astro';
29
+ export { default as Tab } from './components/Tab.astro';
30
+ export { default as CodeGroup } from './components/CodeGroup.astro';
31
+ export { default as Accordion } from './components/Accordion.astro';
32
+ export { default as AccordionGroup } from './components/AccordionGroup.astro';
33
+ export { default as Steps } from './components/Steps.astro';
34
+ export { default as Step } from './components/Step.astro';
35
+ export { default as Hint } from './components/Hint.astro';
36
+ export { default as Image } from './components/Image.astro';
37
+ export { default as Frame } from './components/Frame.astro';
38
+ export { default as Video } from './components/Video.astro';
39
+ export { default as Parameter } from './components/Parameter.astro';
40
+ export { default as Expandable } from './components/Expandable.astro';
41
+ export { default as Searchbar } from './components/Searchbar.astro';
42
+ export { default as Badge } from './components/Badge.astro';
43
+ export { default as Icon } from './components/Icon.astro';
44
+ export { default as RequestExample } from './components/RequestExample.astro';
45
+ export { default as ResponseExample } from './components/ResponseExample.astro';
46
+ export { default as Check } from './components/Check.astro';
47
+ export { default as ParamField } from './components/ParamField.astro';
48
+ export { default as ResponseField } from './components/ResponseField.astro';
49
+ export { default as Columns } from './components/Columns.astro';
50
+ export { default as Column } from './components/Column.astro';
51
+ export { default as CodeBlock } from './components/CodeBlock.astro';
52
+ export { default as Tooltip } from './components/Tooltip.astro';
53
+ export { default as Update } from './components/Update.astro';
54
+ export { default as Tile } from './components/Tile.astro';
55
+ export { default as Panel } from './components/Panel.astro';
56
+ export { default as Prompt } from './components/Prompt.astro';
57
+ export { default as View } from './components/View.astro';
58
+ export { default as Visibility } from './components/Visibility.astro';
59
+ export { Tree, FileTree, Color, GitHub } from './components/compound';