Skip to content

Commit 29f3eee

Browse files
fix: add logo_dark to metadata.json
1 parent 3a560e2 commit 29f3eee

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/afterpython/builders/metadata.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,34 @@ def build_metadata():
5757
website = _from_tomlkit(afterpython.get("website", {}))
5858
metadata_json["announcement"] = str(website.get("announcement", "")).strip()
5959
metadata_json["readme_py"] = _resolve_readme_py(website)
60+
# Logos are served from the site root in _website/ (assets copied from
61+
# afterpython/static/ to _website/static/), so we normalize to a leading-
62+
# slash form that the Svelte side can hand straight to `asset()`.
63+
metadata_json["logo"] = _resolve_logo_path(website.get("logo", ""))
64+
metadata_json["logo_dark"] = _resolve_logo_path(website.get("logo_dark", ""))
6065

6166
with open(build_path / "metadata.json", "w") as f:
6267
json.dump(metadata_json, f, indent=2)
6368

6469
convert_paths()
6570

6671

72+
def _resolve_logo_path(raw: object) -> str:
73+
"""Normalize a logo path from afterpython.toml for consumption by _website/.
74+
75+
normalize_static_path() returns either a bare filename ("logo.svg") or an
76+
absolute path ("/some/dir/logo.svg"). The Svelte side passes this to
77+
`asset()`, which expects a leading slash, so we prepend one when missing.
78+
Returns "" when unset so the Svelte side can fall back to its default.
79+
"""
80+
from afterpython.utils import normalize_static_path
81+
82+
path = normalize_static_path(str(raw))
83+
if not path:
84+
return ""
85+
return path if path.startswith("/") else f"/{path}"
86+
87+
6788
def _resolve_readme_py(website_config: dict) -> str:
6889
"""Resolve the readme_py field for metadata.json.
6990

0 commit comments

Comments
 (0)