Skip to content

Commit 7eea564

Browse files
KianNHthomasgauvin
authored andcommitted
[Docs Site] Add page links in ComponentsUsage (#23606)
1 parent 5d1b40a commit 7eea564

File tree

1 file changed

+63
-13
lines changed

1 file changed

+63
-13
lines changed

src/components/ComponentUsage.astro

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
import { z } from "astro:schema";
33
import { getComponentsUsage } from "~/util/components";
4+
import { slug } from "github-slugger";
5+
46
import Details from "./Details.astro";
57
68
type Props = z.infer<typeof props>;
@@ -20,21 +22,69 @@ const usage = await getComponentsUsage(component);
2022
<code>{usage.pages.size}</code> pages.
2123
</p>
2224
<Details header={`Pages which use ${component}`}>
25+
<p><strong>Pages</strong></p>
26+
<ul>
27+
{
28+
[...usage.pages]
29+
.filter((path) => path.startsWith("src/content/docs/"))
30+
.sort()
31+
.map((path) => {
32+
const slugified =
33+
"/" +
34+
path
35+
.replace("src/content/docs/", "")
36+
.replace(".mdx", "")
37+
.split("/")
38+
.map((segment) => slug(segment))
39+
.join("/") +
40+
"/";
41+
42+
return (
43+
<li>
44+
<a
45+
href={"https://developers.cloudflare.com" + slugified}
46+
target="_blank"
47+
>
48+
{slugified}
49+
</a>
50+
<span>
51+
-
52+
<a
53+
href={
54+
"https://github.com/cloudflare/cloudflare-docs/blob/production/" +
55+
path
56+
}
57+
target="_blank"
58+
>
59+
Source
60+
</a>
61+
</span>
62+
</li>
63+
);
64+
})
65+
}
66+
</ul>
67+
<p><strong>Partials</strong></p>
2368
<ul>
2469
{
25-
[...usage.pages].map((path) => (
26-
<li>
27-
<a
28-
href={
29-
"https://github.com/cloudflare/cloudflare-docs/blob/production/" +
30-
path
31-
}
32-
target="_blank"
33-
>
34-
{path}
35-
</a>
36-
</li>
37-
))
70+
[...usage.pages]
71+
.filter((path) => path.startsWith("src/content/partials/"))
72+
.sort()
73+
.map((path) => {
74+
return (
75+
<li>
76+
<a
77+
href={
78+
"https://github.com/cloudflare/cloudflare-docs/blob/production/" +
79+
path
80+
}
81+
target="_blank"
82+
>
83+
{path}
84+
</a>
85+
</li>
86+
);
87+
})
3888
}
3989
</ul>
4090
</Details>

0 commit comments

Comments
 (0)