From c3ad66b010e1f2401fda8be2eedeac5b050335e3 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 25 Jun 2021 11:04:11 +0200 Subject: [PATCH 1/3] Fix support for html logo and favicon as url Stripping the url in the context setup means that any later isurl() calls will fail and logo_url will always be a local relative path. --- sphinx/builders/html/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index 85669474eab..41e61c69214 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -468,8 +468,8 @@ def prepare_writing(self, docnames: Set[str]) -> None: else: self.last_updated = None - logo = path.basename(self.config.html_logo) if self.config.html_logo else '' - favicon = path.basename(self.config.html_favicon) if self.config.html_favicon else '' + logo = self.config.html_logo if self.config.html_logo else '' + favicon = self.config.html_favicon if self.config.html_favicon else '' self.relations = self.env.collect_relations() From 9f04ac8563f678744c8db628acccabb65abcdb4a Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 28 Jun 2021 11:27:06 +0200 Subject: [PATCH 2/3] Simplify logo and favicon assignment --- sphinx/builders/html/__init__.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index 41e61c69214..ad8436c9324 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -468,9 +468,6 @@ def prepare_writing(self, docnames: Set[str]) -> None: else: self.last_updated = None - logo = self.config.html_logo if self.config.html_logo else '' - favicon = self.config.html_favicon if self.config.html_favicon else '' - self.relations = self.env.collect_relations() rellinks: List[Tuple[str, str, str, str]] = [] @@ -513,8 +510,8 @@ def prepare_writing(self, docnames: Set[str]) -> None: 'rellinks': rellinks, 'builder': self.name, 'parents': [], - 'logo': logo, - 'favicon': favicon, + 'logo': self.config.html_logo or '', + 'favicon': self.config.html_favicon or '', 'html5_doctype': html5_ready and not self.config.html4_writer, } if self.theme: From 6a4c215cf0c0c88b34c7607730e6a940e13804ce Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 28 Jun 2021 13:28:29 +0200 Subject: [PATCH 3/3] Add unit test for remote logo and fav icon --- tests/roots/test-remote-logo/conf.py | 5 ++++ tests/roots/test-remote-logo/index.rst | 32 ++++++++++++++++++++++++++ tests/test_build_html.py | 10 ++++++++ 3 files changed, 47 insertions(+) create mode 100644 tests/roots/test-remote-logo/conf.py create mode 100644 tests/roots/test-remote-logo/index.rst diff --git a/tests/roots/test-remote-logo/conf.py b/tests/roots/test-remote-logo/conf.py new file mode 100644 index 00000000000..07949ba91fc --- /dev/null +++ b/tests/roots/test-remote-logo/conf.py @@ -0,0 +1,5 @@ +latex_documents = [ + ('index', 'test.tex', 'The basic Sphinx documentation for testing', 'Sphinx', 'report') +] +html_logo = "https://www.python.org/static/img/python-logo.png" +html_favicon = "https://www.python.org/static/favicon.ico" diff --git a/tests/roots/test-remote-logo/index.rst b/tests/roots/test-remote-logo/index.rst new file mode 100644 index 00000000000..48407e643c4 --- /dev/null +++ b/tests/roots/test-remote-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 c74552d9e83..2e53bdc54a8 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -1330,6 +1330,16 @@ def test_html_remote_images(app, status, warning): assert not (app.outdir / 'python-logo.png').exists() +@pytest.mark.sphinx('html', testroot='remote-logo') +def test_html_remote_logo(app, status, warning): + app.builder.build_all() + + result = (app.outdir / 'index.html').read_text() + assert ('' in result) + assert ('' in result) + assert not (app.outdir / 'python-logo.png').exists() + + @pytest.mark.sphinx('html', testroot='basic') def test_html_sidebar(app, status, warning): ctx = {}