Force default og:image to https

If we can't figure out a good image to hint as a thumbnail for a page via
`og:image`, we set it to the reddit snoo icon.  However, we have been making
this a protocol-relative url.  This doesn't appear to be against [the spec][0],
but it does create problems for some scrapers.

Now we force it to be an https url, which should resolve some of those issues.

[0]: http://opengraphprotocol.org/#url
This commit is contained in:
xiongchiamiov
2015-03-25 16:08:50 -07:00
parent 0fbea80d45
commit c1e2796da7
2 changed files with 9 additions and 2 deletions

View File

@@ -1511,7 +1511,10 @@ class LinkInfoPage(Reddit):
# thumbnails.
return self.link.thumbnail
return static('icon.png')
# Default to the reddit icon if we've got nothing else. Force it to be
# absolute because not all scrapers handle relative protocols or paths
# well.
return static('icon.png', absolute=True)
def _build_og_description(self, meta_description):
if self.link.selftext:

View File

@@ -65,6 +65,10 @@ def static(path, absolute=False, mangle_name=True):
path_components = []
actual_filename = None if mangle_name else filename
# If building an absolute url, default to https because we like it and the
# static server should support it.
scheme = 'https' if absolute else None
if g.static_domain:
domain = g.static_domain
else:
@@ -93,7 +97,7 @@ def static(path, absolute=False, mangle_name=True):
query = 'v=' + str(file_id)
return urlparse.urlunsplit((
None,
scheme,
domain,
actual_path,
query,