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:
@@ -19,6 +19,18 @@ class DText
|
|||||||
names.uniq
|
names.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.parse_wiki_titles(text)
|
||||||
|
html = DTextRagel.parse(text)
|
||||||
|
fragment = Nokogiri::HTML.fragment(html)
|
||||||
|
|
||||||
|
titles = fragment.css("a.dtext-wiki-link").map do |node|
|
||||||
|
title = node["href"][%r!\A/wiki_pages/show_or_new\?title=(.*)\z!i, 1]
|
||||||
|
title = CGI.unescape(title)
|
||||||
|
title = WikiPage.normalize_title(title)
|
||||||
|
title
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.strip_blocks(string, tag)
|
def self.strip_blocks(string, tag)
|
||||||
n = 0
|
n = 0
|
||||||
stripped = ""
|
stripped = ""
|
||||||
|
|||||||
@@ -42,11 +42,7 @@ class RelatedTagQuery
|
|||||||
end
|
end
|
||||||
|
|
||||||
def wiki_page_tags
|
def wiki_page_tags
|
||||||
results = wiki_page.try(:tags) || []
|
wiki_page.try(:tags) || []
|
||||||
results.reject! do |name|
|
|
||||||
name =~ /^(?:list_of_|tag_group|pool_group|howto:|about:|help:|template:)/
|
|
||||||
end
|
|
||||||
results
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def other_wiki_pages
|
def other_wiki_pages
|
||||||
|
|||||||
@@ -200,13 +200,8 @@ class WikiPage < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def tags
|
def tags
|
||||||
body.scan(/\[\[(.+?)\]\]/).flatten.map do |match|
|
titles = DText.parse_wiki_titles(body)
|
||||||
if match =~ /^(.+?)\|(.+)/
|
Tag.nonempty.where(name: titles.uniq).pluck(:name)
|
||||||
$1
|
|
||||||
else
|
|
||||||
match
|
|
||||||
end
|
|
||||||
end.map {|x| x.mb_chars.downcase.tr(" ", "_").to_s}.uniq
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def visible?
|
def visible?
|
||||||
|
|||||||
Reference in New Issue
Block a user