Skip to content

Commit

Permalink
Merge pull request #204 from basnijholt/do-not-double-copy
Browse files Browse the repository at this point in the history
Do not overwrite files in _static if user already has custom versions of those files
  • Loading branch information
akhmerov committed Jun 25, 2022
2 parents a74b13e + d40b2ad commit 23322c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions doc/source/index.rst
Expand Up @@ -413,6 +413,10 @@ Here is a sample ``custom.css`` file overriding the ``stderr`` background color:
}
Alternatively, you can also completely overwrite the CSS and JS files that are added by Jupyter Sphinx by providing a full copy of a ``jupyter-sphinx.css`` (which can be empty) file in your ``_static`` folder.
This is also possible with the thebelab CSS and JS that is added.


Configuration options
---------------------

Expand Down Expand Up @@ -478,6 +482,7 @@ Release 0.4.0
- Remove deprecated enabling of the extension as ``jupyter_sphinx.execute``.
- Implement different output priorities in HTML and LaTeX builders. In practice this allows to provide a better fallback in PDF output.
- Introduce new ``jupyter-download`` syntax compatible with Sphinx≥4, ``jupyter-download-nb``, ``jupyter-download-notebook``, and ``jupyter-download-script``
- Do not overwrite CSS and JS if files already exist in _static/, this allows to customize the CSS and JS file.

Release 0.3.0
~~~~~~~~~~~~~
Expand Down
17 changes: 11 additions & 6 deletions jupyter_sphinx/__init__.py
Expand Up @@ -113,25 +113,30 @@ def builder_inited(app):
app.add_js_file(embed_url)


def copy_file(src, dst):
if not (dst / src.name).exists():
copy_asset(str(src), str(dst))


def build_finished(app, env):
if app.builder.format != "html":
return

module_dir = Path(__file__).parent
outdir = Path(app.outdir)
static = Path(app.outdir) / "_static"

# Copy stylesheet
src = module_dir / "css"
dst = outdir / "_static"
copy_asset(src, dst)
src = module_dir / "css" / "jupyter-sphinx.css"
copy_file(src, static)

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)
src_dir = module_dir / "thebelab"
for fname in ["thebelab-helper.js", "thebelab.css"]:
copy_file(src_dir / fname, static)


##############################################################################
Expand Down

0 comments on commit 23322c7

Please sign in to comment.