diff --git a/src/components/LeftSidebar/LeftSidebar.astro b/src/components/LeftSidebar/LeftSidebar.astro index cd68f10ec93..5e9dc9b8671 100644 --- a/src/components/LeftSidebar/LeftSidebar.astro +++ b/src/components/LeftSidebar/LeftSidebar.astro @@ -33,19 +33,15 @@ const removeSlashes = (url: string) => { return sanitizedUrl } -// This function checks if the current page is a match for the main section or any of its subpages -// (e.g. /getting-started-hardhat is a subpage of /getting-started). -const isCurrentPageMatch = (sectionUrl: string, currentPage: string): boolean => { +const isCurrentPageMatch = (sectionUrl: string, currentPage: string, highlightAsCurrent: string[] = []): boolean => { const normalizedSectionUrl = removeSlashes(sectionUrl) const normalizedCurrentPage = removeSlashes(currentPage.slice(1)) - // Direct match (e.g., both "/getting-started") if (normalizedCurrentPage === normalizedSectionUrl) { return true } - // Check for subpage match (e.g., currentPage is "/getting-started-hardhat" and sectionUrl is "/getting-started") - if (normalizedCurrentPage.startsWith(`${normalizedSectionUrl}-`)) { + if (highlightAsCurrent.some((url) => removeSlashes(url) === normalizedCurrentPage)) { return true } @@ -59,7 +55,11 @@ const isCurrentPageMatch = (sectionUrl: string, currentPage: string): boolean => sidebarSections.map((s: { parentSection: Sections; contents: SectionContent[]; section: Sections }) => (
  • isCurrentPageMatch(object.url, currentPage)).length} + open={ + !!flattenChildren(s.contents).filter((object) => + isCurrentPageMatch(object.url, currentPage, object.highlightAsCurrent) + ).length + } > {s.section}