Skip to content

Commit e6213e2

Browse files
fix: separate author name into given and surname to suppress mystmd warning
1 parent fde9220 commit e6213e2

3 files changed

Lines changed: 41 additions & 18 deletions

File tree

src/afterpython/cli/commands/sync.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
from tomlkit.toml_document import TOMLDocument
77

88
import afterpython as ap
9-
from afterpython.utils import convert_author_name_to_id, normalize_static_path
9+
from afterpython.utils import (
10+
build_author_name,
11+
convert_author_name_to_id,
12+
normalize_static_path,
13+
)
1014

1115

1216
def _myst_favicon_path(path: str) -> str:
@@ -23,20 +27,21 @@ def _sync_authors_yml(authors: list[tuple[str, str | None]]):
2327

2428
# read myst.yml from docs path to get "version"
2529
doc_myst_yml = read_yaml(ap.paths.afterpython_path / "doc" / "myst.yml")
30+
entries = []
31+
for author in authors:
32+
# author is a tuple of (name, email)
33+
name = str(author[0]).strip()
34+
entries.append(
35+
{
36+
"id": convert_author_name_to_id(name),
37+
"name": build_author_name(name),
38+
"email": str(author[1]),
39+
# "github": ...
40+
}
41+
)
2642
data = {
2743
"version": doc_myst_yml["version"],
28-
"project": {
29-
"contributors": [
30-
# NOTE: author is a tuple of (name, email), so author[0] is the name and author[1] is the email
31-
{
32-
"id": convert_author_name_to_id(str(author[0])),
33-
"name": str(author[0]),
34-
"email": str(author[1]),
35-
# "github": ...
36-
}
37-
for author in authors
38-
]
39-
},
44+
"project": {"authors": entries},
4045
}
4146
update_authors_yml(data)
4247
click.echo("✓ Synced authors.yml with pyproject.toml")

src/afterpython/tools/myst.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ def update_authors_yml(data_update: dict):
3030
# merge authors, keep the author with more fields (e.g. github, x, etc.) to avoid duplication
3131
merged_authors = {}
3232
for author in (
33-
existing_data["project"]["contributors"]
34-
+ data_update["project"]["contributors"]
33+
existing_data["project"].get("authors", []) + data_update["project"]["authors"]
3534
):
3635
author_id = author["id"]
3736
if author_id not in merged_authors:
@@ -40,14 +39,14 @@ def update_authors_yml(data_update: dict):
4039
# keep the author with more fields (e.g. github, x, etc.)
4140
if len(author.keys()) > len(merged_authors[author_id].keys()):
4241
merged_authors[author_id] = author
43-
existing_data["project"]["contributors"] = list(merged_authors.values())
42+
existing_data["project"]["authors"] = list(merged_authors.values())
4443

4544
# set comments for project section for convenience
4645
if "project" in existing_data and not existing_data["project"].ca.items.get(
47-
"contributors"
46+
"authors"
4847
):
4948
existing_data["project"].yaml_set_comment_before_after_key(
50-
"contributors",
49+
"authors",
5150
before="See more at: https://mystmd.org/guide/frontmatter#frontmatter-authors",
5251
)
5352
write_yaml(file_path, existing_data)

src/afterpython/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,25 @@ def convert_author_name_to_id(name: str) -> str:
149149
return name.replace(" ", "_").lower()
150150

151151

152+
def build_author_name(name: str) -> dict:
153+
"""Build a MyST name object from a display name.
154+
155+
A multi-word name ("Stephen Yau") is split into ``given``/``surname`` so MyST
156+
can render and cite it properly. A single-token name (e.g. a username like
157+
"softwareentrepreneer") uses ``literal`` so MyST treats it as the full name
158+
verbatim instead of warning about a missing given name.
159+
160+
Examples:
161+
- "Stephen Yau" -> {"given": "Stephen", "surname": "Yau"}
162+
- "softwareentrepreneer" -> {"literal": "softwareentrepreneer"}
163+
"""
164+
name = name.strip()
165+
if " " in name:
166+
given, surname = name.split(" ", 1)
167+
return {"given": given, "surname": surname}
168+
return {"literal": name}
169+
170+
152171
def find_available_port(
153172
start_port: int = 3000, max_port: int = 3100, host: str = "localhost"
154173
) -> int:

0 commit comments

Comments
 (0)