chiya/lib/chiya_web/controllers/page_controller.ex

33 lines
1,008 B
Elixir
Raw Normal View History

2023-03-05 16:07:40 +01:00
defmodule ChiyaWeb.PageController do
use ChiyaWeb, :controller
def home(conn, _params) do
settings = conn.assigns.settings
channel = case settings.home_channel_id do
nil -> nil
id -> Chiya.Channels.get_channel!(id) |> Chiya.Channels.preload_channel_public()
end
render(conn, :home, layout: {ChiyaWeb.Layouts, "public.html"}, channel: channel, page_title: "Home")
2023-03-05 16:07:40 +01:00
end
2023-03-09 14:43:31 +01:00
def channel(conn, %{"slug" => channel_slug}) do
channel =
Chiya.Channels.get_channel_by_slug!(channel_slug)
|> Chiya.Channels.preload_channel_public()
render(conn, :channel, layout: {ChiyaWeb.Layouts, "public.html"}, channel: channel, page_title: channel.name)
2023-03-09 14:43:31 +01:00
end
def note(conn, %{"slug" => note_slug}) do
note = Chiya.Notes.get_note_by_slug_preloaded!(note_slug)
if is_nil(note.published_at) do
render_error(conn, :not_found)
else
render(conn, :note, layout: {ChiyaWeb.Layouts, "public.html"}, note: note, page_title: note.name)
end
end
2023-03-05 16:07:40 +01:00
end