|
1 | 1 | import { contentManager } from "@/lib/contentManager";
|
2 |
| -import styles from "./HomePage.module.css"; |
| 2 | +import styles from "./HomePageLinks.module.css"; |
3 | 3 | import Link from "next/link";
|
| 4 | +import { useMemo } from "react"; |
| 5 | +import CommunityLinksStyles from "@/app/components/CommunityLinks/CommunityLinks.module.css"; |
4 | 6 |
|
5 | 7 | export default function HomePageLinks() {
|
6 | 8 | 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 | + }, []); |
11 | 26 |
|
12 | 27 | return (
|
13 | 28 | <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 | + ))} |
42 | 38 | </div>
|
43 | 39 | );
|
44 | 40 | }
|
0 commit comments