bonfire-app/lib/web/endpoint.ex

78 lines
2.5 KiB
Elixir
Raw Normal View History

2020-11-10 16:00:02 +00:00
defmodule Bonfire.Web.Endpoint do
use Phoenix.Endpoint, otp_app: :bonfire
use Bonfire.UI.Common.EndpointTemplate
2022-06-13 21:06:17 +00:00
alias Bonfire.Common.Utils
alias Bonfire.Common.Config
2022-06-13 21:06:17 +00:00
# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
if code_reloading? do
socket("/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket)
plug(Phoenix.LiveReloader)
plug(Phoenix.CodeReloader)
plug(Phoenix.Ecto.CheckRepoStatus, otp_app: :bonfire)
2022-10-10 09:29:20 +00:00
# plug(PhoenixProfiler)
end
plug(Bonfire.Web.Router)
2022-06-13 21:06:17 +00:00
def include_assets(conn) do
include_assets(conn, :top)
include_assets(conn, :bottom)
end
def include_assets(conn, :top) do
# unused?
# <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/choices.js/public/assets/styles/choices.min.css" />
# <script src="https://cdn.jsdelivr.net/npm/choices.js/public/assets/scripts/choices.min.js"></script>
# imported into main CSS already
# <link href="https://unpkg.com/@yaireo/tagify/dist/tagify.css" rel="stylesheet" type="text/css" />
2022-09-12 04:34:14 +00:00
font_family =
Bonfire.Me.Settings.get([:ui, :font_family], "Inter (Latin Languages)", conn)
|> Utils.maybe_to_string()
|> String.trim_trailing(" Languages)")
|> String.replace([" ", "-", "(", ")"], "-")
|> String.replace("--", "-")
|> String.downcase()
2022-06-13 21:06:17 +00:00
"""
<link rel="icon" type="image/x-icon" href="/favicon.ico">
2022-09-24 23:40:07 +00:00
<link phx-track-static rel='stylesheet' href='#{static_path("/assets/bonfire_basic.css")}'/>
<link phx-track-static rel='stylesheet' href='#{static_path("/fonts/#{font_family}.css")}'/>
<link rel="manifest" href="/pwa/manifest.json" />
<script type="module">
import 'https://cdn.jsdelivr.net/npm/@pwabuilder/pwaupdate';
const el = document.createElement('pwa-update');
document.body.appendChild(el);
</script>
2022-06-13 21:06:17 +00:00
"""
end
def include_assets(conn, :bottom) do
2022-09-12 04:34:14 +00:00
js =
if Utils.e(conn, :assigns, :current_account, nil) ||
Utils.e(conn, :assigns, :current_user, nil) do
static_path("/assets/bonfire_live.js")
else
static_path("/assets/bonfire_basic.js")
end
"""
#{PhoenixGon.View.render_gon_script(conn) |> Phoenix.HTML.safe_to_string()}
<script defer phx-track-static crossorigin='anonymous' src='#{js}'></script>
"""
2022-06-13 21:06:17 +00:00
end
def reload!(), do: Phoenix.CodeReloader.reload!(__MODULE__)
2022-10-20 03:23:50 +00:00
def generate_reverse_router!() do
Code.eval_file("priv/router_reverse.ex")
end
2020-11-10 16:00:02 +00:00
end