chiya/lib/chiya_web/controllers/page_controller.ex

70 lines
1.7 KiB
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
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-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
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-04-10 19:18:27 +02:00
def tag(conn, %{"slug" => tag_slug}) do
tag = Chiya.Tags.get_tag_by_slug!(tag_slug)
render(conn, :tag,
layout: {ChiyaWeb.Layouts, "public.html"},
tag: tag,
page_title: tag.name
)
end
def note(conn, %{"slug" => note_slug}) do
note = Chiya.Notes.get_note_by_slug_preloaded!(note_slug)
2023-04-30 13:35:22 +02:00
changeset = Chiya.Notes.change_note_comment(%Chiya.Notes.NoteComment{}, %{note_id: note.id})
2023-04-30 11:56:45 +02:00
if is_nil(note.published_at) and is_nil(conn.assigns.current_user) 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,
2023-04-30 13:35:22 +02:00
page_title: note.name,
changeset: changeset
2023-03-31 16:58:10 +02:00
)
end
end
2023-06-02 07:31:47 +02:00
def about(conn, _params) do
2023-07-03 20:38:35 +02:00
note = Chiya.Notes.get_note_by_slug_preloaded("about")
user = Chiya.Accounts.get_user!(1)
render(conn, :about,
layout: {ChiyaWeb.Layouts, "public.html"},
note: note,
user: user,
page_title: "About"
)
2023-06-02 07:31:47 +02:00
end
2023-03-05 16:07:40 +01:00
end