Merge branch 'devel' into renovate/esbuild-0.x-lockfile
This commit is contained in:
commit
de6b62aa35
7 changed files with 60 additions and 45 deletions
|
@ -70,7 +70,10 @@ defmodule Chiya.Tags.TagUpdater do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp add_tags(note, tags) do
|
defp add_tags(note, tags) do
|
||||||
Enum.each(tags, &add_tag(note, &1))
|
tags
|
||||||
|
|> Enum.uniq()
|
||||||
|
|> Enum.each(&add_tag(note, &1))
|
||||||
|
|
||||||
note
|
note
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -102,7 +105,10 @@ defmodule Chiya.Tags.TagUpdater do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp remove_tags(note, tags) do
|
defp remove_tags(note, tags) do
|
||||||
Enum.each(tags, &remove_tag(note, &1))
|
tags
|
||||||
|
|> Enum.uniq()
|
||||||
|
|> Enum.each(&remove_tag(note, &1))
|
||||||
|
|
||||||
note
|
note
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -76,13 +76,13 @@ defmodule ChiyaWeb.PublicComponents do
|
||||||
<span class="inline-flex flex-row gap-1">
|
<span class="inline-flex flex-row gap-1">
|
||||||
<%= for tag <- @note.tags do %>
|
<%= for tag <- @note.tags do %>
|
||||||
<%= if assigns.linked do %>
|
<%= if assigns.linked do %>
|
||||||
<a class={["p-category", @class_tag]} href={~p"/tagged-with/#{tag.slug}"}>
|
<a class={["p-category", @class_tag]} href={~p"/tagged-with/#{tag.slug}"}>
|
||||||
<%= tag.name %>
|
<%= tag.name %>
|
||||||
</a>
|
</a>
|
||||||
<% else %>
|
<% else %>
|
||||||
<span class={["p-category", @class_tag]}>
|
<span class={["p-category", @class_tag]}>
|
||||||
<%= tag.name %>
|
<%= tag.name %>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<.dot class="text-theme-base/50 last:hidden" />
|
<.dot class="text-theme-base/50 last:hidden" />
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -162,9 +162,9 @@ defmodule ChiyaWeb.PublicComponents do
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= if not Enum.empty?(note.tags) do %>
|
<%= if not Enum.empty?(note.tags) do %>
|
||||||
<span class="inline-block">
|
<span class="inline-block">
|
||||||
<.tags note={note} linked={false} />
|
<.tags note={note} linked={false} />
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</a>
|
</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -11,8 +11,8 @@ defmodule ChiyaWeb.NoteController do
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> with_channels()
|
|> with_channels()
|
||||||
|> render(:index,
|
|> render(:index,
|
||||||
notes: notes,
|
notes: notes,
|
||||||
page_title: "Notes"
|
page_title: "Notes"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -22,8 +22,8 @@ defmodule ChiyaWeb.NoteController do
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> with_channels()
|
|> with_channels()
|
||||||
|> render(:index,
|
|> render(:index,
|
||||||
notes: notes,
|
notes: notes,
|
||||||
page_title: "Notes"
|
page_title: "Notes"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,23 +5,29 @@
|
||||||
</.header>
|
</.header>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="mt-6 flex flex-row gap-3 max-w-4xl mx-auto">
|
<section class="mt-6 grid grid-cols-1 md:grid-cols-3 gap-3 max-w-4xl mx-auto">
|
||||||
<section>
|
<section class="col-span-1 md:col-span-2">
|
||||||
<.note_list notes={@notes} layout={@channel.layout} show_content={false} />
|
<.note_list notes={@notes} layout={@channel.layout} show_content={false} />
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<ul>
|
<ul>
|
||||||
<%= for {letter, tag_group} <- @tags do %>
|
<%= for {letter, tag_group} <- @tags do %>
|
||||||
<li class="mb-2">
|
<li class="mb-2">
|
||||||
<span class="capitalize text-theme-primary border border-theme-background1 rounded font-sm px-2 py-1 inline-block mb-2"><%= letter %></span>
|
<span class="capitalize text-theme-primary border border-theme-background1 rounded font-sm px-2 py-1 inline-block mb-2">
|
||||||
|
<%= letter %>
|
||||||
<%= for tag <- tag_group do %>
|
</span>
|
||||||
<a href={~p"/tagged-with/#{tag.slug}"} class="border border-theme-background1 rounded font-sm px-2 py-1 inline-block mb-2 hover:bg-theme-background1 transition"><%= tag.name %></a>
|
|
||||||
<% end %>
|
<%= for tag <- tag_group do %>
|
||||||
|
<a
|
||||||
</li>
|
href={~p"/tagged-with/#{tag.slug}"}
|
||||||
<% end %>
|
class="border border-theme-background1 rounded font-sm px-2 py-1 inline-block mb-2 hover:bg-theme-background1 transition"
|
||||||
|
>
|
||||||
|
<%= tag.name %>
|
||||||
|
</a>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -6,9 +6,8 @@ defmodule ChiyaWeb.Indie.Micropub do
|
||||||
|
|
||||||
def create_note(type, properties) do
|
def create_note(type, properties) do
|
||||||
settings = Chiya.Site.get_settings()
|
settings = Chiya.Site.get_settings()
|
||||||
channel_id = settings.micropub_channel_id
|
|
||||||
|
|
||||||
with {:ok, note_attrs} <- get_create_attrs(type, properties, channel_id),
|
with {:ok, note_attrs} <- get_create_attrs(type, properties, settings),
|
||||||
{:ok, note} <- Chiya.Notes.create_note(note_attrs) do
|
{:ok, note} <- Chiya.Notes.create_note(note_attrs) do
|
||||||
create_photos(note, properties)
|
create_photos(note, properties)
|
||||||
|
|
||||||
|
@ -79,18 +78,13 @@ defmodule ChiyaWeb.Indie.Micropub do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_create_attrs(type, properties, channel_id) do
|
defp get_create_attrs(type, properties, settings) do
|
||||||
{:ok, post_type} = Props.get_post_type(properties)
|
{:ok, post_type} = Props.get_post_type(properties)
|
||||||
Logger.info("Creating a #{type}/#{post_type}..")
|
Logger.info("Creating a #{type}/#{post_type}..")
|
||||||
|
|
||||||
channel =
|
|
||||||
if channel_id,
|
|
||||||
do: Chiya.Channels.get_channel(channel_id),
|
|
||||||
else: nil
|
|
||||||
|
|
||||||
case post_type do
|
case post_type do
|
||||||
:note -> get_note_attrs(properties, channel)
|
:note -> get_note_attrs(properties, settings.micropub_channel_id)
|
||||||
:bookmark -> get_bookmark_attrs(properties, channel)
|
:bookmark -> get_bookmark_attrs(properties, settings.bookmark_channel_id)
|
||||||
_ -> {:error, :insufficient_scope}
|
_ -> {:error, :insufficient_scope}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -163,22 +157,22 @@ defmodule ChiyaWeb.Indie.Micropub do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_note_attrs(properties, channel) do
|
defp get_note_attrs(properties, channel_id) do
|
||||||
attrs =
|
attrs =
|
||||||
properties
|
properties
|
||||||
|> get_base_attrs()
|
|> get_base_attrs()
|
||||||
|> get_channel(channel)
|
|> get_channel(channel_id)
|
||||||
|
|
||||||
{:ok, attrs}
|
{:ok, attrs}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_bookmark_attrs(properties, channel) do
|
defp get_bookmark_attrs(properties, channel_id) do
|
||||||
url = Props.get_bookmarked_url(properties)
|
url = Props.get_bookmarked_url(properties)
|
||||||
|
|
||||||
attrs =
|
attrs =
|
||||||
properties
|
properties
|
||||||
|> get_base_attrs()
|
|> get_base_attrs()
|
||||||
|> get_channel(channel)
|
|> get_channel(channel_id)
|
||||||
|> Map.put_new(:url, url)
|
|> Map.put_new(:url, url)
|
||||||
|> Map.put_new(:kind, :bookmark)
|
|> Map.put_new(:kind, :bookmark)
|
||||||
|
|
||||||
|
@ -205,9 +199,9 @@ defmodule ChiyaWeb.Indie.Micropub do
|
||||||
attrs
|
attrs
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_channel(attrs, channel) do
|
def get_channel(attrs, channel_id) do
|
||||||
if channel,
|
if channel_id,
|
||||||
do: Map.put(attrs, :channels, [channel]),
|
do: Map.put(attrs, :channels, [Chiya.Channels.get_channel(channel_id)]),
|
||||||
else: attrs
|
else: attrs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,4 +6,4 @@ defmodule Chiya.Repo.Migrations.AddBookmarkChannelSetting do
|
||||||
add :bookmark_channel_id, references(:channels, on_delete: :nothing)
|
add :bookmark_channel_id, references(:channels, on_delete: :nothing)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,5 +53,14 @@ defmodule Chiya.TagUpdaterTest do
|
||||||
tag = List.first(note.tags)
|
tag = List.first(note.tags)
|
||||||
assert tag.name == "foo"
|
assert tag.name == "foo"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "with the same tag twice only adds unique tags" do
|
||||||
|
note = note_fixture()
|
||||||
|
assert note.tags == []
|
||||||
|
|
||||||
|
TagUpdater.update_tags(note, "foo,foo")
|
||||||
|
note = Chiya.Notes.get_note_preloaded!(note.id)
|
||||||
|
assert Enum.count(note.tags) == 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue