fix: blog highlighted in nav for child pages (#2516)

Currently, in all blog posts, or any child page under /blog, the "blog"
in nav is not highlighted.

In all other child pages for a parent in nav, the parent is highlighted.
For example, in a sub page of projects, projects in nav is highlighted.

This fix creates a consistent behavior for nav and highlights the blog
in nav if in a blog post.

BEFORE:
<img width="1427" alt="image"
src="https://github.com/alshedivat/al-folio/assets/52665298/fc79727c-dc22-4af7-8c16-80efa216ecbc">

AFTER:
<img width="1434" alt="image"
src="https://github.com/alshedivat/al-folio/assets/52665298/6b32e7f9-e421-4b08-b86e-813b20ac058e">
This commit is contained in:
Andrew Boyer 2024-06-18 18:42:02 +01:00 committed by GitHub
parent 5d3d3ff60b
commit 3b1c10844f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 1 deletions

View File

@ -95,7 +95,8 @@
</div> </div>
</li> </li>
{% else %} {% else %}
<li class="nav-item {% if page.url contains p.permalink %}active{% endif %}"> {% assign parent_link = p.permalink | remove: 'index.html' %}
<li class="nav-item {% if page.url contains parent_link %}active{% endif %}">
{% if p.permalink contains '/blog/' %}{% assign url = '/blog/' %} {% else %}{% assign url = p.url %}{% endif %} {% if p.permalink contains '/blog/' %}{% assign url = '/blog/' %} {% else %}{% assign url = p.url %}{% endif %}
<a class="nav-link" href="{{ url | relative_url }}"> <a class="nav-link" href="{{ url | relative_url }}">
{{- p.title }} {{- p.title }}