Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Fix prepareSitemap function to append index.html to files ending in index.js #444

Merged
merged 1 commit into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/helpers/batfish/__tests__/sitemap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
13 changes: 6 additions & 7 deletions src/helpers/batfish/sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down