Skip to content

Commit 3f63664

Browse files
committed
[Docs Site] Create DashButton component
1 parent 3f03d6a commit 3f63664

File tree

5 files changed

+582
-0
lines changed

5 files changed

+582
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
import { Code } from "@astrojs/starlight/components";
3+
import Routes from "~/content/dash-routes/index.json";
4+
---
5+
6+
<ul>
7+
{
8+
Routes.map((route) => (
9+
<li>
10+
<strong>{(route.parent ?? []).concat(route.name).join(" > ")}</strong>
11+
<br />
12+
<Code lang="mdx" code={`<DashButton url="${route.deeplink}" />`} />
13+
</li>
14+
))
15+
}
16+
</ul>

src/components/DashButton.astro

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
import { z } from "astro:schema";
3+
import { LinkButton } from "@astrojs/starlight/components";
4+
import Routes from "~/content/dash-routes/index.json";
5+
6+
const props = z
7+
.object({
8+
url: z.string(),
9+
})
10+
.strict();
11+
12+
const { url } = props.parse(Astro.props);
13+
14+
const route = Routes.find((route) => route.deeplink === url);
15+
16+
if (!route) {
17+
throw new Error(`[DashButton] No route found for ${url}`);
18+
}
19+
20+
const { name } = route;
21+
22+
const { href } = new URL(route.deeplink, "https://dash.cloudflare.com");
23+
---
24+
25+
<LinkButton href={href}>Go to {name}</LinkButton>

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export { default as ComponentUsage } from "./ComponentUsage.astro";
1414
export { default as ComponentsUsage } from "./ComponentsUsage.astro";
1515
export { default as CopyPageButton } from "./CopyPageButton.tsx";
1616
export { default as CURL } from "./CURL.astro";
17+
export { default as DashButton } from "./DashButton.astro";
1718
export { default as Description } from "./Description.astro";
1819
export { default as Details } from "./Details.astro";
1920
export { default as DirectoryListing } from "./DirectoryListing.astro";

0 commit comments

Comments
 (0)