Skip to content

Commit 1ee81dd

Browse files
feat: support announcement banner (defined in afterpython.toml)
1 parent a3531e5 commit 1ee81dd

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

afterpython/afterpython.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ favicon = "favicon.ico"
99
logo = "logo.svg"
1010
logo_dark = "logo.svg"
1111
thumbnail = "thumbnail.png" # thumbnail for the website, also used as default thumbnail for all content types, e.g. blog posts, tutorials, examples, and guides
12+
announcement = ""
1213

1314
# [website.blog]
1415
# thumbnail = "blog_default_thumbnail.png" # inside blog/static/ folder, default thumbnail for blog posts

src/afterpython/builders/metadata.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,26 @@ def convert_paths():
3636

3737

3838
def build_metadata():
39-
"""Build metadata.json using pyproject.toml"""
39+
"""Build metadata.json using pyproject.toml + afterpython.toml.
40+
41+
Adds an `announcement` field (markdown string) sourced from
42+
`[website].announcement` in afterpython.toml, so the frontend can render
43+
a top-of-site banner. Empty/missing announcement → empty string.
44+
"""
45+
from afterpython._io.toml import _from_tomlkit
46+
from afterpython.tools._afterpython import read_afterpython
4047
from afterpython.tools.pyproject import read_metadata
4148

4249
click.echo("Building metadata.json...")
4350

4451
metadata: StandardMetadata = read_metadata()
52+
metadata_json = metadata.as_json()
53+
54+
afterpython = read_afterpython()
55+
website = _from_tomlkit(afterpython.get("website", {}))
56+
metadata_json["announcement"] = str(website.get("announcement", "")).strip()
4557

46-
# Write to metadata.json
4758
with open(build_path / "metadata.json", "w") as f:
48-
json.dump(metadata.as_json(), f, indent=2)
59+
json.dump(metadata_json, f, indent=2)
4960

5061
convert_paths()

0 commit comments

Comments
 (0)