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