devel #231
8 changed files with 118 additions and 64 deletions
|
@ -55,6 +55,10 @@ defmodule Chiya.Notes.Note do
|
||||||
~p"/note/#{note.slug}"
|
~p"/note/#{note.slug}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def note_path_admin(note) do
|
||||||
|
~p"/admin/note/#{note.slug}"
|
||||||
|
end
|
||||||
|
|
||||||
def note_url(note) do
|
def note_url(note) do
|
||||||
Phoenix.VerifiedRoutes.url(~p"/note/#{note.slug}")
|
Phoenix.VerifiedRoutes.url(~p"/note/#{note.slug}")
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,8 @@ defmodule Chiya.Site.Setting do
|
||||||
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
|
||||||
|
|
||||||
|
field :show_images_on_home, :boolean, default: true
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -34,8 +36,15 @@ defmodule Chiya.Site.Setting do
|
||||||
:home_channel_id,
|
:home_channel_id,
|
||||||
:default_channel_id,
|
:default_channel_id,
|
||||||
:micropub_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
|
||||||
end
|
end
|
||||||
|
|
|
@ -149,7 +149,7 @@ defmodule ChiyaWeb.PublicComponents do
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
attr :note, :map, required: true
|
attr :notes, :list, required: true
|
||||||
|
|
||||||
def note_list_microblog(assigns) do
|
def note_list_microblog(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
|
@ -158,10 +158,10 @@ defmodule ChiyaWeb.PublicComponents do
|
||||||
<article class="mt-4 first:mt-0">
|
<article class="mt-4 first:mt-0">
|
||||||
<.featured_images note={note} />
|
<.featured_images note={note} />
|
||||||
|
|
||||||
<div class="prose prose-gruvbox">
|
<div class="prose prose-gruvbox mt-2">
|
||||||
<%= raw(render(note.content)) %>
|
<%= raw(render(note.content)) %>
|
||||||
</div>
|
</div>
|
||||||
<footer class="mt-1">
|
<footer class="mt-4">
|
||||||
<time class="text-theme-base/75">
|
<time class="text-theme-base/75">
|
||||||
<%= pretty_datetime(note.published_at) %>
|
<%= pretty_datetime(note.published_at) %>
|
||||||
</time>
|
</time>
|
||||||
|
@ -184,6 +184,8 @@ defmodule ChiyaWeb.PublicComponents do
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attr :notes, :list, required: true
|
||||||
|
|
||||||
def note_list_gallery(assigns) do
|
def note_list_gallery(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<section class="note-list gallery | mt-6">
|
<section class="note-list gallery | mt-6">
|
||||||
|
@ -218,6 +220,8 @@ defmodule ChiyaWeb.PublicComponents do
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attr :note, :map, required: true
|
||||||
|
|
||||||
def featured_images(assigns) do
|
def featured_images(assigns) do
|
||||||
images = main_images(assigns.note)
|
images = main_images(assigns.note)
|
||||||
|
|
||||||
|
@ -231,12 +235,8 @@ defmodule ChiyaWeb.PublicComponents do
|
||||||
assigns = assign(assigns, :image, List.first(images))
|
assigns = assign(assigns, :image, List.first(images))
|
||||||
|
|
||||||
~H"""
|
~H"""
|
||||||
<figure class="mb-4">
|
<figure>
|
||||||
<img
|
<.featured_image image={assigns.image} size={:full} class="rounded-lg" />
|
||||||
src={ChiyaWeb.Helpers.image_url(assigns.image, :full)}
|
|
||||||
class="rounded"
|
|
||||||
title={assigns.image.content}
|
|
||||||
/>
|
|
||||||
</figure>
|
</figure>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -248,16 +248,8 @@ defmodule ChiyaWeb.PublicComponents do
|
||||||
|
|
||||||
~H"""
|
~H"""
|
||||||
<figure class="flex gap-1">
|
<figure class="flex gap-1">
|
||||||
<img
|
<.featured_image image={assigns.first} size={:thumb} class="rounded-l flex-1 w-full" />
|
||||||
src={ChiyaWeb.Helpers.image_url(assigns.first, :thumb)}
|
<.featured_image image={assigns.second} size={:thumb} class="rounded-r flex-1 w-full" />
|
||||||
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}
|
|
||||||
/>
|
|
||||||
</figure>
|
</figure>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -270,26 +262,49 @@ defmodule ChiyaWeb.PublicComponents do
|
||||||
|
|
||||||
~H"""
|
~H"""
|
||||||
<figure class="flex gap-1">
|
<figure class="flex gap-1">
|
||||||
<img
|
<.featured_image image={assigns.first} size={:thumb} class="flex-1 w-full rounded-l" />
|
||||||
src={ChiyaWeb.Helpers.image_url(assigns.first, :thumb)}
|
<.featured_image image={assigns.second} size={:thumb} class="flex-1 w-full" />
|
||||||
class="flex-1 w-full rounded-l"
|
<.featured_image image={assigns.third} size={:thumb} class="flex-1 w-full rounded-r" />
|
||||||
title={assigns.first.content}
|
</figure>
|
||||||
/>
|
"""
|
||||||
<img
|
|
||||||
src={ChiyaWeb.Helpers.image_url(assigns.second, :thumb)}
|
_ ->
|
||||||
class="flex-1 w-full"
|
assigns =
|
||||||
title={assigns.second.content}
|
assigns
|
||||||
/>
|
|> assign(:first, Enum.at(images, 0))
|
||||||
<img
|
|> assign(:second, Enum.at(images, 1))
|
||||||
src={ChiyaWeb.Helpers.image_url(assigns.third, :thumb)}
|
|> assign(:third, Enum.at(images, 2))
|
||||||
class="flex-1 w-full rounded-r"
|
|> assign(:fourth, Enum.at(images, 3))
|
||||||
title={assigns.third.content}
|
|
||||||
/>
|
~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>
|
</figure>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
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 gallery_name(note), do: "gallery-#{note.id}"
|
||||||
|
|
||||||
defp main_images(note),
|
defp main_images(note),
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
</section>
|
</section>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<aside class="max-w-2xl mx-auto mt-8">
|
||||||
|
<.featured_images note={@note} />
|
||||||
|
</aside>
|
||||||
|
|
||||||
<%= if has_outline?(@note) do %>
|
<%= if has_outline?(@note) do %>
|
||||||
<aside class="max-w-2xl mx-auto mt-8 prose prose-gruvbox">
|
<aside class="max-w-2xl mx-auto mt-8 prose prose-gruvbox">
|
||||||
<div class="bg-theme-background1 rounded p-2">
|
<div class="bg-theme-background1 rounded p-2">
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
options={@channels}
|
options={@channels}
|
||||||
/>
|
/>
|
||||||
<.input field={f[:wiki_channel_id]} type="select" label="Wiki Channel" 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>
|
<:actions>
|
||||||
<.button>Save Setting</.button>
|
<.button>Save Setting</.button>
|
||||||
</:actions>
|
</:actions>
|
||||||
|
|
|
@ -18,30 +18,29 @@
|
||||||
<.list>
|
<.list>
|
||||||
<:item title="Title"><%= @setting.title %></:item>
|
<:item title="Title"><%= @setting.title %></:item>
|
||||||
<:item title="Subtitle"><%= @setting.subtitle %></: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 css"><%= @setting.custom_css %></:item>
|
||||||
<:item title="Custom html"><%= @setting.custom_html %></:item>
|
<:item title="Custom html"><%= @setting.custom_html %></:item>
|
||||||
<:item title="Default Channel">
|
</.list>
|
||||||
<%= if @setting.default_channel, do: @setting.default_channel.name %>
|
|
||||||
</:item>
|
<.list>
|
||||||
<:item title="Home Channel">
|
<:item title="Default Channel">
|
||||||
<%= if @setting.home_channel, do: @setting.home_channel.name %>
|
<%= if @setting.default_channel, do: @setting.default_channel.name %>
|
||||||
</:item>
|
</:item>
|
||||||
<:item title="Micropub Channel">
|
<:item title="Home Channel">
|
||||||
<%= if @setting.micropub_channel, do: @setting.micropub_channel.name %>
|
<%= if @setting.home_channel, do: @setting.home_channel.name %>
|
||||||
</:item>
|
</:item>
|
||||||
<:item title="Wiki Channel">
|
<:item title="Micropub Channel">
|
||||||
<%= if @setting.micropub_channel, do: @setting.wiki_channel.name %>
|
<%= 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>
|
</:item>
|
||||||
</.list>
|
</.list>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -3,14 +3,12 @@ defmodule ChiyaWeb.NoteShowLive do
|
||||||
|
|
||||||
alias Chiya.Notes
|
alias Chiya.Notes
|
||||||
alias Chiya.Notes.NoteImage
|
alias Chiya.Notes.NoteImage
|
||||||
|
import Phoenix.HTML.Tag
|
||||||
|
|
||||||
@accepted_extensions ~w(.jpg .jpeg .gif .png .webp)
|
@accepted_extensions ~w(.jpg .jpeg .gif .png .webp)
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
channels = Enum.map_join(assigns.note.channels, ", ", fn c -> c.name end)
|
|
||||||
assigns = assign(assigns, :channels, channels)
|
|
||||||
|
|
||||||
~H"""
|
~H"""
|
||||||
<.header>
|
<.header>
|
||||||
<%= @note.name %>
|
<%= @note.name %>
|
||||||
|
@ -43,7 +41,7 @@ defmodule ChiyaWeb.NoteShowLive do
|
||||||
<:item title="Published at">
|
<:item title="Published at">
|
||||||
<%= pretty_date(@note.published_at) %> <span>(<%= from_now(@note.published_at) %>)</span>
|
<%= pretty_date(@note.published_at) %> <span>(<%= from_now(@note.published_at) %>)</span>
|
||||||
</:item>
|
</:item>
|
||||||
<:item title="Channels"><%= @channels %></:item>
|
<:item title="Channels"><%= note_channels(@note.channels) %></:item>
|
||||||
<:item title="Kind"><%= @note.kind %></:item>
|
<:item title="Kind"><%= @note.kind %></:item>
|
||||||
<:item title="Url"><%= @note.url %></:item>
|
<:item title="Url"><%= @note.url %></:item>
|
||||||
<:item title="Tags"><%= note_tags(@note.tags) %></: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))}
|
{:noreply, assign(socket, :note, Notes.get_note_preloaded!(socket.assigns.note.id))}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp note_links(notes), do: Enum.map_join(notes, ", ", fn n -> n.name end)
|
defp note_links(notes), do: content_tag(:ul, do: Enum.map(notes, ¬e_link/1))
|
||||||
defp note_tags(tags), do: Enum.map_join(tags, ", ", fn t -> t.name end)
|
|
||||||
|
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, ¬e_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, ¬e_channel/1))
|
||||||
|
|
||||||
|
defp note_channel(channel),
|
||||||
|
do:
|
||||||
|
content_tag(:li, do: content_tag(:a, channel.name, href: ~p"/admin/channels/#{channel.id}"))
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
Loading…
Reference in a new issue