[Git][noosfero/noosfero][cherry-pick-27b6a398] Merge branch 'metadata-description-too-long' into 'master'

Rodrigo Souto gitlab at mg.gitlab.com
Mon May 23 09:30:45 BRT 2016


Rodrigo Souto pushed to branch cherry-pick-27b6a398 at Noosfero / noosfero


Commits:
fdccae97 by Bráulio Bhavamitra at 2016-05-23T12:30:38+00:00
Merge branch 'metadata-description-too-long' into 'master'

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.

See merge request !873
- - - - -


2 changed files:

- plugins/metadata/lib/ext/article.rb
- plugins/metadata/test/functional/content_viewer_controller_test.rb


Changes:

=====================================
plugins/metadata/lib/ext/article.rb
=====================================
--- a/plugins/metadata/lib/ext/article.rb
+++ b/plugins/metadata/lib/ext/article.rb
@@ -23,14 +23,14 @@ class Article
     'locale:locale' => proc{ |a, c| a.language || a.environment.default_language },
     'locale:alternate' => proc{ |a, c| a.alternate_languages },
 
-    description: proc{ |a, plugin| ActionView::Base.full_sanitizer.sanitize a.body },
+    description: proc{ |a, plugin| ActionView::Base.full_sanitizer.sanitize a.lead },
     rich_attachment: "",
   }
 
   metadata_spec namespace: :twitter, key_attr: :name, tags: {
     card: 'summary',
     description: proc do |a, plugin|
-      description = a.body.to_s || a.environment.name
+      description = a.lead.to_s || a.environment.name
       plugin.helpers.truncate plugin.helpers.strip_tags(description), length: 200
     end,
     title: proc{ |a, plugin| "#{a.title} - #{a.profile.name}" },


=====================================
plugins/metadata/test/functional/content_viewer_controller_test.rb
=====================================
--- a/plugins/metadata/test/functional/content_viewer_controller_test.rb
+++ b/plugins/metadata/test/functional/content_viewer_controller_test.rb
@@ -23,18 +23,18 @@ class ContentViewerControllerTest < ActionController::TestCase
   end
 
   should 'add meta tags with article info' do
-    a = TinyMceArticle.create(name: 'Article to be shared', body: 'This article should be shared with all social networks', profile: profile)
+    a = TinyMceArticle.create(name: 'Article to be shared', body: '<p>This article should be shared with all social networks</p>', profile: profile)
 
     get :view_page, profile: profile.identifier, page: [ a.name.to_slug ]
 
     assert_tag tag: 'meta', attributes: { name: 'twitter:title', content: /#{a.name} - #{a.profile.name}/ }
-    assert_tag tag: 'meta', attributes: { name: 'twitter:description', content: a.body }
+    assert_tag tag: 'meta', attributes: { name: 'twitter:description', content: a.lead.gsub(/<\/?p>/,'') }
     assert_no_tag tag: 'meta', attributes: { name: 'twitter:image' }
     assert_tag tag: 'meta', attributes: { property: 'og:type', content: 'article' }
     assert_tag tag: 'meta', attributes: { property: 'og:url', content: /\/#{profile.identifier}\/#{a.name.to_slug}/ }
     assert_tag tag: 'meta', attributes: { property: 'og:title', content: /#{a.name} - #{a.profile.name}/ }
     assert_tag tag: 'meta', attributes: { property: 'og:site_name', content: a.profile.name }
-    assert_tag tag: 'meta', attributes: { property: 'og:description', content: a.body }
+    assert_tag tag: 'meta', attributes: { property: 'og:description', content: a.lead.gsub(/<\/?p>/,'') }
     assert_no_tag tag: 'meta', attributes: { property: 'og:image' }
   end
 



View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/fdccae978ba2a5ae2bc7792b4abac8af77a96472
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160523/d9e301b1/attachment-0001.html>


More information about the Noosfero-dev mailing list