add make test and Remove vue-cli serve

This commit is contained in:
Vincent
2019-04-17 17:13:20 +02:00
committed by Thomas Citharel
parent e1e410d595
commit ff7fd460f0
14 changed files with 47 additions and 79 deletions

View File

@@ -3,19 +3,15 @@ defmodule MobilizonWeb.PageController do
Controller to load our webapp
"""
use MobilizonWeb, :controller
alias Mobilizon.Service.Metadata
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Events
alias Mobilizon.Events.{Event, Comment}
plug(:put_layout, false)
action_fallback(MobilizonWeb.FallbackController)
def index(conn, _params) do
conn
|> put_resp_content_type("text/html")
|> send_file(200, "priv/static/index.html")
render conn, "app.html"
end
def actor(conn, %{"name" => name}) do
@@ -77,16 +73,6 @@ defmodule MobilizonWeb.PageController do
# Inject OpenGraph information
defp render_with_meta(conn, object) do
{:ok, index_content} = File.read(index_file_path())
tags = Metadata.build_tags(object)
response = String.replace(index_content, "<!--server-generated-meta-->", tags)
conn
|> put_resp_content_type("text/html")
|> send_resp(200, response)
end
defp index_file_path() do
Path.join(Application.app_dir(:mobilizon, "priv/static/"), "index.html")
render conn, "app.html", object: object
end
end

View File

@@ -21,7 +21,7 @@ defmodule MobilizonWeb.Endpoint do
at: "/",
from: :mobilizon,
gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt index.html)
only: ~w(css fonts images js favicon.ico robots.txt)
)
# Code reloading can be explicitly enabled under the

View File

@@ -0,0 +1,23 @@
<!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>

View File

@@ -0,0 +1,5 @@
defmodule MobilizonWeb.LayoutView do
use MobilizonWeb, :view
alias Mobilizon.Service.Metadata
end

View File

@@ -1,17 +1,8 @@
defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do
alias Phoenix.HTML
alias Phoenix.HTML.Tag
alias Mobilizon.Actors.Actor
require Logger
def build_tags(%Actor{} = actor) do
actor
|> do_build_tags()
|> Enum.map(&HTML.safe_to_string/1)
|> Enum.reduce("", fn tag, acc -> acc <> tag end)
end
defp do_build_tags(%Actor{} = actor) do
[
Tag.tag(:meta, property: "og:title", content: Actor.display_name_and_username(actor)),
Tag.tag(:meta, property: "og:url", content: actor.url),

View File

@@ -4,13 +4,6 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Comment do
alias Mobilizon.Events.Comment
def build_tags(%Comment{} = comment) do
comment
|> do_build_tags()
|> Enum.map(&HTML.safe_to_string/1)
|> Enum.reduce("", fn tag, acc -> acc <> tag end)
end
defp do_build_tags(%Comment{} = comment) do
[
Tag.tag(:meta, property: "og:title", content: comment.actor.preferred_username),
Tag.tag(:meta, property: "og:url", content: comment.url),

View File

@@ -5,15 +5,6 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
alias MobilizonWeb.JsonLD.ObjectView
def build_tags(%Event{} = event) do
event
|> do_build_tags()
|> Enum.map(&HTML.safe_to_string/1)
|> Enum.reduce("", fn tag, acc -> acc <> tag end)
|> Kernel.<>(build_json_ld_schema(event))
end
# Build OpenGraph & Twitter Tags
defp do_build_tags(%Event{} = event) do
[
Tag.tag(:meta, property: "og:title", content: event.title),
Tag.tag(:meta, property: "og:url", content: event.url),
@@ -21,14 +12,15 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
Tag.tag(:meta, property: "og:type", content: "website"),
Tag.tag(:meta, property: "og:image", content: event.thumbnail),
Tag.tag(:meta, property: "og:image", content: event.large_image),
Tag.tag(:meta, property: "twitter:card", content: "summary_large_image")
Tag.tag(:meta, property: "twitter:card", content: "summary_large_image"),
~s{<script type="application/ld+json">#{json(event)}</script>} |> HTML.raw()
]
end
# Insert JSON-LD schema by hand because Tag.content_tag wants to escape it
defp build_json_ld_schema(%Event{} = event) do
"<script type=\"application\/ld+json\">" <>
(ObjectView.render("event.json", %{event: event})
|> Jason.encode!()) <> "</script>"
defp json(%Event{} = event) do
"event.json"
|> ObjectView.render(%{event: event})
|> Jason.encode!()
end
end