diff --git a/r2/example.ini b/r2/example.ini index 71e42a5de..ae7890470 100644 --- a/r2/example.ini +++ b/r2/example.ini @@ -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 diff --git a/r2/r2/lib/template_helpers.py b/r2/r2/lib/template_helpers.py index f2c8d44ef..8f68e21c6 100755 --- a/r2/r2/lib/template_helpers.py +++ b/r2/r2/lib/template_helpers.py @@ -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: diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index 5dcd445a2..757c5f597 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -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),