Skip to content

Commit

Permalink
Merge pull request #42 from nephila/feature/fix_meta_author_url
Browse files Browse the repository at this point in the history
Fix G+ author url
  • Loading branch information
yakky committed Mar 3, 2016
2 parents bb7e164 + d616fef commit 8bcb0fc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
History
*******

0.5.10 (unreleased)
===================

* Fix handling Google+ author URL

0.5.9 (2016-02-25)
==================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{% endif %}
{% if meta.use_googleplus %}
{% if meta.gplus_author %}
<link rel="author" href="https://plus.google.com/{{ meta.gplus_author }}"/>
<link rel="author" href="{{ meta.gplus_author }}"/>
{% endif %}
{% if meta.title %}{% googleplus_prop 'name' meta.title %}{% endif %}
{% if meta.published_time %}{% googleplus_prop 'datePublished' meta.published_time %}{% endif %}
Expand Down
5 changes: 5 additions & 0 deletions djangocms_page_meta/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def get_page_meta(page, language):
meta.twitter_author = pagemeta.twitter_author
meta.gplus_type = pagemeta.gplus_type
meta.gplus_author = pagemeta.gplus_author
if not meta.gplus_author.startswith('http'):
if not meta.gplus_author.startswith('/'):
meta.gplus_author = 'https://plus.google.com/{0}'.format(meta.gplus_author)
else:
meta.gplus_author = 'https://plus.google.com{0}'.format(meta.gplus_author)
if page.publication_date:
meta.published_time = page.publication_date.isoformat()
if page.changed_date:
Expand Down
22 changes: 21 additions & 1 deletion tests/test_general.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals

from copy import copy

from django.conf import settings
from django.utils.functional import SimpleLazyObject

Expand Down Expand Up @@ -74,9 +76,27 @@ def test_page_meta_gplus(self):
page.reload()

meta = get_page_meta(page, 'en')
self.assertEqual(meta.gplus_author, self.gplus_data['gplus_author'])
self.assertEqual(meta.gplus_author, 'https://plus.google.com/{0}'.format(self.gplus_data['gplus_author']))
self.assertEqual(meta.gplus_type, self.gplus_data['gplus_type'])

new_data = copy(self.gplus_data)
new_data['gplus_author'] = 'https://plus.google.com/+SomeUser'
for key, val in new_data.items():
setattr(page_meta, key, val)
page_meta.save()
page.reload()
meta = get_page_meta(page, 'en')
self.assertEqual(meta.gplus_author, new_data['gplus_author'])

new_data = copy(self.gplus_data)
new_data['gplus_author'] = '/SomePage'
for key, val in new_data.items():
setattr(page_meta, key, val)
page_meta.save()
page.reload()
meta = get_page_meta(page, 'en')
self.assertEqual(meta.gplus_author, 'https://plus.google.com{0}'.format(new_data['gplus_author']))

def test_none_page(self):
meta = get_page_meta(None, 'en')
self.assertIsNone(meta)
Expand Down

0 comments on commit 8bcb0fc

Please sign in to comment.