This commit is contained in:
Sina Atalay 2024-05-25 12:18:05 +03:00
commit 610f364d3f
2 changed files with 30 additions and 9 deletions

View File

@ -831,7 +831,14 @@ class SocialNetwork(RenderCVBaseModel):
"""This class is the data model of a social network.""" """This class is the data model of a social network."""
network: Literal[ network: Literal[
"LinkedIn", "GitHub", "Instagram", "Orcid", "Mastodon", "Twitter" "LinkedIn",
"GitHub",
"GitLab",
"Instagram",
"Orcid",
"Mastodon",
"Twitter",
"StackOverflow",
] = pydantic.Field( ] = pydantic.Field(
title="Social Network", title="Social Network",
description="The social network name.", description="The social network name.",
@ -871,10 +878,14 @@ class SocialNetwork(RenderCVBaseModel):
# split domain and username # split domain and username
dummy, username, domain = self.username.split("@") dummy, username, domain = self.username.split("@")
url = f"https://{domain}/@{username}" url = f"https://{domain}/@{username}"
elif self.network == "StackOverflow":
user_id, username = self.username.split("/")
url = f"https://stackoverflow.com/users/{user_id}/{username}"
else: else:
url_dictionary = { url_dictionary = {
"LinkedIn": "https://linkedin.com/in/", "LinkedIn": "https://linkedin.com/in/",
"GitHub": "https://github.com/", "GitHub": "https://github.com/",
"GitLab": "https://gitlab.com/",
"Instagram": "https://instagram.com/", "Instagram": "https://instagram.com/",
"Orcid": "https://orcid.org/", "Orcid": "https://orcid.org/",
"Twitter": "https://twitter.com/", "Twitter": "https://twitter.com/",
@ -980,21 +991,26 @@ class CurriculumVitae(RenderCVBaseModel):
icon_dictionary = { icon_dictionary = {
"LinkedIn": "\\faLinkedinIn", "LinkedIn": "\\faLinkedinIn",
"GitHub": "\\faGithub", "GitHub": "\\faGithub",
"GitLab": "\\faGitlab",
"Instagram": "\\faInstagram", "Instagram": "\\faInstagram",
"Mastodon": "\\faMastodon", "Mastodon": "\\faMastodon",
"Orcid": "\\faOrcid", "Orcid": "\\faOrcid",
"StackOverflow": "\\faStackOverflow",
"Twitter": "\\faTwitter", "Twitter": "\\faTwitter",
} }
for social_network in self.social_networks: for social_network in self.social_networks:
clean_url = social_network.url.replace("https://", "").rstrip("/") clean_url = social_network.url.replace("https://", "").rstrip("/")
connections.append( connection = {
{ "latex_icon": icon_dictionary[social_network.network],
"latex_icon": icon_dictionary[social_network.network], "url": social_network.url,
"url": social_network.url, "clean_url": clean_url,
"clean_url": clean_url, "placeholder": social_network.username,
"placeholder": social_network.username, }
}
) if social_network.network == "StackOverflow":
username = social_network.username.split("/")[1]
connection["placeholder"] = username
connections.append(connection)
return connections return connections

View File

@ -426,6 +426,11 @@ def test_invalid_social_networks(network, username):
("Orcid", "myusername", "https://orcid.org/myusername"), ("Orcid", "myusername", "https://orcid.org/myusername"),
("Twitter", "myusername", "https://twitter.com/myusername"), ("Twitter", "myusername", "https://twitter.com/myusername"),
("Mastodon", "@myusername@test.org", "https://test.org/@myusername"), ("Mastodon", "@myusername@test.org", "https://test.org/@myusername"),
(
"StackOverflow",
"4567/myusername",
"https://stackoverflow.com/users/4567/myusername",
),
], ],
) )
def test_social_network_url(network, username, expected_url): def test_social_network_url(network, username, expected_url):