related tags: fix wiki page tag extraction.

* Parse the wiki page with the actual dtext parser instead of by hand.
  This is so that wiki links inside things like [nodtext] or [code]
  blocks are handled properly.

* Only include tags that exist and are nonempty. Don't include links to
  dead pages or blank tags.
This commit is contained in:
evazion
2019-10-11 16:43:34 -05:00
parent 6b4ac0c042
commit 3d9c6fef1d
3 changed files with 15 additions and 12 deletions

View File

@@ -200,13 +200,8 @@ class WikiPage < ApplicationRecord
end
def tags
body.scan(/\[\[(.+?)\]\]/).flatten.map do |match|
if match =~ /^(.+?)\|(.+)/
$1
else
match
end
end.map {|x| x.mb_chars.downcase.tr(" ", "_").to_s}.uniq
titles = DText.parse_wiki_titles(body)
Tag.nonempty.where(name: titles.uniq).pluck(:name)
end
def visible?