Drop the eex template and directly use the webpack index.html
Partly reverts ff7fd460
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
98888c95d6
commit
2749989a28
@ -8,7 +8,7 @@ config :mobilizon, MobilizonWeb.Endpoint,
|
||||
],
|
||||
secret_key_base:
|
||||
System.get_env("MOBILIZON_SECRET") || "ThisShouldBeAVeryStrongStringPleaseReplaceMe",
|
||||
cache_static_manifest: "priv/static/cache_manifest.json"
|
||||
cache_static_manifest: "priv/static/js/manifest.json"
|
||||
|
||||
# Configure your database
|
||||
config :mobilizon, Mobilizon.Repo,
|
||||
|
@ -6,6 +6,7 @@ defmodule MobilizonWeb.PageController do
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Events
|
||||
|
||||
plug(:put_layout, false)
|
||||
action_fallback(MobilizonWeb.FallbackController)
|
||||
|
||||
def index(conn, _params), do: render(conn, :index)
|
||||
|
@ -1,23 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html class="has-navbar-fixed-top">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||
<link rel="icon" href="<%= static_path(@conn, "/js/favicon.ico") %>">
|
||||
<link rel="stylesheet" href="//cdn.materialdesignicons.com/3.5.95/css/materialdesignicons.min.css">
|
||||
<title>mobilizon</title>
|
||||
<%= if assigns[:object], do: Metadata.build_tags(@object) %>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<noscript>
|
||||
<strong>We're sorry but mobilizon doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||
</noscript>
|
||||
<div id="app"></div>
|
||||
<!-- built files will be auto injected -->
|
||||
<script src="<%= static_path(@conn, "/js/app.js") %>"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -1,4 +1,3 @@
|
||||
defmodule MobilizonWeb.LayoutView do
|
||||
use MobilizonWeb, :view
|
||||
alias Mobilizon.Service.Metadata
|
||||
end
|
||||
|
@ -5,6 +5,8 @@ defmodule MobilizonWeb.PageView do
|
||||
use MobilizonWeb, :view
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.ActivityPub.Utils
|
||||
alias Mobilizon.Service.Metadata
|
||||
alias Mobilizon.Service.MetadataUtils
|
||||
|
||||
def render("actor.activity-json", %{conn: %{assigns: %{object: actor}}}) do
|
||||
public_key = Mobilizon.Service.ActivityPub.Utils.pem_to_public_key_pem(actor.keys)
|
||||
@ -82,4 +84,23 @@ defmodule MobilizonWeb.PageView do
|
||||
}
|
||||
|> Map.merge(Utils.make_json_ld_header())
|
||||
end
|
||||
|
||||
def render(page, %{object: object} = _assigns)
|
||||
when page in ["actor.html", "event.html", "comment.html"] do
|
||||
with {:ok, index_content} <- File.read(index_file_path()) do
|
||||
tags = object |> Metadata.build_tags() |> MetadataUtils.stringify_tags()
|
||||
index_content = String.replace(index_content, "<!--server-generated-meta-->", tags)
|
||||
{:safe, index_content}
|
||||
end
|
||||
end
|
||||
|
||||
def render("index.html", _assigns) do
|
||||
with {:ok, index_content} <- File.read(index_file_path()) do
|
||||
{:safe, index_content}
|
||||
end
|
||||
end
|
||||
|
||||
defp index_file_path() do
|
||||
Path.join(Application.app_dir(:mobilizon, "priv/static/js"), "index.html")
|
||||
end
|
||||
end
|
||||
|
@ -4,3 +4,17 @@ defprotocol Mobilizon.Service.Metadata do
|
||||
"""
|
||||
def build_tags(entity)
|
||||
end
|
||||
|
||||
defmodule Mobilizon.Service.MetadataUtils do
|
||||
@moduledoc """
|
||||
Tools to convert tags to string
|
||||
"""
|
||||
alias Phoenix.HTML
|
||||
|
||||
def stringify_tags(tags) do
|
||||
Enum.reduce(tags, "", &stringify_tag/2)
|
||||
end
|
||||
|
||||
defp stringify_tag(tag, acc) when is_tuple(tag), do: acc <> HTML.safe_to_string(tag)
|
||||
defp stringify_tag(tag, acc) when is_binary(tag), do: acc <> tag
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user