in src/theme/SearchBar/SuggestionTemplate.js [9:54]
export function SuggestionTemplate({ document, type, page, metadata, tokens, isInterOfTree, isLastOfTree, }) {
const isTitle = type === SearchDocumentType.Title;
const isKeywords = type === SearchDocumentType.Keywords;
const isTitleRelated = isTitle || isKeywords;
const isHeading = type === SearchDocumentType.Heading;
const tree = [];
if (isInterOfTree) {
tree.push(iconTreeInter);
}
else if (isLastOfTree) {
tree.push(iconTreeLast);
}
const treeWrapper = tree.map((item) => `<span class="${styles.hitTree}">${item}</span>`);
const icon = `<span class="${styles.hitIcon}">${isTitleRelated ? iconTitle : isHeading ? iconHeading : iconContent}</span>`;
const wrapped = [
`<span class="${styles.hitTitle}">${isKeywords
? highlight(document.s, tokens)
: highlightStemmed(document.t, getStemmedPositions(metadata, "t"), tokens)}</span>`,
];
const needsExplicitHitPath = !isInterOfTree && !isLastOfTree && explicitSearchResultPath;
if (needsExplicitHitPath) {
const pathItems = page
? page.b
?.concat(page.t)
.concat(!document.s || document.s === page.t ? [] : document.s)
: document.b;
wrapped.push(`<span class="${styles.hitPath}">${concatDocumentPath(pathItems ?? [])}</span>`);
}
else if (!isTitleRelated) {
wrapped.push(`<span class="${styles.hitPath}">${highlight(page.t ||
// Todo(weareoutman): This is for EasyOps only.
// istanbul ignore next
(document.u.startsWith("/docs/api-reference/")
? "API Reference"
: ""), tokens)}</span>`);
}
const action = `<span class="${styles.hitAction}">${iconAction}</span>`;
return [
...treeWrapper,
icon,
`<span class="${styles.hitWrapper}">`,
...wrapped,
"</span>",
action,
].join("");
}