FIX: Reduce mentions in blurbs to @username or @groupname

The link to the user profile or group is useless and the URL encoded username or group name looks awful for Unicode names
This commit is contained in:
Gerhard Schlager 2019-04-29 17:15:55 +02:00
parent 5d4aa256be
commit 71d19f6e1f
2 changed files with 16 additions and 1 deletions

View File

@ -213,7 +213,9 @@ class SearchIndexer
end
document.css("a[href]").each do |node|
node.remove_attribute("href") if node["href"] == node.text
if node["href"] == node.text || MENTION_CLASSES.include?(node["class"])
node.remove_attribute("href")
end
end
me = new(strip_diacritics: strip_diacritics)
@ -221,6 +223,7 @@ class SearchIndexer
me.scrubbed.squish
end
MENTION_CLASSES ||= %w{mention mention-group}
ATTRIBUTES ||= %w{alt title href data-youtube-title}
def start_element(_name, attributes = [])

View File

@ -38,6 +38,18 @@ describe SearchIndexer do
expect(scrubbed).to eq("http://meta.discourse.org/ link")
end
it 'extracts @username from mentions' do
html = '<p><a class="mention" href="/u/%E7%8B%AE%E5%AD%90">@狮子</a> <a class="mention" href="/u/foo">@foo</a></p>'
scrubbed = scrub(html)
expect(scrubbed).to eq('@狮子 @foo')
end
it 'extracts @groupname from group mentions' do
html = '<p><a class="mention-group" href="/groups/%D0%B0%D0%B2%D1%82%D0%BE%D0%BC%D0%BE%D0%B1%D0%B8%D0%BB%D0%B8%D1%81%D1%82">@автомобилист</a></p>'
scrubbed = scrub(html)
expect(scrubbed).to eq('@автомобилист')
end
it 'uses ignore_accent setting to strip diacritics' do
html = "<p>HELLO Hétérogénéité Здравствуйте هتاف للترحيب 你好</p>"