Generate mobile bi-directional links

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
This commit is contained in:
xiongchiamiov
2015-02-11 11:59:28 -08:00
committed by Jordan Milne
parent 689a9554e6
commit 920abafaa6
2 changed files with 7 additions and 0 deletions

View File

@@ -272,6 +272,10 @@ class Reddit(Templated):
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:

View File

@@ -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()}