From 642e121ad993a8fe98de7195f17682861c2694ea Mon Sep 17 00:00:00 2001 From: BrokenEagle Date: Tue, 7 Jan 2020 05:19:26 +0000 Subject: [PATCH] Have artist wiki links go to artist page --- app/javascript/src/styles/common/dtext.scss | 2 +- app/logical/d_text.rb | 43 ++++++++++++++------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/app/javascript/src/styles/common/dtext.scss b/app/javascript/src/styles/common/dtext.scss index 5518c7daf..d7115ded1 100644 --- a/app/javascript/src/styles/common/dtext.scss +++ b/app/javascript/src/styles/common/dtext.scss @@ -109,7 +109,7 @@ div.prose { vertical-align: 1px; } - a.dtext-wiki-does-not-exist, a.dtext-tag-does-not-exist { + a.dtext-wiki-does-not-exist, a.dtext-tag-does-not-exist, a.dtext-artist-does-not-exist { text-decoration: dotted underline; } diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb index f37c858f7..0aed9a0b5 100644 --- a/app/logical/d_text.rb +++ b/app/logical/d_text.rb @@ -20,11 +20,12 @@ class DText names = dtext_messages.map { |message| parse_wiki_titles(message) }.flatten.uniq wiki_pages = WikiPage.where(title: names) tags = Tag.where(name: names) + artists = Artist.where(name: names) - [wiki_pages, tags] + [wiki_pages, tags, artists] end - def self.postprocess(html, wiki_pages, tags) + def self.postprocess(html, wiki_pages, tags, artists) fragment = Nokogiri::HTML.fragment(html) fragment.css("a.dtext-wiki-link").each do |node| @@ -34,22 +35,34 @@ class DText name = WikiPage.normalize_title(name) wiki = wiki_pages.find { |wiki| wiki.title == name } tag = tags.find { |tag| tag.name == name } + artist = artists.find { |artist| artist.name == name } - if wiki.blank? - node["class"] += " dtext-wiki-does-not-exist" - node["title"] = "This wiki page does not exist" - end + if (tag.present? && tag.category == Tag.categories.artist) || artist.present? + node["href"] = "/artists/show_or_new?name=#{name}" - if WikiPage.is_meta_wiki?(name) - # skip (meta wikis aren't expected to have a tag) - elsif tag.blank? - node["class"] += " dtext-tag-does-not-exist" - node["title"] = "This wiki page does not have a tag" - elsif tag.post_count <= 0 - node["class"] += " dtext-tag-empty" - node["title"] = "This wiki page does not have a tag" + if artist.blank? + node["class"] += " dtext-artist-does-not-exist" + node["title"] = "This artist page does not exist" + end + + node["class"] += " tag-type-#{Tag.categories.artist}" else - node["class"] += " tag-type-#{tag.category}" + if wiki.blank? + node["class"] += " dtext-wiki-does-not-exist" + node["title"] = "This wiki page does not exist" + end + + if WikiPage.is_meta_wiki?(name) + # skip (meta wikis aren't expected to have a tag) + elsif tag.blank? + node["class"] += " dtext-tag-does-not-exist" + node["title"] = "This wiki page does not have a tag" + elsif tag.post_count <= 0 + node["class"] += " dtext-tag-empty" + node["title"] = "This wiki page does not have a tag" + else + node["class"] += " tag-type-#{tag.category}" + end end end