Skip to content

Commit 09345e7

Browse files
kodster28daisyfaithauma
authored andcommitted
[tutorials] Separate out YT videos from tutorials (#22246)
* [tutorials] Separate out YT videos from tutorials * component cleanup
1 parent 33c6669 commit 09345e7

File tree

16 files changed

+88
-64
lines changed

16 files changed

+88
-64
lines changed

src/components/ListTutorials.astro

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { process } from "~/util/rehype";
66
import rehypeExternalLinks from "~/plugins/rehype/external-links";
77
88
type DocsEntry = CollectionEntry<"docs">;
9-
type VideoEntry = CollectionEntry<"videos">;
109
11-
const tutorials: Array<DocsEntry | VideoEntry> = [];
10+
const tutorials: Array<DocsEntry> = [];
1211
1312
const currentSection = Astro.params.slug?.split("/")[0];
1413
const currentProduct = await getEntry("products", currentSection!);
@@ -20,8 +19,6 @@ if (!currentProduct) {
2019
}
2120
2221
const productTitle = currentProduct.data.product.title;
23-
const videoText = "🎥 Video"
24-
const tutorialText = "📝 Tutorial"
2522
2623
const docs = await getCollection("docs", (entry) => {
2724
return (
@@ -38,14 +35,6 @@ const docs = await getCollection("docs", (entry) => {
3835
3936
tutorials.push(...docs);
4037
41-
const videos = await getCollection("videos", (entry) => {
42-
return entry.data.products.some(
43-
(v: string) => v.toUpperCase() === productTitle.toUpperCase(),
44-
);
45-
});
46-
47-
tutorials.push(...videos);
48-
4938
tutorials.sort((a, b) => Number(b.data.updated) - Number(a.data.updated));
5039
5140
const timeAgo = (date?: Date) => {
@@ -66,13 +55,9 @@ const timeAgo = (date?: Date) => {
6655
<tbody>
6756
{
6857
tutorials.map(async (tutorial) => {
69-
const title =
70-
tutorial.collection === "docs" ? tutorial.data.title : tutorial.id;
58+
const title = tutorial.data.title;
7159

72-
const href =
73-
tutorial.collection === "docs"
74-
? `/${tutorial.id}/`
75-
: tutorial.data.link;
60+
const href = `/${tutorial.id}/`;
7661

7762
const anchor = await process(`<a href=${href}>${title}</a>`, [
7863
rehypeExternalLinks,
@@ -84,7 +69,7 @@ const timeAgo = (date?: Date) => {
8469
<Fragment set:html={anchor} />
8570
</td>
8671
<td>{timeAgo(tutorial.data.updated)}</td>
87-
<td>{tutorial.collection === "docs" ? tutorialText : videoText}</td>
72+
<td>📝 Tutorial</td>
8873
<td>{tutorial.data.difficulty}</td>
8974
</tr>
9075
);

src/components/YouTubeVideos.astro

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ if (products.length === 0) {
1414
products.push(currentSection);
1515
}
1616
17-
const videos = await getCollection("videos", (entry) => {
17+
let videos = await getCollection("videos", (entry) => {
1818
return (
19-
entry.data.link.startsWith("https://youtu") &&
20-
entry.data.products?.some((v: string) => products.includes(v))
19+
entry.data.link.includes("youtu") &&
20+
entry.data.products?.some((v: string) =>
21+
products.some((p) => v.trim().toLowerCase() === p.trim().toLowerCase()),
22+
)
2123
);
2224
});
2325
26+
videos = videos.sort(
27+
(a, b) =>
28+
new Date(b.data.updated).getTime() - new Date(a.data.updated).getTime(),
29+
);
2430
const entries = videos.map((video) => ({
2531
href: video.data.link,
2632
title: video.data.id,

src/content/docs/ai-gateway/tutorials/index.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ sidebar:
77
hideIndex: true
88
---
99

10-
import { GlossaryTooltip, ListTutorials } from "~/components";
10+
import { GlossaryTooltip, ListTutorials, YouTubeVideos } from "~/components";
1111

1212
View <GlossaryTooltip term="tutorial">tutorials</GlossaryTooltip> to help you get started with AI Gateway.
1313

14+
## Docs
15+
1416
<ListTutorials />
17+
18+
## Videos
19+
20+
<YouTubeVideos products={["AI Gateway"]} />

src/content/docs/d1/tutorials/index.mdx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ title: Tutorials
55
hideChildren: true
66
sidebar:
77
order: 12
8-
98
---
109

11-
import { GlossaryTooltip, ListTutorials } from "~/components"
10+
import { GlossaryTooltip, ListTutorials, YouTubeVideos } from "~/components";
1211

1312
View <GlossaryTooltip term="tutorial">tutorials</GlossaryTooltip> to help you get started with D1.
1413

14+
## Docs
15+
1516
<ListTutorials />
17+
18+
## Videos
19+
20+
<YouTubeVideos products={["D1"]} />

src/content/docs/developer-spotlight/tutorials/index.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ title: Tutorials
55
hideChildren: true
66
sidebar:
77
order: 2
8-
98
---
109

11-
import { ListTutorials } from "~/components"
10+
import { ListTutorials } from "~/components";
1211

1312
<ListTutorials />

src/content/docs/durable-objects/tutorials/index.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ title: Tutorials
55
hideChildren: true
66
sidebar:
77
order: 9
8-
98
---
109

11-
import { GlossaryTooltip, ListTutorials } from "~/components"
10+
import { GlossaryTooltip, ListTutorials } from "~/components";
1211

1312
View <GlossaryTooltip term="tutorial">tutorials</GlossaryTooltip> to help you get started with Durable Objects.
1413

src/content/docs/kv/tutorials/index.mdx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ pcx_content_type: navigation
44
hideChildren: true
55
sidebar:
66
order: 4
7-
87
---
98

10-
import { GlossaryTooltip, ListTutorials } from "~/components"
9+
import { GlossaryTooltip, ListTutorials, YouTubeVideos } from "~/components";
1110

1211
View <GlossaryTooltip term="tutorial">tutorials</GlossaryTooltip> to help you get started with KV.
1312

13+
## Docs
14+
1415
<ListTutorials />
16+
17+
## Videos
18+
19+
<YouTubeVideos products={["KV"]} />

src/content/docs/pages/tutorials/index.mdx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ title: Tutorials
55
hideChildren: true
66
sidebar:
77
order: 7
8-
98
---
109

11-
import { GlossaryTooltip, ListTutorials } from "~/components"
10+
import { GlossaryTooltip, ListTutorials, YouTubeVideos } from "~/components";
1211

1312
View <GlossaryTooltip term="tutorial">tutorials</GlossaryTooltip> to help you get started with Pages.
1413

14+
## Docs
15+
1516
<ListTutorials />
17+
18+
## Videos
19+
20+
<YouTubeVideos products={["Pages"]} />

src/content/docs/queues/tutorials/index.mdx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ title: Tutorials
55
hideChildren: true
66
sidebar:
77
order: 6
8-
98
---
109

11-
import { ListTutorials } from "~/components"
10+
import { ListTutorials, YouTubeVideos } from "~/components";
11+
12+
## Docs
1213

1314
<ListTutorials />
15+
16+
## Videos
17+
18+
<YouTubeVideos products={["Queues"]} />

src/content/docs/r2/tutorials/index.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ sidebar:
66
order: 9
77
---
88

9-
import { GlossaryTooltip, ListTutorials } from "~/components";
9+
import { GlossaryTooltip, ListTutorials, YouTubeVideos } from "~/components";
1010

1111
View <GlossaryTooltip term="tutorial">tutorials</GlossaryTooltip> to help you get started with R2.
1212

13+
## Docs
14+
1315
<ListTutorials />
16+
17+
## Videos
18+
19+
<YouTubeVideos products={["R2"]} />

0 commit comments

Comments
 (0)