Mercurial > public > sg101
changeset 485:7c69b1449d7a
For #233, make sure og:url and og:image are fully qualified (http://).
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 18 Oct 2011 00:14:34 +0000 |
parents | bbbc357ac5f3 |
children | 7854d75427af |
files | gpp/core/templatetags/core_tags.py |
diffstat | 1 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/gpp/core/templatetags/core_tags.py Tue Oct 18 00:04:37 2011 +0000 +++ b/gpp/core/templatetags/core_tags.py Tue Oct 18 00:14:34 2011 +0000 @@ -66,6 +66,18 @@ } +def _fully_qualify(url, domain): + """ + Returns a "fully qualified" URL by checking the given url. + If the url starts with '/' then http://domain is pre-pended + onto it. Otherwise the original URL is returned. + + """ + if url.startswith('/'): + url = "http://%s%s" % (domain, url) + return url + + @register.inclusion_tag('core/open_graph_meta_tag.html') def open_graph_meta_tags(item): """ @@ -81,6 +93,12 @@ if 'og:image' not in props: props['og:image'] = settings.OGP_DEFAULT_IMAGE + if 'og:url' in props: + props['og:url'] = _fully_qualify(props['og:url'], site.domain) + + if 'og:image' in props: + props['og:image'] = _fully_qualify(props['og:image'], site.domain) + return {'props': props}