Skip to content

Commit 23322c7

Browse files
authored
Merge pull request #204 from basnijholt/do-not-double-copy
Do not overwrite files in _static if user already has custom versions of those files
2 parents a74b13e + d40b2ad commit 23322c7

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

doc/source/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ Here is a sample ``custom.css`` file overriding the ``stderr`` background color:
413413
}
414414
415415
416+
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.
417+
This is also possible with the thebelab CSS and JS that is added.
418+
419+
416420
Configuration options
417421
---------------------
418422

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

482487
Release 0.3.0
483488
~~~~~~~~~~~~~

jupyter_sphinx/__init__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,25 +113,30 @@ def builder_inited(app):
113113
app.add_js_file(embed_url)
114114

115115

116+
def copy_file(src, dst):
117+
if not (dst / src.name).exists():
118+
copy_asset(str(src), str(dst))
119+
120+
116121
def build_finished(app, env):
117122
if app.builder.format != "html":
118123
return
119124

120125
module_dir = Path(__file__).parent
121-
outdir = Path(app.outdir)
126+
static = Path(app.outdir) / "_static"
122127

123128
# Copy stylesheet
124-
src = module_dir / "css"
125-
dst = outdir / "_static"
126-
copy_asset(src, dst)
129+
src = module_dir / "css" / "jupyter-sphinx.css"
130+
copy_file(src, static)
127131

128132
thebe_config = app.config.jupyter_sphinx_thebelab_config
129133
if not thebe_config:
130134
return
131135

132136
# Copy all thebelab related assets
133-
src = module_dir / "thebelab"
134-
copy_asset(src, dst)
137+
src_dir = module_dir / "thebelab"
138+
for fname in ["thebelab-helper.js", "thebelab.css"]:
139+
copy_file(src_dir / fname, static)
135140

136141

137142
##############################################################################

0 commit comments

Comments
 (0)