mirror of
https://framagit.org/framasoft/mobilizon.git
synced 2024-12-26 01:38:36 +00:00
334d66bf5d
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
69 lines
2.1 KiB
Elixir
69 lines
2.1 KiB
Elixir
defmodule MobilizonWeb.PageView do
|
|
@moduledoc """
|
|
View for our webapp
|
|
"""
|
|
use MobilizonWeb, :view
|
|
alias Mobilizon.Actors.Actor
|
|
alias Mobilizon.Tombstone
|
|
alias Mobilizon.Service.ActivityPub.{Convertible, Utils}
|
|
alias Mobilizon.Service.Metadata
|
|
alias Mobilizon.Service.MetadataUtils
|
|
alias Mobilizon.Service.Metadata.Instance
|
|
alias Mobilizon.Events.{Comment, Event}
|
|
|
|
def render("actor.activity-json", %{conn: %{assigns: %{object: %Actor{} = actor}}}) do
|
|
actor
|
|
|> Convertible.model_to_as()
|
|
|> Map.merge(Utils.make_json_ld_header())
|
|
end
|
|
|
|
def render("event.activity-json", %{conn: %{assigns: %{object: %Event{} = event}}}) do
|
|
event
|
|
|> Convertible.model_to_as()
|
|
|> Map.merge(Utils.make_json_ld_header())
|
|
end
|
|
|
|
def render("event.activity-json", %{conn: %{assigns: %{object: %Tombstone{} = event}}}) do
|
|
event
|
|
|> Convertible.model_to_as()
|
|
|> Map.merge(Utils.make_json_ld_header())
|
|
end
|
|
|
|
def render("comment.activity-json", %{conn: %{assigns: %{object: %Comment{} = comment}}}) do
|
|
comment
|
|
|> Convertible.model_to_as()
|
|
|> 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 = replace_meta(index_content, tags)
|
|
|
|
{:safe, index_content}
|
|
end
|
|
end
|
|
|
|
def render("index.html", _assigns) do
|
|
with {:ok, index_content} <- File.read(index_file_path()) do
|
|
tags = Instance.build_tags() |> MetadataUtils.stringify_tags()
|
|
|
|
index_content = replace_meta(index_content, tags)
|
|
|
|
{:safe, index_content}
|
|
end
|
|
end
|
|
|
|
defp index_file_path do
|
|
Path.join(Application.app_dir(:mobilizon, "priv/static"), "index.html")
|
|
end
|
|
|
|
# TODO: Find why it's different in dev/prod and during tests
|
|
defp replace_meta(index_content, tags) do
|
|
index_content
|
|
|> String.replace("<meta name=\"server-injected-data\" />", tags)
|
|
|> String.replace("<meta name=server-injected-data>", tags)
|
|
end
|
|
end
|