Skip to content

Commit

Permalink
Update just-the-docs to 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
muryoimpl committed Jan 15, 2024
1 parent df540ae commit d5dfc50
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 144 deletions.
48 changes: 28 additions & 20 deletions _includes/components/breadcrumbs.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,38 @@
Depends on: page, site.
Results in: HTML for the breadcrumbs component.
Overwrites:
pages_list, parent_page, grandparent_page.
node, pages_list, parent_page, grandparent_page.
{%- endcomment -%}

{%- if page.url != "/" and page.parent -%}

{%- assign pages_list = site[page.collection]
| default: site.html_pages
| where_exp: "item", "item.title != nil"
| where_exp: "item", "item.has_children != nil" -%}

{%- if page.grand_parent -%}
{%- assign parent_page = pages_list
| where: "title", page.parent
| where: "parent", page.grand_parent
| first -%}
{%- assign grandparent_page = pages_list
| where: "title", page.grand_parent
| first -%}
{%- else -%}
{%- assign parent_page = pages_list
| where: "title", page.parent
| where_exp: "item", "item.parent == nil"
| first -%}
{%- endif -%}
{%- assign pages_list = site[page.collection] | default: site.html_pages -%}

{%- assign parent_page = nil -%}
{%- assign grandparent_page = nil -%}

{%- for node in pages_list -%}

{%- if node.has_children and page.grand_parent -%}

{%- if node.title == page.parent and node.parent == page.grand_parent -%}
{%- assign parent_page = node -%}
{%- endif -%}
{%- if node.title == page.grand_parent -%}
{%- assign grandparent_page = node -%}
{%- endif -%}
{%- if parent_page and grandparent_page -%}
{%- break -%}
{%- endif -%}

{%- elsif node.has_children and node.title == page.parent and node.parent == nil -%}

{%- assign parent_page = node -%}
{%- break -%}

{%- endif -%}

{%- endfor -%}

<nav aria-label="Breadcrumb" class="breadcrumb-nav">
<ol class="breadcrumb-nav-list">
Expand Down
75 changes: 75 additions & 0 deletions _includes/components/nav.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{%- comment -%}
Include as: {%- include components/nav.html pages=pages -%}
Depends on: include.pages.
Results in: HTML for the navigation panel.
Includes:
sorted_pages.html
Overwrites:
nav_pages, first_level_pages, second_level_pages, third_level_pages,
node, children_list, child, grand_children_list, grand_child.
{%- endcomment -%}

{%- assign nav_pages = include.pages
| where_exp: "item", "item.title != nil"
| where_exp: "item", "item.nav_exclude != true" -%}

{%- include sorted_pages.html pages = nav_pages -%}

{%- comment -%}
It might be more efficient to sort the pages at each level separately.
{%- endcomment -%}

{%- assign first_level_pages = sorted_pages
| where_exp: "item", "item.parent == nil" -%}
{%- assign second_level_pages = sorted_pages
| where_exp: "item", "item.parent != nil"
| where_exp: "item", "item.grand_parent == nil" -%}
{%- assign third_level_pages = sorted_pages
| where_exp: "item", "item.grand_parent != nil" -%}

<ul class="nav-list">
{%- for node in first_level_pages -%}
<li class="nav-list-item">
{%- if node.has_children -%}
<button class="nav-list-expander btn-reset" aria-label="toggle items in {{ node.title }} category" aria-pressed="false">
<svg viewBox="0 0 24 24" aria-hidden="true"><use xlink:href="#svg-arrow-right"></use></svg>
</button>
{%- endif -%}
<a href="{{ node.url | relative_url }}" class="nav-list-link">{{ node.title }}</a>
{%- if node.has_children -%}
{%- assign children_list = second_level_pages
| where: "parent", node.title -%}
{%- if node.child_nav_order == 'desc' or node.child_nav_order == 'reversed' -%}
{%- assign children_list = children_list | reverse -%}
{%- endif -%}
<ul class="nav-list">
{%- for child in children_list -%}
<li class="nav-list-item">
{%- if child.has_children -%}
<button class="nav-list-expander btn-reset" aria-label="toggle items in {{ child.title }} category" aria-pressed="false">
<svg viewBox="0 0 24 24" aria-hidden="true"><use xlink:href="#svg-arrow-right"></use></svg>
</button>
{%- endif -%}
<a href="{{ child.url | relative_url }}" class="nav-list-link">{{ child.title }}</a>
{%- if child.has_children -%}
{%- assign grand_children_list = third_level_pages
| where: "parent", child.title
| where: "grand_parent", node.title -%}
{%- if child.child_nav_order == 'desc' or child.child_nav_order == 'reversed' -%}
{%- assign grand_children_list = grand_children_list | reverse -%}
{%- endif -%}
<ul class="nav-list">
{%- for grand_child in grand_children_list -%}
<li class="nav-list-item">
<a href="{{ grand_child.url | relative_url }}" class="nav-list-link">{{ grand_child.title }}</a>
</li>
{%- endfor -%}
</ul>
{%- endif -%}
</li>
{%- endfor -%}
</ul>
{%- endif -%}
</li>
{%- endfor -%}
</ul>
61 changes: 5 additions & 56 deletions _includes/components/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
Depends on: page(?), site.
Results in: HTML for the side bar.
Includes:
title.html, nav.html, nav_footer_custom.html
Overwrites:
pages_top_size, collections_size, collection_entry,
collection_key, collection_value, collection, nav_footer_custom.
title.html, components/site_nav.html, nav_footer_custom.html
Overwrites:
nav_footer_custom.
Should not be cached, because nav_footer_custom.html might depend on page.
{%- endcomment -%}

Expand All @@ -17,58 +16,8 @@
<svg viewBox="0 0 24 24" class="icon" aria-hidden="true"><use xlink:href="#svg-menu"></use></svg>
</button>
</div>
<nav aria-label="Main" id="site-nav" class="site-nav">
{% assign pages_top_size = site.html_pages
| where_exp:"item", "item.title != nil"
| where_exp:"item", "item.parent == nil"
| where_exp:"item", "item.nav_exclude != true"
| size %}
{% if pages_top_size > 0 %}
{% include_cached nav.html pages=site.html_pages %}
{% endif %}
{%- if site.nav_external_links -%}
<ul class="nav-list">
{%- for node in site.nav_external_links -%}
<li class="nav-list-item external">
<a href="{{ node.url | absolute_url }}" class="nav-list-link external">
{{ node.title }}
{% unless node.hide_icon %}<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>{% endunless %}
</a>
</li>
{%- endfor -%}
</ul>
{%- endif -%}
{% if site.just_the_docs.collections %}
{% assign collections_size = site.just_the_docs.collections | size %}
{% for collection_entry in site.just_the_docs.collections %}
{% assign collection_key = collection_entry[0] %}
{% assign collection_value = collection_entry[1] %}
{% assign collection = site[collection_key] %}
{% if collection_value.nav_exclude != true %}
{% if collections_size > 1 or pages_top_size > 0 %}
{% if collection_value.nav_fold == true %}
<ul class="nav-list nav-category-list">
<li class="nav-list-item{% if page.collection == collection_key %} active{% endif %}">
{%- if collection.size > 0 -%}
<button class="nav-list-expander btn-reset" aria-label="Toggle collection {{ collection_value.name }}" aria-pressed="{% if page.collection == collection_key %}true{% else %}false{% endif %}">
<svg viewBox="0 0 24 24" aria-hidden="true"><use xlink:href="#svg-arrow-right"></use></svg>
</button>
{%- endif -%}
<div class="nav-category">{{ collection_value.name }}</div>
{% include_cached nav.html pages=collection %}
</li>
</ul>
{% else %}
<div class="nav-category">{{ collection_value.name }}</div>
{% include_cached nav.html pages=collection %}
{% endif %}
{% else %}
{% include_cached nav.html pages=collection %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
</nav>

{% include_cached components/site_nav.html %}

{% capture nav_footer_custom %}
{%- include nav_footer_custom.html -%}
Expand Down
67 changes: 67 additions & 0 deletions _includes/components/site_nav.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{%- comment -%}
Include as: {%- include_cached components/site_nav.html -%}
Depends on: site.
Results in: HTML for the site-nav.
Includes:
components/nav.html
Overwrites:
pages_top_size, collections_size, collection_entry,
collection_key, collection_value, collection.
{%- endcomment -%}

<nav aria-label="Main" id="site-nav" class="site-nav">
{% assign pages_top_size = site.html_pages
| where_exp:"item", "item.title != nil"
| where_exp:"item", "item.parent == nil"
| where_exp:"item", "item.nav_exclude != true"
| size %}
{% if pages_top_size > 0 %}
{% include components/nav.html pages=site.html_pages %}
{% endif %}
{%- if site.nav_external_links -%}
<ul class="nav-list">
{%- for node in site.nav_external_links -%}
<li class="nav-list-item external">
<a href="{{ node.url | absolute_url }}" class="nav-list-link external"
{% if node.opens_in_new_tab or node.opens_in_new_tab == nil and site.nav_external_links_new_tab %}
target="_blank" rel="noopener noreferrer"
{% endif %}
>
{{ node.title }}
{% unless node.hide_icon %}<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>{% endunless %}
</a>
</li>
{%- endfor -%}
</ul>
{%- endif -%}
{% if site.just_the_docs.collections %}
{% assign collections_size = site.just_the_docs.collections | size %}
{% for collection_entry in site.just_the_docs.collections %}
{% assign collection_key = collection_entry[0] %}
{% assign collection_value = collection_entry[1] %}
{% assign collection = site[collection_key] %}
{% if collection_value.nav_exclude != true %}
{% if collections_size > 1 or pages_top_size > 0 %}
{% if collection_value.nav_fold == true %}
<ul class="nav-list nav-category-list">
<li class="nav-list-item">
{%- if collection.size > 0 -%}
<button class="nav-list-expander btn-reset" aria-label="Toggle collection {{ collection_value.name }}" aria-pressed="false">
<svg viewBox="0 0 24 24" aria-hidden="true"><use xlink:href="#svg-arrow-right"></use></svg>
</button>
{%- endif -%}
<div class="nav-category">{{ collection_value.name }}</div>
{% include components/nav.html pages=collection %}
</li>
</ul>
{% else %}
<div class="nav-category">{{ collection_value.name }}</div>
{% include components/nav.html pages=collection %}
{% endif %}
{% else %}
{% include components/nav.html pages=collection %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
</nav>
Loading

0 comments on commit d5dfc50

Please sign in to comment.