This commit is contained in:
r888888888
2017-10-09 13:34:58 -07:00
parent 28c3f8321a
commit da170aa413
3 changed files with 8 additions and 5 deletions

View File

@@ -684,13 +684,12 @@ class Post < ApplicationRecord
def normalize_tags
normalized_tags = Tag.scan_tags(tag_string)
normalized_tags = filter_metatags(normalized_tags)
normalized_tags = normalized_tags.map{|tag| tag.downcase}
normalized_tags = normalized_tags.map {|tag| tag.downcase}
normalized_tags = remove_negated_tags(normalized_tags)
normalized_tags = normalized_tags.map {|x| Tag.find_or_create_by_name(x).name}
normalized_tags = %w(tagme) if normalized_tags.empty?
normalized_tags = TagAlias.to_aliased(normalized_tags)
normalized_tags = add_automatic_tags(normalized_tags)
normalized_tags = normalized_tags + TagImplication.automatic_tags_for(normalized_tags)
normalized_tags = Tag.create_for_list(add_automatic_tags(normalized_tags))
normalized_tags = normalized_tags + Tag.create_for_list(TagImplication.automatic_tags_for(normalized_tags))
normalized_tags = TagImplication.with_descendants(normalized_tags)
normalized_tags = normalized_tags.compact
normalized_tags.sort!

View File

@@ -194,6 +194,10 @@ class Tag < ApplicationRecord
name.to_s.mb_chars.downcase.strip.tr(" ", "_").to_s
end
def create_for_list(names)
names.map {|x| find_or_create_by_name(x).name}
end
def find_or_create_by_name(name, options = {})
name = normalize_name(name)
category = nil

View File

@@ -21,7 +21,7 @@ class TagImplication < TagRelationship
end
def automatic_tags_for(names)
tags = names.grep(/\A(.+)_\(cosplay\)\Z/) { $1 }
tags = names.grep(/\A(.+)_\(cosplay\)\Z/) { "char:#{$1}" }
tags << "cosplay" if tags.present?
tags.uniq
end