diff --git a/aio/tools/transforms/angular-base-package/processors/createSitemap.js b/aio/tools/transforms/angular-base-package/processors/createSitemap.js index b9d4b89b51..4cbf8f5287 100644 --- a/aio/tools/transforms/angular-base-package/processors/createSitemap.js +++ b/aio/tools/transforms/angular-base-package/processors/createSitemap.js @@ -1,5 +1,15 @@ module.exports = function createSitemap() { return { + blacklistedDocTypes: [ + 'navigation-json', + 'contributors-json', + 'resources-json', + ], + blacklistedPaths: [ + 'test', + 'file-not-found', + 'overview-dump' + ], $runAfter: ['paths-computed'], $runBefore: ['rendering-docs'], $process(docs) { @@ -8,7 +18,16 @@ module.exports = function createSitemap() { path: 'sitemap.xml', outputPath: '../sitemap.xml', template: 'sitemap.template.xml', - urls: docs.filter(doc => doc.outputPath).map(doc => doc.path) + urls: docs + // Filter out docs that are not outputted + .filter(doc => doc.outputPath) + // Filter out unwanted docs + .filter(doc => this.blacklistedDocTypes.indexOf(doc.docType) === -1) + .filter(doc => this.blacklistedPaths.indexOf(doc.path) === -1) + // Capture the path of each doc + .map(doc => doc.path) + // Convert the homepage: `index` to `/` + .map(path => path === 'index' ? '' : path) }); } }; diff --git a/aio/tools/transforms/angular-base-package/processors/createSitemap.spec.js b/aio/tools/transforms/angular-base-package/processors/createSitemap.spec.js index c56d81f965..5559d0c80e 100644 --- a/aio/tools/transforms/angular-base-package/processors/createSitemap.spec.js +++ b/aio/tools/transforms/angular-base-package/processors/createSitemap.spec.js @@ -46,6 +46,38 @@ describe('createSitemap processor', () => { processor.$process(docs); expect(docs.pop().urls).toEqual(['abc', 'fgh']); }); + + it('ignoring blacklisted doc types', () => { + const docs = [ + { path: 'abc', outputPath: 'abc', docType: 'good' }, + { path: 'cde', outputPath: 'cde', docType: 'bad' }, + { path: 'fgh', outputPath: 'fgh', docType: 'good' }, + ]; + processor.blacklistedDocTypes = ['bad']; + processor.$process(docs); + expect(docs.pop().urls).toEqual(['abc', 'fgh']); + }); + + it('ignoring blacklisted paths', () => { + const docs = [ + { path: 'abc', outputPath: 'abc' }, + { path: 'cde', outputPath: 'cde' }, + { path: 'fgh', outputPath: 'fgh' }, + ]; + processor.blacklistedPaths = ['cde']; + processor.$process(docs); + expect(docs.pop().urls).toEqual(['abc', 'fgh']); + }); + + it('mapping the home page\'s path to `/`', () => { + const docs = [ + { path: 'abc', outputPath: 'abc' }, + { path: 'index', outputPath: 'index.json' }, + { path: 'fgh', outputPath: 'fgh' }, + ]; + processor.$process(docs); + expect(docs.pop().urls).toEqual(['abc', '', 'fgh']); + }); }); }); }); \ No newline at end of file