From 8eaad498f6b0bc975209f1c7642a20eaa83f9a37 Mon Sep 17 00:00:00 2001 From: Katy DeCorah Date: Fri, 23 Apr 2021 12:52:57 -0400 Subject: [PATCH] append index.html to files ending in index.js --- .../fixtures/android-sitemap-pages.json | 0 src/helpers/batfish/__tests__/sitemap.test.js | 49 +++++++++++++++++++ src/helpers/batfish/sitemap.js | 13 +++-- 3 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 src/helpers/batfish/__tests__/fixtures/android-sitemap-pages.json diff --git a/src/helpers/batfish/__tests__/fixtures/android-sitemap-pages.json b/src/helpers/batfish/__tests__/fixtures/android-sitemap-pages.json new file mode 100644 index 000000000..e69de29bb diff --git a/src/helpers/batfish/__tests__/sitemap.test.js b/src/helpers/batfish/__tests__/sitemap.test.js index b0e225fd3..ad02f2d40 100644 --- a/src/helpers/batfish/__tests__/sitemap.test.js +++ b/src/helpers/batfish/__tests__/sitemap.test.js @@ -64,6 +64,55 @@ describe('prepareSitemap', () => { ]); }); + it('append index.html to files ending in index.js', () => { + const ignoreFile = prepareSitemap({ + pages: [ + { + filePath: '/android-docs/src/pages/index.js', + path: '/android/', + frontMatter: { + hideFromSearchEngines: true + } + }, + { + filePath: '/android-docs/src/pages/core/index.js', + path: '/android/core/', + frontMatter: { + hideFromSearchEngines: true + } + }, + { + filePath: '/android-docs/src/pages/java/index.js', + path: '/android/java/', + frontMatter: { + hideFromSearchEngines: true + } + }, + { + filePath: '/android-docs/src/pages/core/api-reference/index.md', + path: '/android/core/api-reference/', + frontMatter: { + title: 'API Reference' + } + }, + { + filePath: '/android-docs/src/pages/core/guides/hidden.md', + path: '/android/core/guides/hidden/', + frontMatter: { + hideFromSearchEngines: true + } + } + ], + siteBasePath: '/android' + }).map((f) => f.replace(process.cwd(), '')); + expect(ignoreFile).toEqual([ + '/_site/index.html', + '/_site/core/index.html', + '/_site/java/index.html', + '/_site/core/guides/hidden/' + ]); + }); + // travis is configured to run this test file again after build // this test asserts the URLs in the sitemap if (existsSync(siteMap)) { diff --git a/src/helpers/batfish/sitemap.js b/src/helpers/batfish/sitemap.js index 87165e598..7ddbfc33c 100644 --- a/src/helpers/batfish/sitemap.js +++ b/src/helpers/batfish/sitemap.js @@ -13,13 +13,12 @@ function prepareSitemap({ ({ frontMatter }) => frontMatter.hideFromSearchEngines || frontMatter.splitPage ) - .map(({ path }) => { - // fix root index path to return full path - if (path === `${siteBasePath}/`) { - return path.replace( - join(siteBasePath, '/'), - join(process.cwd(), docsPath, outputDirectory, 'index.html') - ); + .map(({ path, filePath }) => { + // append index.html to files ending in index.js + if (filePath.endsWith('index.js')) { + return path + .replace(siteBasePath, join(process.cwd(), docsPath, outputDirectory)) + .replace(/\/$/, '/index.html'); } else { return path.replace( siteBasePath,