diff --git a/website/src/components/Navigation/DocsMenu.tsx b/website/src/components/Navigation/DocsMenu.tsx index ff0283d416..7e9e383141 100644 --- a/website/src/components/Navigation/DocsMenu.tsx +++ b/website/src/components/Navigation/DocsMenu.tsx @@ -15,15 +15,21 @@ interface DocsMenuProps { const groupPagesByDirectory = (pages: Page[]): Record => { const groupedPages: Record = {}; + const indexPages: Record = {}; pages.forEach((page) => { const pathParts = page.url !== undefined ? page.url.split('/') : ['']; const dir = pathParts.slice(2, -1).join('/'); + const fileName = pathParts[pathParts.length - 1]; - if (groupedPages.hasOwnProperty(dir) === false) { - groupedPages[dir] = []; + if (fileName === 'index') { + indexPages[dir] = page; + } else { + if (groupedPages.hasOwnProperty(dir) === false) { + groupedPages[dir] = []; + } + groupedPages[dir].push(page); } - groupedPages[dir].push(page); }); Object.keys(groupedPages).forEach((dir) => { @@ -37,7 +43,7 @@ const groupPagesByDirectory = (pages: Page[]): Record => { }); }); - return groupedPages; + return { groupedPages, indexPages }; }; const toTitleCase = (str: string): string => { @@ -45,7 +51,7 @@ const toTitleCase = (str: string): string => { }; const DocsMenu: React.FC = ({ docsPages, currentPageUrl, title }) => { - const groupedPages = groupPagesByDirectory(docsPages); + const { groupedPages, indexPages } = groupPagesByDirectory(docsPages); return ( @@ -69,7 +75,18 @@ const DocsMenu: React.FC = ({ docsPages, currentPageUrl, title }) {Object.entries(groupedPages).map(([dir, pages]) => (
  • - {toTitleCase(dir.replaceAll('-', ' '))} + {indexPages[dir] ? ( + + {toTitleCase(dir.replaceAll('-', ' '))} + + ) : ( + toTitleCase(dir.replaceAll('-', ' ')) + )}
      {pages.map((page) => ( @@ -95,7 +112,18 @@ const DocsMenu: React.FC = ({ docsPages, currentPageUrl, title }) {Object.entries(groupedPages).map(([dir, pages]) => (
    • - {toTitleCase(dir.replaceAll('-', ' '))} + {indexPages[dir] ? ( + + {toTitleCase(dir.replaceAll('-', ' '))} + + ) : ( + toTitleCase(dir.replaceAll('-', ' ')) + )}
        {pages.map((page) => ( @@ -121,4 +149,4 @@ const DocsMenu: React.FC = ({ docsPages, currentPageUrl, title }) ); }; -export default DocsMenu; +export default DocsMenu; \ No newline at end of file