Skip to content

Commit 8012ae2

Browse files
Strip index from routes
1 parent b63d962 commit 8012ae2

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

lib/prember-urls.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ module.exports = function premberUrls({ distDir }) {
4747
continue;
4848
}
4949

50-
let url = '/' + doc.route.replace(/\./g, '/');
51-
urls.add(url);
50+
let routePath = doc.route.replace(/\./g, '/').replace(/\/index$/, '');
51+
if (routePath === 'index') routePath = '';
52+
urls.add('/' + routePath);
5253
}
5354
}
5455
}

tests-node/unit/prember-urls-test.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,41 @@ describe('Unit | prember-urls', function () {
9191
let urls = premberUrls({ distDir: tmpDir });
9292
assert.include(urls, '/docs/quickstart');
9393
assert.include(urls, '/docs/usage');
94-
assert.include(urls, '/docs/components/index');
94+
// docs.components.index should become /docs/components (strip trailing /index)
95+
assert.include(urls, '/docs/components');
96+
assert.notInclude(urls, '/docs/components/index');
97+
});
98+
99+
it('strips trailing /index from routes', function () {
100+
fs.ensureDirSync(path.join(tmpDir, 'ember-cli-addon-docs'));
101+
fs.writeJsonSync(
102+
path.join(tmpDir, 'ember-cli-addon-docs', 'search-index.json'),
103+
{
104+
index: {},
105+
documents: {
106+
'template:docs.index': {
107+
type: 'template',
108+
route: 'docs.index',
109+
},
110+
'template:sandbox.docs.index': {
111+
type: 'template',
112+
route: 'sandbox.docs.index',
113+
},
114+
'template:index': {
115+
type: 'template',
116+
route: 'index',
117+
},
118+
},
119+
},
120+
);
121+
122+
let urls = premberUrls({ distDir: tmpDir });
123+
assert.include(urls, '/docs');
124+
assert.include(urls, '/sandbox/docs');
125+
assert.include(urls, '/');
126+
assert.notInclude(urls, '/docs/index');
127+
assert.notInclude(urls, '/sandbox/docs/index');
128+
assert.notInclude(urls, '/index');
95129
});
96130

97131
it('filters out internal routes from search index', function () {

0 commit comments

Comments
 (0)