Build navigation list include helper

- Update navigation.yml to support multiple navigations and levels
- Optional include navigation into left sidebar
This commit is contained in:
Michael Rose 2016-03-25 14:12:03 -04:00
parent e52c06273e
commit 678aecdd61
5 changed files with 157 additions and 14 deletions

56
_data/docs.yml Normal file
View file

@ -0,0 +1,56 @@
- title: Getting Started
children:
- title: "Quick Start Guide"
path: quick-start-guide
- title: "Installation"
path: installation
- title: "Upgrading"
path: upgrading
- title: "Structure"
path: structure
- title: Customization
children:
- title: "Configuration"
path: configuration
- title: "Navigation"
path: navigation
- title: "Authors"
path: authors
- title: "UI Text"
path: ui-text
- title: "Layouts"
path: layouts
- title: Content
children:
- title: "Working with Posts"
path: working-with-posts
- title: "Working with Pages"
path: working-with-pages
- title: "Working with Collections"
path: working-with-collections
- title: "Jekyll Include Helpers"
path: include-helpers
- title: "Images"
path: images
- title: Miscellaneous
children:
- title: "Pagination"
path: pagination
- title: "Archives"
path: archives
- title: "Development"
path: development
- title: "v2 Documentation"
path: docs-2
- title: Meta
children:
- title: "Contributing"
path: contributing
- title: "License"
path: license
- title: "History"
path: history

View file

@ -1,19 +1,79 @@
# Site navigation links # main links links
main:
- title: "Theme Setup"
url: /theme-setup/
- title: "Theme Setup" - title: "Posts"
url: /theme-setup/ url: /year-archive/
- title: "Posts" - title: "Categories"
url: /year-archive/ url: /categories/
- title: "Categories" - title: "Tags"
url: /categories/ url: /tags/
- title: "Tags" - title: "Pages"
url: /tags/ url: /page-archive/
- title: "Pages" - title: "Collections"
url: /page-archive/ url: /collection-archive/
- title: "Collections"
url: /collection-archive/ # documentation links
docs:
- title: Getting Started
children:
- title: "Quick Start Guide"
path: quick-start-guide
- title: "Installation"
path: installation
- title: "Upgrading"
path: upgrading
- title: "Structure"
path: structure
- title: Customization
children:
- title: "Configuration"
path: configuration
- title: "Navigation"
path: navigation
- title: "Authors"
path: authors
- title: "UI Text"
path: ui-text
- title: "Layouts"
path: layouts
- title: Content
children:
- title: "Working with Posts"
path: working-with-posts
- title: "Working with Pages"
path: working-with-pages
- title: "Working with Collections"
path: working-with-collections
- title: "Jekyll Include Helpers"
path: include-helpers
- title: "Images"
path: images
- title: Miscellaneous
children:
- title: "Pagination"
path: pagination
- title: "Archives"
path: archives
- title: "Development"
path: development
- title: "v2 Documentation"
path: docs-2
- title: Meta
children:
- title: "Contributing"
path: contributing
- title: "License"
path: license
- title: "History"
path: history

View file

@ -7,7 +7,7 @@
<nav id="site-nav" class="greedy-nav"> <nav id="site-nav" class="greedy-nav">
<button><div class="navicon"></div></button> <button><div class="navicon"></div></button>
<ul class="visible-links"> <ul class="visible-links">
{% for link in site.data.navigation %} {% for link in site.data.navigation.main %}
{% if link.url contains 'http' %} {% if link.url contains 'http' %}
{% assign domain = '' %} {% assign domain = '' %}
{% else %} {% else %}

24
_includes/nav_list.html Normal file
View file

@ -0,0 +1,24 @@
{% include base_path %}
{% assign navigation = site.data.navigation[page.sidebar.nav] %}
<nav>
<ul>
{% for nav in navigation %}
<li>{{ nav.title }}
{% if nav.children != null %}
<ul>
{% for child in nav.children %}
{% assign nav_url = child.path | prepend: "/" | prepend: page.sidebar.nav | prepend: "/" | append: "/" | prepend: base_path %}
{% if nav_url contains page.url %}
{% assign c = "current" %}
{% else %}
{% assign c = "" %}
{% endif %}
<li><a href="{{ nav_url }}" class="{{ c }}">{{ child.title }}</a></li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
</nav>

View file

@ -15,6 +15,9 @@
{% if s.title %}<h3>{{ s.title }}</h3>{% endif %} {% if s.title %}<h3>{{ s.title }}</h3>{% endif %}
{% if s.text %}{{ s.text | markdownify }}{% endif %} {% if s.text %}{{ s.text | markdownify }}{% endif %}
{% endfor %} {% endfor %}
{% if page.sidebar.nav %}
{% include nav_list.html items=page.sidebar.nav %}
{% endif %}
{% endif %} {% endif %}
</div> </div>
{% endif %} {% endif %}