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 23 'locale:locale' => proc{ |a, c| a.language || a.environment.default_language },
24 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 27 rich_attachment: "",
28 28 }
29 29  
30 30 metadata_spec namespace: :twitter, key_attr: :name, tags: {
31 31 card: 'summary',
32 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 34 plugin.helpers.truncate plugin.helpers.strip_tags(description), length: 200
35 35 end,
36 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 23 end
24 24  
25 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 28 get :view_page, profile: profile.identifier, page: [ a.name.to_slug ]
29 29  
30 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 32 assert_no_tag tag: 'meta', attributes: { name: 'twitter:image' }
33 33 assert_tag tag: 'meta', attributes: { property: 'og:type', content: 'article' }
34 34 assert_tag tag: 'meta', attributes: { property: 'og:url', content: /\/#{profile.identifier}\/#{a.name.to_slug}/ }
35 35 assert_tag tag: 'meta', attributes: { property: 'og:title', content: /#{a.name} - #{a.profile.name}/ }
36 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 38 assert_no_tag tag: 'meta', attributes: { property: 'og:image' }
39 39 end
40 40  
... ...