feat(docs-infra): add `searchKeywords` preprocessor (#35539)

This commit adds a new preprocessor to use `${@searchKeywords}`, allowing
the docs to use a list of custom search phrases that will be
prioritized over the keywords found in the content.

Closes #35449

PR Close #35539
This commit is contained in:
Sonu Kapoor 2020-02-18 21:47:21 -05:00 committed by atscott
parent d3c0d92d28
commit 7ca2a2a863
5 changed files with 19 additions and 1 deletions

View File

@ -9,6 +9,7 @@ export interface SearchResult {
type: string;
titleWords: string;
keywords: string;
topics?: string;
deprecated: boolean;
}

View File

@ -15,6 +15,7 @@ interface PageInfo {
type: string;
titleWords: string;
keyWords: string;
topics?: string;
}
addEventListener('message', handleMessage);
@ -27,6 +28,7 @@ function createIndex(loadIndexFn: IndexLoader): lunr.Index {
queryLexer.termSeparator = lunr.tokenizer.separator = /\s+/;
return lunr(/** @this */function() {
this.ref('path');
this.field('topics', { boost: 15 });
this.field('titleWords', { boost: 10 });
this.field('headingWords', { boost: 5 });
this.field('members', { boost: 4 });

View File

@ -45,6 +45,11 @@ module.exports = new Package('angular-base', [
.factory(require('./post-processors/add-image-dimensions'))
.factory(require('./post-processors/auto-link-code'))
// Configure jsdoc-style tag parsing
.config(function(inlineTagProcessor) {
inlineTagProcessor.inlineTagDefinitions.push(require('./inline-tag-defs/custom-search-defs/'));
})
.config(function(checkAnchorLinksProcessor) {
// This is disabled here to prevent false negatives for the `docs-watch` task.
// It is re-enabled in the main `angular.io-package`

View File

@ -0,0 +1,9 @@
module.exports = {
name: 'searchKeywords',
description: 'A shorthand for creating elements with search terms. Usage: `{@searchKeywords term1 term2 termN }`',
handler: function(doc, tagName, tagDescription) {
doc.searchKeywords = tagDescription;
return doc;
}
};

View File

@ -91,7 +91,8 @@ module.exports = function generateKeywordsProcessor(log, readFilesProcessor) {
titleWords: tokenize(doc.searchTitle).join(' '),
headingWords: headingWords.sort().join(' '),
keywords: words.sort().join(' '),
members: members.sort().join(' ')
members: members.sort().join(' '),
topics: doc.searchKeywords
};
});