Skip to content

Commit 8e730ae

Browse files
committed
Move the content root marker to the <html> element
1 parent 818895a commit 8e730ae

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

sphinx/builders/html/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from sphinx.util.i18n import format_date
4646
from sphinx.util.inventory import InventoryFile
4747
from sphinx.util.matching import DOTFILES, Matcher, patmatch
48-
from sphinx.util.osutil import copyfile, ensuredir, os_path, relative_uri
48+
from sphinx.util.osutil import SEP, copyfile, ensuredir, os_path, relative_uri
4949
from sphinx.util.tags import Tags
5050
from sphinx.writers.html import HTMLWriter
5151
from sphinx.writers.html5 import HTML5Translator
@@ -360,8 +360,7 @@ def add_css_file(self, filename: str, **kwargs: Any) -> None:
360360

361361
def init_js_files(self) -> None:
362362
self.script_files = []
363-
self.add_js_file('documentation_options.js', id="documentation_options",
364-
data_url_root='', priority=200)
363+
self.add_js_file('documentation_options.js', priority=200)
365364
self.add_js_file('doctools.js', priority=200)
366365
self.add_js_file('sphinx_highlight.js', priority=200)
367366

@@ -1075,6 +1074,9 @@ def hasdoc(name: str) -> bool:
10751074
self.add_sidebars(pagename, ctx)
10761075
ctx.update(addctx)
10771076

1077+
# 'blah.html' should have content_root = './' not ''.
1078+
ctx['content_root'] = (f'..{SEP}' * default_baseuri.count(SEP)) or f'.{SEP}'
1079+
10781080
# revert script_files and css_files
10791081
self.script_files[:] = self._script_files
10801082
self.css_files[:] = self._css_files
@@ -1233,8 +1235,6 @@ def js_tag(js: JavaScript) -> str:
12331235
if value is not None:
12341236
if key == 'body':
12351237
body = value
1236-
elif key == 'data_url_root':
1237-
attrs.append(f'data-url_root="{pathto("", resource=True)}"')
12381238
else:
12391239
attrs.append(f'{key}="{html.escape(value, True)}"')
12401240
if js.filename:

sphinx/themes/basic/layout.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ <h3>{{ _('Navigation') }}</h3>
102102
{%- if html_tag %}
103103
{{ html_tag }}
104104
{%- else %}
105-
<html{% if language is not none %} lang="{{ language }}"{% endif %}>
105+
<html{% if language is not none %} lang="{{ language }}"{% endif %} data-content_root="{{ content_root }}">
106106
{%- endif %}
107107
<head>
108108
<meta charset="{{ encoding }}" />

sphinx/themes/basic/static/documentation_options.js_t

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var DOCUMENTATION_OPTIONS = {
2-
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
32
VERSION: '{{ release|e }}',
43
LANGUAGE: '{{ language }}',
54
COLLAPSE_INDEX: false,

sphinx/themes/basic/static/searchtools.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ const _escapeRegExp = (string) =>
5959

6060
const _displayItem = (item, searchTerms) => {
6161
const docBuilder = DOCUMENTATION_OPTIONS.BUILDER;
62-
const docUrlRoot = DOCUMENTATION_OPTIONS.URL_ROOT;
6362
const docFileSuffix = DOCUMENTATION_OPTIONS.FILE_SUFFIX;
6463
const docLinkSuffix = DOCUMENTATION_OPTIONS.LINK_SUFFIX;
6564
const showSearchSummary = DOCUMENTATION_OPTIONS.SHOW_SEARCH_SUMMARY;
65+
const contentRoot = document.documentElement.dataset.content_root;
6666

6767
const [docName, title, anchor, descr, score, _filename] = item;
6868

@@ -75,11 +75,11 @@ const _displayItem = (item, searchTerms) => {
7575
if (dirname.match(/\/index\/$/))
7676
dirname = dirname.substring(0, dirname.length - 6);
7777
else if (dirname === "index/") dirname = "";
78-
requestUrl = docUrlRoot + dirname;
78+
requestUrl = contentRoot + dirname;
7979
linkUrl = requestUrl;
8080
} else {
8181
// normal html builders
82-
requestUrl = docUrlRoot + docName + docFileSuffix;
82+
requestUrl = contentRoot + docName + docFileSuffix;
8383
linkUrl = docName + docLinkSuffix;
8484
}
8585
let linkEl = listItem.appendChild(document.createElement("a"));

0 commit comments

Comments
 (0)