Skip to content

Commit 3782933

Browse files
KianNHRebeccaTamachiro
authored andcommitted
[Docs Site] Surface tags and which pages use them in style guide (#20598)
* [Docs Site] Surface tags and which pages use them in style guide * link from components
1 parent aa8c15f commit 3782933

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-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";

src/content/docs/style-guide/components/external-resources.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ The type of resources to show, apps or videos.
4040

4141
Filter resources down to those where the `tags` property contains any of these strings.
4242

43+
To see a list of the available tags, and which pages are associated with them, refer to [this list](/style-guide/frontmatter/tags/).
44+
4345
### `products`
4446

4547
**type:** `string[]`

src/content/docs/style-guide/components/products-by-tag.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ styleGuide:
44
component: ProductsByTag
55
---
66

7+
To see a list of the available tags, and which pages are associated with them, refer to [this list](/style-guide/frontmatter/tags/).
8+
79
```mdx live
810
import { ProductsByTag } from "~/components";
911

src/content/docs/style-guide/components/resources-by-selector.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import { ResourcesBySelector } from "~/components";
2929

3030
An array of `tags` values to filter by.
3131

32+
To see a list of the available tags, and which pages are associated with them, refer to [this list](/style-guide/frontmatter/tags/).
33+
3234
- `products` <Type text="string[]" /> <MetaInfo text="optional" />
3335

3436
An array of `products` values to filter by.
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)