Skip to content

Commit

Permalink
Do not use query components in URLs for assets in EPUB rendering (#11766
Browse files Browse the repository at this point in the history
)

Signed-off-by: David Runge <dave@sleepmap.de>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
  • Loading branch information
dvzrv and AA-Turner committed Jan 18, 2024
1 parent d69d191 commit a8f35bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -70,6 +70,8 @@ Bugs fixed
Patch by James Addison.
* #11886: Print the Jinja2 template path chain in ``TemplateNotFound`` exceptions.
Patch by Colin Marquardt.
* #11598: Do not use query components in URLs for assets in EPUB rendering.
Patch by David Runge.

Testing
-------
Expand Down
12 changes: 8 additions & 4 deletions sphinx/builders/html/__init__.py
Expand Up @@ -1051,8 +1051,10 @@ def css_tag(css: _CascadingStyleSheet) -> str:
for key, value in css.attributes.items()
if value is not None]
uri = pathto(os.fspath(css.filename), resource=True)
if checksum := _file_checksum(outdir, css.filename):
uri += f'?v={checksum}'
# the EPUB format does not allow the use of query components
if self.name != 'epub':
if checksum := _file_checksum(outdir, css.filename):
uri += f'?v={checksum}'
return f'<link {" ".join(sorted(attrs))} href="{uri}" />'

ctx['css_tag'] = css_tag
Expand All @@ -1079,8 +1081,10 @@ def js_tag(js: _JavaScript | str) -> str:
# https://docs.mathjax.org/en/v2.7-latest/configuration.html#considerations-for-using-combined-configuration-files
# https://github.com/sphinx-doc/sphinx/issues/11658
pass
elif checksum := _file_checksum(outdir, js.filename):
uri += f'?v={checksum}'
# the EPUB format does not allow the use of query components
elif self.name != 'epub':
if checksum := _file_checksum(outdir, js.filename):
uri += f'?v={checksum}'
if attrs:
return f'<script {" ".join(sorted(attrs))} src="{uri}"></script>'
return f'<script src="{uri}"></script>'
Expand Down

0 comments on commit a8f35bb

Please sign in to comment.