build(aio): `doc.searchTitle` can override name in search results
This commit is contained in:
parent
895f47a9c2
commit
978376a46e
|
@ -23,6 +23,7 @@ module.exports = new Package('angular-api', [basePackage, typeScriptPackage])
|
|||
.processor(require('./processors/filterMemberDocs'))
|
||||
.processor(require('./processors/markBarredODocsAsPrivate'))
|
||||
.processor(require('./processors/filterPrivateDocs'))
|
||||
.processor(require('./processors/computeSearchTitle'))
|
||||
|
||||
// Where do we get the source files?
|
||||
.config(function(readTypeScriptModules, readFilesProcessor, collectExamples) {
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
module.exports = function computeSearchTitleProcessor() {
|
||||
return {
|
||||
$runAfter: ['ids-computed'],
|
||||
$runBefore: ['generateKeywordsProcessor'],
|
||||
$process(docs) {
|
||||
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,59 @@
|
|||
const testPackage = require('../../helpers/test-package');
|
||||
const processorFactory = require('./computeSearchTitle');
|
||||
const Dgeni = require('dgeni');
|
||||
|
||||
fdescribe('computeSearchTitle processor', () => {
|
||||
|
||||
it('should be available on the injector', () => {
|
||||
const dgeni = new Dgeni([testPackage('angular-api-package')]);
|
||||
const injector = dgeni.configureInjector();
|
||||
const processor = injector.get('computeSearchTitleProcessor');
|
||||
expect(processor.$process).toBeDefined();
|
||||
});
|
||||
|
||||
it('should run after the correct processor', () => {
|
||||
const processor = processorFactory();
|
||||
expect(processor.$runAfter).toEqual(['ids-computed']);
|
||||
});
|
||||
|
||||
it('should run before the correct processor', () => {
|
||||
const processor = processorFactory();
|
||||
expect(processor.$runBefore).toEqual(['generateKeywordsProcessor']);
|
||||
});
|
||||
|
||||
it('should compute a search title for class-like docs', () => {
|
||||
const processor = processorFactory();
|
||||
const docs = [
|
||||
{ docType: 'class', name: 'MyClass' },
|
||||
{ docType: 'interface', name: 'MyInterface' },
|
||||
{ docType: 'pipe', name: 'MyPipe', pipeOptions: { name: 'myPipe' } }
|
||||
];
|
||||
processor.$process(docs);
|
||||
expect(docs[0].searchTitle).toEqual('class MyClass');
|
||||
expect(docs[0].searchTitle).toEqual('interface MyInterface');
|
||||
expect(docs[0].searchTitle).toEqual('myPipe (pipe)');
|
||||
});
|
||||
|
||||
it('should compute a class search title', () => {
|
||||
const processor = processorFactory();
|
||||
const docs = [
|
||||
{ docType: 'class', name: 'MyClass' }
|
||||
];
|
||||
processor.$process(docs);
|
||||
expect(docs[0].searchTitle).toEqual('class MyClass');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
// 'decorator',
|
||||
// 'directive',
|
||||
// 'module'
|
||||
// 'function',
|
||||
// 'var',
|
||||
// 'const',
|
||||
// 'let',
|
||||
// 'enum',
|
||||
// 'type-alias',
|
||||
// 'value-module'
|
|
@ -115,7 +115,7 @@ 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.name || page.title, type: page.docType}, page.searchTerms);
|
||||
{path: page.path, title: page.searchTitle || page.name || page.title, type: page.docType}, page.searchTerms);
|
||||
});
|
||||
|
||||
docs.push({
|
||||
|
|
|
@ -38,4 +38,15 @@ describe('generateKeywords processor', () => {
|
|||
jasmine.objectContaining({ title: 'PublicExport', type: 'class'})
|
||||
]);
|
||||
});
|
||||
|
||||
it('should use `doc.searchTitle` as the title if available', () => {
|
||||
const processor = processorFactory(mockLogger, mockReadFilesProcessor);
|
||||
const docs = [
|
||||
{ docType: 'class', name: 'PublicExport', searchTitle: 'class PublicExport' },
|
||||
];
|
||||
processor.$process(docs);
|
||||
expect(docs[docs.length - 1].data).toEqual([
|
||||
jasmine.objectContaining({ title: 'class PublicExport', type: 'class'})
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue