Skip to content

Commit f20230a

Browse files
committed
Partition docs
1 parent 9f9db4b commit f20230a

File tree

2 files changed

+65
-13
lines changed

2 files changed

+65
-13
lines changed

src/app/(main)/resources/[category]/docs-section.tsx

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { clsx } from "clsx"
22

33
import { Button } from "@/app/conf/_design-system/button"
44
import { Eyebrow } from "@/_design-system/eyebrow"
5-
5+
import { partition } from "@/app/conf/_design-system/utils/partition"
66
import { TeaserSectionListItem } from "@/components/learn-aggregator/teaser-section-list-item"
77
import {
8+
LearnPageItem,
89
LearnPagePath,
910
learnPages,
1011
} from "@/components/learn-aggregator/learn-pages"
@@ -27,6 +28,11 @@ export function DocsSection({
2728
const pages =
2829
docs?.map(path => learnPages[path]).filter(page => page !== null) ?? []
2930

31+
const [gettingStarted, bestPractices] = partition(
32+
pages,
33+
page => page.section === "getting-started",
34+
)
35+
3036
return (
3137
<section
3238
id={sectionIds["docs"]}
@@ -48,18 +54,40 @@ export function DocsSection({
4854
</Button>
4955
</header>
5056

51-
<ul className="grid grid-cols-1 gap-6 md:grid-cols-2">
52-
{pages.map((page, index) => (
53-
<TeaserSectionListItem
54-
key={index}
55-
title={page.title}
56-
description={page.description}
57-
icon={<img src={page.icon} alt="" />}
58-
section={page.section}
59-
href={page.href}
60-
/>
61-
))}
62-
</ul>
57+
{gettingStarted && (
58+
<>
59+
<h3 className="typography-h3">Getting Started</h3>
60+
<ul className="grid grid-cols-1 gap-6 md:grid-cols-2">
61+
{gettingStarted.map((page, index) => (
62+
<TeaserSectionListItem
63+
key={index}
64+
title={page.title}
65+
description={page.description}
66+
icon={<img src={page.icon} alt="" />}
67+
section={page.section}
68+
href={page.href}
69+
/>
70+
))}
71+
</ul>
72+
</>
73+
)}
74+
{bestPractices && (
75+
<>
76+
<h3 className="typography-h3">Best Practices</h3>
77+
<ul className="grid grid-cols-1 gap-6 md:grid-cols-2">
78+
{bestPractices.map((page, index) => (
79+
<TeaserSectionListItem
80+
key={index}
81+
title={page.title}
82+
description={page.description}
83+
icon={<img src={page.icon} alt="" />}
84+
section={page.section}
85+
href={page.href}
86+
/>
87+
))}
88+
</ul>
89+
</>
90+
)}
6391
</section>
6492
)
6593
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export function partition<T, X extends T>(
2+
array: T[],
3+
predicate: (item: T) => item is X,
4+
): [X[], Exclude<T, X>[]]
5+
export function partition<T>(
6+
array: T[],
7+
predicate: (item: T) => boolean,
8+
): [T[], T[]]
9+
export function partition<T>(
10+
array: T[],
11+
predicate: (item: T) => boolean,
12+
): [T[], T[]] {
13+
const left: T[] = []
14+
const right: T[] = []
15+
16+
for (const item of array) {
17+
if (predicate(item)) {
18+
left.push(item)
19+
} else {
20+
right.push(item)
21+
}
22+
}
23+
return [left, right]
24+
}

0 commit comments

Comments
 (0)