Skip to content

Commit

Permalink
Fix #8885: html: AttributeError for CSS/JS files on html_context
Browse files Browse the repository at this point in the history
Since 3.5.0, priority has been added to control CSS/JS files.  But it's
not working if projects installs custom CSS/JS files via `html_context`
instead of `html_css_files` and `html_js_files`.  This avoids the crash
to keep it "not broken".
  • Loading branch information
tk0miya committed Feb 15, 2021
1 parent 8205283 commit 82501a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Bugs fixed
----------

* #8884: html: minified js stemmers not included in the distributed package
* #8885: html: AttributeError is raised if CSS/JS files are installed via
:confval:`html_context`
* #8880: viewcode: ExtensionError is raised on incremental build after
unparsable python module found

Expand Down
16 changes: 14 additions & 2 deletions sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,8 +1035,20 @@ def hasdoc(name: str) -> bool:
templatename = newtmpl

# sort JS/CSS before rendering HTML
ctx['script_files'].sort(key=lambda js: js.priority)
ctx['css_files'].sort(key=lambda css: css.priority)
try:
# Convert script_files to list to support non-list script_files (refs: #8889)
ctx['script_files'] = sorted(list(ctx['script_files']), key=lambda js: js.priority)
except AttributeError:
# Skip sorting if users modifies script_files directly (maybe via `html_context`).
# refs: #8885
#
# Note: priority sorting feature will not work in this case.
pass

try:
ctx['css_files'] = sorted(list(ctx['css_files']), key=lambda css: css.priority)
except AttributeError:
pass

try:
output = self.templates.render(templatename, ctx)
Expand Down

0 comments on commit 82501a6

Please sign in to comment.