Skip to content

Commit

Permalink
Fix breadcrumb links when deploying with a prefix
Browse files Browse the repository at this point in the history
Issue #330
  • Loading branch information
jeremyh committed Oct 14, 2021
1 parent 1060b76 commit b8afe09
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
26 changes: 19 additions & 7 deletions cubedash/_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,29 +439,41 @@ def inject_globals():
"CUBEDASH_INSTANCE_TITLE",
)
or app.config.get("STAC_ENDPOINT_TITLE", ""),
breadcrumb=_get_breadcrumbs(request.path),
breadcrumb=_get_breadcrumbs(request.path, request.script_root),
)


def _get_breadcrumbs(url: str):
HREF = str
SHOULD_LINK = bool


def _get_breadcrumbs(url: str, script_root: str) -> List[Tuple[HREF, str, SHOULD_LINK]]:
"""
>>> _get_breadcrumbs('/products/great_product')
>>> _get_breadcrumbs('/products/great_product', '/')
[('/products', 'products', True), ('/products/great_product', 'great_product', False)]
>>> _get_breadcrumbs('/products')
>>> _get_breadcrumbs('/products/great_product', '/prefix')
[('/prefix/products', 'products', True), ('/prefix/products/great_product', 'great_product', False)]
>>> _get_breadcrumbs('/products', '/')
[('/products', 'products', False)]
>>> _get_breadcrumbs('/')
>>> _get_breadcrumbs('/products', '/pref')
[('/pref/products', 'products', False)]
>>> _get_breadcrumbs('/', '/')
[]
>>> _get_breadcrumbs('')
>>> _get_breadcrumbs('/', '/pref')
[]
>>> _get_breadcrumbs('', '/')
[]
"""
breadcrumb = []
i = 2
script_root = script_root.rstrip("/")

for part_name in url.split("/"):
if part_name:
part_href = "/".join(url.split("/")[:i])
breadcrumb.append(
(
part_href,
f"{script_root}{part_href}",
part_name,
# Don't link to the current page.
part_href != url,
Expand Down
2 changes: 1 addition & 1 deletion cubedash/templates/layout/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</div>
</div>
<div id="breadcrumb">
<a class="item" href="/">home</a>
<a class="item" href="{{url_for('default_redirect')}}">home</a>
{% if breadcrumb %}
{% for url, title, valid_link in breadcrumb %}
{% if valid_link %}
Expand Down

0 comments on commit b8afe09

Please sign in to comment.