[search] constraint retrieval for anchored search result summary (#12105)

This is a post-merge adjustments for #11944.
This commit is contained in:
James Addison 2024-03-16 10:34:59 +00:00 committed by GitHub
parent 16748aef2d
commit 6aaeee206b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -164,11 +164,11 @@ const Search = {
const htmlElement = new DOMParser().parseFromString(htmlString, 'text/html');
htmlElement.querySelectorAll(".headerlink").forEach((el) => { el.remove() });
if (anchor) {
const anchorContent = htmlElement.querySelector(anchor);
const anchorContent = htmlElement.querySelector(`[role="main"] ${anchor}`);
if (anchorContent) return anchorContent.textContent;
console.warn(
`Anchor block not found. Sphinx search tries to obtain it via '${anchor}'. Check your theme or template.`
`Anchored content block not found. Sphinx search tries to obtain it via DOM query '[role=main] ${anchor}'. Check your theme or template.`
);
}
@ -177,7 +177,7 @@ const Search = {
if (docContent) return docContent.textContent;
console.warn(
"Content block not found. Sphinx search tries to obtain it via '[role=main]'. Could you check your theme or template."
"Content block not found. Sphinx search tries to obtain it via DOM query '[role=main]'. Check your theme or template."
);
return "";
},