FEATURE: replace emoji with unicode in title and description meta tags

This commit is contained in:
Neil Lalonde 2017-02-22 16:24:05 -05:00
parent 0fc2b64f65
commit 0551b3f5ee
2 changed files with 15 additions and 2 deletions

View File

@ -188,8 +188,9 @@ module ApplicationHelper
[:url, :title, :description].each do |property|
if opts[property].present?
escape = (property != :image)
result << tag(:meta, { property: "og:#{property}", content: opts[property] }, nil, escape)
result << tag(:meta, { name: "twitter:#{property}", content: opts[property] }, nil, escape)
content = (property == :url ? opts[property] : gsub_emoji_to_unicode(opts[property]))
result << tag(:meta, { property: "og:#{property}", content: content }, nil, escape)
result << tag(:meta, { name: "twitter:#{property}", content: content }, nil, escape)
end
end
@ -217,6 +218,12 @@ module ApplicationHelper
content_tag(:script, MultiJson.dump(json).html_safe, type: 'application/ld+json'.freeze)
end
def gsub_emoji_to_unicode(str)
if str
str.gsub(/:([\w\-+]*):/) { |name| Emoji.lookup_unicode($1) || name }
end
end
def application_logo_url
@application_logo_url ||= (mobile_view? && SiteSetting.mobile_logo_url) || SiteSetting.logo_url
end

View File

@ -106,4 +106,10 @@ describe ApplicationHelper do
end
end
describe 'gsub_emoji_to_unicode' do
it "converts all emoji to unicode" do
expect(helper.gsub_emoji_to_unicode('Boat Talk: my :sailboat: boat: why is it so slow? :snail:')).to eq("Boat Talk: my ⛵ boat: why is it so slow? 🐌")
end
end
end