* Retrieves the section title based on the provided pathname. * * @param {string} pathname - The current pathname. * @returns {string} - The section title.
({
pathname,
isLearnPath
}: {
pathname: string;
isLearnPath: boolean;
})
| 26 | * @returns {string} - The section title. |
| 27 | */ |
| 28 | function getSectionTitle({ |
| 29 | pathname, |
| 30 | isLearnPath |
| 31 | }: { |
| 32 | pathname: string; |
| 33 | isLearnPath: boolean; |
| 34 | }) { |
| 35 | let currentTitle = ''; |
| 36 | const navData = isLearnPath ? navLearn : navigationData; |
| 37 | |
| 38 | for (const item of navData) { |
| 39 | const foundLink = item.links.find(link => { |
| 40 | if (link.href === pathname) { |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | if (link.sections) { |
| 45 | return link.sections.find(section => section.href === pathname); |
| 46 | } |
| 47 | }); |
| 48 | |
| 49 | // If the link has sections, we need to find the matching section title |
| 50 | if (foundLink?.sections?.length) { |
| 51 | currentTitle = foundLink.title; |
| 52 | break; // Stop searching once we've found the matching href |
| 53 | } |
| 54 | |
| 55 | // If the link has no sections, we can use the link title |
| 56 | if (foundLink) { |
| 57 | currentTitle = item.title; |
| 58 | break; // Stop searching once we've found the matching href |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return currentTitle; |
| 63 | } |
| 64 | |
| 65 | function HeaderLinks() { |
| 66 | const pathname = usePathname(); |