Merge pull request #4297 from BrokenEagle/add-cosplay-related-tags

Add cosplay related tags for other wikis
This commit is contained in:
evazion
2020-02-18 15:58:39 -06:00
committed by GitHub

View File

@@ -46,10 +46,29 @@ class RelatedTagQuery
end
def other_wiki_pages
return [] unless Tag.category_for(query) == Tag.categories.copyright
if Tag.category_for(query) == Tag.categories.copyright
copyright_other_wiki_pages
elsif Tag.category_for(query) == Tag.categories.general
general_other_wiki_pages
else
[]
end
end
other_wikis = DText.parse_wiki_titles(wiki_page&.body&.to_s).grep(/\Alist_of_/i)
other_wikis = other_wikis.map { |name| WikiPage.titled(name).first }
def copyright_other_wiki_pages
list_of_wikis = DText.parse_wiki_titles(wiki_page&.body&.to_s).grep(/\Alist_of_/i)
map_tags_to_wikis(list_of_wikis)
end
def general_other_wiki_pages
match = query.match(/(.+?)_\(cosplay\)/)
return [] unless match
map_tags_to_wikis([match[1]])
end
def map_tags_to_wikis(other_tags)
other_wikis = other_tags.map { |name| WikiPage.titled(name).first }
other_wikis = other_wikis.reject { |wiki| wiki.nil? }
other_wikis = other_wikis.select { |wiki| wiki.tags.present? }
other_wikis
end