File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -327,7 +327,7 @@ defmodule Algora.Accounts.User do
327327 bio: meta [ "bio" ] ,
328328 location: meta [ "location" ] ,
329329 avatar_url: meta [ "avatar_url" ] ,
330- website_url: meta [ "blog" ] ,
330+ website_url: Algora.Util . normalize_url ( meta [ "blog" ] ) ,
331331 github_url: meta [ "html_url" ]
332332 }
333333
Original file line number Diff line number Diff line change @@ -168,6 +168,20 @@ defmodule Algora.Util do
168168 |> String . replace ( ~r/ \/ (issues|pull|discussions)\/ / , "#" )
169169 end
170170
171+ def normalize_url ( nil ) , do: nil
172+
173+ def normalize_url ( url ) when is_binary ( url ) do
174+ url = String . trim ( url )
175+
176+ # Add https:// if no scheme present
177+ url = if String . contains? ( url , "://" ) , do: url , else: "https://" <> url
178+
179+ case URI . parse ( url ) do
180+ % URI { scheme: scheme , host: host } when not is_nil ( scheme ) and scheme != "" and not is_nil ( host ) and host != "" -> url
181+ _ -> nil
182+ end
183+ end
184+
171185 def get_gravatar_url ( email , opts \\ [ ] ) do
172186 default = Keyword . get ( opts , :default , "" )
173187 size = Keyword . get ( opts , :size , 460 )
You can’t perform that action at this time.
0 commit comments