Skip to content

Commit

Permalink
Merge pull request #32 from collective/pinterest_metadata_support
Browse files Browse the repository at this point in the history
Fixed metadata og:type, used value 'article' for internal page
  • Loading branch information
hvelarde committed Nov 4, 2014
2 parents fbed1dc + 17b6e94 commit 3fcc64d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog
2.0rc2 (unreleased)
^^^^^^^^^^^^^^^^^^^

- Nothing changed yet.
- Fixed metadata og:type, used value 'article' for internal page [fdelia]


2.0rc1 (2014-10-14)
Expand Down
20 changes: 20 additions & 0 deletions sc/social/like/plugins/facebook/browser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding:utf-8 -*-
from Acquisition import aq_parent, aq_inner
from Products.CMFCore.interfaces import ISiteRoot
from Products.CMFCore.utils import getToolByName
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
Expand Down Expand Up @@ -87,3 +89,21 @@ def typebutton(self):
typebutton = 'box_count'
self.width = '55px'
return typebutton

def _isPortalDefaultView(self):
context = self.context
if ISiteRoot.providedBy(aq_parent(aq_inner(context))):
putils = getToolByName(context, 'plone_utils')
return putils.isDefaultPage(context)
return False

def _isPortal(self):
context = self.context
if ISiteRoot.providedBy(aq_inner(context)):
return True
return self._isPortalDefaultView()

def type(self):
if self._isPortal():
return "website"
return "article"
4 changes: 2 additions & 2 deletions sc/social/like/plugins/facebook/templates/metadata.pt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<tal:fb>
<meta property="og:site_name" tal:attributes="content view/portal_title" />
<meta property="og:url" tal:attributes="content view/url" />
<meta property="og:type" content="website" />
<meta property="og:type" tal:attributes="content view/type" />
<meta property="og:locale" tal:attributes="content view/language" />
<meta property="og:title" tal:attributes="content view/title" />
<meta property="og:description" tal:attributes="content view/description" />
Expand All @@ -10,7 +10,7 @@
<meta property="og:image:height" tal:attributes="content view/image_height" />
<meta property="og:image:width" tal:attributes="content view/image_width" />
<meta property="og:image:type" tal:attributes="content view/image_type" />
</tal:image>
</tal:image>
<meta tal:condition="view/fbadmins" property="fb:admins" tal:attributes="content view/fbadmins" />
<meta tal:condition="view/fbapp_id" property="fb:app_id" tal:attributes="content view/fbapp_id" />
<script
Expand Down
14 changes: 14 additions & 0 deletions sc/social/like/tests/test_plugin_facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,14 @@ def test_plugin_view_metadata(self):
image_url = view.image_url()
self.assertTrue('logo.png' in image_url)

# At root, use website type
og_type = view.type()
self.assertTrue('website' in og_type)

def test_plugin_view_document(self):
plugin = self.plugin
document = self.document
portal = self.portal

plugin_view = plugin.view()
view = document.restrictedTraverse(plugin_view)
Expand All @@ -126,6 +131,15 @@ def test_plugin_view_document(self):
image_url = view.image_url()
self.assertTrue('logo.png' in image_url)

# At document, use article type
og_type = view.type()
self.assertTrue('article' in og_type)

# At document, default page of portal, use website type
portal.setDefaultPage(document.id)
og_type = view.type()
self.assertTrue('website' in og_type)

def test_plugin_view_image(self):
plugin = self.plugin
image = self.image
Expand Down

0 comments on commit 3fcc64d

Please sign in to comment.