Skip to content

Commit

Permalink
Expand and move all navigation creation to nav.html.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosperate committed Nov 22, 2019
1 parent 6255630 commit a3a6c66
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 83 deletions.
1 change: 0 additions & 1 deletion _includes/breadcrumbs.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
</li>
</ul>

{%- include paginationlist.html %}
{%- if (site.prev_next_buttons_location == 'top' or site.prev_next_buttons_location =='both') and (previous_page or next_page) %}
<div class="rst-breadcrumbs-buttons" role="navigation" aria-label="breadcrumb navigation">
{%- if next_page %}
Expand Down
1 change: 0 additions & 1 deletion _includes/footer.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<footer>
{%- include paginationlist.html %}
{%- if (site.prev_next_buttons_location == 'bottom' or site.prev_next_buttons_location =='both') and (previous_page or next_page) %}
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
{%- if next_page %}
Expand Down
79 changes: 79 additions & 0 deletions _includes/nav.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{%- comment -%}
This will generate a list (<ul> and <li>) with all the pages not marked to
be excluded from the navigation.
The entries will be ordered by the "nav_order" front matter, and if the
pages are within a folder it will create a section for those entries (only
1 level deep).

Jekyll doesn't offer a way to see if there are next or previous pages, as
it is only available for posts. As we have a specific other anyway, this
will also create the "previous_page" and "next_page" global variables with
URLs to add as links/buttons in other parts of the layout.

WARNING! The looping around the list of pages here is not a good method
to implement this, but the Liquid template language is very limited.
{%- endcomment -%}

{%- assign sections = "" %}
{%- assign last_loop_page = false %}
{%- assign set_next_page = false %}
{%- assign nav = site.pages | sort:"nav_order" %}

{%- comment %} First loop to print pages without categories and collect an array of categories {%- endcomment %}
{%- for nav_item in nav %}
{%- if nav_item.hide != true and nav_item.nav_exclude != true %}
{%- assign path_array = nav_item.dir | split: "/" %}
{%- assign array_size = path_array | size %}
{%- if array_size == 0 %}
{%- if nav_item.url == page.url %}
{%- include toc.html html=content sanitize=true h_max=4 item_class="toctree-l%level%" %}
{%- if nav_item.url == page.url %}
{%- assign previous_page = last_loop_page %}
{%- assign set_next_page = true %}
{%- endif %}
{%- else %}
<ul>
<li class="toctree-l1">
<a class="reference internal current" href="{{ nav_item.url | absolute_url}}">{{ nav_item.title }}</a>
</li>
</ul>
{%- assign last_loop_page = nav_item %}
{%- if set_next_page %}
{%- assign next_page = nav_item %}
{%- assign set_next_page = false %}
{% endif %}
{%- endif %}
{%- else %}
{%- assign sections = sections | append: path_array[1] | append: "|" %}
{%- endif %}
{%- endif %}
{%- endfor %}

{%- assign sections = sections | split: "|" | uniq | sort %}
{%- for section in sections %}
<p class="caption"><span class="caption-text">{{ section }}</span></p>
{%- for nav_item in nav %}
{%- assign path_array = nav_item.dir | split: "/" %}
{%- assign page_section = path_array[1] %}
{%- if page_section == section and nav_item.hide != true and nav_item.nav_exclude != true %}
{%- if nav_item.url == page.url %}
{%- include toc.html html=content sanitize=true h_max=4 item_class="toctree-l%level%" %}
{%- if nav_item.url == page.url %}
{%- assign previous_page = last_loop_page %}
{%- assign set_next_page = true %}
{%- endif %}
{%- else %}
<ul>
<li class="toctree-l1">
<a class="reference internal current" href="{{ nav_item.url | absolute_url}}">{{ nav_item.title }}</a>
</li>
</ul>
{%- assign last_loop_page = nav_item %}
{%- if set_next_page %}
{%- assign next_page = nav_item %}
{%- assign set_next_page = false %}
{% endif %}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- endfor %}
39 changes: 0 additions & 39 deletions _includes/paginationlist.html

This file was deleted.

43 changes: 1 addition & 42 deletions _layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,47 +44,7 @@
</div>

<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
{%- assign nav = site.pages | sort:"nav_order" %}
{%- assign sections = "" %}
{%- for nav_item in nav %}
{%- if nav_item.hide != true and nav_item.nav_exclude != true %}
{%- assign path_array = nav_item.dir | split: "/" %}
{%- assign array_size = path_array | size %}
{%- if array_size == 0 %}
{%- if nav_item.url != page.url %}
<ul>
<li class="toctree-l1">
<a class="reference internal current" href="{{ nav_item.url | absolute_url}}">{{ nav_item.title }}</a>
</li>
</ul>
{%- else %}
{% include toc.html html=content sanitize=true h_max=4 item_class="toctree-l%level%" %}
{%- endif %}
{%- else %}
{%- assign sections = sections | append: path_array[1] | append: "|" %}
{%- endif %}
{%- endif %}
{%- endfor %}

{%- assign sections = sections | split: "|" | uniq | sort %}
{%- for section in sections %}
<p class="caption"><span class="caption-text">{{ section }}</span></p>
{%- for nav_item in nav %}
{%- assign path_array = nav_item.dir | split: "/" %}
{%- assign page_section = path_array[1] %}
{%- if page_section == section and nav_item.hide != true and nav_item.nav_exclude != true %}
{%- if nav_item.url != page.url %}
<ul>
<li class="toctree-l1">
<a class="reference internal current" href="{{ nav_item.url | absolute_url}}">{{ nav_item.title }}</a>
</li>
</ul>
{%- else %}
{% include toc.html html=content sanitize=true h_max=4 item_class="toctree-l%level%" %}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- endfor %}
{% include nav.html %}
</div>
</div>
</nav>
Expand Down Expand Up @@ -130,4 +90,3 @@
<!-- Build Date: {{ site.time | date: "%Y-%m-%d %H:%M" }} -->
</body>
</html>

0 comments on commit a3a6c66

Please sign in to comment.