Skip to content

Commit 3285039

Browse files
KianNHRebeccaTamachiro
authored andcommitted
[Docs Site] Track component usage in style guide (#20596)
1 parent 8ef17a7 commit 3285039

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+220
-4
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@
7474
"jsonc-parser": "3.3.1",
7575
"lz-string": "1.5.0",
7676
"marked": "15.0.7",
77+
"mdast-util-from-markdown": "2.0.2",
78+
"mdast-util-mdx": "3.0.0",
7779
"mdast-util-mdx-expression": "2.0.1",
7880
"mermaid": "11.4.1",
81+
"micromark-extension-mdxjs": "3.0.0",
7982
"node-html-parser": "7.0.1",
8083
"openapi-types": "12.1.3",
8184
"parse-duration": "2.1.3",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
import { getComponentsUsage } from "~/util/components";
3+
import AnchorHeading from "./AnchorHeading.astro";
4+
import Details from "./Details.astro";
5+
6+
const components = await getComponentsUsage();
7+
8+
const alphabetical = Object.entries(components).sort(([a], [b]) =>
9+
a.localeCompare(b),
10+
);
11+
---
12+
13+
{
14+
alphabetical.map(([component, usage]) => (
15+
<>
16+
<AnchorHeading depth={2} title={component} />
17+
<p>
18+
<code>{component}</code> is used <code>{usage.count}</code> times on{" "}
19+
<code>{usage.pages.size}</code> pages.
20+
</p>
21+
<Details header={`Pages which use ${component}`}>
22+
<ul>
23+
{[...usage.pages].map((path) => (
24+
<li>
25+
<a
26+
href={
27+
"https://github.com/cloudflare/cloudflare-docs/blob/production/" +
28+
path
29+
}
30+
target="_blank"
31+
>
32+
{path}
33+
</a>
34+
</li>
35+
))}
36+
</ul>
37+
</Details>
38+
</>
39+
))
40+
}

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export { default as APIRequest } from "./APIRequest.astro";
1010
export { default as AvailableNotifications } from "./AvailableNotifications.astro";
1111
export { default as CompatibilityFlag } from "./CompatibilityFlag.astro";
1212
export { default as CompatibilityFlags } from "./CompatibilityFlags.astro";
13+
export { default as ComponentsUsage } from "./ComponentsUsage.astro";
1314
export { default as CURL } from "./CURL.astro";
1415
export { default as Description } from "./Description.astro";
1516
export { default as Details } from "./Details.astro";

src/components/overrides/PageTitle.astro

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ import { marked } from "marked";
55
import { Breadcrumbs } from "astro-breadcrumbs";
66
import "astro-breadcrumbs/breadcrumbs.css";
77
8+
import { Aside } from "@astrojs/starlight/components";
89
import Description from "~/components/Description.astro";
910
import SpotlightAuthorDetails from "~/components/SpotlightAuthorDetails.astro";
1011
import LastReviewed from "~/components/LastReviewed.astro";
1112
1213
import { getEntry } from "astro:content";
1314
14-
const spotlightDetails = Astro.locals.starlightRoute.entry.data.spotlight;
15-
const updated = Astro.locals.starlightRoute.entry.data.updated;
16-
const summary = Astro.locals.starlightRoute.entry.data.summary;
15+
const frontmatter = Astro.locals.starlightRoute.entry.data;
16+
17+
const spotlightDetails = frontmatter.spotlight;
18+
const updated = frontmatter.updated;
19+
const summary = frontmatter.summary;
20+
const component = frontmatter.styleGuide?.component;
1721
1822
const slug = Astro.locals.starlightRoute.entry.slug;
1923
@@ -107,6 +111,8 @@ const hideBreadcrumbs = Astro.locals.starlightRoute.hideBreadcrumbs;
107111

108112
{summary && <Description set:html={marked.parse(summary)} />}
109113

114+
{component && <Aside>To see a list of pages this component is used on, please visit the <a href={`/style-guide/components/usage/#${component.toLowerCase()}`}>usage page</a>.</Aside>}
115+
110116
<style>
111117
:root {
112118
--color-link-breadcrumbs: var(--sl-color-text-accent);

src/content/docs/style-guide/components/anchor-heading.mdx

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

57
The `AnchorHeading` component defines headings. Specifically, `AnchorHeading` performs the following:

src/content/docs/style-guide/components/api-request.mdx

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

57
## Import

src/content/docs/style-guide/components/available-notifications.mdx

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

57
## Components

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

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

57
```mdx live

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

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

57
Cards are a built-in component provided by [Starlight](https://starlight.astro.build/components/cards/).

0 commit comments

Comments
 (0)