all developments of milestone 1
This commit is contained in:
58
lib/web/controllers/manifest_controller.ex
Normal file
58
lib/web/controllers/manifest_controller.ex
Normal file
@@ -0,0 +1,58 @@
|
||||
defmodule Mobilizon.Web.ManifestController do
|
||||
use Mobilizon.Web, :controller
|
||||
|
||||
alias Mobilizon.Config
|
||||
alias Mobilizon.Medias.Media
|
||||
|
||||
@spec manifest(Plug.Conn.t(), any) :: Plug.Conn.t()
|
||||
def manifest(conn, _params) do
|
||||
favicons =
|
||||
case Config.instance_favicon() do
|
||||
%Media{file: %{url: url}, metadata: metadata} ->
|
||||
[
|
||||
Map.merge(
|
||||
%{
|
||||
src: url
|
||||
},
|
||||
case metadata do
|
||||
%{width: width} -> %{sizes: "#{width}x#{width}"}
|
||||
_ -> %{}
|
||||
end
|
||||
)
|
||||
]
|
||||
|
||||
_ ->
|
||||
[
|
||||
%{
|
||||
src: "./img/icons/android-chrome-512x512.png",
|
||||
sizes: "512x512",
|
||||
type: "image/png"
|
||||
},
|
||||
%{
|
||||
src: "./img/icons/android-chrome-192x192.png",
|
||||
sizes: "192x192",
|
||||
type: "image/png"
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
json(conn, %{
|
||||
name: Config.instance_name(),
|
||||
start_url: "/",
|
||||
scope: "/",
|
||||
display: "standalone",
|
||||
background_color: "#ffffff",
|
||||
theme_color: "#ffd599",
|
||||
orientation: "portrait-primary",
|
||||
icons: favicons
|
||||
})
|
||||
end
|
||||
|
||||
@spec favicon(Plug.Conn.t(), any) :: Plug.Conn.t()
|
||||
def favicon(conn, _params) do
|
||||
case Config.instance_favicon() do
|
||||
%Media{file: %{url: url}} -> redirect(conn, external: url)
|
||||
_ -> redirect(conn, to: "/img/icons/favicon.ico")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -18,6 +18,8 @@ defmodule Mobilizon.Web.PageController do
|
||||
defdelegate my_events(conn, params), to: PageController, as: :index
|
||||
@spec create_event(Plug.Conn.t(), any) :: Plug.Conn.t()
|
||||
defdelegate create_event(conn, params), to: PageController, as: :index
|
||||
@spec calendar(Plug.Conn.t(), any) :: Plug.Conn.t()
|
||||
defdelegate calendar(conn, params), to: PageController, as: :index
|
||||
@spec list_events(Plug.Conn.t(), any) :: Plug.Conn.t()
|
||||
defdelegate list_events(conn, params), to: PageController, as: :index
|
||||
@spec edit_event(Plug.Conn.t(), any) :: Plug.Conn.t()
|
||||
|
||||
@@ -18,8 +18,7 @@ defmodule Mobilizon.Web do
|
||||
"""
|
||||
|
||||
def static_paths,
|
||||
do:
|
||||
~w(index.html manifest.json manifest.webmanifest service-worker.js css fonts img js favicon.ico robots.txt assets)
|
||||
do: ~w(index.html service-worker.js css fonts img js robots.txt assets)
|
||||
|
||||
def controller do
|
||||
quote do
|
||||
|
||||
@@ -77,7 +77,7 @@ defmodule Mobilizon.Web.Plugs.HTTPSecurityPlug do
|
||||
# unsafe-eval is because of JS issues with regenerator-runtime
|
||||
@script_src "script-src 'self' 'unsafe-eval' "
|
||||
@style_src "style-src 'self' "
|
||||
@font_src "font-src 'self' "
|
||||
@font_src "font-src 'self' data: "
|
||||
|
||||
@spec csp_string(Keyword.t()) :: String.t()
|
||||
defp csp_string(options) do
|
||||
@@ -117,6 +117,8 @@ defmodule Mobilizon.Web.Plugs.HTTPSecurityPlug do
|
||||
|
||||
style_src = [style_src] ++ [get_csp_config(:style_src, options)]
|
||||
|
||||
style_src = [style_src] ++ ["'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='"]
|
||||
|
||||
font_src = [@font_src] ++ [get_csp_config(:font_src, options)]
|
||||
|
||||
frame_src = build_csp_field(:frame_src, options)
|
||||
|
||||
@@ -113,6 +113,12 @@ defmodule Mobilizon.Web.Router do
|
||||
get("/nodeinfo/:version", NodeInfoController, :nodeinfo)
|
||||
end
|
||||
|
||||
scope "/", Mobilizon.Web do
|
||||
get("/manifest.webmanifest", ManifestController, :manifest)
|
||||
get("/manifest.json", ManifestController, :manifest)
|
||||
get("/favicon.ico", ManifestController, :favicon)
|
||||
end
|
||||
|
||||
scope "/", Mobilizon.Web do
|
||||
pipe_through(:activity_pub_and_html)
|
||||
pipe_through(:activity_pub_signature)
|
||||
@@ -120,6 +126,7 @@ defmodule Mobilizon.Web.Router do
|
||||
get("/@:name", PageController, :actor)
|
||||
get("/events/me", PageController, :my_events)
|
||||
get("/events/create", PageController, :create_event)
|
||||
get("/events/calendar", PageController, :calendar)
|
||||
get("/events/:uuid", PageController, :event)
|
||||
get("/comments/:uuid", PageController, :comment)
|
||||
get("/resource/:uuid", PageController, :resource)
|
||||
@@ -188,6 +195,7 @@ defmodule Mobilizon.Web.Router do
|
||||
get("/events/create", PageController, :create_event)
|
||||
get("/events/list", PageController, :list_events)
|
||||
get("/events/me", PageController, :my_events)
|
||||
get("/events/calendar", PageController, :calendar)
|
||||
get("/events/:uuid/edit", PageController, :edit_event)
|
||||
|
||||
# This is a hack to ease link generation into emails
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
<p>
|
||||
<%= pgettext(
|
||||
"terms",
|
||||
"When we say “we”, “our”, or “us” in this document, we are referring to the owners, operators and administrators of this Mobilizon instance. The Mobilizon software is provided by the team of Mobilizon contributors, supported by <a href=\"https://framasoft.org\">Framasoft</a>, a French not-for-profit organization advocating for Free/Libre Software. Unless explicitly stated, this Mobilizon instance is an independent service using Mobilizon's source code. You may find more information about this instance on the <a href=\"/about/instance\">\"About this instance\"</a> page."
|
||||
"When we say “we”, “our”, or “us” in this document, we are referring to the owners, operators and administrators of this Mobilizon instance. The Mobilizon software is provided by the team of Mobilizon contributors. Unless explicitly stated, this Mobilizon instance is an independent service using Mobilizon's source code. You may find more information about this instance on the <a href=\"/about/instance\">\"About this instance\"</a> page."
|
||||
)
|
||||
|> raw %>
|
||||
</p>
|
||||
|
||||
@@ -4,15 +4,16 @@
|
||||
<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="apple-touch-icon" href="/img/icons/apple-touch-icon-152x152.png" sizes="152x152" />
|
||||
<link rel="apple-touch-icon" href={favicon_url()} sizes={favicon_sizes()} />
|
||||
<link rel="icon" href={favicon_url()} sizes={favicon_sizes()} />
|
||||
<link rel="mask-icon" href="/img/icons/safari-pinned-tab.svg" color={theme_color()} />
|
||||
<link rel="manifest" href="/manifest.webmanifest" />
|
||||
<meta name="theme-color" content={theme_color()} />
|
||||
<script>
|
||||
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
||||
document.documentElement.classList.add('dark')
|
||||
document.documentElement.classList.add('dark')
|
||||
} else {
|
||||
document.documentElement.classList.remove('dark')
|
||||
document.documentElement.classList.remove('dark')
|
||||
}
|
||||
</script>
|
||||
<%= if root?(assigns) do %>
|
||||
@@ -24,6 +25,7 @@
|
||||
<%= Vite.vite_client() %>
|
||||
<%= Vite.vite_snippet("src/main.ts") %>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<noscript>
|
||||
<strong>
|
||||
|
||||
@@ -6,6 +6,7 @@ defmodule Mobilizon.Web.PageView do
|
||||
use Mobilizon.Web, :view
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Config
|
||||
alias Mobilizon.Discussions.{Comment, Discussion}
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Posts.Post
|
||||
@@ -91,4 +92,27 @@ defmodule Mobilizon.Web.PageView do
|
||||
def root?(assigns) do
|
||||
assigns |> Map.get(:conn, %{request_path: "/"}) |> Map.get(:request_path, "/") == "/"
|
||||
end
|
||||
|
||||
defp favicon do
|
||||
case Config.instance_favicon() do
|
||||
%{file: %{url: url}, metadata: metadata} ->
|
||||
%{
|
||||
src: url,
|
||||
sizes:
|
||||
case metadata do
|
||||
%{width: width} -> "#{width}x#{width}"
|
||||
_ -> "any"
|
||||
end
|
||||
}
|
||||
|
||||
_ ->
|
||||
%{
|
||||
src: "/img/icons/apple-touch-icon-152x152.png",
|
||||
sizes: "152x152"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def favicon_url, do: Map.get(favicon(), :src)
|
||||
def favicon_sizes, do: Map.get(favicon(), :sizes)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user