devel #239

Merged
inhji merged 9 commits from devel into main 2023-07-29 16:44:26 +02:00
8 changed files with 75 additions and 3 deletions

View file

@ -17,6 +17,7 @@ defmodule Chiya.Site.Setting do
belongs_to :default_channel, Chiya.Channels.Channel belongs_to :default_channel, Chiya.Channels.Channel
belongs_to :micropub_channel, Chiya.Channels.Channel belongs_to :micropub_channel, Chiya.Channels.Channel
belongs_to :wiki_channel, Chiya.Channels.Channel belongs_to :wiki_channel, Chiya.Channels.Channel
belongs_to :bookmark_channel, Chiya.Channels.Channel
field :show_images_on_home, :boolean, default: true field :show_images_on_home, :boolean, default: true
@ -37,6 +38,7 @@ defmodule Chiya.Site.Setting do
:default_channel_id, :default_channel_id,
:micropub_channel_id, :micropub_channel_id,
:wiki_channel_id, :wiki_channel_id,
:bookmark_channel_id,
:show_images_on_home :show_images_on_home
]) ])
|> validate_required([ |> validate_required([

View file

@ -43,7 +43,7 @@
<ul class="flex gap-3"> <ul class="flex gap-3">
<li> <li>
<a href="/" class="button"> <a href="/" class="button">
<.icon name="hero-home" /> Home <.icon name="hero-home" />
</a> </a>
</li> </li>
<li> <li>
@ -56,14 +56,19 @@
<.icon name="hero-paper-clip" /> Wiki <.icon name="hero-paper-clip" /> Wiki
</a> </a>
</li> </li>
<li>
<a href="/bookmarks" class="button">
<.icon name="hero-bookmark" /> Bookmarks
</a>
</li>
<li class="flex-1"></li>
<%= if @current_user do %> <%= if @current_user do %>
<li> <li>
<a href="/admin" class="button"> <a href="/admin" class="button">
<.icon name="hero-beaker" /> Admin <.icon name="hero-beaker" />
</a> </a>
</li> </li>
<% end %> <% end %>
<li class="flex-1"></li>
<li> <li>
<.darkmode_toggle class="button" /> <.darkmode_toggle class="button" />
</li> </li>

View file

@ -86,4 +86,23 @@ defmodule ChiyaWeb.PageController do
page_title: "Wiki" page_title: "Wiki"
) )
end end
def bookmarks(conn, _params) do
[channel, notes] =
case conn.assigns.settings.wiki_channel_id do
nil ->
[nil, nil]
id ->
channel = Chiya.Channels.get_channel!(id)
notes = Chiya.Notes.list_notes_by_channel_updated(channel, 5)
[channel, notes]
end
render(conn, :wiki,
channel: channel,
notes: notes,
page_title: "Bookmarks"
)
end
end end

View file

@ -0,0 +1,27 @@
<%= if @channel do %>
<section class="mx-auto max-w-2xl">
<.header>
<%= @channel.name %>
</.header>
</section>
<section class="mt-6 flex flex-col gap-3 max-w-2xl mx-auto">
<section class="prose prose-gruvbox md:prose-lg lg:prose-xl max-w-none">
<%= Markdown.render(@channel.content) |> raw %>
</section>
<section class="mt-6">
<.note_list notes={@notes} layout={@channel.layout} show_content={false} />
</section>
</section>
<% else %>
<section class="mx-auto max-w-2xl">
<.header>
Wiki
</.header>
<section class="prose prose-gruvbox mt-6">
Wiki is not set up.
</section>
</section>
<% end %>

View file

@ -21,6 +21,12 @@
label="Micropub Channel" label="Micropub Channel"
options={@channels} options={@channels}
/> />
<.input
field={f[:bookmark_channel_id]}
type="select"
label="Bookmark Channel"
options={@channels}
/>
<.input <.input
field={f[:default_channel_id]} field={f[:default_channel_id]}
type="select" type="select"

View file

@ -32,6 +32,9 @@
<:item title="Micropub Channel"> <:item title="Micropub Channel">
<%= if @setting.micropub_channel, do: @setting.micropub_channel.name %> <%= if @setting.micropub_channel, do: @setting.micropub_channel.name %>
</:item> </:item>
<:item title="Bookmark Channel">
<%= if @setting.bookmark_channel, do: @setting.bookmark_channel.name %>
</:item>
<:item title="Wiki Channel"> <:item title="Wiki Channel">
<%= if @setting.micropub_channel, do: @setting.wiki_channel.name %> <%= if @setting.micropub_channel, do: @setting.wiki_channel.name %>
</:item> </:item>

View file

@ -138,6 +138,7 @@ defmodule ChiyaWeb.Router do
get "/about", PageController, :about get "/about", PageController, :about
get "/wiki", PageController, :wiki get "/wiki", PageController, :wiki
get "/bookmarks", PageController, :bookmarks
get "/", PageController, :home get "/", PageController, :home
end end

View file

@ -0,0 +1,9 @@
defmodule Chiya.Repo.Migrations.AddBookmarkChannelSetting do
use Ecto.Migration
def change do
alter table(:settings) do
add :bookmark_channel_id, references(:channels, on_delete: :nothing)
end
end
end