Compare commits
2 commits
devel
...
renovate/p
Author | SHA1 | Date | |
---|---|---|---|
8ecf5f5f68 | |||
1ed915c7d8 |
8 changed files with 22 additions and 181 deletions
|
@ -40,19 +40,6 @@
|
||||||
:root[data-mode=dark] .prose {
|
:root[data-mode=dark] .prose {
|
||||||
@apply prose-invert;
|
@apply prose-invert;
|
||||||
}
|
}
|
||||||
/* https://stackoverflow.com/questions/5379752/css-style-external-links */
|
|
||||||
a[href]:not(:where(
|
|
||||||
/* exclude hash only links */
|
|
||||||
[href^="#"],
|
|
||||||
/* exclude relative but not double slash only links */
|
|
||||||
[href^="/"]:not([href^="//"]),
|
|
||||||
/* domains to exclude */
|
|
||||||
[href*="//inhji.de"],
|
|
||||||
/* subdomains to exclude */
|
|
||||||
[href*="//cloud.inhji.de"],
|
|
||||||
)):after {
|
|
||||||
content: '↬';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -72,7 +72,7 @@ defmodule Chiya.Notes.Note do
|
||||||
end
|
end
|
||||||
|
|
||||||
def note_path_admin(note) do
|
def note_path_admin(note) do
|
||||||
~p"/admin/notes/#{note.id}"
|
~p"/admin/notes/#{note.slug}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def note_url(note) do
|
def note_url(note) do
|
||||||
|
|
|
@ -586,9 +586,7 @@ defmodule ChiyaWeb.CoreComponents do
|
||||||
<dt class="w-1/4 flex-none text-[0.8125rem] leading-6 text-gray-500 dark:text-gray-300">
|
<dt class="w-1/4 flex-none text-[0.8125rem] leading-6 text-gray-500 dark:text-gray-300">
|
||||||
<%= item.title %>
|
<%= item.title %>
|
||||||
</dt>
|
</dt>
|
||||||
<dd class="text-sm leading-6 text-gray-700 dark:text-gray-400 overflow-auto">
|
<dd class="text-sm leading-6 text-gray-700 dark:text-gray-400"><%= render_slot(item) %></dd>
|
||||||
<%= render_slot(item) %>
|
|
||||||
</dd>
|
|
||||||
</div>
|
</div>
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -43,14 +43,14 @@
|
||||||
|
|
||||||
<aside class="prose max-w-none">
|
<aside class="prose max-w-none">
|
||||||
<%= if has_outline?(@note) do %>
|
<%= if has_outline?(@note) do %>
|
||||||
<h3><.icon name="hero-rectangle-stack" /> Outline</h3>
|
<h3>Outline</h3>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<%= raw(render_outline(@note)) %>
|
<%= raw(render_outline(@note)) %>
|
||||||
</section>
|
</section>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<h3><.icon name="hero-rectangle-group" /> Properties</h3>
|
<h3>Properties</h3>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -82,7 +82,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= if not Enum.empty?(@note.links_to) do %>
|
<%= if not Enum.empty?(@note.links_to) do %>
|
||||||
<h3><.icon name="hero-arrow-down-on-square" /> Notes linking here</h3>
|
<h3>Notes linking here</h3>
|
||||||
<section>
|
<section>
|
||||||
<ul>
|
<ul>
|
||||||
<%= for link <- @note.links_to do %>
|
<%= for link <- @note.links_to do %>
|
||||||
|
@ -92,7 +92,7 @@
|
||||||
</section>
|
</section>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<h3><.icon name="hero-wrench-screwdriver" /> Admin</h3>
|
<h3>Admin</h3>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<ul>
|
<ul>
|
||||||
|
|
|
@ -1,132 +0,0 @@
|
||||||
defmodule ChiyaWeb.NoteEditLive do
|
|
||||||
use ChiyaWeb, :live_view
|
|
||||||
|
|
||||||
def render(assigns) do
|
|
||||||
~H"""
|
|
||||||
<.header>
|
|
||||||
<:actions>
|
|
||||||
<.link href={~p"/admin/notes/#{@note.id}"}>
|
|
||||||
<.button><.icon name="hero-arrow-left" /> Back to Note</.button>
|
|
||||||
</.link>
|
|
||||||
</:actions>
|
|
||||||
</.header>
|
|
||||||
|
|
||||||
<.simple_form for={@note_form} id="note_form" phx-change="validate_note" phx-submit="update_note">
|
|
||||||
<header>
|
|
||||||
<.input
|
|
||||||
field={@note_form[:name]}
|
|
||||||
type="text"
|
|
||||||
class="border-none dark:border-none text-2xl dark:text-2xl"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<.input field={@note_form[:slug]} type="text" class="bg-gray-200 dark:bg-gray-900 font-mono" />
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<section class="grid grid-cols-5 gap-6">
|
|
||||||
<section class="col-span-5 md:col-span-3">
|
|
||||||
<.input
|
|
||||||
field={@note_form[:content]}
|
|
||||||
type="textarea"
|
|
||||||
label="Content"
|
|
||||||
rows="20"
|
|
||||||
class="font-mono"
|
|
||||||
/>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section class="col-span-5 md:col-span-2 flex flex-col gap-6">
|
|
||||||
<.input field={@note_form[:published_at]} type="datetime-local" label="Published at" />
|
|
||||||
<.input
|
|
||||||
field={@note_form[:kind]}
|
|
||||||
type="select"
|
|
||||||
label="Kind"
|
|
||||||
prompt="Choose a value"
|
|
||||||
options={Ecto.Enum.values(Chiya.Notes.Note, :kind)}
|
|
||||||
/>
|
|
||||||
<.input field={@note_form[:url]} type="text" label="Url" />
|
|
||||||
<.input
|
|
||||||
field={@note_form[:tags_string]}
|
|
||||||
type="text"
|
|
||||||
label="Tags"
|
|
||||||
value={tags_to_string(@note.tags)}
|
|
||||||
/>
|
|
||||||
<.input
|
|
||||||
field={@note_form[:channels]}
|
|
||||||
type="select"
|
|
||||||
label="Channel"
|
|
||||||
multiple={true}
|
|
||||||
options={@channels}
|
|
||||||
value={@selected_channels}
|
|
||||||
/>
|
|
||||||
</section>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<:actions>
|
|
||||||
<.button>Save Note</.button>
|
|
||||||
</:actions>
|
|
||||||
</.simple_form>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
def mount(%{"id" => id}, _session, socket) do
|
|
||||||
note = Chiya.Notes.get_note_preloaded!(id)
|
|
||||||
changeset = Chiya.Notes.change_note(note)
|
|
||||||
selected_channels = Enum.map(note.channels, fn c -> c.id end)
|
|
||||||
|
|
||||||
{:ok,
|
|
||||||
socket
|
|
||||||
|> assign(%{
|
|
||||||
note_form: to_form(changeset),
|
|
||||||
note: note,
|
|
||||||
action: ~p"/admin/notes/#{note}",
|
|
||||||
channels: to_channel_options(),
|
|
||||||
selected_channels: selected_channels
|
|
||||||
})}
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle_event("validate_note", params, socket) do
|
|
||||||
%{"note" => note_params} = params
|
|
||||||
|
|
||||||
note_form =
|
|
||||||
socket.assigns.note
|
|
||||||
|> Chiya.Notes.change_note(note_params)
|
|
||||||
|> Map.put(:action, :validate)
|
|
||||||
|> to_form()
|
|
||||||
|
|
||||||
{:noreply, socket |> assign(:note_form, note_form)}
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle_event("update_note", params, socket) do
|
|
||||||
%{"note" => note_params} = params
|
|
||||||
note_params = from_channel_ids(note_params)
|
|
||||||
note = socket.assigns.note
|
|
||||||
|
|
||||||
case Chiya.Notes.update_note(note, note_params) do
|
|
||||||
{:ok, note} ->
|
|
||||||
{:noreply,
|
|
||||||
socket
|
|
||||||
|> put_flash(:info, "Note updated successfully.")
|
|
||||||
|> redirect(to: ~p"/admin/notes/#{note}")}
|
|
||||||
|
|
||||||
{:error, %Ecto.Changeset{} = changeset} ->
|
|
||||||
{:noreply, assign(socket, :note_form, to_form(Map.put(changeset, :action, :update)))}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def tags_to_string(tags), do: Enum.map_join(tags, ", ", fn t -> t.name end)
|
|
||||||
|
|
||||||
defp from_channel_ids(note_params) do
|
|
||||||
selected_ids = Enum.map(note_params["channels"] || [], &String.to_integer/1)
|
|
||||||
|
|
||||||
selected_channels =
|
|
||||||
Chiya.Channels.list_channels()
|
|
||||||
|> Enum.filter(fn c -> Enum.member?(selected_ids, c.id) end)
|
|
||||||
|
|
||||||
Map.put(note_params, "channels", selected_channels)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp to_channel_options(items \\ nil),
|
|
||||||
do:
|
|
||||||
Enum.map(items || Chiya.Channels.list_channels(), fn c ->
|
|
||||||
{Chiya.Channels.Channel.icon(c) <> " " <> c.name, c.id}
|
|
||||||
end)
|
|
||||||
end
|
|
|
@ -37,31 +37,20 @@ defmodule ChiyaWeb.NoteShowLive do
|
||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
<section class="mt-4">
|
<.list>
|
||||||
<div class="select-all font-mono bg-white p-1 rounded">[[<%= @note.slug %>]]</div>
|
<:item title="Published at">
|
||||||
</section>
|
<%= pretty_date(@note.published_at) %> <span>(<%= from_now(@note.published_at) %>)</span>
|
||||||
|
</:item>
|
||||||
<section class="grid grid-cols-2">
|
<:item title="Channels"><%= note_channels(@note.channels) %></:item>
|
||||||
<section class="col-span-1">
|
<:item title="Kind"><%= @note.kind %></:item>
|
||||||
<.list>
|
<:item title="Url"><%= @note.url %></:item>
|
||||||
<:item title="Published at">
|
<:item title="Tags"><%= note_tags(@note.tags) %></:item>
|
||||||
<%= pretty_date(@note.published_at) %> <span>(<%= from_now(@note.published_at) %>)</span>
|
<:item title="Links outgoing"><%= note_links(@note.links_from) %></:item>
|
||||||
</:item>
|
<:item title="Links incoming"><%= note_links(@note.links_to) %></:item>
|
||||||
<:item title="Channels"><%= note_channels(@note.channels) %></:item>
|
<:item title="Embed">
|
||||||
<:item title="Kind"><%= @note.kind %></:item>
|
<pre class="p-1 bg-gray-100 text-black rounded select-all">[[<%= @note.slug %>]]</pre>
|
||||||
<:item title="Url"><a href={@note.url} target="_blank"><%= @note.url %></a></:item>
|
</:item>
|
||||||
<:item title="Tags"><%= note_tags(@note.tags) %></:item>
|
</.list>
|
||||||
<:item title="Links outgoing"><%= note_links(@note.links_from) %></:item>
|
|
||||||
<:item title="Links incoming"><%= note_links(@note.links_to) %></:item>
|
|
||||||
</.list>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section class="col-span-1 p-6">
|
|
||||||
<section class="prose">
|
|
||||||
<%= raw(Markdown.render(@note.content)) %>
|
|
||||||
</section>
|
|
||||||
</section>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<.line />
|
<.line />
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ defmodule ChiyaWeb.Router do
|
||||||
live "/", AdminHomeLive, :index
|
live "/", AdminHomeLive, :index
|
||||||
|
|
||||||
resources "/channels", ChannelController
|
resources "/channels", ChannelController
|
||||||
resources "/notes", NoteController, except: [:show, :index, :edit]
|
resources "/notes", NoteController, except: [:show, :index]
|
||||||
resources "/settings", SettingController, singleton: true
|
resources "/settings", SettingController, singleton: true
|
||||||
resources "/identities", IdentityController
|
resources "/identities", IdentityController
|
||||||
resources "/comments", CommentController, only: [:index, :show]
|
resources "/comments", CommentController, only: [:index, :show]
|
||||||
|
@ -85,7 +85,6 @@ defmodule ChiyaWeb.Router do
|
||||||
|
|
||||||
live "/notes", NoteListLive, :index
|
live "/notes", NoteListLive, :index
|
||||||
live "/notes/:id", NoteShowLive, :show
|
live "/notes/:id", NoteShowLive, :show
|
||||||
live "/notes/:id/edit", NoteEditLive, :edit
|
|
||||||
|
|
||||||
get "/notes/:id/raw", NoteController, :raw
|
get "/notes/:id/raw", NoteController, :raw
|
||||||
get "/notes/:id/publish", NoteController, :publish
|
get "/notes/:id/publish", NoteController, :publish
|
||||||
|
|
2
mix.exs
2
mix.exs
|
@ -52,7 +52,7 @@ defmodule Chiya.MixProject do
|
||||||
{:phoenix_html, "~> 3.3"},
|
{:phoenix_html, "~> 3.3"},
|
||||||
{:phoenix_live_dashboard, "~> 0.8.0"},
|
{:phoenix_live_dashboard, "~> 0.8.0"},
|
||||||
{:phoenix_live_reload, "~> 1.2", only: :dev},
|
{:phoenix_live_reload, "~> 1.2", only: :dev},
|
||||||
{:phoenix_live_view, "~> 0.19"},
|
{:phoenix_live_view, "~> 0.20"},
|
||||||
{:plug_cowboy, "~> 2.5"},
|
{:plug_cowboy, "~> 2.5"},
|
||||||
{:postgrex, ">= 0.0.0"},
|
{:postgrex, ">= 0.0.0"},
|
||||||
{:slugger, "~> 0.3"},
|
{:slugger, "~> 0.3"},
|
||||||
|
|
Loading…
Reference in a new issue