add viewport meta hook

This commit is contained in:
byte[] 2019-12-20 09:19:43 -05:00
parent 5fe3fc2e00
commit 40debb9634
2 changed files with 18 additions and 1 deletions

View file

@ -3,7 +3,8 @@ html lang="en"
head
meta charset="utf-8"
meta http-equiv="X-UA-Compatible" content="IE=edge"
meta name="viewport" content="width=device-width, initial-scale=1"
= viewport_meta_tag(@conn)
title
= if assigns[:title] do
=> assigns[:title]

View file

@ -117,4 +117,20 @@ defmodule PhilomenaWeb.LayoutView do
def manages_bans?(conn),
do: can?(conn, :create, Philomena.Bans.User)
def viewport_meta_tag(conn) do
ua = get_user_agent(conn)
case String.contains?(ua, ["Mobile", "webOS"]) do
true -> tag(:meta, name: "viewport", content: "width=device-width, initial-scale=1")
_false -> tag(:meta, name: "viewport", content: "width=1024, initial-scale=1")
end
end
defp get_user_agent(conn) do
case Plug.Conn.get_req_header(conn, "user-agent") do
[ua] -> ua
_ -> ""
end
end
end