forked from e621ng/e621ng
[Tags] Make tag preview case insensitive
This commit is contained in:
parent
f7e47b6141
commit
d235ce223f
@ -344,7 +344,6 @@ Layout/SpaceAfterComma:
|
||||
- 'app/indexes/post_index.rb'
|
||||
- 'app/logical/storage_manager.rb'
|
||||
- 'app/logical/storage_manager/local.rb'
|
||||
- 'app/logical/tags_preview.rb'
|
||||
- 'app/presenters/post_presenter.rb'
|
||||
- 'app/serializers/post_serializer.rb'
|
||||
- 'app/views/admin/danger_zone/index.html.erb'
|
||||
@ -403,7 +402,6 @@ Layout/SpaceAroundOperators:
|
||||
Layout/SpaceBeforeBlockBraces:
|
||||
Exclude:
|
||||
- 'app/controllers/posts_controller.rb'
|
||||
- 'app/logical/tags_preview.rb'
|
||||
- 'app/models/post.rb'
|
||||
- 'app/models/tag_relationship.rb'
|
||||
- 'app/models/user.rb'
|
||||
@ -459,7 +457,6 @@ Layout/SpaceInsideBlockBraces:
|
||||
- 'app/logical/post_sets/base.rb'
|
||||
- 'app/logical/related_tag_calculator.rb'
|
||||
- 'app/logical/sources/alternates.rb'
|
||||
- 'app/logical/tags_preview.rb'
|
||||
- 'app/models/artist.rb'
|
||||
- 'app/models/bulk_update_request.rb'
|
||||
- 'app/models/favorite.rb'
|
||||
@ -531,7 +528,6 @@ Layout/SpaceInsideHashLiteralBraces:
|
||||
- 'app/logical/session_creator.rb'
|
||||
- 'app/logical/session_loader.rb'
|
||||
- 'app/logical/sources/strategies/pixiv_slim.rb'
|
||||
- 'app/logical/tags_preview.rb'
|
||||
- 'app/logical/user_deletion.rb'
|
||||
- 'app/models/ban.rb'
|
||||
- 'app/models/bulk_update_request.rb'
|
||||
@ -1166,7 +1162,6 @@ Rails/CompactBlank:
|
||||
Exclude:
|
||||
- 'app/controllers/posts_controller.rb'
|
||||
- 'app/logical/bulk_update_request_importer.rb'
|
||||
- 'app/logical/tags_preview.rb'
|
||||
- 'app/models/post_replacement.rb'
|
||||
- 'app/models/tag_alias.rb'
|
||||
|
||||
@ -1311,7 +1306,6 @@ Rails/OutputSafety:
|
||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||
Rails/Pluck:
|
||||
Exclude:
|
||||
- 'app/logical/tags_preview.rb'
|
||||
- 'app/models/post.rb'
|
||||
- 'test/functional/forum_topics_controller_test.rb'
|
||||
- 'test/functional/post_events_controller_test.rb'
|
||||
@ -2462,7 +2456,6 @@ Style/StringLiterals:
|
||||
- 'app/logical/session_loader.rb'
|
||||
- 'app/logical/storage_manager.rb'
|
||||
- 'app/logical/storage_manager/local.rb'
|
||||
- 'app/logical/tags_preview.rb'
|
||||
- 'app/logical/upload_service/replacer.rb'
|
||||
- 'app/logical/user_deletion.rb'
|
||||
- 'app/logical/user_email_change.rb'
|
||||
@ -2653,7 +2646,6 @@ Style/SymbolProc:
|
||||
- 'app/controllers/posts_controller.rb'
|
||||
- 'app/logical/post_sets/base.rb'
|
||||
- 'app/logical/post_sets/post.rb'
|
||||
- 'app/logical/tags_preview.rb'
|
||||
- 'app/models/artist_url.rb'
|
||||
- 'app/models/post.rb'
|
||||
- 'app/models/user.rb'
|
||||
|
@ -69,7 +69,7 @@ class TagQuery
|
||||
end
|
||||
|
||||
def self.scan(query)
|
||||
tagstr = query.to_s.downcase.unicode_normalize(:nfc).strip
|
||||
tagstr = query.to_s.unicode_normalize(:nfc).strip
|
||||
quote_delimited = []
|
||||
tagstr = tagstr.gsub(/[-~]?\w*?:".*?"/) do |match|
|
||||
quote_delimited << match
|
||||
|
@ -2,18 +2,18 @@
|
||||
|
||||
class TagsPreview
|
||||
def initialize(tags: nil)
|
||||
@tags = TagQuery.scan(tags).map {|x| {a: x, type: 'tag'}}
|
||||
@tags = TagQuery.scan(tags).map { |x| { a: x.downcase, type: "tag" } }
|
||||
aliases
|
||||
implications
|
||||
tag_types
|
||||
end
|
||||
|
||||
def aliases
|
||||
names = @tags.map{ |tag| tag[:a] }.reject {|y| y.blank?}
|
||||
aliased = TagAlias.to_aliased_with_originals(names).reject {|k,v| k == v }
|
||||
names = @tags.pluck(:a).compact_blank
|
||||
aliased = TagAlias.to_aliased_with_originals(names).reject { |k, v| k == v }
|
||||
@tags.map! do |tag|
|
||||
if aliased[tag[:a]]
|
||||
{a: tag[:a], b: aliased[tag[:a]], type: 'alias'}
|
||||
{ a: tag[:a], b: aliased[tag[:a]], type: "alias" }
|
||||
else
|
||||
tag
|
||||
end
|
||||
@ -21,10 +21,10 @@ class TagsPreview
|
||||
end
|
||||
|
||||
def implications
|
||||
names = @tags.map {|tag| tag[:b] || tag[:a] }
|
||||
names = @tags.map { |tag| tag[:b] || tag[:a] }
|
||||
implications = TagImplication.descendants_with_originals(names)
|
||||
implications.each do |implication, descendants|
|
||||
@tags += descendants.map { |descendant| {a: implication, b: descendant, type: 'implication'} }
|
||||
@tags += descendants.map { |descendant| { a: implication, b: descendant, type: "implication" } }
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user