add global_assigns and public pipeline

This commit is contained in:
Inhji 2023-03-09 21:43:56 +01:00
parent 7236ac409c
commit 83e5356e80
2 changed files with 28 additions and 1 deletions

View file

@ -0,0 +1,21 @@
defmodule ChiyaWeb.GlobalAssigns do
import Plug.Conn
def fetch_settings(conn, _opts) do
settings = Chiya.Site.get_settings()
assign(conn, :settings, settings)
end
def fetch_identities(conn, _opts) do
identities = Chiya.Identities.list_identities()
assign(conn, :identities, identities)
end
def fetch_public_channels(conn, _opts) do
channels =
Chiya.Channels.list_channels()
|> Enum.filter(fn c -> c.visibility == :public end)
assign(conn, :channels, channels)
end
end

View file

@ -2,6 +2,7 @@ defmodule ChiyaWeb.Router do
use ChiyaWeb, :router
import ChiyaWeb.UserAuth
import ChiyaWeb.GlobalAssigns
pipeline :browser do
plug :accepts, ["html"]
@ -13,6 +14,11 @@ defmodule ChiyaWeb.Router do
plug :fetch_current_user
end
pipeline :public do
plug :fetch_settings
plug :fetch_identities
end
pipeline :api do
plug :accepts, ["json"]
end
@ -93,7 +99,7 @@ defmodule ChiyaWeb.Router do
## Public routes
scope "/", ChiyaWeb do
pipe_through :browser
pipe_through [:browser, :public]
get "/:slug", PageController, :channel
get "/", PageController, :home