Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thebe assets added to html head but not added to _static #163

Open
jorisvandenbossche opened this issue Aug 31, 2020 · 4 comments · Fixed by #227
Open

Thebe assets added to html head but not added to _static #163

jorisvandenbossche opened this issue Aug 31, 2020 · 4 comments · Fixed by #227
Labels
Milestone

Comments

@jorisvandenbossche
Copy link

Using jupyter-sphinx pydata-sphinx-theme docs (https://pydata-sphinx-theme.readthedocs.io/en/latest/), I noticed that it gives errors in the browser console related to thebe css/js:

/_static/thebelab.css(127.0.0.1) | Failed to load resource: the server responded with a status of 404 (Not Found)
...

This seems to be caused because it is added to the html output of sphinx. From the source of the html of the url linked above:

...
    <link rel="stylesheet" type="text/css" href="_static/jupyter-sphinx.css" />
    <link rel="stylesheet" type="text/css" href="_static/thebelab.css" />
....

But this thebelab.css is not actually to the _static dir of the build html. And thus giving a 404 error.

Based on a quick look, I think this is because here the thebelab css is only copied if there is a configuration active:

src = module_dir / "css"
dst = outdir / "_static"
copy_asset(src, dst)
thebe_config = app.config.jupyter_sphinx_thebelab_config
if not thebe_config:
return
# Copy all thebelab related assets
src = module_dir / "thebelab"
copy_asset(src, dst)

but it gets always registered to sphinx regardless of that configuration option:

# add jupyter-sphinx and thebelab js and css
app.add_css_file("jupyter-sphinx.css")
app.add_js_file("thebelab-helper.js")
app.add_css_file("thebelab.css")

@chrisjsewell
Copy link
Contributor

This is timely, given the comment I just made in executablebooks/meta#119 (comment).

You should probably use the mathjax approach to only add JS (but CSS in this case) given an env value you set when you copy the CSS: https://github.com/sphinx-doc/sphinx/blob/a16cca27ef1415ff271084f156e0fb33ccfbefae/sphinx/ext/mathjax.py#L84

@akhmerov
Copy link
Member

akhmerov commented Aug 31, 2020

Tricky: injecting css during build prevents users from overriding it since it is then inserted after the user-provided css.

This change is due to fixing #149

@jorisvandenbossche
Copy link
Author

The original issue report was about jupyter-sphinx.css, which could still be kept in the app setup. Of course the same issue applies to thebelab.css, but that is maybe less common to want to override?

@akhmerov
Copy link
Member

akhmerov commented Oct 7, 2020

This comment sphinx-doc/sphinx#6241 (comment) contains an implementation of conditional js/css inclusion, however I believe the proper way to address this issue is to switch to sphinx-thebe #137

Still, we may want to use the same logic for widgets code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants