mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-24 22:38:09 -05:00
Add a contextual description metatag for scrapers.
This commit is contained in:
@@ -28,6 +28,9 @@ allow_wiki_editing = true
|
||||
# a modified read only mode used for cache shown during heavy load 503s
|
||||
heavy_load_mode = false
|
||||
|
||||
# the site's tagline, used in the title and description
|
||||
short_description = open source is awesome
|
||||
|
||||
# -- SECRETS! <-- update these first! --
|
||||
# global secret
|
||||
SECRET = abcdefghijklmnopqrstuvwxyz0123456789
|
||||
|
||||
@@ -50,6 +50,7 @@ from r2.lib.subreddit_search import popular_searches
|
||||
from r2.lib.scraper import get_media_embed
|
||||
from r2.lib.log import log_text
|
||||
from r2.lib.memoize import memoize
|
||||
from r2.lib.utils import trunc_string as _truncate
|
||||
|
||||
import sys, random, datetime, locale, calendar, simplejson, re, time
|
||||
import graph, pycountry, time
|
||||
@@ -60,6 +61,8 @@ from things import wrap_links, default_thing_wrapper
|
||||
|
||||
datefmt = _force_utf8(_('%d %b %Y'))
|
||||
|
||||
MAX_DESCRIPTION_LENGTH = 150
|
||||
|
||||
def get_captcha():
|
||||
if not c.user_is_loggedin or c.user.needs_captcha():
|
||||
return get_iden()
|
||||
@@ -113,11 +116,12 @@ class Reddit(Templated):
|
||||
additional_css = None
|
||||
|
||||
def __init__(self, space_compress = True, nav_menus = None, loginbox = True,
|
||||
infotext = '', content = None, title = '', robots = None,
|
||||
infotext = '', content = None, short_description='', title = '', robots = None,
|
||||
show_sidebar = True, footer = True, srbar = True,
|
||||
**context):
|
||||
Templated.__init__(self, **context)
|
||||
self.title = title
|
||||
self.short_description = short_description
|
||||
self.robots = robots
|
||||
self.infotext = infotext
|
||||
self.loginbox = True
|
||||
@@ -802,7 +806,9 @@ class LinkInfoPage(Reddit):
|
||||
# defaults whether or not there is a comment
|
||||
params = {'title':_force_unicode(link_title), 'site' : c.site.name}
|
||||
title = strings.link_info_title % params
|
||||
|
||||
short_description = None
|
||||
if link and link.selftext:
|
||||
short_description = _truncate(link.selftext.strip(), MAX_DESCRIPTION_LENGTH)
|
||||
# only modify the title if the comment/author are neither deleted nor spam
|
||||
if comment and not comment._deleted and not comment._spam:
|
||||
author = Account._byID(comment.author_id, data=True)
|
||||
@@ -810,6 +816,8 @@ class LinkInfoPage(Reddit):
|
||||
if not author._deleted and not author._spam:
|
||||
params = {'author' : author.name, 'title' : _force_unicode(link_title)}
|
||||
title = strings.permalink_title % params
|
||||
short_description = _truncate(comment.body.strip(), MAX_DESCRIPTION_LENGTH) if comment.body else None
|
||||
|
||||
|
||||
self.subtitle = subtitle
|
||||
|
||||
@@ -823,7 +831,7 @@ class LinkInfoPage(Reddit):
|
||||
else:
|
||||
self.duplicates = duplicates
|
||||
|
||||
Reddit.__init__(self, title = title, *a, **kw)
|
||||
Reddit.__init__(self, title = title, short_description=short_description, *a, **kw)
|
||||
|
||||
def build_toolbars(self):
|
||||
base_path = "/%s/%s/" % (self.link._id36, title_to_url(self.link.title))
|
||||
|
||||
@@ -304,6 +304,9 @@ def sanitize_url(url, require_scheme = False):
|
||||
return
|
||||
return url
|
||||
|
||||
def trunc_string(text, length):
|
||||
return text[0:length]+'...' if len(text)>length else text
|
||||
|
||||
# Truncate a time to a certain number of minutes
|
||||
# e.g, trunc_time(5:52, 30) == 5:30
|
||||
def trunc_time(time, mins, hours=None):
|
||||
|
||||
@@ -819,7 +819,7 @@ class _DefaultSR(FakeSubreddit):
|
||||
|
||||
@property
|
||||
def title(self):
|
||||
return _("reddit: the front page of the internet")
|
||||
return _(g.short_description)
|
||||
|
||||
# This is the base class for the instantiated front page reddit
|
||||
class DefaultSR(_DefaultSR):
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
|
||||
<title>${self.Title()}</title>
|
||||
<meta name="title" content="${self.Title()}" />
|
||||
<meta name="description" content="${thing.short_description or g.short_description}" />
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
${self.robots()}
|
||||
<link rel="stylesheet" href="${static('compact.css')}" type="text/css" media="screen" />
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
<meta name="keywords" content="${self.keywords()}" />
|
||||
<meta name="title" content="${self.Title()}" />
|
||||
<meta name="description" content="${getattr(thing, 'short_description', None) or g.short_description}" />
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
${self.robots()}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user