Have artist wiki links go to artist page

This commit is contained in:
BrokenEagle
2020-01-07 05:19:26 +00:00
parent f1528e0fae
commit 642e121ad9
2 changed files with 29 additions and 16 deletions

View File

@@ -109,7 +109,7 @@ div.prose {
vertical-align: 1px; 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; text-decoration: dotted underline;
} }

View File

@@ -20,11 +20,12 @@ class DText
names = dtext_messages.map { |message| parse_wiki_titles(message) }.flatten.uniq names = dtext_messages.map { |message| parse_wiki_titles(message) }.flatten.uniq
wiki_pages = WikiPage.where(title: names) wiki_pages = WikiPage.where(title: names)
tags = Tag.where(name: names) tags = Tag.where(name: names)
artists = Artist.where(name: names)
[wiki_pages, tags] [wiki_pages, tags, artists]
end end
def self.postprocess(html, wiki_pages, tags) def self.postprocess(html, wiki_pages, tags, artists)
fragment = Nokogiri::HTML.fragment(html) fragment = Nokogiri::HTML.fragment(html)
fragment.css("a.dtext-wiki-link").each do |node| fragment.css("a.dtext-wiki-link").each do |node|
@@ -34,7 +35,18 @@ class DText
name = WikiPage.normalize_title(name) name = WikiPage.normalize_title(name)
wiki = wiki_pages.find { |wiki| wiki.title == name } wiki = wiki_pages.find { |wiki| wiki.title == name }
tag = tags.find { |tag| tag.name == name } tag = tags.find { |tag| tag.name == name }
artist = artists.find { |artist| artist.name == name }
if (tag.present? && tag.category == Tag.categories.artist) || artist.present?
node["href"] = "/artists/show_or_new?name=#{name}"
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
if wiki.blank? if wiki.blank?
node["class"] += " dtext-wiki-does-not-exist" node["class"] += " dtext-wiki-does-not-exist"
node["title"] = "This wiki page does not exist" node["title"] = "This wiki page does not exist"
@@ -52,6 +64,7 @@ class DText
node["class"] += " tag-type-#{tag.category}" node["class"] += " tag-type-#{tag.category}"
end end
end end
end
fragment.to_s fragment.to_s
end end