Skip to content

Commit

Permalink
Fix Navbar Hidden Pages Bug
Browse files Browse the repository at this point in the history
The navbar contained hidden pages like: 404.html and index.html, this
commit filters the site.html_pages with a better algorithm; any page
having a path in site.nav_exclude won't be included in the navbar. Also
adds a more dynamic way to configure/update the excluded pages.
  • Loading branch information
yousinix committed Jan 10, 2020
1 parent aae026c commit fd051b5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
16 changes: 14 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ baseurl : "/portfolYOU" # subpath of your site (e
repository : YoussefRaafatNasry/portfolYOU # repository metadata on GitHub Pages [know more at https://help.github.com/en/articles/repository-metadata-on-github-pages]
#remote_theme : YoussefRaafatNasry/portfolYOU # uncomment this if you are using it as a remote theme


### Build Settings ###
plugins:
- jemoji


### Navbar Settings ###
nav_exclude: # Pages with the following paths will be excluded from navbar
- 404.html
- index.html
- articles/tags.html
- articles/page-:num/index.html


### Author Info ###
author:
name : John Doe
Expand Down Expand Up @@ -57,8 +71,6 @@ defaults:
values:
layout: "page"

plugins:
- jemoji

### Exclude from processing ###
exclude:
Expand Down
50 changes: 40 additions & 10 deletions _includes/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,55 @@
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav ml-auto">

{% assign pages = site.html_pages | sort: 'weight' %}

{% for nav_page in pages %}
{% assign html_pages = site.html_pages | sort: 'weight' %}
{% assign filtered_pages = "" | split: "" %}

{% if page.url contains nav_page.url %}
{% for html_page in html_pages %}

{% assign exclude = false %}

{% for exclude_path in site.nav_exclude %}

{% if html_page.path == exclude_path %}
{% assign exclude = true %}
{% break %}
{% else if exclude_path contains ':num' %}
{% assign temp = html_page.path %}
{% assign parts = exclude_path | split: ':num' %}
{% for part in parts %}
{% assign temp = temp | remove: part %}
{% endfor %}
{% assign test_num = temp | plus: 0 | downcase %}
{% if temp == test_num %}
{% assign exclude = true %}
{% break %}
{% endif %}
{% endif %}

{% endfor %}

{% unless exclude %}
{% assign filtered_pages = filtered_pages | push: html_page %}
{% endunless %}

{% endfor %}


{% for html_page in filtered_pages %}

{% if page.url contains html_page.url %}
{% assign active_status = "active" %}
{% else %}
{% assign active_status = "" %}
{% endif %}

{% if nav_page.external_url %}
{% assign url = nav_page.external_url %}
{% if html_page.external_url %}
{% assign url = html_page.external_url %}
{% else %}
{% assign url = nav_page.url | relative_url %}
{% assign url = html_page.url | relative_url %}
{% endif %}

{% unless nav_page.url contains 'page' or nav_page.url contains 'tags' %}
<a class="nav-item nav-link {{ active_status }}" href="{{ url }}">{{ nav_page.title }}</a>
{% endunless %}
<a class="nav-item nav-link {{ active_status }}" href="{{ url }}">{{ html_page.title }}</a>

{% endfor %}

Expand Down

0 comments on commit fd051b5

Please sign in to comment.