Skip to content

Commit 14d3617

Browse files
committed
refactor: use CSS grids
1 parent f3c12a7 commit 14d3617

File tree

2 files changed

+36
-58
lines changed

2 files changed

+36
-58
lines changed
Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
1-
.column{
2-
display: flex;
3-
flex-direction: column;
4-
gap: 0.5em;
1+
/* grid of 4 rows */
2+
.HomePageLinks {
3+
display: grid;
4+
grid-template-rows: repeat(4, 1fr);
5+
gap: 16px;
6+
column-gap: 32px;
7+
grid-auto-flow: column;
58
}
6-
7-
.HomePageLinks{
8-
width: 440px;
9-
display: flex;
10-
justify-content:center;
11-
align-items: center;
12-
gap: 4em;
13-
position: relative;
14-
padding-top: 2.5em;
15-
color: hsl(var(--primary));
16-
}
17-
18-
.HomePageLinkTitle{
19-
text-decoration: underline;
20-
text-underline-offset: 0.15em;
21-
text-decoration-color: hsl(var(--primary) / 0.3);
22-
}
23-
24-
.HomePageLinkTitle:hover {
25-
text-decoration-color: hsl(var(--primary));
26-
}
Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,40 @@
11
import { contentManager } from "@/lib/contentManager";
2-
import styles from "./HomePage.module.css";
2+
import styles from "./HomePageLinks.module.css";
33
import Link from "next/link";
4+
import { useMemo } from "react";
5+
import CommunityLinksStyles from "@/app/components/CommunityLinks/CommunityLinks.module.css";
46

57
export default function HomePageLinks() {
68
const outline = contentManager.getOutline();
7-
8-
const half = Math.ceil(outline.length / 2);
9-
const firstColumn = outline.slice(0, half);
10-
const secondColumn = outline.slice(half);
9+
const totalChapters = contentManager.getTotalChapters();
10+
const chapterInfo: {
11+
title: string;
12+
link: string;
13+
}[] = useMemo(() => {
14+
const chapterInfo = [];
15+
for (let i = 0; i < totalChapters; i++) {
16+
const chapter = outline[i];
17+
chapterInfo.push({
18+
title: chapter.title,
19+
link: contentManager.getPathWithPrefix(
20+
chapter.steps[0].fullPath,
21+
) as string,
22+
});
23+
}
24+
return chapterInfo;
25+
}, []);
1126

1227
return (
1328
<div className={styles.HomePageLinks}>
14-
<div className={styles.column}>
15-
{firstColumn.map((ele, index) => (
16-
<Link
17-
key={index}
18-
className={styles.HomePageLink}
19-
href={
20-
contentManager.getPathWithPrefix(ele.steps[0].fullPath) as string
21-
}
22-
>
23-
<span>{index + 1}. </span>
24-
<span className={styles.HomePageLinkTitle}>{ele.title}</span>
25-
</Link>
26-
))}
27-
</div>
28-
<div className={styles.column}>
29-
{secondColumn.map((ele, index) => (
30-
<Link
31-
key={index + half + 1}
32-
className={styles.HomePageLink}
33-
href={
34-
contentManager.getPathWithPrefix(ele.steps[0].fullPath) as string
35-
}
36-
>
37-
<span>{index + half + 1}. </span>
38-
<span className={styles.HomePageLinkTitle}>{ele.title}</span>
39-
</Link>
40-
))}
41-
</div>
29+
{chapterInfo.map((chapter, index) => (
30+
<Link
31+
key={index}
32+
href={chapter.link}
33+
className={CommunityLinksStyles.footerLink}
34+
>
35+
{index + 1}. {chapter.title}
36+
</Link>
37+
))}
4238
</div>
4339
);
4440
}

0 commit comments

Comments
 (0)