Skip to content

Commit 397af18

Browse files
Limit copying _sphinx_design_static to HTML based builders
Signed-off-by: Putnam, Kevin <kevin.putnam@intel.com>
1 parent b3d6edd commit 397af18

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

sphinx_design/extension.py

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,35 +80,37 @@ def update_css_js(app: Sphinx):
8080
"""Copy the CSS to the build directory."""
8181
# reset changed identifier
8282
app.env.sphinx_design_css_changed = False
83-
# setup up new static path in output dir
84-
static_path = (Path(app.outdir) / "_sphinx_design_static").absolute()
85-
static_existed = static_path.exists()
86-
static_path.mkdir(exist_ok=True)
87-
app.config.html_static_path.append(str(static_path))
88-
# Copy JS to the build directory.
89-
js_path = static_path / "design-tabs.js"
90-
app.add_js_file(js_path.name)
91-
if not js_path.exists():
92-
content = read_text(static_module, "sd_tabs.js")
93-
js_path.write_text(content)
94-
# Read the css content and hash it
95-
content = read_text(static_module, "style.min.css")
96-
# Write the css file
97-
if sphinx_version < (7, 1):
98-
hash = hashlib.md5(content.encode("utf8"), usedforsecurity=False).hexdigest()
99-
css_path = static_path / f"sphinx-design.{hash}.min.css"
100-
else:
101-
# since sphinx 7.1 a checksum is added to the css file URL, so there is no need to do it here
102-
# https://github.com/sphinx-doc/sphinx/pull/11415
103-
css_path = static_path / "sphinx-design.min.css"
104-
app.add_css_file(css_path.name)
105-
if css_path.exists():
106-
return
107-
if static_existed:
108-
app.env.sphinx_design_css_changed = True
109-
for path in static_path.glob("*.css"):
110-
path.unlink()
111-
css_path.write_text(content, encoding="utf8")
83+
# only do this for html builders
84+
if 'html' in app.builder.name:
85+
# setup up new static path in output dir
86+
static_path = (Path(app.outdir) / "_sphinx_design_static").absolute()
87+
static_existed = static_path.exists()
88+
static_path.mkdir(exist_ok=True)
89+
app.config.html_static_path.append(str(static_path))
90+
# Copy JS to the build directory.
91+
js_path = static_path / "design-tabs.js"
92+
app.add_js_file(js_path.name)
93+
if not js_path.exists():
94+
content = read_text(static_module, "sd_tabs.js")
95+
js_path.write_text(content)
96+
# Read the css content and hash it
97+
content = read_text(static_module, "style.min.css")
98+
# Write the css file
99+
if sphinx_version < (7, 1):
100+
hash = hashlib.md5(content.encode("utf8"), usedforsecurity=False).hexdigest()
101+
css_path = static_path / f"sphinx-design.{hash}.min.css"
102+
else:
103+
# since sphinx 7.1 a checksum is added to the css file URL, so there is no need to do it here
104+
# https://github.com/sphinx-doc/sphinx/pull/11415
105+
css_path = static_path / "sphinx-design.min.css"
106+
app.add_css_file(css_path.name)
107+
if css_path.exists():
108+
return
109+
if static_existed:
110+
app.env.sphinx_design_css_changed = True
111+
for path in static_path.glob("*.css"):
112+
path.unlink()
113+
css_path.write_text(content, encoding="utf8")
112114

113115

114116
def update_css_links(app: Sphinx, env: BuildEnvironment):

0 commit comments

Comments
 (0)