diff options
author | Simon Hausmann <hausmann@gmail.com> | 2021-07-13 08:49:01 +0200 |
---|---|---|
committer | Simon Hausmann <hausmann@gmail.com> | 2021-07-13 18:03:36 +0200 |
commit | 3a50abc5c97489734adbda0e8cc0a343735eb958 (patch) | |
tree | a086ecf8311f857f4ced2a53e8b9f7a19b968479 | |
parent | 3c3a734b97c99a9f2b32bd33f7b98921d9da294f (diff) | |
download | sphinx-git-3a50abc5c97489734adbda0e8cc0a343735eb958.tar.gz |
Fix handling of local paths in html_logo/html_favicon directorives in conf.py
Merge request #9381 broke support for local logos/favicons as it
retained the paths that are passed to the template engine. That's wrong
as the actual path will be in _static/.
This should fix #9438
-rw-r--r-- | sphinx/builders/html/__init__.py | 14 | ||||
-rw-r--r-- | tests/roots/test-local-logo/conf.py | 4 | ||||
-rw-r--r-- | tests/roots/test-local-logo/images/img.png | bin | 0 -> 66247 bytes | |||
-rw-r--r-- | tests/roots/test-local-logo/index.rst | 32 | ||||
-rw-r--r-- | tests/test_build_html.py | 9 |
5 files changed, 57 insertions, 2 deletions
diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index ad8436c93..7265370bb 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -468,6 +468,16 @@ class StandaloneHTMLBuilder(Builder): else: self.last_updated = None + # If the logo or favicon are urls, keep them as-is, otherwise + # strip the relative path as the files will be copied into _static. + logo = self.config.html_logo or '' + favicon = self.config.html_favicon or '' + + if not isurl(logo): + logo = path.basename(logo) + if not isurl(favicon): + favicon = path.basename(favicon) + self.relations = self.env.collect_relations() rellinks: List[Tuple[str, str, str, str]] = [] @@ -510,8 +520,8 @@ class StandaloneHTMLBuilder(Builder): 'rellinks': rellinks, 'builder': self.name, 'parents': [], - 'logo': self.config.html_logo or '', - 'favicon': self.config.html_favicon or '', + 'logo': logo, + 'favicon': favicon, 'html5_doctype': html5_ready and not self.config.html4_writer, } if self.theme: diff --git a/tests/roots/test-local-logo/conf.py b/tests/roots/test-local-logo/conf.py new file mode 100644 index 000000000..1a166c130 --- /dev/null +++ b/tests/roots/test-local-logo/conf.py @@ -0,0 +1,4 @@ +latex_documents = [ + ('index', 'test.tex', 'The basic Sphinx documentation for testing', 'Sphinx', 'report') +] +html_logo = "images/img.png" diff --git a/tests/roots/test-local-logo/images/img.png b/tests/roots/test-local-logo/images/img.png Binary files differnew file mode 100644 index 000000000..a97e86d66 --- /dev/null +++ b/tests/roots/test-local-logo/images/img.png diff --git a/tests/roots/test-local-logo/index.rst b/tests/roots/test-local-logo/index.rst new file mode 100644 index 000000000..48407e643 --- /dev/null +++ b/tests/roots/test-local-logo/index.rst @@ -0,0 +1,32 @@ +The basic Sphinx documentation for testing +========================================== + +Sphinx is a tool that makes it easy to create intelligent and beautiful +documentation for Python projects (or other documents consisting of multiple +reStructuredText sources), written by Georg Brandl. It was originally created +for the new Python documentation, and has excellent facilities for Python +project documentation, but C/C++ is supported as well, and more languages are +planned. + +Sphinx uses reStructuredText as its markup language, and many of its strengths +come from the power and straightforwardness of reStructuredText and its parsing +and translating suite, the Docutils. + +features +-------- + +Among its features are the following: + +* Output formats: HTML (including derivative formats such as HTML Help, Epub + and Qt Help), plain text, manual pages and LaTeX or direct PDF output + using rst2pdf +* Extensive cross-references: semantic markup and automatic links + for functions, classes, glossary terms and similar pieces of information +* Hierarchical structure: easy definition of a document tree, with automatic + links to siblings, parents and children +* Automatic indices: general index as well as a module index +* Code handling: automatic highlighting using the Pygments highlighter +* Flexible HTML output using the Jinja 2 templating engine +* Various extensions are available, e.g. for automatic testing of snippets + and inclusion of appropriately formatted docstrings +* Setuptools integration diff --git a/tests/test_build_html.py b/tests/test_build_html.py index e74319f19..d295cf982 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -1340,6 +1340,15 @@ def test_html_remote_logo(app, status, warning): assert not (app.outdir / 'python-logo.png').exists() +@pytest.mark.sphinx('html', testroot='local-logo') +def test_html_local_logo(app, status, warning): + app.builder.build_all() + + result = (app.outdir / 'index.html').read_text() + assert ('<img class="logo" src="_static/img.png" alt="Logo"/>' in result) + assert (app.outdir / '_static/img.png').exists() + + @pytest.mark.sphinx('html', testroot='basic') def test_html_sidebar(app, status, warning): ctx = {} |