diff --git a/rendercv/data_model.py b/rendercv/data_model.py index b18f3c3..5cc3482 100644 --- a/rendercv/data_model.py +++ b/rendercv/data_model.py @@ -788,12 +788,12 @@ class PublicationEntry(Event): @classmethod def check_doi(cls, doi: str) -> str: doi_url = f"https://doi.org/{doi}" - + try: urllib.request.urlopen(doi_url) except: raise ValueError(f"{doi} cannot be found in the DOI System.") - + return doi @computed_field @@ -833,21 +833,33 @@ class Connection(BaseModel): ] value: str + @field_validator("value") + @classmethod + def check_type_of_value( + cls, value: str + ) -> str: + if not re.search(r"[^\d\-+]", str(value)): + # If there is nothing other than digits, hyphens, and plus signs, then it is + # a phone number + value = "tel:" + value + + return value + @computed_field @cached_property def url(self) -> HttpUrl: if self.name == "LinkedIn": url = f"https://www.linkedin.com/in/{self.value}" elif self.name == "GitHub": - url = f"https:www.github.com/{self.value}" + url = f"https://www.github.com/{self.value}" elif self.name == "Instagram": url = f"https://www.instagram.com/{self.value}" elif self.name == "email": url = f"mailto:{self.value}" elif self.name == "website": - url = f"{self.value}" + url = self.value elif self.name == "phone": - url = f"{self.value}" + url = self.value elif self.name == "location": url = None else: diff --git a/rendercv/templates/components/classic/header_connections.tex.j2 b/rendercv/templates/components/classic/header_connections.tex.j2 index eb1dc0c..0da8719 100644 --- a/rendercv/templates/components/classic/header_connections.tex.j2 +++ b/rendercv/templates/components/classic/header_connections.tex.j2 @@ -8,11 +8,11 @@ ((*- endmacro *)) ((* macro Instagram(username, url) -*)) -\mbox{\href{}{{\small\faInstagram}\hspace{0.13cm}<>}} +\mbox{\href{<>}{{\small\faInstagram}\hspace{0.13cm}<>}} ((*- endmacro *)) ((* macro phone(number, url) -*)) -\mbox{{\footnotesize\faPhone*}\hspace{0.13cm}<>} +\mbox{\href{<>}{{\footnotesize\faPhone*}\hspace{0.13cm}<>}} ((*- endmacro *)) ((* macro email(email, url) -*)) diff --git a/tests/test_rendercv.py b/tests/test_rendercv.py index a09b19c..07e056c 100644 --- a/tests/test_rendercv.py +++ b/tests/test_rendercv.py @@ -482,6 +482,32 @@ class TestRendercv(unittest.TestCase): result = publication.doi_url self.assertEqual(result, expected) + def test_data_connection_url(self): + # Github link: + inputs = [ + {"name": "LinkedIn", "value": "username"}, + {"name": "GitHub", "value": "sinaatalay"}, + {"name": "Instagram", "value": "username"}, + {"name": "phone", "value": "+909999999999"}, + {"name": "email", "value": "example@example.com"}, + {"name": "website", "value": "https://www.example.com/"}, + {"name": "location", "value": "My Location"}, + ] + expected_results = [ + "https://www.linkedin.com/in/username", + "https://www.github.com/sinaatalay", + "https://www.instagram.com/username", + "tel:+909999999999", + "mailto:example@example.com", + "https://www.example.com/", + None, + ] + for input, expected in zip(inputs, expected_results): + with self.subTest(type=input["name"]): + connection = data_model.Connection(**input) + result = connection.url + self.assertEqual(result, expected) + if __name__ == "__main__": unittest.main()