mirror of https://github.com/eyhc1/rendercv.git
WIP: more mast parsing
This commit is contained in:
parent
edeadabeb1
commit
bfbd05a3e8
|
@ -1068,8 +1068,8 @@ class Connection(BaseModel):
|
|||
value: str
|
||||
|
||||
@staticmethod
|
||||
def MastodonUname2Url(uname: str) ->Optional[HttpUrl]:
|
||||
"""From a Mastodon-style "user@domain.example" returns profile url."""
|
||||
def MastodonUname2Url(id: str) -> Optional[HttpUrl]:
|
||||
"""From a Mastodon id "user@domain.example" returns profile url."""
|
||||
|
||||
# The closest thing to a formal spec of Mastodon usernames
|
||||
# where these regular expressions from a (reference?)
|
||||
|
@ -1077,10 +1077,24 @@ class Connection(BaseModel):
|
|||
#
|
||||
# https://github.com/mastodon/mastodon/blob/852123867768e23410af5bd07ac0327bead0d9b2/app/models/account.rb#L68
|
||||
#
|
||||
# USERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i
|
||||
# SERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i
|
||||
# MENTION_RE = %r{(?<![=/[:word:]])@((#{USERNAME_RE})(?:@[[:word:].-]+[[:word:]]+)?)}i
|
||||
# URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+}
|
||||
|
||||
pattern = re.compile(r"""
|
||||
@? # Optional @ prefix
|
||||
(?P<uname>[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?) # username part
|
||||
@ # separator
|
||||
(?P<domain>[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?) # domain part
|
||||
""", re.VERBOSE | re.IGNORECASE)
|
||||
|
||||
m = pattern.match(id)
|
||||
uname = m.group("uname")
|
||||
domain = m.group("domain")
|
||||
|
||||
url = HttpUrl(f'https://{domain}/@{uname}')
|
||||
return url
|
||||
|
||||
@computed_field
|
||||
@cached_property
|
||||
|
@ -1094,7 +1108,7 @@ class Connection(BaseModel):
|
|||
elif self.name == "Orcid":
|
||||
url = f"https://orcid.org/{self.value}"
|
||||
elif self.name == "Mastodon":
|
||||
url = MastodonUname2Url(self.value)
|
||||
url = self.MastodonUname2Url(self.value)
|
||||
elif self.name == "email":
|
||||
url = f"mailto:{self.value}"
|
||||
elif self.name == "website":
|
||||
|
|
Loading…
Reference in New Issue