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:
parent
d3c0d92d28
commit
7ca2a2a863
|
@ -9,6 +9,7 @@ export interface SearchResult {
|
|||
type: string;
|
||||
titleWords: string;
|
||||
keywords: string;
|
||||
topics?: string;
|
||||
deprecated: boolean;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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`
|
||||
|
|
9
aio/tools/transforms/angular-base-package/inline-tag-defs/custom-search-defs/index.js
vendored
Normal file
9
aio/tools/transforms/angular-base-package/inline-tag-defs/custom-search-defs/index.js
vendored
Normal 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;
|
||||
}
|
||||
};
|
||||
|
|
@ -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
|
||||
};
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue