Skip to content

Commit 7d4de67

Browse files
authored
[Docs Site] Create YouTubeVideos component (#21414)
* [Docs Site] Create YouTubeVideos component * link * add products filter
1 parent ccb8035 commit 7d4de67

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed

package-lock.json

+109
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
"starlight-image-zoom": "0.11.1",
110110
"starlight-links-validator": "0.14.3",
111111
"starlight-package-managers": "0.10.0",
112+
"starlight-showcases": "0.3.0",
112113
"strip-markdown": "6.0.0",
113114
"svgo": "3.3.2",
114115
"tailwindcss": "3.4.17",

src/components/YouTubeVideos.astro

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
import { z } from "astro:schema";
3+
import { getCollection } from "astro:content";
4+
import { ShowcaseYouTube } from "starlight-showcases";
5+
6+
const props = z.object({
7+
products: z.string().array().default([]),
8+
});
9+
10+
const { products } = props.parse(Astro.props);
11+
12+
if (products.length === 0) {
13+
const [currentSection] = Astro.url.pathname.split("/").filter(Boolean);
14+
products.push(currentSection);
15+
}
16+
17+
const videos = await getCollection("videos", (entry) => {
18+
return (
19+
entry.data.link.startsWith("https://youtu") &&
20+
entry.data.products?.some((v: string) => products.includes(v))
21+
);
22+
});
23+
24+
const entries = videos.map((video) => ({
25+
href: video.data.link,
26+
title: video.data.id,
27+
description: video.data.description,
28+
}));
29+
---
30+
31+
<ShowcaseYouTube entries={entries} />

src/components/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export { default as WorkersArchitectureDiagram } from "./WorkersArchitectureDiag
6464
export { default as WorkersIsolateDiagram } from "./WorkersIsolateDiagram.astro";
6565
export { default as WorkerStarter } from "./WorkerStarter.astro";
6666
export { default as YouTube } from "./YouTube.astro";
67+
export { default as YouTubeVideos } from "./YouTubeVideos.astro";
6768

6869
// Taken from Astro
6970
export { default as ListCard } from "./astro/ListCard.astro";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: YouTube Videos
3+
styleGuide:
4+
component: YouTubeVideos
5+
---
6+
7+
## Usage
8+
9+
```mdx live
10+
import { YouTubeVideos } from "~/components";
11+
12+
<YouTubeVideos products={["Workers"]} />
13+
```
14+
15+
## `<YouTubeVideos>` Props
16+
17+
### `products`
18+
19+
**type:** `string[]`
20+
21+
An array of products to show associated videos for.
22+
23+
If not specified, the product where the component is used will be used.

0 commit comments

Comments
 (0)