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
|
||||
|
||||
defp add_tags(note, tags) do
|
||||
Enum.each(tags, &add_tag(note, &1))
|
||||
tags
|
||||
|> Enum.uniq()
|
||||
|> Enum.each(&add_tag(note, &1))
|
||||
|
||||
note
|
||||
end
|
||||
|
||||
|
@ -102,7 +105,10 @@ defmodule Chiya.Tags.TagUpdater do
|
|||
end
|
||||
|
||||
defp remove_tags(note, tags) do
|
||||
Enum.each(tags, &remove_tag(note, &1))
|
||||
tags
|
||||
|> Enum.uniq()
|
||||
|> Enum.each(&remove_tag(note, &1))
|
||||
|
||||
note
|
||||
end
|
||||
|
||||
|
|
|
@ -76,13 +76,13 @@ defmodule ChiyaWeb.PublicComponents do
|
|||
<span class="inline-flex flex-row gap-1">
|
||||
<%= for tag <- @note.tags do %>
|
||||
<%= if assigns.linked do %>
|
||||
<a class={["p-category", @class_tag]} href={~p"/tagged-with/#{tag.slug}"}>
|
||||
<%= tag.name %>
|
||||
</a>
|
||||
<a class={["p-category", @class_tag]} href={~p"/tagged-with/#{tag.slug}"}>
|
||||
<%= tag.name %>
|
||||
</a>
|
||||
<% else %>
|
||||
<span class={["p-category", @class_tag]}>
|
||||
<%= tag.name %>
|
||||
</span>
|
||||
<span class={["p-category", @class_tag]}>
|
||||
<%= tag.name %>
|
||||
</span>
|
||||
<% end %>
|
||||
<.dot class="text-theme-base/50 last:hidden" />
|
||||
<% end %>
|
||||
|
@ -162,9 +162,9 @@ defmodule ChiyaWeb.PublicComponents do
|
|||
<% end %>
|
||||
|
||||
<%= if not Enum.empty?(note.tags) do %>
|
||||
<span class="inline-block">
|
||||
<.tags note={note} linked={false} />
|
||||
</span>
|
||||
<span class="inline-block">
|
||||
<.tags note={note} linked={false} />
|
||||
</span>
|
||||
<% end %>
|
||||
</a>
|
||||
<% end %>
|
||||
|
|
|
@ -5,23 +5,29 @@
|
|||
</.header>
|
||||
</section>
|
||||
|
||||
<section class="mt-6 flex flex-row gap-3 max-w-4xl mx-auto">
|
||||
<section>
|
||||
<section class="mt-6 grid grid-cols-1 md:grid-cols-3 gap-3 max-w-4xl mx-auto">
|
||||
<section class="col-span-1 md:col-span-2">
|
||||
<.note_list notes={@notes} layout={@channel.layout} show_content={false} />
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<ul>
|
||||
<%= for {letter, tag_group} <- @tags do %>
|
||||
<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>
|
||||
<%= for {letter, tag_group} <- @tags do %>
|
||||
<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>
|
||||
|
||||
<%= for tag <- tag_group do %>
|
||||
<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 %>
|
||||
|
||||
</li>
|
||||
<% end %>
|
||||
<%= for tag <- tag_group do %>
|
||||
<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 %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</section>
|
||||
</section>
|
||||
|
|
|
@ -6,9 +6,8 @@ defmodule ChiyaWeb.Indie.Micropub do
|
|||
|
||||
def create_note(type, properties) do
|
||||
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
|
||||
create_photos(note, properties)
|
||||
|
||||
|
@ -79,18 +78,13 @@ defmodule ChiyaWeb.Indie.Micropub do
|
|||
)
|
||||
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)
|
||||
Logger.info("Creating a #{type}/#{post_type}..")
|
||||
|
||||
channel =
|
||||
if channel_id,
|
||||
do: Chiya.Channels.get_channel(channel_id),
|
||||
else: nil
|
||||
|
||||
case post_type do
|
||||
:note -> get_note_attrs(properties, channel)
|
||||
:bookmark -> get_bookmark_attrs(properties, channel)
|
||||
:note -> get_note_attrs(properties, settings.micropub_channel_id)
|
||||
:bookmark -> get_bookmark_attrs(properties, settings.bookmark_channel_id)
|
||||
_ -> {:error, :insufficient_scope}
|
||||
end
|
||||
end
|
||||
|
@ -163,22 +157,22 @@ defmodule ChiyaWeb.Indie.Micropub do
|
|||
end
|
||||
end
|
||||
|
||||
defp get_note_attrs(properties, channel) do
|
||||
defp get_note_attrs(properties, channel_id) do
|
||||
attrs =
|
||||
properties
|
||||
|> get_base_attrs()
|
||||
|> get_channel(channel)
|
||||
|> get_channel(channel_id)
|
||||
|
||||
{:ok, attrs}
|
||||
end
|
||||
|
||||
defp get_bookmark_attrs(properties, channel) do
|
||||
defp get_bookmark_attrs(properties, channel_id) do
|
||||
url = Props.get_bookmarked_url(properties)
|
||||
|
||||
attrs =
|
||||
properties
|
||||
|> get_base_attrs()
|
||||
|> get_channel(channel)
|
||||
|> get_channel(channel_id)
|
||||
|> Map.put_new(:url, url)
|
||||
|> Map.put_new(:kind, :bookmark)
|
||||
|
||||
|
@ -205,9 +199,9 @@ defmodule ChiyaWeb.Indie.Micropub do
|
|||
attrs
|
||||
end
|
||||
|
||||
def get_channel(attrs, channel) do
|
||||
if channel,
|
||||
do: Map.put(attrs, :channels, [channel]),
|
||||
def get_channel(attrs, channel_id) do
|
||||
if channel_id,
|
||||
do: Map.put(attrs, :channels, [Chiya.Channels.get_channel(channel_id)]),
|
||||
else: attrs
|
||||
end
|
||||
|
||||
|
|
|
@ -53,5 +53,14 @@ defmodule Chiya.TagUpdaterTest do
|
|||
tag = List.first(note.tags)
|
||||
assert tag.name == "foo"
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue