Skip to content

Commit 8a24c6c

Browse files
committed
docs(fix[ext{sphinx_fonts}]): skip font_faces entry on download failure
why: font_faces.append() ran unconditionally, emitting @font-face CSS rules pointing to missing files when download failed (browser 404s). what: - Move font_faces.append() inside the if _download_font() block - Update test to expect 0 entries on download failure
1 parent afdf9c5 commit 8a24c6c

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

docs/_ext/sphinx_fonts.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ def _on_builder_inited(app: Sphinx) -> None:
9595
url = _cdn_url(package, version, font_id, subset, weight, style)
9696
if _download_font(url, cached):
9797
shutil.copy2(cached, fonts_dir / filename)
98-
font_faces.append(
99-
{
100-
"family": font["family"],
101-
"style": style,
102-
"weight": str(weight),
103-
"filename": filename,
104-
}
105-
)
98+
font_faces.append(
99+
{
100+
"family": font["family"],
101+
"style": style,
102+
"weight": str(weight),
103+
"filename": filename,
104+
}
105+
)
106106

107107
preload_hrefs: list[str] = []
108108
preload_specs: list[tuple[str, int, str]] = app.config.sphinx_font_preload

tests/docs/_ext/test_sphinx_fonts.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def test_on_builder_inited_download_failure(
262262
tmp_path: pathlib.Path,
263263
monkeypatch: pytest.MonkeyPatch,
264264
) -> None:
265-
"""_on_builder_inited still builds font_faces entry on download failure."""
265+
"""_on_builder_inited skips font_faces entry on download failure."""
266266
monkeypatch.setattr("sphinx_fonts._cache_dir", lambda: tmp_path / "cache")
267267

268268
msg = "offline"
@@ -285,8 +285,7 @@ def fake_urlretrieve(url: str, filename: t.Any) -> t.NoReturn:
285285

286286
sphinx_fonts._on_builder_inited(app)
287287

288-
assert len(app._font_faces) == 1
289-
assert app._font_faces[0]["family"] == "Inter"
288+
assert len(app._font_faces) == 0
290289

291290

292291
def test_on_builder_inited_explicit_subset(

0 commit comments

Comments
 (0)