1
0
mirror of https://github.com/thangisme/notes.git synced 2024-12-22 07:46:41 -05:00

Merge pull request #236 from pdmosses/default-nav-order

Default nav order
This commit is contained in:
Patrick Marsceill 2020-04-27 11:12:26 -04:00 committed by GitHub
commit b51decd020
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 28 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
*.gem *.gem
.bundle .bundle
.jekyll-cache
.sass-cache .sass-cache
_site _site
Gemfile.lock Gemfile.lock

View File

@ -38,6 +38,10 @@ aux_links:
"Just the Docs on GitHub": "Just the Docs on GitHub":
- "//github.com/pmarsceill/just-the-docs" - "//github.com/pmarsceill/just-the-docs"
# Sort order for navigation links
nav_sort: case_insensitive # default, equivalent to nil
# nav_sort: case_sensitive # Capital letters sorted before lowercase
# Footer content # Footer content
# appears at the bottom of every page's main content # appears at the bottom of every page's main content
footer_content: "Copyright &copy; 2017-2019 Patrick Marsceill. Distributed by an <a href=\"https://github.com/pmarsceill/just-the-docs/tree/master/LICENSE.txt\">MIT license.</a>" footer_content: "Copyright &copy; 2017-2019 Patrick Marsceill. Distributed by an <a href=\"https://github.com/pmarsceill/just-the-docs/tree/master/LICENSE.txt\">MIT license.</a>"

View File

@ -1,6 +1,15 @@
<nav role="navigation" aria-label="Main navigation"> <nav role="navigation" aria-label="Main navigation">
<ul class="navigation-list"> <ul class="navigation-list">
{%- assign pages_list = site.html_pages | sort:"nav_order" -%} {%- assign ordered_pages_list = site.html_pages | where_exp:"item", "item.nav_order != nil" -%}
{%- assign unordered_pages_list = site.html_pages | where_exp:"item", "item.nav_order == nil" -%}
{%- if site.nav_sort == 'case_sensitive' -%}
{%- assign sorted_ordered_pages_list = ordered_pages_list | sort:"nav_order" -%}
{%- assign sorted_unordered_pages_list = unordered_pages_list | sort:"title" -%}
{%- else -%}
{%- assign sorted_ordered_pages_list = ordered_pages_list | sort_natural:"nav_order" -%}
{%- assign sorted_unordered_pages_list = unordered_pages_list | sort_natural:"title" -%}
{%- endif -%}
{%- assign pages_list = sorted_ordered_pages_list | concat: sorted_unordered_pages_list -%}
{%- for node in pages_list -%} {%- for node in pages_list -%}
{%- unless node.nav_exclude -%} {%- unless node.nav_exclude -%}
{%- if node.parent == nil -%} {%- if node.parent == nil -%}
@ -10,29 +19,27 @@
{%- endif -%} {%- endif -%}
<a href="{{ node.url | absolute_url }}" class="navigation-list-link{% if page.url == node.url %} active{% endif %}">{{ node.title }}</a> <a href="{{ node.url | absolute_url }}" class="navigation-list-link{% if page.url == node.url %} active{% endif %}">{{ node.title }}</a>
{%- if node.has_children -%} {%- if node.has_children -%}
{%- assign children_list = site.html_pages | where: "parent", node.title | sort:"nav_order" -%} {%- assign children_list = pages_list | where: "parent", node.title -%}
<ul class="navigation-list-child-list "> <ul class="navigation-list-child-list ">
{%- for child in children_list -%} {%- for child in children_list -%}
{%- unless child.nav_exclude -%} {%- unless child.nav_exclude -%}
<li class="navigation-list-item {% if page.url == child.url or page.parent == child.title %} active{% endif %}"> <li class="navigation-list-item {% if page.url == child.url or page.parent == child.title %} active{% endif %}">
{%- if page.url == child.url or page.parent == child.title -%} {%- if page.url == child.url or page.parent == child.title -%}
{%- assign second_level_url = child.url | absolute_url -%} {%- assign second_level_url = child.url | absolute_url -%}
{%- endif -%} {%- endif -%}
<a href="{{ child.url | absolute_url }}" class="navigation-list-link{% if page.url == child.url %} active{% endif %}">{{ child.title }}</a> <a href="{{ child.url | absolute_url }}" class="navigation-list-link{% if page.url == child.url %} active{% endif %}">{{ child.title }}</a>
{%- if child.has_children -%} {%- if child.has_children -%}
{%- assign grand_children_list = site.html_pages | where: "parent", child.title | sort:"nav_order" -%} {%- assign grand_children_list = pages_list | where: "parent", child.title -%}
<ul class="navigation-list-child-list"> <ul class="navigation-list-child-list">
{%- for grand_child in grand_children_list -%} {%- for grand_child in grand_children_list -%}
{%- unless grand_child.nav_exclude -%} <li class="navigation-list-item {% if page.url == grand_child.url %} active{% endif %}">
<li class="navigation-list-item {% if page.url == grand_child.url %} active{% endif %}"> <a href="{{ grand_child.url | absolute_url }}" class="navigation-list-link{% if page.url == grand_child.url %} active{% endif %}">{{ grand_child.title }}</a>
<a href="{{ grand_child.url | absolute_url }}" class="navigation-list-link{% if page.url == grand_child.url %} active{% endif %}">{{ grand_child.title }}</a> </li>
</li> {%- endfor -%}
{%- endunless -%} </ul>
{%- endfor -%} {%- endif -%}
</ul> </li>
{%- endif -%} {%- endunless -%}
</li>
{%- endunless -%}
{%- endfor -%} {%- endfor -%}
</ul> </ul>
{%- endif -%} {%- endif -%}

View File

@ -74,9 +74,8 @@ layout: table_wrappers
{% if page.has_children == true and page.has_toc != false %} {% if page.has_children == true and page.has_toc != false %}
<hr> <hr>
<h2 class="text-delta">Table of contents</h2> <h2 class="text-delta">Table of contents</h2>
{% assign children_list = site.pages | sort:"nav_order" %}
<ul> <ul>
{% for child in children_list %} {% for child in pages_list %}
{% if child.parent == page.title and child.title != page.title %} {% if child.parent == page.title and child.title != page.title %}
<li> <li>
<a href="{{ child.url | absolute_url }}">{{ child.title }}</a>{% if child.summary %} - {{ child.summary }}{% endif %} <a href="{{ child.url | absolute_url }}">{{ child.title }}</a>{% if child.summary %} - {{ child.summary }}{% endif %}

View File

@ -38,6 +38,12 @@ nav_order: 4
--- ---
``` ```
The specified `nav_order` parameters on a site should be all integers or all strings.
Pages without a `nav_order` parameter are ordered alphabetically by their `title`,
and appear after the explicitly-ordered pages at each level.
To sort all Capital letters before lowercase letters,
add `nav_sort: case_sensitive` in the configuration file.
--- ---
## Excluding pages ## Excluding pages

View File

@ -2,7 +2,6 @@
layout: default layout: default
title: Color title: Color
parent: Utilities parent: Utilities
nav_order: 3
--- ---
# Color Utilities # Color Utilities

View File

@ -2,7 +2,6 @@
layout: default layout: default
title: Layout title: Layout
parent: Utilities parent: Utilities
nav_order: 2
--- ---
# Layout Utilities # Layout Utilities

View File

@ -2,7 +2,6 @@
layout: default layout: default
title: Responsive Modifiers title: Responsive Modifiers
parent: Utilities parent: Utilities
nav_order: 1
--- ---
# Responsive modifiers # Responsive modifiers

View File

@ -2,7 +2,6 @@
layout: default layout: default
title: Typography title: Typography
parent: Utilities parent: Utilities
nav_order: 4
--- ---
# Typography Utilities # Typography Utilities