diff --git a/buildNavigation.js b/buildNavigation.js index 8b133c44..edfeac78 100644 --- a/buildNavigation.js +++ b/buildNavigation.js @@ -8,7 +8,7 @@ const { siteMetadata, pathPrefix } = require('./gatsby-config.js'); try { if(!pathPrefix) { throw new TypeError("pathPrefix not found"); - } + } let topNavMarkdown = ``; // TODO: prob need url fixer from gatsby theme @@ -46,10 +46,12 @@ try { siteMetadata.pages?.forEach((navItem) => { //let pathText = navItem.path ? navItem.path : ''; if(navItem.path) { + navItem = buildDirectoryIndexFile(navItem); topNavMarkdown += ` - [${navItem.title}](${navItem.path})\n`; } else { topNavMarkdown += ` - ${navItem.title}\n`; navItem.menu.forEach((menuItem) =>{ + menuItem = buildDirectoryIndexFile(menuItem); topNavMarkdown += ` - [${menuItem.title}](${menuItem.path})\n`; }); } @@ -59,7 +61,7 @@ try { topNavMarkdown += `\n- subPages:\n`; let sideNavMarkdown = ``; let depth = 1; - + sideNavMarkdown += buildSideNavRecursively(siteMetadata.subPages, depth); topNavMarkdown += sideNavMarkdown; } @@ -71,18 +73,26 @@ try { } catch (err) { console.error(err); } + +function buildDirectoryIndexFile(navItem){ + // when it's internal link, any directory should point specifically to index.md. + if (!navItem.path.startsWith("http") && navItem.path.endsWith('/')){ + navItem.path = navItem.path + 'index.md'; + } + return navItem; +} // subpages menu should only appear on the subpages path // need to check paths to function buildSideNavRecursively(sideNav, depth) { let sideNavMarkdown = ''; for (var k in sideNav) { - let header = sideNav[k].header ? 'header' : ''; + let header = sideNav[k].header ? 'header' : ''; + sideNav[k] = buildDirectoryIndexFile(sideNav[k]); sideNavMarkdown += `${insertSpace(depth)}- [${sideNav[k].title}](${sideNav[k].path}) ${header}\n`; - if (sideNav[k].pages) { sideNavMarkdown += buildSideNavRecursively(sideNav[k].pages, depth+1); - } + } } return sideNavMarkdown; } @@ -96,11 +106,11 @@ function insertSpace(indentLevel) { } // src/pages/topNav.md -// src/pages/sideNav.md +// src/pages/sideNav.md // src/pages/get-started/sideNav.md -// go through each subPages and find each path that relates to a subfolder +// go through each subPages and find each path that relates to a subfolder // title with path only -// header setting \ No newline at end of file +// header setting diff --git a/src/pages/config.md b/src/pages/config.md index 22045dc3..d3477a94 100644 --- a/src/pages/config.md +++ b/src/pages/config.md @@ -3,37 +3,37 @@ - versions: - [v2.0](/) selected - - [v1.4](https://github.com/AdobeDocs/dev-site) + - [v1.4](https://github.com/AdobeDocs/dev-site) - pages: - - [Cat Analytics](/) - - [Guides](/guides/) + - [Cat Analytics](/index.md) + - [Guides](/guides/index.md) - API Reference - [Cat Reference v2.0](/api/index.md) - [Cat Reference v1.4](/api/1-4.md) - - [Support](/support/) - - [Test](/test/) + - [Support](/support/index.md) + - [Test](/test/index.md) - subPages: - - [Get Started](/guides/) - - [Dummy an OAuth Client](/guides/dummy_oauth_client/) - - [Dummy OAuth using POSTMAN](/guides/dummy_using_postman/) - - [Cat Metrics API](/guides/dummy_metrics_api/) - - [Migrating](/guides/migrating/) - - [Overview](/support/) header - - [Help](/support/) - - [FAQ](/support/FAQ/) - - [How to contribute](/support/contribute/) - - [Community](/support/community/) header - - [Information](/support/community/) - - [Test](/test/) - - [Code](/test/code/) - - [CodeBlock](/test/code-block/) - - [CodeBlock with Picklist](/test/code-block-with-picklist/) - - [CodeBlock without Picklist](/test/code-block-without-picklist/) - - [Code in List](/test/code-in-list/) - - [Code in Table](/test/code-in-table/) - - [InlineAlert](/test/inline-alert/) - - [ListBlock](/test/list-block/) - - [RedoclyAPIBlock](/test/redocly-api-block/) - - [TabsBlock](/test/tabs-block/) + - [Get Started](/guides/index.md) + - [Dummy an OAuth Client](/guides/dummy_oauth_client/index.md) + - [Dummy OAuth using POSTMAN](/guides/dummy_using_postman/index.md) + - [Cat Metrics API](/guides/dummy_metrics_api/index.md) + - [Migrating](/guides/migrating/index.md) + - [Overview](/support/index.md) header + - [Help](/support/index.md) + - [FAQ](/support/FAQ/index.md) + - [How to contribute](/support/contribute/index.md) + - [Community](/support/community/index.md) header + - [Information](/support/community/index.md) + - [Test](/test/index.md) + - [Code](/test/code/index.md) + - [CodeBlock](/test/code-block/index.md) + - [CodeBlock with Picklist](/test/code-block-with-picklist/index.md) + - [CodeBlock without Picklist](/test/code-block-without-picklist/index.md) + - [Code in List](/test/code-in-list/index.md) + - [Code in Table](/test/code-in-table/index.md) + - [InlineAlert](/test/inline-alert/index.md) + - [ListBlock](/test/list-block/index.md) + - [RedoclyAPIBlock](/test/redocly-api-block/index.md) + - [TabsBlock](/test/tabs-block/index.md)