From fc376d4ea0b28054acc7b636420681439d79e43f Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Sat, 16 Sep 2023 21:31:53 +0200 Subject: [PATCH] generate urls in python side --- rendercv/data_model.py | 16 ++++++++++++++++ .../templates/components/classic/header.tex.j2 | 2 +- .../components/classic/header_connections.tex.j2 | 12 ++++++------ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/rendercv/data_model.py b/rendercv/data_model.py index 8fad94e2..6184e3be 100644 --- a/rendercv/data_model.py +++ b/rendercv/data_model.py @@ -680,6 +680,22 @@ class Connection(BaseModel): name: Literal["LinkedIn", "GitHub", "Instagram", "phone", "email", "website"] value: str + @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}" + 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 = self.value + else: + raise RuntimeError(f'"{self.name}" is not a valid connection!"') + class Section(BaseModel): """This class stores a section information.""" diff --git a/rendercv/templates/components/classic/header.tex.j2 b/rendercv/templates/components/classic/header.tex.j2 index 5db7c866..f7e90c9e 100644 --- a/rendercv/templates/components/classic/header.tex.j2 +++ b/rendercv/templates/components/classic/header.tex.j2 @@ -6,7 +6,7 @@ \normalsize ((* for connection in connections *)) - <> + <> ((* if not loop.last *)) \hspace{0.5cm} ((* endif *)) diff --git a/rendercv/templates/components/classic/header_connections.tex.j2 b/rendercv/templates/components/classic/header_connections.tex.j2 index 2c6df996..2795e8e1 100644 --- a/rendercv/templates/components/classic/header_connections.tex.j2 +++ b/rendercv/templates/components/classic/header_connections.tex.j2 @@ -1,8 +1,8 @@ ((# Each macro in here is a link with an icon for header. #)) -((* macro LinkedIn(username) *))\href{https://www.linkedin.com/in/<>}{{\small\faLinkedinIn}\hspace{0.13cm}<>}((* endmacro *)) -((* macro GitHub(username) *))\href{https://www.github.com/<>}{{\small\faGithub}\hspace{0.13cm}<>}((* endmacro *)) -((* macro Instagram(username) *))\href{https://www.instagram.com/<>}{{\small\faInstagram}\hspace{0.13cm}<>}((* endmacro *)) -((* macro phone(number) *)){\footnotesize\faPhone*}\hspace{0.13cm}<>((* endmacro *)) -((* macro email(email) *))\href{mailto:<>}{{\small\faEnvelope[regular]}\hspace{0.13cm}<>}((* endmacro *)) -((* macro website(url) *))\href{<>}{{\small\faLink}\hspace{0.13cm}<>}((* endmacro *)) +((* macro LinkedIn(username, url) *))\href{<>}{{\small\faLinkedinIn}\hspace{0.13cm}<>}((* endmacro *)) +((* macro GitHub(username, url) *))\href{<>}{{\small\faGithub}\hspace{0.13cm}<>}((* endmacro *)) +((* macro Instagram(username, url) *))\href{}{{\small\faInstagram}\hspace{0.13cm}<>}((* endmacro *)) +((* macro phone(number, url) *)){\footnotesize\faPhone*}\hspace{0.13cm}<>((* endmacro *)) +((* macro email(email, url) *))\href{<>}{{\small\faEnvelope[regular]}\hspace{0.13cm}<>}((* endmacro *)) +((* macro website(url, dummy) *))\href{<>}{{\small\faLink}\hspace{0.13cm}<>}((* endmacro *))