-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from functools import wraps | ||
|
||
from django.core.exceptions import ImproperlyConfigured | ||
try: | ||
from jinja2 import Markup | ||
except ImportError: | ||
Markup = None | ||
|
||
from .templatetags import meta | ||
|
||
|
||
class MetaProxy(object): | ||
|
||
def __init__(self, *args, **kwargs): | ||
if Markup is None: | ||
raise ImproperlyConfigured('Jinja2 package is not installed') | ||
|
||
def __getattr__(self, item): | ||
f = getattr(meta, item) | ||
|
||
@wraps(f) | ||
def wrapped(*args, **kwargs): | ||
tag = f(*args, **kwargs) | ||
return Markup(tag) | ||
|
||
return wrapped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{% macro meta_macro() -%} | ||
{% if meta is defined %} | ||
{% if meta.description %}{{ meta_global.meta('description', meta.description) }}{% endif %} | ||
{% if meta.keywords %}{{ meta_global.meta_list('keywords', meta.keywords) }}{% endif %} | ||
{% if meta.extra_props %}{{ meta_global.meta_extras(meta.extra_props) }}{% endif %} | ||
{% if meta.extra_custom_props %}{{ meta_global.custom_meta_extras(meta.extra_custom_props) }}{% endif %} | ||
{% if meta.use_title_tag %} | ||
{% if meta.title %}{{ meta_global.title_prop(meta.title) }}{% endif %} | ||
{% endif %} | ||
{% if meta.use_og %} | ||
{% if meta.title %}{{ meta_global.og_prop('title', meta.title) }}{% endif %} | ||
{% if meta.url %}{{ meta_global.og_prop('url', meta.url) }}{% endif %} | ||
{% if meta.og_description %}{{ meta_global.og_prop('description', meta.og_description) }} | ||
{% elif meta.description %}{{ meta_global.og_prop('description', meta.description) }}{% endif %} | ||
{% if meta.image %}{{ meta_global.og_prop('image', meta.image) }}{% endif %} | ||
{% if meta.og_type %}{{ meta_global.og_prop('type', meta.og_type) }} | ||
{% elif meta.object_type %}{{ meta_global.og_prop('type', meta.object_type) }}{% endif %} | ||
{% if meta.site_name %}{{ meta_global.og_prop('site_name', meta.site_name) }}{% endif %} | ||
{% if meta.og_author_url %}{{ meta_global.generic_prop('article', 'author', meta.og_author_url) }} | ||
{% elif meta.og_author %}{{ meta_global.generic_prop('article', 'author', meta.og_author) }}{% endif %} | ||
{% if meta.published_time %}{{ meta_global.generic_prop('article', 'published_time', meta.published_time) }}{% endif %} | ||
{% if meta.modified_time %}{{ meta_global.generic_prop('article', 'modified_time', meta.modified_time) }}{% endif %} | ||
{% if meta.expiration_time %}{{ meta_global.generic_prop('article', 'expiration_time', meta.expiration_time) }}{% endif %} | ||
{% if meta.og_publisher %}{{ meta_global.generic_prop('article', 'publisher', meta.og_publisher) }}{% endif %} | ||
{% if meta.og_app_id %}{{ meta_global.facebook_prop('app_id', meta.og_app_id) }} | ||
{% elif meta.facebook_app_id %}{{ meta_global.facebook_prop('app_id', meta.facebook_app_id) }}{% endif %} | ||
{% if meta.fb_pages %}{{ meta_global.facebook_prop('pages', meta.fb_pages) }}{% endif %} | ||
{% if meta.og_profile_id %}{{ meta_global.facebook_prop('profile_id', meta.og_profile_id) }}{% endif %} | ||
{% if meta.tag %}{{ meta_global.generic_prop('article', 'tag', meta.tag) }}{% endif %} | ||
{% if meta.locale %}{{ meta_global.og_prop('locale', meta.locale) }}{% endif %} | ||
{% endif %} | ||
{% if meta.use_twitter %} | ||
{{ meta_global.twitter_prop('domain', meta.get_domain) }} | ||
{% if meta.twitter_type %}{{ meta_global.twitter_prop('card', meta.twitter_type) }} | ||
{% elif meta.twitter_card %}{{ meta_global.twitter_prop('card', meta.twitter_card) }}{% endif %} | ||
{% if meta.title %}{{ meta_global.twitter_prop('title', meta.title) }}{% endif %} | ||
{% if meta.url %}{{ meta_global.twitter_prop('url', meta.url) }}{% endif %} | ||
{% if meta.twitter_description %}{{ meta_global.twitter_prop('description', meta.twitter_description) }} | ||
{% elif meta.description %}{{ meta_global.twitter_prop('description', meta.description) }}{% endif %} | ||
{% if meta.image %}{{ meta_global.twitter_prop('image', meta.image) }}{% endif %} | ||
{% if meta.twitter_creator %}{{ meta_global.twitter_prop('creator', meta.twitter_creator) }}{% endif %} | ||
{% if meta.twitter_site %}{{ meta_global.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 %} | ||
{% if meta.title %}{{ meta_global.googleplus_prop('name', meta.title) }}{% endif %} | ||
{% if meta.published_time %}{{ meta_global.googleplus_prop('datePublished', meta.published_time) }}{% endif %} | ||
{% if meta.modified_time %}{{ meta_global.googleplus_prop('dateModified', meta.modified_time) }}{% endif %} | ||
{% if meta.url %}{{ meta_global.googleplus_prop('url', meta.url) }}{% endif %} | ||
{% if meta.gplus_description %}{{ meta_global.googleplus_prop('description', meta.gplus_description) }} | ||
{% elif meta.description %}{{ meta_global.googleplus_prop('description', meta.description) }}{% endif %} | ||
{% if meta.image %}{{ meta_global.googleplus_prop('image', meta.image) }}{% endif %} | ||
{% endif %} | ||
{% endif %} | ||
{%- endmacro %} |