Skip to content

Commit 0a0d6b8

Browse files
fix: the anchor url of search with the switcher version (#497)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 54b211c commit 0a0d6b8

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

doc/changelog.d/497.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: the anchor url of search with the switcher version

src/ansys_sphinx_theme/search/fuse_search.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
class SearchIndex:
3232
"""Class to get search index."""
3333

34-
def __init__(self, doc_name, app):
34+
def __init__(self, doc_name, app, version_url_prefix):
3535
"""Initialize the class.
3636
3737
Parameters
@@ -40,12 +40,15 @@ def __init__(self, doc_name, app):
4040
Document name.
4141
app : Sphinx
4242
Sphinx application.
43+
version : str
44+
Version of the document for prefixing the path.
4345
"""
4446
self._doc_name = doc_name
4547
self.doc_path = f"{self._doc_name}.html"
4648
self.doc_title = app.env.titles[self._doc_name].astext()
4749
self._doc_tree = app.env.get_doctree(self._doc_name)
4850
self.sections = []
51+
self.url_prefix = version_url_prefix
4952

5053
def iterate_through_docs(self):
5154
"""Iterate through the document."""
@@ -71,7 +74,7 @@ def indices(self):
7174
for sections in self.sections:
7275
search_index = {
7376
"objectID": self._doc_name,
74-
"href": f"{self.doc_path}#{sections['section_anchor_id']}",
77+
"href": f"{self.url_prefix}{self.doc_path}#{sections['section_anchor_id']}",
7578
"title": self.doc_title,
7679
"section": sections["section_title"],
7780
"text": sections["section_text"],
@@ -100,11 +103,14 @@ def create_search_index(app, exception):
100103
if not app.config.html_theme_options.get("static_search", {}):
101104
return
102105

106+
switcher_version = app.config.html_theme_options.get("switcher", {}).get("version_match", "")
107+
version_url_prefix = f"version/{switcher_version}/" if switcher_version else ""
108+
103109
all_docs = app.env.found_docs
104110
search_index_list = []
105111

106112
for document in all_docs:
107-
search_index = SearchIndex(document, app)
113+
search_index = SearchIndex(document, app, version_url_prefix)
108114
search_index.iterate_through_docs()
109115
search_index_list.extend(search_index.indices)
110116

0 commit comments

Comments
 (0)