mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
Display trending subreddits on the front page.
This commit is contained in:
@@ -61,6 +61,8 @@ default_sr = reddit.com
|
||||
admin_message_acct = reddit
|
||||
# subreddit used for DMCA takedowns
|
||||
takedown_sr = _takedowns
|
||||
# subreddit used for trending subreddits postings
|
||||
trending_sr = trendingsubreddits
|
||||
# list of subreddits to auto-subscribe users to
|
||||
automatic_reddits =
|
||||
# special subreddit that only reddit gold subscribers can use
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
# Inc. All Rights Reserved.
|
||||
###############################################################################
|
||||
|
||||
import re
|
||||
import urllib
|
||||
|
||||
from oauth2 import require_oauth2_scope
|
||||
@@ -43,6 +44,7 @@ import r2.lib.search as search
|
||||
from r2.lib.template_helpers import add_sr
|
||||
from r2.lib.utils import iters, check_cheating, timeago
|
||||
from r2.lib import sup
|
||||
from r2.lib.memoize import memoize
|
||||
from r2.lib.validator import *
|
||||
from r2.lib.butler import extract_user_mentions
|
||||
import socket
|
||||
@@ -302,6 +304,8 @@ class ListingWithPromos(ListingController):
|
||||
elif show_sponsors:
|
||||
spotlight = self.make_single_ad()
|
||||
|
||||
self.spotlight = spotlight
|
||||
|
||||
if spotlight:
|
||||
return PaneStack([spotlight, self.listing_obj],
|
||||
css_class='spacer')
|
||||
@@ -341,6 +345,41 @@ class HotController(ListingWithPromos):
|
||||
# no sticky or sticky hidden
|
||||
return c.site.get_links('hot', 'all')
|
||||
|
||||
subreddit_re = re.compile(r'/r/(\w+)')
|
||||
|
||||
@classmethod
|
||||
@memoize('trending_subreddits', time=5*60)
|
||||
def trending_subreddits(cls):
|
||||
subreddit = Subreddit._by_name(g.config['trending_sr'])
|
||||
q = subreddit.get_links('new', 'all')
|
||||
ids = list(q)
|
||||
builder = IDBuilder(ids, skip=True, num=1)
|
||||
posts = builder.get_items()[0]
|
||||
if not posts:
|
||||
return None
|
||||
post = posts[0]
|
||||
subreddits = cls.subreddit_re.findall(post.title)
|
||||
|
||||
return {
|
||||
'subreddits': subreddits,
|
||||
'comment_url': post.permalink,
|
||||
'comment_count': post.num_comments,
|
||||
}
|
||||
|
||||
def content(self):
|
||||
content = super(HotController, self).content()
|
||||
if (c.render_style == "html" and isinstance(c.site, DefaultSR) and
|
||||
not self.listing_obj.prev):
|
||||
trending_info = self.trending_subreddits()
|
||||
if trending_info:
|
||||
return PaneStack(filter(None, [
|
||||
self.spotlight,
|
||||
TrendingSubredditsBar(**trending_info),
|
||||
self.listing_obj,
|
||||
]), css_class='spacer')
|
||||
return content
|
||||
|
||||
|
||||
def title(self):
|
||||
return c.site.title
|
||||
|
||||
|
||||
@@ -79,7 +79,13 @@ from r2.lib.strings import plurals, rand_strings, strings, Score
|
||||
from r2.lib.utils import title_to_url, query_string, UrlParser, vote_hash
|
||||
from r2.lib.utils import url_links_builder, make_offset_date, median, to36
|
||||
from r2.lib.utils import trunc_time, timesince, timeuntil, weighted_lottery
|
||||
from r2.lib.template_helpers import add_sr, get_domain, format_number, media_https_if_secure
|
||||
from r2.lib.template_helpers import (
|
||||
add_sr,
|
||||
get_domain,
|
||||
format_number,
|
||||
media_https_if_secure,
|
||||
comment_label,
|
||||
)
|
||||
from r2.lib.subreddit_search import popular_searches
|
||||
from r2.lib.log import log_text
|
||||
from r2.lib.memoize import memoize
|
||||
@@ -4371,3 +4377,13 @@ class ExploreItemListing(Templated):
|
||||
rec.sr = wrapped_srs[rec.sr._id]
|
||||
self.things.append(rec)
|
||||
Templated.__init__(self)
|
||||
|
||||
|
||||
class TrendingSubredditsBar(Templated):
|
||||
def __init__(self, subreddits, comment_url, comment_count):
|
||||
Templated.__init__(self)
|
||||
self.subreddits = subreddits
|
||||
self.comment_url = comment_url
|
||||
self.comment_count = comment_count
|
||||
self.comment_label, self.comment_label_cls = \
|
||||
comment_label(comment_count)
|
||||
|
||||
@@ -8324,3 +8324,57 @@ body.with-listing-chooser {
|
||||
font-style: italic;
|
||||
}
|
||||
}
|
||||
|
||||
.trending-subreddits {
|
||||
// required so that ex units are in sync with .midcol
|
||||
font-size: small;
|
||||
margin-top: -4px;
|
||||
line-height: 1.75em;
|
||||
|
||||
// the combined padding/margins of .link and .midcol
|
||||
margin-left: 17px;
|
||||
body.compressed-display & {
|
||||
margin-left: 15px;
|
||||
padding-left: 15px;
|
||||
}
|
||||
|
||||
strong, ul, a {
|
||||
font-size: x-small;
|
||||
}
|
||||
|
||||
strong {
|
||||
color: #29541c;
|
||||
|
||||
&:before {
|
||||
height: 14px;
|
||||
width: 14px;
|
||||
display: inline-block;
|
||||
content: " ";
|
||||
margin-right: 5px;
|
||||
background-image: url(../trending.png); /* SPRITE */
|
||||
vertical-align: middle;
|
||||
}
|
||||
}
|
||||
|
||||
ul {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
li {
|
||||
display: inline-block;
|
||||
margin-left: 0.5em;
|
||||
}
|
||||
|
||||
li:first-child {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
ul, .comments {
|
||||
margin-left: 1em;
|
||||
}
|
||||
|
||||
.comments {
|
||||
color: #888;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ r.analytics = {
|
||||
}
|
||||
|
||||
r.analytics.breadcrumbs = {
|
||||
selector: '.thing, .side, .sr-list, .srdrop, .tagline, .md, .organic-listing, .gadget, .sr-interest-bar, a, button, input',
|
||||
selector: '.thing, .side, .sr-list, .srdrop, .tagline, .md, .organic-listing, .gadget, .sr-interest-bar, .trending-subreddits, a, button, input',
|
||||
maxLength: 3,
|
||||
sendLength: 2,
|
||||
|
||||
|
||||
BIN
r2/r2/public/static/trending.png
Normal file
BIN
r2/r2/public/static/trending.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 497 B |
@@ -29,5 +29,8 @@
|
||||
body > .content .link .midcol {
|
||||
width: ${thing.midcol_width}ex
|
||||
}
|
||||
.content .trending-subreddits {
|
||||
padding-left: ${thing.midcol_width}ex
|
||||
}
|
||||
</style>
|
||||
<%include file="listing.html"/>
|
||||
|
||||
31
r2/r2/templates/trendingsubredditsbar.html
Normal file
31
r2/r2/templates/trendingsubredditsbar.html
Normal file
@@ -0,0 +1,31 @@
|
||||
## The contents of this file are subject to the Common Public Attribution
|
||||
## License Version 1.0. (the "License"); you may not use this file except in
|
||||
## compliance with the License. You may obtain a copy of the License at
|
||||
## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
|
||||
## License Version 1.1, but Sections 14 and 15 have been added to cover use of
|
||||
## software over a computer network and provide for limited attribution for the
|
||||
## Original Developer. In addition, Exhibit A has been modified to be
|
||||
## consistent with Exhibit B.
|
||||
##
|
||||
## Software distributed under the License is distributed on an "AS IS" basis,
|
||||
## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
||||
## the specific language governing rights and limitations under the License.
|
||||
##
|
||||
## The Original Code is reddit.
|
||||
##
|
||||
## The Original Developer is the Initial Developer. The Initial Developer of
|
||||
## the Original Code is reddit Inc.
|
||||
##
|
||||
## All portions of the code written by reddit are Copyright (c) 2006-2013
|
||||
## reddit Inc. All Rights Reserved.
|
||||
###############################################################################
|
||||
|
||||
<div class="trending-subreddits">
|
||||
<strong>${_('trending subreddits')}</strong>
|
||||
<ul>
|
||||
%for subreddit in thing.subreddits:
|
||||
<li><a href="/r/${subreddit}" target="_blank">/r/${subreddit}</a></li>
|
||||
%endfor
|
||||
</ul>
|
||||
<a href="${thing.comment_url}" class="${thing.comment_label_cls}">${thing.comment_label}</a>
|
||||
</div>
|
||||
Reference in New Issue
Block a user