@writedocs/generator 0.14.0 → 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.
- package/astro.config.mjs +31 -69
- package/package.json +4 -2
- package/packages/components/package.json +53 -0
- package/{src → packages/components/src}/components/Accordion.astro +2 -2
- package/{src → packages/components/src}/components/AppIcon.astro +3 -3
- package/{src → packages/components/src}/components/Callout.astro +3 -3
- package/{src → packages/components/src}/components/CodeBlock.astro +8 -27
- package/{src → packages/components/src}/components/CodeGroup.astro +3 -3
- package/{src → packages/components/src}/components/Image.astro +7 -9
- package/{src → packages/components/src}/components/compound.ts +1 -1
- package/packages/components/src/host.js +24 -0
- package/packages/components/src/index.ts +59 -0
- package/packages/components/src/integration.js +151 -0
- package/packages/components/src/lib/base-path.js +39 -0
- package/{src → packages/components/src}/lib/code-line-numbers.js +1 -1
- package/packages/components/src/lib/code-transformers.js +45 -0
- package/{src → packages/components/src}/lib/icons.js +13 -7
- package/{src → packages/components/src}/lib/shiki-code-block.js +9 -9
- package/{src → packages/components/src}/lib/site-base.ts +9 -6
- package/packages/components/src/scripts/code-block.ts +62 -0
- package/packages/components/src/styles/components.css +373 -0
- package/packages/components/src/styles/theme.css +63 -0
- package/src/cli/run-astro.js +1 -1
- package/src/components/ApiPlayground.astro +2 -2
- package/src/components/ApiSchemaField.astro +1 -1
- package/src/components/CopyPageMenu.astro +2 -2
- package/src/icons/README.md +1 -1
- package/src/layout/BaseLayout.astro +7 -2
- package/src/layout/components/AnalyticsScripts.astro +2 -2
- package/src/layout/components/Breadcrumbs.astro +1 -1
- package/src/layout/components/ConsentBanner.astro +1 -1
- package/src/layout/components/MobileMenu.astro +2 -2
- package/src/layout/components/NavTree.astro +2 -2
- package/src/layout/components/Sidebar.astro +2 -2
- package/src/layout/components/SiteFooter.astro +2 -2
- package/src/layout/components/TopBar.astro +2 -2
- package/src/layout/styles/base.css +4 -37
- package/src/lib/a11y-check.js +1 -1
- package/src/lib/base-path.js +4 -25
- package/src/lib/color.js +1 -1
- package/src/lib/components-host.ts +21 -0
- package/src/lib/config-file.js +1 -1
- package/src/lib/config.ts +4 -3
- package/src/lib/content-check.js +2 -2
- package/src/lib/link-check.js +2 -2
- package/src/lib/mdx-inject-builtins.js +2 -2
- package/src/lib/mdx-inline-react.js +1 -1
- package/src/lib/mdx-title-anchor-ids.js +2 -2
- package/src/lib/mdx-unknown-components.js +1 -1
- package/src/lib/mintlify-convert.js +2 -2
- package/src/lib/openapi-reload-integration.js +1 -1
- package/src/lib/pages.js +1 -1
- package/src/lib/project-files-integration.js +1 -1
- package/src/lib/rehype-base-path.js +1 -1
- package/src/lib/writedocs-legacy-convert.js +1 -1
- package/src/pages/404.astro +1 -1
- package/src/pages/[...slug].astro +53 -416
- package/src/components/index.ts +0 -62
- /package/{src → packages/components/src}/components/AccordionGroup.astro +0 -0
- /package/{src → packages/components/src}/components/Badge.astro +0 -0
- /package/{src → packages/components/src}/components/Card.astro +0 -0
- /package/{src → packages/components/src}/components/CardGroup.astro +0 -0
- /package/{src → packages/components/src}/components/Check.astro +0 -0
- /package/{src → packages/components/src}/components/Color.astro +0 -0
- /package/{src → packages/components/src}/components/ColorItem.astro +0 -0
- /package/{src → packages/components/src}/components/ColorRow.astro +0 -0
- /package/{src → packages/components/src}/components/Column.astro +0 -0
- /package/{src → packages/components/src}/components/Columns.astro +0 -0
- /package/{src → packages/components/src}/components/Danger.astro +0 -0
- /package/{src → packages/components/src}/components/Expandable.astro +0 -0
- /package/{src → packages/components/src}/components/Frame.astro +0 -0
- /package/{src → packages/components/src}/components/GitHubRepo.astro +0 -0
- /package/{src → packages/components/src}/components/Hint.astro +0 -0
- /package/{src → packages/components/src}/components/Icon.astro +0 -0
- /package/{src → packages/components/src}/components/Info.astro +0 -0
- /package/{src → packages/components/src}/components/Note.astro +0 -0
- /package/{src → packages/components/src}/components/Panel.astro +0 -0
- /package/{src → packages/components/src}/components/ParamField.astro +0 -0
- /package/{src → packages/components/src}/components/Parameter.astro +0 -0
- /package/{src → packages/components/src}/components/Prompt.astro +0 -0
- /package/{src → packages/components/src}/components/RequestExample.astro +0 -0
- /package/{src → packages/components/src}/components/ResponseExample.astro +0 -0
- /package/{src → packages/components/src}/components/ResponseField.astro +0 -0
- /package/{src → packages/components/src}/components/Searchbar.astro +0 -0
- /package/{src → packages/components/src}/components/Step.astro +0 -0
- /package/{src → packages/components/src}/components/Steps.astro +0 -0
- /package/{src → packages/components/src}/components/Tab.astro +0 -0
- /package/{src → packages/components/src}/components/Tabs.astro +0 -0
- /package/{src → packages/components/src}/components/Tile.astro +0 -0
- /package/{src → packages/components/src}/components/Tip.astro +0 -0
- /package/{src → packages/components/src}/components/Tooltip.astro +0 -0
- /package/{src → packages/components/src}/components/Tree.astro +0 -0
- /package/{src → packages/components/src}/components/TreeFile.astro +0 -0
- /package/{src → packages/components/src}/components/TreeFolder.astro +0 -0
- /package/{src → packages/components/src}/components/Update.astro +0 -0
- /package/{src → packages/components/src}/components/Video.astro +0 -0
- /package/{src → packages/components/src}/components/View.astro +0 -0
- /package/{src → packages/components/src}/components/Visibility.astro +0 -0
- /package/{src → packages/components/src}/components/Warning.astro +0 -0
- /package/{src → packages/components/src}/components/class-names.ts +0 -0
- /package/{src → packages/components/src}/lib/cli-report.js +0 -0
- /package/{src → packages/components/src}/lib/inline-markdown.js +0 -0
- /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
|
-
|
|
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
|
-
//
|
|
519
|
-
//
|
|
520
|
-
//
|
|
521
|
-
|
|
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
|
|
612
|
-
//
|
|
613
|
-
//
|
|
614
|
-
//
|
|
615
|
-
//
|
|
616
|
-
//
|
|
617
|
-
//
|
|
618
|
-
//
|
|
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, '
|
|
602
|
+
replacement: path.join(packageRoot, 'packages/components/src/index.ts'),
|
|
641
603
|
},
|
|
642
604
|
],
|
|
643
605
|
},
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@writedocs/generator",
|
|
3
|
-
"version": "0.
|
|
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": "./
|
|
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
|
|
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/
|
|
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/
|
|
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
|
|
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
|
|
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
|
|
142
|
-
|
|
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
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// numbers, wrap, copy button, expandable, highlight and focus all look
|
|
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
|
-
|
|
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
|
|
70
|
-
const
|
|
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
|
-
|
|
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
|
|
117
|
-
|
|
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 {
|
|
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
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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/
|
|
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';
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// The Astro integration that sets a project up for the components:
|
|
2
|
+
//
|
|
3
|
+
// // astro.config.mjs
|
|
4
|
+
// import writedocsComponents from '@writedocs/components/integration';
|
|
5
|
+
// export default defineConfig({ integrations: [writedocsComponents()] });
|
|
6
|
+
//
|
|
7
|
+
// What it adds, each one an option that's on unless turned off:
|
|
8
|
+
// - icons: astro-icon, which renders every icon (<Icon>, a Card's icon,
|
|
9
|
+
// ...), with the @iconify-json/* collections this package depends on.
|
|
10
|
+
// astro-icon itself only loads the collections the project's own
|
|
11
|
+
// package.json lists, so a plugin here adds the others to its
|
|
12
|
+
// `virtual:astro-icon` module (iconSetsPlugin()). Off when the project
|
|
13
|
+
// registers astro-icon itself - and then it lists the collections it uses.
|
|
14
|
+
// - styles: theme.css (the --wd-* variables and their defaults) and
|
|
15
|
+
// components.css (code blocks, Shiki's dark theme, image icons) on every
|
|
16
|
+
// page.
|
|
17
|
+
// - scripts: the code blocks' copy and Show more buttons on every page
|
|
18
|
+
// (scripts/code-block.ts). Each component's own <script> comes with it.
|
|
19
|
+
// - markdown: the project's own ``` fences (in .md/.mdx, and so inside a
|
|
20
|
+
// <CodeGroup>) through the same Shiki transformers as <CodeBlock>
|
|
21
|
+
// (lib/code-transformers.js), so they get the code-block frame, title and
|
|
22
|
+
// copy button - and, when the project hasn't picked Shiki themes of its
|
|
23
|
+
// own, the light and dark pair <CodeBlock> uses by default, which
|
|
24
|
+
// components.css swaps between with data-theme.
|
|
25
|
+
// And two that are off unless given:
|
|
26
|
+
// - host: a module that answers what the components ask of the site - the
|
|
27
|
+
// code theme, image sizes (host.js has the default and the functions it
|
|
28
|
+
// exports). A path, relative to the project's root unless absolute. The
|
|
29
|
+
// generator passes its own (src/lib/components-host.ts).
|
|
30
|
+
// - base: the base the site is served under ("/docs"), put in front of the
|
|
31
|
+
// addresses the components write (lib/site-base.ts). The generator defines
|
|
32
|
+
// it itself, from writedocs.json's basePath.
|
|
33
|
+
//
|
|
34
|
+
// The writedocs generator uses this too (astro.config.mjs), with icons,
|
|
35
|
+
// styles, scripts and markdown off: it has its own of each.
|
|
36
|
+
import fs from 'node:fs';
|
|
37
|
+
import path from 'node:path';
|
|
38
|
+
import { fileURLToPath } from 'node:url';
|
|
39
|
+
import { codeTransformers } from './lib/code-transformers.js';
|
|
40
|
+
import { loadIconCollection } from './lib/icons.js';
|
|
41
|
+
import { codeblockTheme } from './host.js';
|
|
42
|
+
|
|
43
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
44
|
+
const DEFAULT_HOST = path.join(HERE, 'host.js');
|
|
45
|
+
|
|
46
|
+
/** The icon collections this package depends on ("lucide", "mdi", ...). */
|
|
47
|
+
function iconSetNames() {
|
|
48
|
+
const { dependencies = {} } = JSON.parse(fs.readFileSync(path.join(HERE, '..', 'package.json'), 'utf8'));
|
|
49
|
+
return Object.keys(dependencies)
|
|
50
|
+
.filter((name) => name.startsWith('@iconify-json/'))
|
|
51
|
+
.map((name) => name.slice('@iconify-json/'.length));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** A Vite plugin that adds this package's icon collections to astro-icon's
|
|
55
|
+
* module - `export default <collections>;\nexport const config = <json>`,
|
|
56
|
+
* the shape the generator's src/lib/icon-data-dev.js reads too - when the
|
|
57
|
+
* project's package.json doesn't list them. A module of another shape (a
|
|
58
|
+
* new astro-icon) is left as it is. */
|
|
59
|
+
function iconSetsPlugin() {
|
|
60
|
+
return {
|
|
61
|
+
name: '@writedocs/components:icon-sets',
|
|
62
|
+
transform(code, id) {
|
|
63
|
+
if (id !== '\0virtual:astro-icon') return null;
|
|
64
|
+
const match = /^export default (\{[\s\S]*\});\nexport const config = (\{[\s\S]*\})\s*$/.exec(code);
|
|
65
|
+
if (!match) return null;
|
|
66
|
+
const collections = JSON.parse(match[1]);
|
|
67
|
+
const missing = iconSetNames().filter((name) => !collections[name]);
|
|
68
|
+
for (const name of missing) {
|
|
69
|
+
const data = loadIconCollection(name);
|
|
70
|
+
if (data) collections[name] = data;
|
|
71
|
+
}
|
|
72
|
+
if (!missing.length) return null;
|
|
73
|
+
return { code: `export default ${JSON.stringify(collections)};\nexport const config = ${match[2]}`, map: null };
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The same file, however Vite or Windows spells it: separators, a drive
|
|
79
|
+
* letter's case, a ?query - or a link to it (pnpm's node_modules, or Vite's
|
|
80
|
+
* preserveSymlinks, give the package's path through a link, while Node
|
|
81
|
+
* loaded this file from its real path). */
|
|
82
|
+
function sameFile(a, b) {
|
|
83
|
+
const norm = (p) => {
|
|
84
|
+
const file = p.split('?')[0];
|
|
85
|
+
let real = file;
|
|
86
|
+
try {
|
|
87
|
+
real = fs.realpathSync(file);
|
|
88
|
+
} catch {
|
|
89
|
+
// Not a file on disk (a virtual id) - compared as it is.
|
|
90
|
+
}
|
|
91
|
+
return path.normalize(real).toLowerCase();
|
|
92
|
+
};
|
|
93
|
+
return norm(a) === norm(b);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** A Vite plugin that puts `hostFile` where the components import the
|
|
97
|
+
* default host.js from. */
|
|
98
|
+
function hostPlugin(hostFile) {
|
|
99
|
+
const id = path.resolve(hostFile).split(path.sep).join('/');
|
|
100
|
+
return {
|
|
101
|
+
name: '@writedocs/components:host',
|
|
102
|
+
enforce: 'pre',
|
|
103
|
+
async resolveId(source, importer, options) {
|
|
104
|
+
if (!importer || !/(^|\/)host\.js$/.test(source)) return null;
|
|
105
|
+
const resolved = await this.resolve(source, importer, { ...options, skipSelf: true });
|
|
106
|
+
return resolved && sameFile(resolved.id, DEFAULT_HOST) ? id : null;
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export default function writedocsComponents({ host, base, icons = true, styles = true, scripts = true, markdown = true } = {}) {
|
|
112
|
+
return {
|
|
113
|
+
name: '@writedocs/components',
|
|
114
|
+
hooks: {
|
|
115
|
+
'astro:config:setup': async ({ config, updateConfig, injectScript }) => {
|
|
116
|
+
const integrations = [];
|
|
117
|
+
if (icons) {
|
|
118
|
+
const { default: icon } = await import('astro-icon');
|
|
119
|
+
integrations.push(icon());
|
|
120
|
+
}
|
|
121
|
+
// Astro's own default is a single theme and no `themes`; a project
|
|
122
|
+
// that set `themes` keeps them.
|
|
123
|
+
const ownThemes = Object.keys(config.markdown?.shikiConfig?.themes ?? {}).length > 0;
|
|
124
|
+
updateConfig({
|
|
125
|
+
...(integrations.length ? { integrations } : {}),
|
|
126
|
+
...(markdown
|
|
127
|
+
? { markdown: { shikiConfig: { transformers: codeTransformers(), ...(ownThemes ? {} : { themes: codeblockTheme() }) } } }
|
|
128
|
+
: {}),
|
|
129
|
+
vite: {
|
|
130
|
+
plugins: [...(host ? [hostPlugin(path.resolve(fileURLToPath(config.root), host))] : []), ...(icons ? [iconSetsPlugin()] : [])],
|
|
131
|
+
...(base !== undefined ? { define: { __WD_BASE__: JSON.stringify(base) } } : {}),
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
if (styles) {
|
|
135
|
+
injectScript('page-ssr', "import '@writedocs/components/styles/theme.css';\nimport '@writedocs/components/styles/components.css';");
|
|
136
|
+
}
|
|
137
|
+
if (scripts) {
|
|
138
|
+
injectScript(
|
|
139
|
+
'page',
|
|
140
|
+
[
|
|
141
|
+
"import { initCodeCopyButtons, initCodeExpandButtons } from '@writedocs/components/scripts/code-block';",
|
|
142
|
+
'const init = () => { initCodeCopyButtons(document); initCodeExpandButtons(document); };',
|
|
143
|
+
'init();',
|
|
144
|
+
"document.addEventListener('astro:page-load', init);",
|
|
145
|
+
].join('\n')
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|