From 71ea931df5308975e3d58b35756fd0bcee308e03 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Wed, 7 Feb 2018 10:46:37 +0000 Subject: [PATCH] build(aio): blacklist unwanted URLs from the generated sitemap.xml (#22061) Closes #22017 PR Close #22061 --- .../processors/createSitemap.js | 21 +++++++++++- .../processors/createSitemap.spec.js | 32 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) 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