Skip to content

Commit

Permalink
Fix search bug with Sphinx>=7.2 (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsalvino authored Oct 28, 2024
1 parent db925d8 commit 25ccf64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ document.addEventListener('DOMContentLoaded', () => {
document.dispatchEvent(new CustomEvent('theme:toggle-theme-mode', event));
});

// Sphinx compatibility.
// Prior to Sphinx 7.2, URL_ROOT was part of DOCUMENTATION_OPTIONS.
let URL_ROOT = "";
// Sphinx >= 7.2
if (document.documentElement.dataset.content_root) {
URL_ROOT = document.documentElement.dataset.content_root;
}
// Sphinx < 7.2
else if (typeof DOCUMENTATION_OPTIONS.URL_ROOT !== 'undefined') {
URL_ROOT = DOCUMENTATION_OPTIONS.URL_ROOT;
}

// Search.
var searchform = document.getElementById('search-form');
var searchinput = document.getElementById('searchinput');
Expand Down Expand Up @@ -126,13 +138,11 @@ document.addEventListener('DOMContentLoaded', () => {
} else if (dirname === 'index/') {
dirname = '';
}
linkUrl = DOCUMENTATION_OPTIONS.URL_ROOT + dirname;
linkUrl = URL_ROOT + dirname;
} else {
// normal html builders
linkUrl =
DOCUMENTATION_OPTIONS.URL_ROOT +
item.docname +
DOCUMENTATION_OPTIONS.FILE_SUFFIX;
URL_ROOT + item.docname + DOCUMENTATION_OPTIONS.FILE_SUFFIX;
}
// Go to the URL.
window.location.href = linkUrl;
Expand Down
2 changes: 1 addition & 1 deletion sphinx_wagtail_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{%- endif %}
{%- set sphinx_version_info = sphinx_version.split('.') | map('int') | list -%}
<!DOCTYPE html>
<html class="no-js" {% if language is not none %}lang="{{ language }}"{% endif %}>
<html class="no-js" {% if language is not none %}lang="{{ language }}"{% endif %} data-content_root="{{ content_root }}">
<head>
<meta charset="utf-8" />
{%- if metatags %}
Expand Down

0 comments on commit 25ccf64

Please sign in to comment.