forked from e621ng/e621ng
[UploadPresenter] Normalize tags & strip metatags
This commit is contained in:
parent
f5fcd8a53b
commit
5edbb507b6
@ -105,4 +105,5 @@ class TagCategory
|
||||
CATEGORIZED_LIST = %w[invalid artist copyright character species meta general lore].freeze
|
||||
|
||||
SHORT_NAME_REGEX = SHORT_NAME_LIST.join("|").freeze
|
||||
ALL_NAMES_REGEX = MAPPING.keys.join("|").freeze
|
||||
end
|
||||
|
@ -7,6 +7,16 @@ class UploadPresenter < Presenter
|
||||
end
|
||||
|
||||
def tag_set_presenter
|
||||
@tag_set_presenter ||= TagSetPresenter.new(upload.tag_string.split)
|
||||
@tag_set_presenter ||= TagSetPresenter.new(normalize_tags(upload.tag_string.split))
|
||||
end
|
||||
|
||||
def strip_metatags(tags)
|
||||
tags.grep_v(/\A(?:rating|-?parent|-?locked|-?pool|newpool|-?set|-?fav|-?child|upvote|downvote):/i)
|
||||
end
|
||||
|
||||
def normalize_tags(tags)
|
||||
tags = tags.map(&:downcase)
|
||||
tags = strip_metatags(tags)
|
||||
tags.map { |tag| tag.gsub(/(?:#{TagCategory::ALL_NAMES_REGEX}):/, "") }
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user