diff --git a/rendercv/data_model.py b/rendercv/data_model.py index df5ff9b..cbcdfd1 100644 --- a/rendercv/data_model.py +++ b/rendercv/data_model.py @@ -1036,7 +1036,7 @@ class SocialNetwork(BaseModel): Currently, only LinkedIn, Github, and Instagram are supported. """ - network: Literal["LinkedIn", "GitHub", "Instagram", "Orcid"] = Field( + network: Literal["LinkedIn", "GitHub", "Instagram", "Orcid", "Mastodon"] = Field( title="Social Network", description="The social network name.", ) @@ -1059,6 +1059,7 @@ class Connection(BaseModel): "GitHub", "Instagram", "Orcid", + "Mastodon", "phone", "email", "website", @@ -1066,6 +1067,21 @@ class Connection(BaseModel): ] value: str + @staticmethod + def MastodonUname2Url(uname: str) ->Optional[HttpUrl]: + """From a Mastodon-style "user@domain.example" returns profile url.""" + + # The closest thing to a formal spec of Mastodon usernames + # where these regular expressions from a (reference?) + # implementation + # + # https://github.com/mastodon/mastodon/blob/852123867768e23410af5bd07ac0327bead0d9b2/app/models/account.rb#L68 + # + # SERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i + # MENTION_RE = %r{(? Optional[HttpUrl | str]: @@ -1077,6 +1093,8 @@ class Connection(BaseModel): url = f"https://www.instagram.com/{self.value}" elif self.name == "Orcid": url = f"https://orcid.org/{self.value}" + elif self.name == "Mastodon": + url = MastodonUname2Url(self.value) elif self.name == "email": url = f"mailto:{self.value}" elif self.name == "website": diff --git a/schema.json b/schema.json index b581509..9182c6b 100644 --- a/schema.json +++ b/schema.json @@ -1532,7 +1532,8 @@ "LinkedIn", "GitHub", "Instagram", - "Orcid" + "Orcid", + "Mastodon" ], "title": "Social Network", "type": "string"