Skip to content

Commit faa2590

Browse files
committed
[Docs Site] Surface tags and which pages use them in style guide
1 parent f295b86 commit faa2590

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

src/components/TagsUsage.astro

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
import { getCollection } from "astro:content";
3+
import AnchorHeading from "./AnchorHeading.astro";
4+
import Details from "./Details.astro";
5+
6+
const entries = await getCollection("docs", (e) => Boolean(e.data.tags));
7+
8+
const byTag: Record<string, string[]> = {};
9+
10+
for (const entry of entries) {
11+
for (const tag of entry.data.tags!) {
12+
byTag[tag] ??= [];
13+
byTag[tag].push(entry.id);
14+
}
15+
}
16+
---
17+
18+
{
19+
Object.entries(byTag)
20+
.sort()
21+
.map(([tag, pages]) => (
22+
<>
23+
<AnchorHeading depth={3} title={tag} />
24+
<p>
25+
<code>{tag}</code> is used on <code>{pages.length}</code> pages.
26+
</p>
27+
<Details header={`Pages tagged with ${tag}`}>
28+
<ul>
29+
{pages.map((path) => (
30+
<li>
31+
<a href={`/${path}/`} target="_blank">
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
@@ -51,6 +51,7 @@ export { default as ResourcesBySelector } from "./ResourcesBySelector.astro";
5151
export { default as RuleID } from "./RuleID.astro";
5252
export { default as SpotlightAuthorDetails } from "./SpotlightAuthorDetails.astro";
5353
export { default as Stream } from "./Stream.astro";
54+
export { default as TagsUsage } from "./TagsUsage.astro";
5455
export { default as TroubleshootingList } from "./TroubleshootingList.astro";
5556
export { default as TunnelCalculator } from "./TunnelCalculator.astro";
5657
export { default as Type } from "./Type.astro";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: Tags
3+
---
4+
5+
import { TagsUsage } from "~/components";
6+
7+
Tags are currently used to filter content in the [`ExternalResources`](/style-guide/components/external-resources/), [`ProductsByTag`](/style-guide/components/products-by-tag/) and the [`ResourcesBySelector`](/style-guide/components/resources-by-selector/) components.
8+
9+
## Examples
10+
11+
```mdx
12+
---
13+
title: Example
14+
tags:
15+
- foo
16+
- bar
17+
---
18+
```
19+
20+
## Tags
21+
22+
<TagsUsage />

0 commit comments

Comments
 (0)