Skip to content

Commit da8c28e

Browse files
KianNHsdnts
authored andcommitted
[Docs Site] Track Mermaid usage in ComponentsUsage (cloudflare#23826)
1 parent 6360c79 commit da8c28e

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"@tailwindcss/postcss": "4.1.4",
5252
"@types/hast": "3.0.4",
5353
"@types/he": "1.2.3",
54+
"@types/mdast": "4.0.4",
5455
"@types/node": "24.0.14",
5556
"@types/react": "19.0.7",
5657
"@types/react-dom": "19.0.4",

src/content/docs/style-guide/components/mermaid.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
title: Mermaid
3+
styleGuide:
4+
component: Mermaid
35
---
46

57
Mermaid diagrams are added with [`remark-mermaid`](https://github.com/remcohaszing/rehype-mermaid/) and [`mermaid`](https://www.npmjs.com/package/mermaid).

src/util/components.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
type MdxJsxFlowElement,
88
type MdxJsxTextElement,
99
} from "mdast-util-mdx";
10+
import type { Code } from "mdast";
1011
import { visit } from "unist-util-visit";
1112

1213
type Usage = { count: number; pages: Set<string> };
@@ -52,6 +53,14 @@ export async function getComponentsUsage(
5253
usages[typed.name].count++;
5354
usages[typed.name].pages.add(fullName);
5455
});
56+
57+
visit(tree, "code", function (node: Code) {
58+
if (node.lang === "mermaid") {
59+
usages["Mermaid"] ||= { count: 0, pages: new Set() };
60+
usages["Mermaid"].count++;
61+
usages["Mermaid"].pages.add(fullName);
62+
}
63+
});
5564
}
5665
}
5766

0 commit comments

Comments
 (0)