diff --git a/cactus/site.py b/cactus/site.py index 780a53f..e63b059 100644 --- a/cactus/site.py +++ b/cactus/site.py @@ -56,6 +56,7 @@ def __init__(self, path, config_paths=None, ui=None, # Load site-specific config values self.prettify_urls = self.config.get('prettify', False) + self.root_url = self.config.get('root_url', None) self.compress_extensions = self.config.get('compress', ['html', 'css', 'js', 'txt', 'xml']) self.fingerprint_extensions = self.config.get('fingerprint', []) self.use_translate = self.config.get('use_translate', False) diff --git a/cactus/template_tags.py b/cactus/template_tags.py index 54b2661..483450f 100644 --- a/cactus/template_tags.py +++ b/cactus/template_tags.py @@ -11,6 +11,10 @@ register = Library() +def add_root_url(current_url, root_url): + return f'/{root_url}{current_url}' + + def static(context, link_url): """ Get the path for a static file in the Cactus build. @@ -36,12 +40,17 @@ def static(context, link_url): url_helper_key = site.get_url_for_static(helper_key) if url_helper_key is not None: + if site.root_url is not None: + url_helper_key = add_root_url(url_helper_key, site.root_url) return url_helper_key logger.warning('%s: static resource does not exist: %s', page.link_url, link_url) url = link_url + if site.root_url is not None: + url = add_root_url(url, site.root_url) + return url @@ -72,7 +81,10 @@ def url(context, link_url): url = u"/%s%s" % (site.config.get("locale"), url) if site.prettify_urls: - return url.rsplit('index.html', 1)[0] + url = url.rsplit('index.html', 1)[0] + + if site.root_url is not None: + url = add_root_url(url, site.root_url) return url