From 905b7a360a726d7c39fd6a26a95bb97d15abc4e0 Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Tue, 16 Apr 2024 14:40:56 +0300 Subject: [PATCH] data_models: improve mastodon links --- rendercv/data_models.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/rendercv/data_models.py b/rendercv/data_models.py index 6a4377a..ec9119f 100644 --- a/rendercv/data_models.py +++ b/rendercv/data_models.py @@ -821,8 +821,8 @@ class SocialNetwork(RenderCVBaseModel): if network == "Mastodon": if not username.startswith("@"): raise ValueError("Mastodon username should start with '@'!") - if username.count("@") > 2: - raise ValueError("Mastodon username should contain only two '@'!") + if username.count("@") != 2: + raise ValueError("Mastodon username should contain two '@'!") return username @@ -838,15 +838,19 @@ class SocialNetwork(RenderCVBaseModel): @functools.cached_property def url(self) -> str: """Return the URL of the social network.""" - url_dictionary = { - "LinkedIn": "https://linkedin.com/in/", - "GitHub": "https://github.com/", - "Instagram": "https://instagram.com/", - "Orcid": "https://orcid.org/", - "Mastodon": "https://mastodon.social/", - "Twitter": "https://twitter.com/", - } - url = url_dictionary[self.network] + self.username + if self.network == "Mastodon": + # split domain and username + dummy, username, domain = self.username.split("@") + url = f"https://{domain}/@{username}" + else: + url_dictionary = { + "LinkedIn": "https://linkedin.com/in/", + "GitHub": "https://github.com/", + "Instagram": "https://instagram.com/", + "Orcid": "https://orcid.org/", + "Twitter": "https://twitter.com/", + } + url = url_dictionary[self.network] + self.username return url @@ -920,7 +924,7 @@ class CurriculumVitae(RenderCVBaseModel): "placeholder": self.email, } ) - + if self.phone is not None: phone_placeholder = self.phone.replace("tel:", "").replace("-", " ") connections.append(