Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Generate mobile bi-directional links
Browse files Browse the repository at this point in the history
We have canonical links that point to the desktop site from mobile, but Google
would really like us to point the other way, too - to mobile from desktop.
They call these "bi-directional annotations".  More on that here:

    https://developers.google.com/webmasters/mobile-sites/mobile-seo/configurations/separate-urls?hl=en
  • Loading branch information
xiongchiamiov authored and JordanMilne committed Mar 19, 2015
1 parent 689a955 commit 920abaf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions r2/r2/lib/pages/pages.py
Expand Up @@ -272,6 +272,10 @@ def __init__(self, space_compress=None, nav_menus=None, loginbox=True,
if g.domain_prefix:
u.hostname = "%s.%s" % (g.domain_prefix, u.hostname)
self.canonical_link = u.unparse()
# Generate a mobile link for Google.
u = UrlParser(request.fullpath)
u.hostname = 'i.%s' % g.domain
self.mobile_link = u.unparse()

if self.show_infobar:
if not infotext:
Expand Down
3 changes: 3 additions & 0 deletions r2/r2/templates/base.html
Expand Up @@ -35,6 +35,9 @@
<meta name="description" content="${getattr(thing, 'short_description', None) or g.short_description}" />
<meta name="referrer" content="${c.referrer_policy}">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
%if hasattr(thing, 'mobile_link'):
<link rel="alternate" media="only screen and (max-width: 640px)" href="${thing.mobile_link}" />
%endif
${self.viewport()}
${self.robots()}
${self.pagemeta()}
Expand Down

0 comments on commit 920abaf

Please sign in to comment.