Skip to content

Commit 3a50abc

Browse files
committed
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
1 parent 3c3a734 commit 3a50abc

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

sphinx/builders/html/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,16 @@ def prepare_writing(self, docnames: Set[str]) -> None:
468468
else:
469469
self.last_updated = None
470470

471+
# If the logo or favicon are urls, keep them as-is, otherwise
472+
# strip the relative path as the files will be copied into _static.
473+
logo = self.config.html_logo or ''
474+
favicon = self.config.html_favicon or ''
475+
476+
if not isurl(logo):
477+
logo = path.basename(logo)
478+
if not isurl(favicon):
479+
favicon = path.basename(favicon)
480+
471481
self.relations = self.env.collect_relations()
472482

473483
rellinks: List[Tuple[str, str, str, str]] = []
@@ -510,8 +520,8 @@ def prepare_writing(self, docnames: Set[str]) -> None:
510520
'rellinks': rellinks,
511521
'builder': self.name,
512522
'parents': [],
513-
'logo': self.config.html_logo or '',
514-
'favicon': self.config.html_favicon or '',
523+
'logo': logo,
524+
'favicon': favicon,
515525
'html5_doctype': html5_ready and not self.config.html4_writer,
516526
}
517527
if self.theme:

tests/roots/test-local-logo/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
latex_documents = [
2+
('index', 'test.tex', 'The basic Sphinx documentation for testing', 'Sphinx', 'report')
3+
]
4+
html_logo = "images/img.png"
64.7 KB
Loading

tests/roots/test-local-logo/index.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
The basic Sphinx documentation for testing
2+
==========================================
3+
4+
Sphinx is a tool that makes it easy to create intelligent and beautiful
5+
documentation for Python projects (or other documents consisting of multiple
6+
reStructuredText sources), written by Georg Brandl. It was originally created
7+
for the new Python documentation, and has excellent facilities for Python
8+
project documentation, but C/C++ is supported as well, and more languages are
9+
planned.
10+
11+
Sphinx uses reStructuredText as its markup language, and many of its strengths
12+
come from the power and straightforwardness of reStructuredText and its parsing
13+
and translating suite, the Docutils.
14+
15+
features
16+
--------
17+
18+
Among its features are the following:
19+
20+
* Output formats: HTML (including derivative formats such as HTML Help, Epub
21+
and Qt Help), plain text, manual pages and LaTeX or direct PDF output
22+
using rst2pdf
23+
* Extensive cross-references: semantic markup and automatic links
24+
for functions, classes, glossary terms and similar pieces of information
25+
* Hierarchical structure: easy definition of a document tree, with automatic
26+
links to siblings, parents and children
27+
* Automatic indices: general index as well as a module index
28+
* Code handling: automatic highlighting using the Pygments highlighter
29+
* Flexible HTML output using the Jinja 2 templating engine
30+
* Various extensions are available, e.g. for automatic testing of snippets
31+
and inclusion of appropriately formatted docstrings
32+
* Setuptools integration

tests/test_build_html.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,15 @@ def test_html_remote_logo(app, status, warning):
13401340
assert not (app.outdir / 'python-logo.png').exists()
13411341

13421342

1343+
@pytest.mark.sphinx('html', testroot='local-logo')
1344+
def test_html_local_logo(app, status, warning):
1345+
app.builder.build_all()
1346+
1347+
result = (app.outdir / 'index.html').read_text()
1348+
assert ('<img class="logo" src="_static/img.png" alt="Logo"/>' in result)
1349+
assert (app.outdir / '_static/img.png').exists()
1350+
1351+
13431352
@pytest.mark.sphinx('html', testroot='basic')
13441353
def test_html_sidebar(app, status, warning):
13451354
ctx = {}

0 commit comments

Comments
 (0)