devel #231

Merged
inhji merged 6 commits from devel into main 2023-07-25 07:05:47 +02:00
8 changed files with 118 additions and 64 deletions

View file

@ -55,6 +55,10 @@ defmodule Chiya.Notes.Note do
~p"/note/#{note.slug}"
end
def note_path_admin(note) do
~p"/admin/note/#{note.slug}"
end
def note_url(note) do
Phoenix.VerifiedRoutes.url(~p"/note/#{note.slug}")
end

View file

@ -18,6 +18,8 @@ defmodule Chiya.Site.Setting do
belongs_to :micropub_channel, Chiya.Channels.Channel
belongs_to :wiki_channel, Chiya.Channels.Channel
field :show_images_on_home, :boolean, default: true
timestamps()
end
@ -34,8 +36,15 @@ defmodule Chiya.Site.Setting do
:home_channel_id,
:default_channel_id,
:micropub_channel_id,
:wiki_channel_id
:wiki_channel_id,
:show_images_on_home
])
|> validate_required([
:title,
:subtitle,
:theme,
:user_agent,
:show_images_on_home
])
|> validate_required([:title, :subtitle, :theme, :user_agent])
end
end

View file

@ -149,7 +149,7 @@ defmodule ChiyaWeb.PublicComponents do
"""
end
attr :note, :map, required: true
attr :notes, :list, required: true
def note_list_microblog(assigns) do
~H"""
@ -158,10 +158,10 @@ defmodule ChiyaWeb.PublicComponents do
<article class="mt-4 first:mt-0">
<.featured_images note={note} />
<div class="prose prose-gruvbox">
<div class="prose prose-gruvbox mt-2">
<%= raw(render(note.content)) %>
</div>
<footer class="mt-1">
<footer class="mt-4">
<time class="text-theme-base/75">
<%= pretty_datetime(note.published_at) %>
</time>
@ -184,6 +184,8 @@ defmodule ChiyaWeb.PublicComponents do
"""
end
attr :notes, :list, required: true
def note_list_gallery(assigns) do
~H"""
<section class="note-list gallery | mt-6">
@ -218,6 +220,8 @@ defmodule ChiyaWeb.PublicComponents do
"""
end
attr :note, :map, required: true
def featured_images(assigns) do
images = main_images(assigns.note)
@ -231,12 +235,8 @@ defmodule ChiyaWeb.PublicComponents do
assigns = assign(assigns, :image, List.first(images))
~H"""
<figure class="mb-4">
<img
src={ChiyaWeb.Helpers.image_url(assigns.image, :full)}
class="rounded"
title={assigns.image.content}
/>
<figure>
<.featured_image image={assigns.image} size={:full} class="rounded-lg" />
</figure>
"""
@ -248,16 +248,8 @@ defmodule ChiyaWeb.PublicComponents do
~H"""
<figure class="flex gap-1">
<img
src={ChiyaWeb.Helpers.image_url(assigns.first, :thumb)}
class="rounded-l flex-1 w-full"
title={assigns.first.content}
/>
<img
src={ChiyaWeb.Helpers.image_url(assigns.second, :thumb)}
class="rounded-r flex-1 w-full"
title={assigns.second.content}
/>
<.featured_image image={assigns.first} size={:thumb} class="rounded-l flex-1 w-full" />
<.featured_image image={assigns.second} size={:thumb} class="rounded-r flex-1 w-full" />
</figure>
"""
@ -270,26 +262,49 @@ defmodule ChiyaWeb.PublicComponents do
~H"""
<figure class="flex gap-1">
<img
src={ChiyaWeb.Helpers.image_url(assigns.first, :thumb)}
class="flex-1 w-full rounded-l"
title={assigns.first.content}
/>
<img
src={ChiyaWeb.Helpers.image_url(assigns.second, :thumb)}
class="flex-1 w-full"
title={assigns.second.content}
/>
<img
src={ChiyaWeb.Helpers.image_url(assigns.third, :thumb)}
class="flex-1 w-full rounded-r"
title={assigns.third.content}
/>
<.featured_image image={assigns.first} size={:thumb} class="flex-1 w-full rounded-l" />
<.featured_image image={assigns.second} size={:thumb} class="flex-1 w-full" />
<.featured_image image={assigns.third} size={:thumb} class="flex-1 w-full rounded-r" />
</figure>
"""
_ ->
assigns =
assigns
|> assign(:first, Enum.at(images, 0))
|> assign(:second, Enum.at(images, 1))
|> assign(:third, Enum.at(images, 2))
|> assign(:fourth, Enum.at(images, 3))
~H"""
<figure class="flex gap-1 flex-col">
<section class="flex gap-1">
<.featured_image image={assigns.first} size={:thumb} class="flex-1 w-full rounded-tl-lg" />
<.featured_image image={assigns.second} size={:thumb} class="flex-1 w-full rounded-tr-lg" />
</section>
<section class="flex gap-1">
<.featured_image image={assigns.third} size={:thumb} class="flex-1 w-full rounded-bl-lg" />
<.featured_image image={assigns.fourth} size={:thumb} class="flex-1 w-full rounded-br-lg" />
</section>
</figure>
"""
end
end
attr :image, :map, required: true
attr :class, :string
attr :size, :atom, default: :thumb
defp featured_image(assigns) do
~H"""
<img
src={ChiyaWeb.Helpers.image_url(assigns.image, assigns.size)}
class={assigns.class}
title={assigns.image.content}
/>
"""
end
defp gallery_name(note), do: "gallery-#{note.id}"
defp main_images(note),

View file

@ -16,6 +16,10 @@
</section>
<% end %>
<aside class="max-w-2xl mx-auto mt-8">
<.featured_images note={@note} />
</aside>
<%= if has_outline?(@note) do %>
<aside class="max-w-2xl mx-auto mt-8 prose prose-gruvbox">
<div class="bg-theme-background1 rounded p-2">

View file

@ -28,6 +28,8 @@
options={@channels}
/>
<.input field={f[:wiki_channel_id]} type="select" label="Wiki Channel" options={@channels} />
<.input field={f[:show_images_on_home]} type="checkbox" label="Show Images on Home" />
<:actions>
<.button>Save Setting</.button>
</:actions>

View file

@ -18,30 +18,29 @@
<.list>
<:item title="Title"><%= @setting.title %></:item>
<:item title="Subtitle"><%= @setting.subtitle %></:item>
<:item title="Theme">
<%= @setting.theme %>
<div class="flex flex-row gap-2 bg-theme-background p-1 rounded-lg border">
<.icon name="hero-heart-solid" class="bg-theme-primary" />
<.icon name="hero-heart-solid" class="bg-theme-heading" />
<.icon name="hero-heart-solid" class="bg-theme-base" />
<.icon name="hero-heart-solid" class="bg-theme-muted" />
<.icon name="hero-heart-solid" class="bg-theme-dim" />
</div>
</:item>
<:item title="User agent"><%= @setting.user_agent %></:item>
<:item title="Custom css"><%= @setting.custom_css %></:item>
<:item title="Custom html"><%= @setting.custom_html %></:item>
<:item title="Default Channel">
<%= if @setting.default_channel, do: @setting.default_channel.name %>
</:item>
<:item title="Home Channel">
<%= if @setting.home_channel, do: @setting.home_channel.name %>
</:item>
<:item title="Micropub Channel">
<%= if @setting.micropub_channel, do: @setting.micropub_channel.name %>
</:item>
<:item title="Wiki Channel">
<%= if @setting.micropub_channel, do: @setting.wiki_channel.name %>
</.list>
<.list>
<:item title="Default Channel">
<%= if @setting.default_channel, do: @setting.default_channel.name %>
</:item>
<:item title="Home Channel">
<%= if @setting.home_channel, do: @setting.home_channel.name %>
</:item>
<:item title="Micropub Channel">
<%= if @setting.micropub_channel, do: @setting.micropub_channel.name %>
</:item>
<:item title="Wiki Channel">
<%= if @setting.micropub_channel, do: @setting.wiki_channel.name %>
</:item>
</.list>
<.list>
<:item title="Show Images on Home">
<%= if @setting.show_images_on_home, do: "✅", else: "❌" %>
</:item>
</.list>
<% end %>

View file

@ -3,14 +3,12 @@ defmodule ChiyaWeb.NoteShowLive do
alias Chiya.Notes
alias Chiya.Notes.NoteImage
import Phoenix.HTML.Tag
@accepted_extensions ~w(.jpg .jpeg .gif .png .webp)
@impl true
def render(assigns) do
channels = Enum.map_join(assigns.note.channels, ", ", fn c -> c.name end)
assigns = assign(assigns, :channels, channels)
~H"""
<.header>
<%= @note.name %>
@ -43,7 +41,7 @@ defmodule ChiyaWeb.NoteShowLive do
<:item title="Published at">
<%= pretty_date(@note.published_at) %> <span>(<%= from_now(@note.published_at) %>)</span>
</:item>
<:item title="Channels"><%= @channels %></:item>
<:item title="Channels"><%= note_channels(@note.channels) %></:item>
<:item title="Kind"><%= @note.kind %></:item>
<:item title="Url"><%= @note.url %></:item>
<:item title="Tags"><%= note_tags(@note.tags) %></:item>
@ -187,6 +185,20 @@ defmodule ChiyaWeb.NoteShowLive do
{:noreply, assign(socket, :note, Notes.get_note_preloaded!(socket.assigns.note.id))}
end
defp note_links(notes), do: Enum.map_join(notes, ", ", fn n -> n.name end)
defp note_tags(tags), do: Enum.map_join(tags, ", ", fn t -> t.name end)
defp note_links(notes), do: content_tag(:ul, do: Enum.map(notes, &note_link/1))
defp note_link(note) do
content_tag(:li, do: content_tag(:a, note.name, href: Chiya.Notes.Note.note_path_admin(note)))
end
defp note_tags(tags), do: content_tag(:ul, do: Enum.map(tags, &note_tag/1))
defp note_tag(tag),
do: content_tag(:li, do: content_tag(:a, tag.name, href: ~p"/tagged-with/#{tag.slug}"))
defp note_channels(channels), do: content_tag(:ul, do: Enum.map(channels, &note_channel/1))
defp note_channel(channel),
do:
content_tag(:li, do: content_tag(:a, channel.name, href: ~p"/admin/channels/#{channel.id}"))
end

View file

@ -0,0 +1,9 @@
defmodule Chiya.Repo.Migrations.AddBooleanSettings do
use Ecto.Migration
def change do
alter table(:settings) do
add :show_images_on_home, :boolean, default: true
end
end
end