executablebooks / sphinx-thebe

A Sphinx extension to convert static code into interactive code cells with Jupyter, Thebe, and Binder.
https://sphinx-thebe.readthedocs.io/en/latest/
MIT License
28 stars 15 forks source link

✨ IMPROVE: Conditionally load on pages #30

Closed choldgraf closed 3 years ago

choldgraf commented 3 years ago

This conditionally loads thebe so that the JS is only loaded on pages that have a thebe button.

supercedes https://github.com/executablebooks/sphinx-thebe/pull/14

Also pins our Sphinx lower bound to 3.5 since that is when conditional loading was introduced.

akhmerov commented 3 years ago

What happens if the button is provided by the theme?

choldgraf commented 3 years ago

Right now it will purely look for ThebeButtonNode and if that doesn't exist, it won't load thebe. I guess the assumption is that if the theme is hard-coding a button then they could also manually load the JS itself? What do you think is a good solution there (other than loading it on every single page regardless of whether there's a button on it)?

akhmerov commented 3 years ago

Perhaps checking if thebe is configured and there are cells to execute? This seems to be agnostic with respect to the execution method.

choldgraf commented 3 years ago

@akhmerov I opened up this one to track this: https://github.com/executablebooks/sphinx-thebe/issues/34

I think the main question is "are there cells to execute". e.g., how do you define what that means? (wanna take conversation over to https://github.com/executablebooks/sphinx-thebe/issues/34?)