mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
automatically categorize certain tags based on their namespaces
This commit is contained in:
parent
57fcb8504c
commit
5fc1768454
1 changed files with 22 additions and 0 deletions
|
@ -29,6 +29,20 @@ defmodule Philomena.Tags.Tag do
|
|||
"video"
|
||||
]
|
||||
|
||||
@namespace_categories %{
|
||||
"artist" => "origin",
|
||||
"art pack" => "content-fanmade",
|
||||
"colorist" => "origin",
|
||||
"comic" => "content-fanmade",
|
||||
"editor" => "origin",
|
||||
"fanfic" => "content-fanmade",
|
||||
"oc" => "oc",
|
||||
"photographer" => "origin",
|
||||
"series" => "content-fanmade",
|
||||
"spoiler" => "spoiler",
|
||||
"video" => "content-fanmade"
|
||||
}
|
||||
|
||||
schema "tags" do
|
||||
belongs_to :aliased_tag, Tag, source: :aliased_tag_id
|
||||
has_many :aliases, Tag, foreign_key: :aliased_tag_id
|
||||
|
@ -65,6 +79,7 @@ defmodule Philomena.Tags.Tag do
|
|||
|> validate_required([:name])
|
||||
|> put_slug()
|
||||
|> put_name_and_namespace()
|
||||
|> put_namespace_category()
|
||||
end
|
||||
|
||||
def parse_tag_list(list) do
|
||||
|
@ -156,4 +171,11 @@ defmodule Philomena.Tags.Tag do
|
|||
{nil, name}
|
||||
end
|
||||
end
|
||||
|
||||
defp put_namespace_category(changeset) do
|
||||
namespace = changeset |> get_field(:namespace)
|
||||
|
||||
changeset
|
||||
|> change(category: @namespace_categories[namespace])
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue