diff --git a/templates/macros/menu.html b/templates/macros/menu.html index 2a803a3..ca7fc67 100644 --- a/templates/macros/menu.html +++ b/templates/macros/menu.html @@ -5,20 +5,30 @@ {%- for item in menu_items %} - {%- set rel_item_url = item.url | replace(from="$BASE_URL", to="") -%} - {%- set current = rel_item_url == current_path - or rel_item_url == "/" ~ current_path - or rel_item_url ~ "/" == "/" ~ current_path - or rel_item_url == "" and current_path == "/" + {%- set abs_item_url = item.url | replace(from="$BASE_URL", to=config.base_url) -%} + {%- set is_current = current_url == abs_item_url ~ "/" + or current_url is starting_with(abs_item_url) -%} - {%- if current %} + {%- set is_base = abs_item_url == config.base_url + or abs_item_url == config.base_url ~ "/" + -%} + + {%- if is_base %} + {%- set_global base_item = item -%} + {% endif -%} + + {%- if is_current and not is_base %} {%- set_global current_item = item -%} {% endif -%} {% endfor -%} + {%- if not current_item and base_item %} + {# Did not match any menu URLs -- assume it's a blog post #} + {%- set current_item = base_item -%} + {% endif -%} + {%- for item in menu_items %} - {%- set blog_post = not current_item and item.url == "$BASE_URL" -%} - + {%- if item.newtab -%} {{ item.name | safe }} {%- else -%}