mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-27 15:58:06 -05:00
Allow a static domain to be specified for subreddit stylesheets.
Since the S3 bucket we upload stylesheets to is not necessarily the same as the rest of the statics, it is useful to be able to specify this static domain separately.
This commit is contained in:
@@ -370,6 +370,10 @@ static_path = /static/
|
||||
# if not set, no domain will be specified
|
||||
static_domain =
|
||||
static_secure_domain =
|
||||
# if set, stylesheets will be sourced from these domains
|
||||
# if not set, stylesheets will use the default static_domain
|
||||
static_sr_stylesheet_domain =
|
||||
static_secure_sr_stylesheet_domain =
|
||||
# if this is true, append .gz to CSS and JS files served from the static domain
|
||||
# this is for hosts that don't do on-the-fly gzipping (e.g. s3)
|
||||
static_pre_gzipped = false
|
||||
|
||||
@@ -40,12 +40,25 @@ from pylons import g, c, request
|
||||
from pylons.i18n import _, ungettext
|
||||
|
||||
|
||||
def static_domain(kind, secure):
|
||||
if kind == 'sr_stylesheet':
|
||||
if secure:
|
||||
return g.static_secure_sr_stylesheet_domain
|
||||
else:
|
||||
return g.static_sr_stylesheet_domain
|
||||
else:
|
||||
if secure:
|
||||
return g.static_secure_domain
|
||||
else:
|
||||
return g.static_domain
|
||||
|
||||
|
||||
static_text_extensions = {
|
||||
'.js': 'js',
|
||||
'.css': 'css',
|
||||
'.less': 'css'
|
||||
}
|
||||
def static(path, allow_gzip=True):
|
||||
def static(path, allow_gzip=True, kind='default'):
|
||||
"""
|
||||
Simple static file maintainer which automatically paths and
|
||||
versions files being served out of static.
|
||||
@@ -63,15 +76,16 @@ def static(path, allow_gzip=True):
|
||||
|
||||
path_components = []
|
||||
actual_filename = None
|
||||
suffix = ''
|
||||
|
||||
if not c.secure and g.static_domain:
|
||||
scheme = 'http'
|
||||
domain = g.static_domain
|
||||
suffix = '.gzip' if should_gzip and g.static_pre_gzipped else ''
|
||||
elif c.secure and g.static_secure_domain:
|
||||
scheme = 'https'
|
||||
domain = g.static_secure_domain
|
||||
suffix = '.gzip' if should_gzip and g.static_secure_pre_gzipped else ''
|
||||
scheme = 'https' if c.secure else 'http'
|
||||
domain = static_domain(kind, c.secure)
|
||||
if domain:
|
||||
if should_gzip:
|
||||
if c.secure and g.static_secure_pre_gzipped:
|
||||
suffix = '.gzip'
|
||||
elif not c.secure and g.static_pre_gzipped:
|
||||
suffix = '.gzip'
|
||||
else:
|
||||
path_components.append(c.site.static_path)
|
||||
|
||||
@@ -85,7 +99,6 @@ def static(path, allow_gzip=True):
|
||||
|
||||
scheme = None
|
||||
domain = None
|
||||
suffix = ''
|
||||
|
||||
path_components.append(dirname)
|
||||
if not actual_filename:
|
||||
|
||||
@@ -342,7 +342,7 @@ class Subreddit(Thing, Printable, BaseSite):
|
||||
from r2.lib.template_helpers import static, get_domain
|
||||
|
||||
if self.stylesheet_is_static:
|
||||
return static(self.static_stylesheet_name)
|
||||
return static(self.static_stylesheet_name, kind='sr_stylesheet')
|
||||
else:
|
||||
return "http://%s/stylesheet.css?v=%s" % (get_domain(cname=False,
|
||||
subreddit=True),
|
||||
|
||||
Reference in New Issue
Block a user