From dfbbbb5e3e872f150802af038e09b70bf6dcd87b Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Tue, 30 May 2017 22:24:54 +0300 Subject: [PATCH] build(aio): the the captured h1 as the title for the search index If there is no title already provided, use the one captured from the renderedContent. --- .../transforms/angular-base-package/index.js | 1 + .../processors/generateKeywords.js | 13 +++---- .../processors/generateKeywords.spec.js | 34 +++++++++++++++++-- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/aio/tools/transforms/angular-base-package/index.js b/aio/tools/transforms/angular-base-package/index.js index ab05c4e976..427eae281e 100644 --- a/aio/tools/transforms/angular-base-package/index.js +++ b/aio/tools/transforms/angular-base-package/index.js @@ -55,6 +55,7 @@ module.exports = new Package('angular-base', [ generateKeywordsProcessor.ignoreWordsFile = path.resolve(__dirname, 'ignore.words'); generateKeywordsProcessor.docTypesToIgnore = ['example-region']; + generateKeywordsProcessor.propertiesToIgnore = ['renderedContent']; }) // Where do we write the output files? diff --git a/aio/tools/transforms/angular-base-package/processors/generateKeywords.js b/aio/tools/transforms/angular-base-package/processors/generateKeywords.js index 078127a413..99ee65d8d4 100644 --- a/aio/tools/transforms/angular-base-package/processors/generateKeywords.js +++ b/aio/tools/transforms/angular-base-package/processors/generateKeywords.js @@ -22,8 +22,8 @@ module.exports = function generateKeywordsProcessor(log, readFilesProcessor) { propertiesToIgnore: {}, outputFolder: {presence: true} }, - $runAfter: ['paths-computed'], - $runBefore: ['rendering-docs'], + $runAfter: ['postProcessHtml'], + $runBefore: ['writing-files'], $process: function(docs) { // Keywords to ignore @@ -103,9 +103,10 @@ module.exports = function generateKeywordsProcessor(log, readFilesProcessor) { } }); + doc.searchTitle = doc.searchTitle || doc.title || doc.vFile && doc.vFile.title || doc.name; doc.searchTerms = { - titleWords: extractTitleWords(doc.title || doc.name), + titleWords: extractTitleWords(doc.searchTitle), keywords: words.sort().join(' '), members: members.sort().join(' ') }; @@ -115,16 +116,16 @@ module.exports = function generateKeywordsProcessor(log, readFilesProcessor) { var searchData = filteredDocs.filter(function(page) { return page.searchTerms; }).map(function(page) { return Object.assign( - {path: page.path, title: page.searchTitle || page.name || page.title, type: page.docType}, page.searchTerms); + {path: page.path, title: page.searchTitle, type: page.docType}, page.searchTerms); }); docs.push({ docType: 'json-doc', id: 'search-data-json', - template: 'json-doc.template.json', path: this.outputFolder + '/search-data.json', outputPath: this.outputFolder + '/search-data.json', - data: searchData + data: searchData, + renderedContent: JSON.stringify(searchData) }); } }; diff --git a/aio/tools/transforms/angular-base-package/processors/generateKeywords.spec.js b/aio/tools/transforms/angular-base-package/processors/generateKeywords.spec.js index ef2e546d99..318b5b9dcd 100644 --- a/aio/tools/transforms/angular-base-package/processors/generateKeywords.spec.js +++ b/aio/tools/transforms/angular-base-package/processors/generateKeywords.spec.js @@ -18,12 +18,12 @@ describe('generateKeywords processor', () => { it('should run after the correct processor', () => { const processor = processorFactory(mockLogger, mockReadFilesProcessor); - expect(processor.$runAfter).toEqual(['paths-computed']); + expect(processor.$runAfter).toEqual(['postProcessHtml']); }); it('should run before the correct processor', () => { const processor = processorFactory(mockLogger, mockReadFilesProcessor); - expect(processor.$runBefore).toEqual(['rendering-docs']); + expect(processor.$runBefore).toEqual(['writing-files']); }); it('should ignore internal and private exports', () => { @@ -39,7 +39,24 @@ describe('generateKeywords processor', () => { ]); }); - it('should use `doc.searchTitle` as the title if available', () => { + it('should compute `doc.searchTitle` from the doc properties if not already provided', () => { + const processor = processorFactory(mockLogger, mockReadFilesProcessor); + const docs = [ + { docType: 'class', name: 'A', searchTitle: 'searchTitle A', title: 'title A', vFile: { title: 'vFile A'} }, + { docType: 'class', name: 'B', title: 'title B', vFile: { title: 'vFile B'} }, + { docType: 'class', name: 'C', vFile: { title: 'vFile C'} }, + { docType: 'class', name: 'D' }, + ]; + processor.$process(docs); + expect(docs[docs.length - 1].data).toEqual([ + jasmine.objectContaining({ title: 'searchTitle A' }), + jasmine.objectContaining({ title: 'title B' }), + jasmine.objectContaining({ title: 'vFile C' }), + jasmine.objectContaining({ title: 'D' }), + ]); + }); + + it('should use `doc.searchTitle` as the title in the search index', () => { const processor = processorFactory(mockLogger, mockReadFilesProcessor); const docs = [ { docType: 'class', name: 'PublicExport', searchTitle: 'class PublicExport' }, @@ -49,4 +66,15 @@ describe('generateKeywords processor', () => { jasmine.objectContaining({ title: 'class PublicExport', type: 'class'}) ]); }); + + it('should generate renderedContent property', () => { + const processor = processorFactory(mockLogger, mockReadFilesProcessor); + const docs = [ + { docType: 'class', name: 'SomeClass', description: 'The is the documentation for the SomeClass API.' }, + ]; + processor.$process(docs); + expect(docs[docs.length - 1].renderedContent).toEqual( + '[{"title":"SomeClass","type":"class","titleWords":"SomeClass","keywords":"api class documentation for is someclass the","members":""}]' + ); + }); });