Skip to content

Commit

Permalink
Remove G+ support - Replace with Schema.org
Browse files Browse the repository at this point in the history
  • Loading branch information
yakky committed Jul 6, 2020
1 parent 7eb034d commit ecb9bc2
Show file tree
Hide file tree
Showing 23 changed files with 193 additions and 122 deletions.
4 changes: 2 additions & 2 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
History
*******

Unreleased
2.0.0 (unreleased)
==================

* Nothing yet
* Replace Google+ support with schema.org

1.6.1 (2020-01-16)
==================
Expand Down
13 changes: 3 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@ django-meta
|Gitter| |PyPiVersion| |PyVersion| |Status| |TestCoverage| |CodeClimate| |License|

This pluggable app allows Django developers to quickly add meta tags and
OpenGraph_, Twitter, and Google Plus properties to their HTML responses.
OpenGraph_, Twitter, and Schema.org properties to their HTML responses.


.. note:: django-meta is now maintained by Nephila on `github`_. Old bitbucket
repository won't be updated anymore.

.. warning:: as of version 1.0 django-meta has included django-meta-mixin 0.2.1;
django-meta 1.0 is a drop in replacement for django-meta-mixin:
as a result django-meta-mixin is no longer actively developed

.. warning:: As of version 1.4, the support for Python 2.6 and Django<1.8 has been dropped
.. warning:: **INCOMPATIBLE CHANGE**: as of version 2.0 django-meta has no
longer supports Google+, basic Schema.org support has been introduced.

.. contents::

Expand Down
2 changes: 1 addition & 1 deletion cms_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
META_USE_SITES=True,
META_USE_OG_PROPERTIES=True,
META_USE_TWITTER_PROPERTIES=True,
META_USE_GOOGLEPLUS_PROPERTIES=True,
META_USE_SCHEMAORG_PROPERTIES=True,
FILE_UPLOAD_TEMP_DIR=mkdtemp()
)

Expand Down
6 changes: 5 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ django meta
###########

A pluggable app allows Django developers to quickly add meta tags and
OpenGraph_, Twitter, and Google Plus properties to their HTML responses.
OpenGraph_, Twitter, and Schema.org properties to their HTML responses.

.. warning:: **INCOMPATIBLE CHANGE**: as of version 2.0 django-meta has no
longer supports Google+, basic Schema.org support has been introduced.

Usage
-----
Expand All @@ -19,6 +22,7 @@ django meta has two different operating mode:
:maxdepth: 2

installation
upgrading
models
views
settings
Expand Down
1 change: 0 additions & 1 deletion docs/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ Usage
Note
++++

* For Google+ support you must add ``{% render_block 'html_extra' %}`` in your template to add object type definition. See relevant Google+ snippets documentation (https://developers.google.com/+/web/snippet/)
* For OpenGraph / Facebook support, edit your ``<head>`` tag to use ``meta_namespaces`` templatetags

Reference template
Expand Down
4 changes: 2 additions & 2 deletions docs/rendering.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ them in the <head> tag, as follow::

This will take care of rendering OpenGraph namespaces in the ``<head prefix="...">``.

If you enabled Google+ Support you have to add the following templatetag to the ``<html>`` tag::
If you enabled Schema.org support and you want to mark the whole page as Schema.org object, add the following templatetag to the ``<html>`` tag::

{% load meta %}
...
<html {% meta_namespaces_gplus %}>
<html {% meta_namespaces_schemaorg %}>

For compatibility with 1.0 and previous version you can keep the sekizai version of the above::

Expand Down
11 changes: 6 additions & 5 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ raised when dealing with ``url`` and ``image`` properties.
You can either set them, or overload the ``Meta`` class' ``get_domain`` and
``get_protocol`` methods (see :ref:`Meta object` section).

.. warning:: **INCOMPATIBLE CHANGE**: as of version 2.0 django-meta has no
longer supports Google+, basic Schema.org support has been introduced.

.. _META_SITE_PROTOCOL:

META_SITE_PROTOCOL
Expand Down Expand Up @@ -101,10 +104,10 @@ Default is ``False``.

.. _META_USE_GOOGLEPLUS_PROPERTIES:

META_USE_GOOGLEPLUS_PROPERTIES
META_USE_SCHEMAORG_PROPERTIES
------------------------------

This setting tells django-meta whether to render the Google properties.
This setting tells django-meta whether to render the Schema.org properties.
Default is ``False``.

.. _META_USE_TITLE_TAG:
Expand Down Expand Up @@ -154,6 +157,4 @@ attribute for both :ref:`views` and :ref:`models`
* twitter_type: ``META_TWITTER_TYPE`` (default: first ``META_TWITTER_TYPES``)
* twitter_site: ``META_TWITTER_SITE`` (default: blank)
* twitter_author: ``META_TWITTER_AUTHOR`` (default: blank)
* gplus_type: ``META_GPLUS_TYPE`` (default: first ``META_GPLUS_TYPES``)
* gplus_author: ``META_GPLUS_AUTHOR`` (default: blank)
* gplus_publisher: ``META_GPLUS_PUBLISHER`` (default: blank)
* schemaorg_type: ``META_SCHEMAORG_TYPE`` (default: first ``META_SCHEMAORG_TYPE``)
12 changes: 12 additions & 0 deletions docs/upgrading.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Upgrading
============

When upgrading from version 1.x to 2.0 you must

* Replace ``META_GPLUS_TYPE`` with ``META_SCHEMAORG_TYPE``;
* Replace ``META_USE_GPLUS_PROPERTIES`` with ``META_USE_SCHEMAORG_PROPERTIES``;
* Remove all references to ``gplus_author``, ``gplus_publisher``;
* Replace all ``gplus_title``, ``gplus_description``, ``gplus_type``,
``use_gplus`` with the corresponding ``schemaorg`` attributes`;
* Replace all ``googleplus_prop``, ``googleplus_html_scope``, ``googleplus_scope``
with the corresponding ``schemaorg`` templatetags;
10 changes: 5 additions & 5 deletions docs/views.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ the template context which contains any of the following attributes:
+ use_og
+ use_twitter
+ use_facebook
+ use_googleplus
+ use_schemaorg
+ use_title_tag
+ title
+ og_title
+ twitter_title
+ gplus_title
+ schemaorg_title
+ description
+ keywords
+ url
Expand Down Expand Up @@ -217,7 +217,7 @@ This key contains a boolean value, and instructs the template to render the
Facebook properties. These are usually used by Facebook to get more
information about your site's pages.

use_googleplus
use_schemaorg
~~~~~~~~~~~~~~~~~~~

This key contains a boolean value, and instructs the template to render the
Expand All @@ -237,14 +237,14 @@ title

This key is used in the ``og:title`` OpenGraph property if ``use_og`` is
``True``, ``twitter:title`` if ``use_twitter`` is ``True``,
``itemprop="title"`` if ``use_googleplus`` is ``True`` or ``<title></title>`` tag
``itemprop="title"`` if ``use_schemaorg`` is ``True`` or ``<title></title>`` tag
if ``use_title_tag`` is ``True``.

The service-specific variants are also supported:

* ``og_title``
* ``twitter_title``
* ``gplus_title``
* ``schema_title``

If set on the ``Meta`` object, they will be used insteaf of the generic title
which will be used as a fallback.
Expand Down
20 changes: 9 additions & 11 deletions meta/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class ModelMeta(object):
'title': False,
'og_title': False,
'twitter_title': False,
'gplus_title': False,
'schemaorg_title': False,
'description': False,
'og_description': False,
'twitter_description': False,
'gplus_description': False,
'schemaorg_description': False,
'keywords': False,
'image': settings.DEFAULT_IMAGE,
'image_width': False,
Expand All @@ -41,9 +41,7 @@ class ModelMeta(object):
'twitter_type': settings.TWITTER_TYPE,
'twitter_site': settings.TWITTER_SITE,
'twitter_author': settings.TWITTER_AUTHOR,
'gplus_type': settings.GPLUS_TYPE,
'gplus_author': settings.GPLUS_AUTHOR,
'gplus_publisher': settings.GPLUS_PUBLISHER,
'schemaorg_type': settings.SCHEMAORG_TYPE,
'published_time': False,
'modified_time': False,
'expiration_time': False,
Expand Down Expand Up @@ -101,11 +99,11 @@ def as_meta(self, request=None):
meta = Meta(request=request)
for field, data in self._retrieve_data(request, metadata):
setattr(meta, field, data)
for field in ('og_title', 'twitter_title', 'gplus_title'):
for field in ('og_title', 'twitter_title', 'schemaorg_title'):
generaltitle = getattr(meta, 'title', False)
if not getattr(meta, field, False) and generaltitle:
setattr(meta, field, generaltitle)
for field in ('og_description', 'twitter_description', 'gplus_description'):
for field in ('og_description', 'twitter_description', 'schemaorg_description'):
generaldesc = getattr(meta, 'description', False)
if not getattr(meta, field, False) and generaldesc:
setattr(meta, field, generaldesc)
Expand Down Expand Up @@ -134,7 +132,7 @@ def get_author(self):
class Author(object):
fb_url = None
twitter_profile = None
gplus_profile = None
schemaorg_profile = None

def get_full_name(self): # pragma: no cover
return None
Expand Down Expand Up @@ -167,12 +165,12 @@ def get_author_twitter(self):
except AttributeError: # pragma: no cover
return ''

def get_author_gplus(self):
def get_author_schemaorg(self):
"""
Sample method to return the author google plus URL
Sample method to return the author Schema.org URL
"""
try:
return self.get_author().gplus_profile
return self.get_author().schemaorg_profile
except AttributeError: # pragma: no cover
return ''

Expand Down
10 changes: 4 additions & 6 deletions meta/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
USE_OG_PROPERTIES = getattr(django_settings, 'META_USE_OG_PROPERTIES', False)
USE_TWITTER_PROPERTIES = getattr(django_settings, 'META_USE_TWITTER_PROPERTIES', False)
USE_FACEBOOK_PROPERTIES = getattr(django_settings, 'META_USE_FACEBOOK_PROPERTIES', False)
USE_GOOGLEPLUS_PROPERTIES = getattr(django_settings, 'META_USE_GOOGLEPLUS_PROPERTIES', False)
USE_SCHEMAORG_PROPERTIES = getattr(django_settings, 'META_USE_SCHEMAORG_PROPERTIES', False)
USE_SITES = getattr(django_settings, 'META_USE_SITES', False)
USE_TITLE_TAG = getattr(django_settings, 'META_USE_TITLE_TAG', False)
OG_NAMESPACES = getattr(django_settings, 'META_OG_NAMESPACES', None)
Expand All @@ -32,7 +32,7 @@
('app', _('App')),
)
FB_TYPES = OBJECT_TYPES
GPLUS_TYPES = (
SCHEMAORG_TYPES = (
('Article', _('Article')),
('Blog', _('Blog')),
('WebPage', _('Page')),
Expand Down Expand Up @@ -61,7 +61,5 @@
TWITTER_TYPES = getattr(django_settings, 'META_TWITTER_TYPES', TWITTER_TYPES)
TWITTER_SITE = getattr(django_settings, 'META_TWITTER_SITE', '')
TWITTER_AUTHOR = getattr(django_settings, 'META_TWITTER_AUTHOR', '')
GPLUS_TYPE = getattr(django_settings, 'META_GPLUS_TYPE', GPLUS_TYPES[0][0])
GPLUS_TYPES = getattr(django_settings, 'META_GPLUS_TYPES', GPLUS_TYPES)
GPLUS_AUTHOR = getattr(django_settings, 'META_GPLUS_AUTHOR', '')
GPLUS_PUBLISHER = getattr(django_settings, 'META_GPLUS_PUBLISHER', '')
SCHEMAORG_TYPE = getattr(django_settings, 'META_SCHEMAORG_TYPE', SCHEMAORG_TYPES[0][0])
SCHEMAORG_TYPES = getattr(django_settings, 'META_SCHEMAORG_TYPES', SCHEMAORG_TYPES)
10 changes: 4 additions & 6 deletions meta/templates/meta/meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@
{% if meta.twitter_creator %}{% twitter_prop 'creator' meta.twitter_creator %}{% endif %}
{% if meta.twitter_site %}{% twitter_prop 'site' meta.twitter_site %}{% endif %}
{% endif %}
{% if meta.use_googleplus %}
{% if meta.gplus_author %}<link rel="author" href="https://plus.google.com/{{ meta.gplus_author }}"/>{% endif %}
{% if meta.gplus_publisher %}<link rel="publisher" href="https://plus.google.com/{{ meta.gplus_publisher }}"/>{% endif %}
{% addtoblock 'html_extra' %}{% googleplus_html_scope meta.gplus_type %}{% endaddtoblock %}
{% if meta.gplus_title %}{% googleplus_prop 'name' meta.gplus_title %}
{% if meta.use_schemaorg %}
{% addtoblock 'html_extra' %}{% googleplus_html_scope meta.schemaorg_type %}{% endaddtoblock %}
{% if meta.schemaorg_title %}{% googleplus_prop 'name' meta.schemaorg_title %}
{% elif meta.title %}{% googleplus_prop 'name' meta.title %}{% endif %}
{% if meta.published_time %}{% googleplus_prop 'datePublished' meta.published_time %}{% endif %}
{% if meta.modified_time %}{% googleplus_prop 'dateModified' meta.modified_time %}{% endif %}
{% if meta.url %}{% googleplus_prop 'url' meta.url %}{% endif %}
{% if meta.gplus_description %}{% googleplus_prop 'description' meta.gplus_description %}
{% if meta.schemaorg_description %}{% googleplus_prop 'description' meta.schemaorg_description %}
{% elif meta.description %}{% googleplus_prop 'description' meta.description %}{% endif %}
{% if meta.image %}{% googleplus_prop 'image' meta.image %}{% endif %}
{% endif %}
Expand Down
68 changes: 59 additions & 9 deletions meta/templatetags/meta.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

import warnings

from django import template
from django.apps import apps
from django.utils.html import escape
Expand Down Expand Up @@ -148,9 +150,9 @@ def twitter_prop(name, value):


@register.simple_tag
def googleplus_prop(name, value):
def schemaorg_prop(name, value):
"""
Generic Google+ property
Generic Schema.org property
:param name: property name
:param value: property value
Expand All @@ -159,7 +161,7 @@ def googleplus_prop(name, value):


@register.simple_tag
def googleplus_html_scope(value):
def schemaorg_html_scope(value):
"""
This is meant to be used as attribute to html / body or other tags to
define schema.org type
Expand All @@ -170,13 +172,49 @@ def googleplus_html_scope(value):


@register.simple_tag
def googleplus_scope(value):
def schemaorg_scope(value):
"""
Alias for googleplus_html_scope
:param value: declared scope
"""
return googleplus_html_scope(value)
return schemaorg_html_scope(value)


@register.simple_tag
def googleplus_prop(name, value):
"""
Legacy Google+ property
"""
warnings.warn(
"googleplus_prop will be removed in version 3.0",
PendingDeprecationWarning
)
return schemaorg_prop(name, value)


@register.simple_tag
def googleplus_html_scope(value):
"""
Legacy Google+ scope
"""
warnings.warn(
"googleplus_html_scope will be removed in version 3.0",
PendingDeprecationWarning
)
return schemaorg_html_scope(value)


@register.simple_tag
def googleplus_scope(value):
"""
Legacy Google+ scope
"""
warnings.warn(
"googleplus_scope will be removed in version 3.0",
PendingDeprecationWarning
)
return schemaorg_html_scope(value)


@register.simple_tag(takes_context=True)
Expand Down Expand Up @@ -209,13 +247,25 @@ def meta_namespaces(context):


@register.simple_tag(takes_context=True)
def meta_namespaces_gplus(context):
def meta_namespaces_schemaorg(context):
"""
Include google+ attributes. To be used in the <html> or <body> tag.
Include Schema.org attributes. To be used in the <html> or <body> tag.
"""
# do nothing if meta is not in context or if G+ is not enabled
if not context.get('meta') or not context['meta'].use_googleplus:
if not context.get('meta') or not context['meta'].use_schemaorg:
return ''
return mark_safe(
' itemscope itemtype="http://schema.org/{0}" '.format(context['meta'].gplus_type)
' itemscope itemtype="http://schema.org/{0}" '.format(context['meta'].schemaorg_type)
)


@register.simple_tag(takes_context=True)
def meta_namespaces_gplus(context):
"""
Legacy Google+ attributes.
"""
warnings.warn(
"meta_namespaces_gplus will be removed in version 3.0",
PendingDeprecationWarning
)
return meta_namespaces_schemaorg(context)
Loading

0 comments on commit ecb9bc2

Please sign in to comment.