Commit f2bfd9e0010c0c891d5554e0f90f9b051fcc3719

Authored by Larissa Reis
1 parent 270578d4

metadata: Use lead instead of body for description

  Most social networks limit the description length so it's not
  necessary to put the whole article body in the description meta tag so
  we use the lead instead.

  Also if the article is reasonably long, the user could be unable to
  share it, getting a "Request-URI Too Large" error.
plugins/metadata/lib/ext/article.rb
@@ -23,14 +23,14 @@ class Article @@ -23,14 +23,14 @@ class Article
23 'locale:locale' => proc{ |a, c| a.language || a.environment.default_language }, 23 'locale:locale' => proc{ |a, c| a.language || a.environment.default_language },
24 'locale:alternate' => proc{ |a, c| a.alternate_languages }, 24 'locale:alternate' => proc{ |a, c| a.alternate_languages },
25 25
26 - description: proc{ |a, plugin| ActionView::Base.full_sanitizer.sanitize a.body }, 26 + description: proc{ |a, plugin| ActionView::Base.full_sanitizer.sanitize a.lead },
27 rich_attachment: "", 27 rich_attachment: "",
28 } 28 }
29 29
30 metadata_spec namespace: :twitter, key_attr: :name, tags: { 30 metadata_spec namespace: :twitter, key_attr: :name, tags: {
31 card: 'summary', 31 card: 'summary',
32 description: proc do |a, plugin| 32 description: proc do |a, plugin|
33 - description = a.body.to_s || a.environment.name 33 + description = a.lead.to_s || a.environment.name
34 plugin.helpers.truncate plugin.helpers.strip_tags(description), length: 200 34 plugin.helpers.truncate plugin.helpers.strip_tags(description), length: 200
35 end, 35 end,
36 title: proc{ |a, plugin| "#{a.title} - #{a.profile.name}" }, 36 title: proc{ |a, plugin| "#{a.title} - #{a.profile.name}" },
plugins/metadata/test/functional/content_viewer_controller_test.rb
@@ -23,18 +23,18 @@ class ContentViewerControllerTest < ActionController::TestCase @@ -23,18 +23,18 @@ class ContentViewerControllerTest < ActionController::TestCase
23 end 23 end
24 24
25 should 'add meta tags with article info' do 25 should 'add meta tags with article info' do
26 - a = TinyMceArticle.create(name: 'Article to be shared', body: 'This article should be shared with all social networks', profile: profile) 26 + a = TinyMceArticle.create(name: 'Article to be shared', body: '<p>This article should be shared with all social networks</p>', profile: profile)
27 27
28 get :view_page, profile: profile.identifier, page: [ a.name.to_slug ] 28 get :view_page, profile: profile.identifier, page: [ a.name.to_slug ]
29 29
30 assert_tag tag: 'meta', attributes: { name: 'twitter:title', content: /#{a.name} - #{a.profile.name}/ } 30 assert_tag tag: 'meta', attributes: { name: 'twitter:title', content: /#{a.name} - #{a.profile.name}/ }
31 - assert_tag tag: 'meta', attributes: { name: 'twitter:description', content: a.body } 31 + assert_tag tag: 'meta', attributes: { name: 'twitter:description', content: a.lead.gsub(/<\/?p>/,'') }
32 assert_no_tag tag: 'meta', attributes: { name: 'twitter:image' } 32 assert_no_tag tag: 'meta', attributes: { name: 'twitter:image' }
33 assert_tag tag: 'meta', attributes: { property: 'og:type', content: 'article' } 33 assert_tag tag: 'meta', attributes: { property: 'og:type', content: 'article' }
34 assert_tag tag: 'meta', attributes: { property: 'og:url', content: /\/#{profile.identifier}\/#{a.name.to_slug}/ } 34 assert_tag tag: 'meta', attributes: { property: 'og:url', content: /\/#{profile.identifier}\/#{a.name.to_slug}/ }
35 assert_tag tag: 'meta', attributes: { property: 'og:title', content: /#{a.name} - #{a.profile.name}/ } 35 assert_tag tag: 'meta', attributes: { property: 'og:title', content: /#{a.name} - #{a.profile.name}/ }
36 assert_tag tag: 'meta', attributes: { property: 'og:site_name', content: a.profile.name } 36 assert_tag tag: 'meta', attributes: { property: 'og:site_name', content: a.profile.name }
37 - assert_tag tag: 'meta', attributes: { property: 'og:description', content: a.body } 37 + assert_tag tag: 'meta', attributes: { property: 'og:description', content: a.lead.gsub(/<\/?p>/,'') }
38 assert_no_tag tag: 'meta', attributes: { property: 'og:image' } 38 assert_no_tag tag: 'meta', attributes: { property: 'og:image' }
39 end 39 end
40 40