build(docs-infra): add auto-link-filter for generic words (#34835)
Fixes #34794 PR Close #34835
This commit is contained in:
parent
5b77e67dff
commit
a3b2d6735a
|
@ -40,6 +40,7 @@ module.exports = new Package('angular-base', [
|
|||
.factory(require('./services/auto-link-filters/filterPipes'))
|
||||
.factory(require('./services/auto-link-filters/filterAmbiguousDirectiveAliases'))
|
||||
.factory(require('./services/auto-link-filters/ignoreHttpInUrls'))
|
||||
.factory(require('./services/auto-link-filters/ignoreGenericWords'))
|
||||
|
||||
.factory(require('./post-processors/add-image-dimensions'))
|
||||
.factory(require('./post-processors/auto-link-code'))
|
||||
|
@ -129,9 +130,9 @@ module.exports = new Package('angular-base', [
|
|||
})
|
||||
|
||||
|
||||
.config(function(postProcessHtml, addImageDimensions, autoLinkCode, filterPipes, filterAmbiguousDirectiveAliases, ignoreHttpInUrls) {
|
||||
.config(function(postProcessHtml, addImageDimensions, autoLinkCode, filterPipes, filterAmbiguousDirectiveAliases, ignoreHttpInUrls, ignoreGenericWords) {
|
||||
addImageDimensions.basePath = path.resolve(AIO_PATH, 'src');
|
||||
autoLinkCode.customFilters = [ignoreHttpInUrls, filterPipes, filterAmbiguousDirectiveAliases];
|
||||
autoLinkCode.customFilters = [ignoreGenericWords, ignoreHttpInUrls, filterPipes, filterAmbiguousDirectiveAliases];
|
||||
postProcessHtml.plugins = [
|
||||
require('./post-processors/autolink-headings'),
|
||||
addImageDimensions,
|
||||
|
|
10
aio/tools/transforms/angular-base-package/services/auto-link-filters/ignoreGenericWords.js
vendored
Normal file
10
aio/tools/transforms/angular-base-package/services/auto-link-filters/ignoreGenericWords.js
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
/**
|
||||
* This service is used by the autoLinkCode post-processor to ignore generic words
|
||||
* that could be mistaken as classes, functions, etc.
|
||||
*/
|
||||
|
||||
module.exports = function ignoreGenericWords() {
|
||||
const ignoredWords = new Set(['a', 'create', 'error', 'group', 'request', 'value']);
|
||||
return (docs, words, index) => ignoredWords.has(words[index].toLowerCase()) ? [] : docs;
|
||||
};
|
|
@ -0,0 +1,21 @@
|
|||
const ignoreGenericWords = require('./ignoreGenericWords')();
|
||||
|
||||
describe('ignoreGenericWords', () => {
|
||||
it('should ignore generic words in all docs', () => {
|
||||
const docs = [{docType: 'package', name: 'create'}, {docType: 'class', name: 'Foo'}];
|
||||
const words = ['create', 'a', 'thing'];
|
||||
expect(ignoreGenericWords(docs, words, 0)).toEqual([]);
|
||||
expect(ignoreGenericWords(docs, words, 1)).toEqual([]);
|
||||
expect(ignoreGenericWords(docs, words, 2)).toEqual(docs);
|
||||
});
|
||||
|
||||
it('should ignore generic words with mixed case in all docs', () => {
|
||||
const docs = [{docType: 'package', name: 'create'}, {docType: 'class', name: 'Foo'}];
|
||||
const words = ['Create', 'eRrOr', 'STUFF'];
|
||||
expect(ignoreGenericWords(docs, words, 0)).toEqual([]);
|
||||
expect(ignoreGenericWords(docs, words, 1)).toEqual([]);
|
||||
expect(ignoreGenericWords(docs, words, 2)).toEqual(docs);
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue