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.
This commit is contained in:
		
							parent
							
								
									89f317915d
								
							
						
					
					
						commit
						dfbbbb5e3e
					
				| @ -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?
 | ||||
|  | ||||
| @ -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) | ||||
|       }); | ||||
|     } | ||||
|   }; | ||||
|  | ||||
| @ -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":""}]' | ||||
|     ); | ||||
|   }); | ||||
| }); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user