From 5fc1768454b7d6767898e2f7e6b6dd6a2cfdf859 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Fri, 29 Nov 2019 00:45:41 -0500 Subject: [PATCH] automatically categorize certain tags based on their namespaces --- lib/philomena/tags/tag.ex | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/philomena/tags/tag.ex b/lib/philomena/tags/tag.ex index 17d99032..0522792a 100644 --- a/lib/philomena/tags/tag.ex +++ b/lib/philomena/tags/tag.ex @@ -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