chiya/lib/chiya_web/controllers/page_controller.ex

89 lines
2.1 KiB
Elixir
Raw Normal View History

2023-03-05 16:07:40 +01:00
defmodule ChiyaWeb.PageController do
use ChiyaWeb, :controller
2023-07-03 21:08:34 +02:00
plug :put_layout, html: {ChiyaWeb.Layouts, :public}
2023-03-05 16:07:40 +01:00
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,
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,
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,
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,
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,
note: note,
user: user,
page_title: "About"
)
2023-06-02 07:31:47 +02:00
end
def wiki(conn, _params) do
settings = conn.assigns.settings
[notes_updated, notes_published] =
case settings.wiki_channel_id do
nil ->
[nil, nil]
id ->
channel = Chiya.Channels.get_channel!(id)
updated = Chiya.Notes.list_notes_by_channel_updated(channel)
published = Chiya.Notes.list_notes_by_channel_published(channel)
[updated, published]
end
render(conn, :wiki,
channel: channel,
notes_updated: notes_updated,
notes_published: notes_published,
page_title: "Wiki"
)
end
2023-03-05 16:07:40 +01:00
end