Skip to content

Commit

Permalink
avoid hyphens in email addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
breunigs committed Jul 20, 2024
1 parent 68801f5 commit f0af5a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 deletions assets/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,10 @@ body.showSidebar::before {
}
}

.noHyphens {
hyphens: none;
}

.hideSidebar #content {
pointer-events: none;
}
Expand Down
26 changes: 16 additions & 10 deletions lib/components/tag_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -210,36 +210,42 @@ defmodule Components.TagHelpers do
attr :email, :string
attr :subject, :string
attr :body, :string
attr :rest, :global
slot(:inner_block)

def mailto(%{inner_block: _x, email: _e} = assigns) do
~H"""
<a href={"mailto:#{@email}"}><%= render_slot(@inner_block) %></a>
"""
end

def mailto(%{inner_block: _x, subject: subject, body: body} = assigns) do
assigns =
Map.merge(assigns, %{
email: Settings.email(),
email: assigns.email || Settings.email(),
subject: URI.encode(subject),
body: URI.encode(body)
})

assigns =
if assigns |> inner_text() |> String.contains?("@"),
do: assign(assigns, :rest, Map.put_new(assigns.rest, "class", "noHyphens")),
else: assigns

~H"""
<a href={"mailto:#{@email}?subject=#{@subject}&body=#{@body}"} {@rest}><%= render_slot(@inner_block) %></a>
"""
end

def mailto(%{inner_block: _x, email: _e} = assigns) do
~H"""
<a href={"mailto:#{@email}?subject=#{@subject}&body=#{@body}"}><%= render_slot(@inner_block) %></a>
<a href={"mailto:#{@email}"} {@rest}><%= render_slot(@inner_block) %></a>
"""
end

def mailto(%{inner_block: []} = assigns) do
~H"""
<a href={"mailto:"<>Settings.email()}><%= Settings.email() %></a>
<a href={"mailto:"<>Settings.email()} class="noHyphens" {@rest}><%= Settings.email() %></a>
"""
end

def mailto(%{inner_block: _x} = assigns) do
~H"""
<a href={"mailto:"<>Settings.email()}><%= render_slot(@inner_block) %></a>
<a href={"mailto:"<>Settings.email()} {@rest}><%= render_slot(@inner_block) %></a>
"""
end

Expand Down

0 comments on commit f0af5a0

Please sign in to comment.