chiya/lib/chiya_web/controllers/page_controller.ex

32 lines
1,008 B
Elixir

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")
end
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)
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
end