Skip to content

Commit 7085323

Browse files
committed
[Docs Site] Add file prop to Stream component
1 parent 415babd commit 7085323

File tree

2 files changed

+78
-26
lines changed

2 files changed

+78
-26
lines changed

src/components/Stream.astro

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { z } from "astro:schema";
33
import { Badge } from "@astrojs/starlight/components";
44
import parse from "parse-duration";
55
import Details from "./Details.astro";
6+
import { reference, getEntry } from "astro:content";
67
78
type Props = z.input<typeof props>;
89
@@ -15,10 +16,51 @@ const props = z
1516
showMoreVideos: z.boolean().default(false),
1617
expandChapters: z.boolean().default(false),
1718
})
18-
.strict();
19+
.strict()
20+
.or(
21+
z
22+
.object({
23+
file: reference("stream"),
24+
showMoreVideos: z.boolean().default(false),
25+
expandChapters: z.boolean().default(false),
26+
})
27+
.strict(),
28+
);
29+
30+
const input = props.parse(Astro.props);
31+
32+
let id;
33+
let title;
34+
let thumbnail;
35+
let chapters;
36+
const { showMoreVideos, expandChapters } = input;
37+
38+
if ("id" in input) {
39+
id = input.id;
40+
title = input.title;
41+
thumbnail = input.thumbnail;
42+
chapters = input.chapters;
43+
} else {
44+
const { file } = input;
45+
46+
const entry = await getEntry(file);
47+
48+
if (!entry) {
49+
throw new Error(`[Stream] Could not find "${file}"`);
50+
}
51+
52+
id = entry.data.id;
53+
title = entry.data.title;
54+
chapters = entry.data.chapters;
1955
20-
const { id, title, thumbnail, chapters, showMoreVideos, expandChapters } =
21-
props.parse(Astro.props);
56+
if (entry.data.thumbnail) {
57+
if ("url" in entry.data.thumbnail) {
58+
thumbnail = entry.data.thumbnail.url;
59+
} else {
60+
thumbnail = entry.data.thumbnail.timestamp;
61+
}
62+
}
63+
}
2264
2365
const BASE_URL = `https://customer-1mwganm1ma0xgnmj.cloudflarestream.com/`;
2466

src/content/docs/style-guide/components/stream.mdx

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,43 @@ styleGuide:
77
## Import
88

99
```mdx
10-
import { Stream } from "~/components"
10+
import { Stream } from "~/components";
1111
```
1212

1313
## Usage
1414

15-
import { Stream } from "~/components"
15+
import { Stream } from "~/components";
1616

1717
<Stream
18-
id="0f5d548ef3f606e6833b78e0193847c4"
19-
title="Connect and secure from any network to anywhere"
20-
thumbnail="https://pub-d9bf66e086fb4b639107aa52105b49dd.r2.dev/Connect-and-secure-from-any-network-to-anywhere.jpg"
21-
chapters={{
22-
"Chapter 1": "30s",
23-
"Chapter 2": "1m30s",
24-
"Chapter 3": "3m15s",
25-
"Chapter 4": "3m25s",
26-
"Chapter 5": "3m35s",
27-
}}
18+
id="0f5d548ef3f606e6833b78e0193847c4"
19+
title="Connect and secure from any network to anywhere"
20+
thumbnail="https://pub-d9bf66e086fb4b639107aa52105b49dd.r2.dev/Connect-and-secure-from-any-network-to-anywhere.jpg"
21+
chapters={{
22+
"Chapter 1": "30s",
23+
"Chapter 2": "1m30s",
24+
"Chapter 3": "3m15s",
25+
"Chapter 4": "3m25s",
26+
"Chapter 5": "3m35s",
27+
}}
2828
/>
2929

30+
<Stream file="warp-1-basics" />
31+
3032
```mdx
3133
<Stream
32-
id="0f5d548ef3f606e6833b78e0193847c4"
33-
title="Connect and secure from any network to anywhere"
34-
thumbnail="https://pub-d9bf66e086fb4b639107aa52105b49dd.r2.dev/Connect-and-secure-from-any-network-to-anywhere.jpg"
35-
chapters={{
36-
"Chapter 1": "30s",
37-
"Chapter 2": "1m30s",
38-
"Chapter 3": "3m15s",
39-
"Chapter 4": "3m25s",
40-
"Chapter 5": "3m35s",
41-
}}
34+
id="0f5d548ef3f606e6833b78e0193847c4"
35+
title="Connect and secure from any network to anywhere"
36+
thumbnail="https://pub-d9bf66e086fb4b639107aa52105b49dd.r2.dev/Connect-and-secure-from-any-network-to-anywhere.jpg"
37+
chapters={{
38+
"Chapter 1": "30s",
39+
"Chapter 2": "1m30s",
40+
"Chapter 3": "3m15s",
41+
"Chapter 4": "3m25s",
42+
"Chapter 5": "3m35s",
43+
}}
4244
/>
45+
46+
<Stream file="warp-1-basics" />
4347
```
4448

4549
## `<Stream>` Props
@@ -86,4 +90,10 @@ If `chapters` is present, is passed through to the `open` property of the [Detai
8690

8791
**default:** `true`
8892

89-
Whether to show the "Watch more videos on our Developer Channel" link below the video.
93+
Whether to show the "Watch more videos on our Developer Channel" link below the video.
94+
95+
### `file`
96+
97+
**type:** `string`
98+
99+
If `file` is provided, the `id`, `title`,` thumbnail` and `chapters` properties cannot be used and are instead retrieved from the YAML file in the [`stream`](https://github.com/cloudflare/cloudflare-docs/tree/production/src/content/stream) collection.

0 commit comments

Comments
 (0)