Skip to content

Commit

Permalink
FEATURE: replace emoji with unicode in title and description meta tags
Browse files Browse the repository at this point in the history
  • Loading branch information
nlalonde committed Feb 22, 2017
1 parent 0fc2b64 commit 0551b3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/helpers/application_helper.rb
Expand Up @@ -188,8 +188,9 @@ def crawlable_meta_data(opts=nil)
[: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

Expand Down Expand Up @@ -217,6 +218,12 @@ def render_sitelinks_search_tag
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
Expand Down
6 changes: 6 additions & 0 deletions spec/helpers/application_helper_spec.rb
Expand Up @@ -106,4 +106,10 @@
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

1 comment on commit 0551b3f

@coding-horror
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 UNICODE

Please sign in to comment.