Skip to content

Commit

Permalink
add root_url in site and templates
Browse files Browse the repository at this point in the history
  • Loading branch information
quillcraftsman committed Oct 1, 2024
1 parent 7824e5a commit 4255f03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions cactus/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion cactus/template_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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


Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 4255f03

Please sign in to comment.