mirror of
https://github.com/snachodog/just-the-docs.git
synced 2025-09-13 05:13:33 -06:00
Feature: Allow unlimited multi-level navigation (#1431)
* Allow unlimited multi-level navigation This PR supersedes #462. The only user-level difference from #462 is that disambiguation of parent pages has to use either `grand_parent` or `ancestor` titles: the somewhat unnatural `section_id` and `in_section` fields are not supported. The implementation has been significantly simplified by the changes introduced in v0.7.0 of the theme. * Detect cyclic parenthood A page should not have a parent or ancestor with the same title. If it does, the location of the repeated link is marked by ∞, to facilitate debugging the navigation (and an unbounded loop leading to a build exception is avoided). * Add nav_error_report warning in main navigation When activated by `nav_error_report: true` in `_config.yml`, displays warnings about pages with the same title as their parent page or an ancestral page. * Cache site-nav with links to all pages The extra cached site-nav is used for determining breadcrumbs and children navigation, which may involve pages that are excluded from the main navigation. * Replace code for determining children by inclusion of components/nav/children.html * Update CHANGELOG.md --------- Co-authored-by: Matt Wang <matt@matthewwang.me>
This commit is contained in:
48
_includes/components/nav/children.html
Normal file
48
_includes/components/nav/children.html
Normal file
@@ -0,0 +1,48 @@
|
||||
{%- comment -%}
|
||||
Include as: {%- include components/nav/children.html node=node ancestors=title_array all=bool -%}
|
||||
Depends on: include.node, include.ancestors, include.all, nav_parenthood, nav_top_node_titles.
|
||||
Includes: components/nav/sorted.html.
|
||||
Assigns to: nav_children.
|
||||
Overwrites:
|
||||
nav_candidates, nav_child, nav_child_ok.
|
||||
{%- endcomment -%}
|
||||
|
||||
{%- assign nav_children = "" | split: "" -%}
|
||||
|
||||
{%- if include.all == true or include.node.has_children != false -%}
|
||||
|
||||
{%- assign nav_candidates = nav_parenthood
|
||||
| where: "name", include.node.title | map: "items" | first -%}
|
||||
|
||||
{%- for nav_child in nav_candidates -%}
|
||||
{%- assign nav_child_ok = true -%}
|
||||
|
||||
{%- if nav_child.grand_parent and nav_child.grand_parent != include.node.parent -%}
|
||||
{%- assign nav_child_ok = false -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- if nav_child.ancestor and nav_child.ancestor != include.node.title -%}
|
||||
{%- unless include.ancestors contains nav_child.ancestor -%}
|
||||
{%- assign nav_child_ok = false -%}
|
||||
{%- endunless -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- comment -%}
|
||||
The following check rejects nav_child as 3rd-level when include.node is 2nd-level
|
||||
and nav_child can also be 2nd-level. This is for backwards compatibility with
|
||||
existing 3-level sites.
|
||||
{%- endcomment -%}
|
||||
{%- if nav_child.grand_parent == nil and nav_child.ancestor == nil and
|
||||
nav_top_node_titles contains nav_child.parent and include.ancestors.size >= 1 -%}
|
||||
{%- assign nav_child_ok = false -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- if nav_child_ok -%}
|
||||
{%- assign nav_children = nav_children | push: nav_child -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
||||
{%- endif -%}
|
||||
|
||||
{%- include components/nav/sorted.html pages=nav_children -%}
|
||||
{%- assign nav_children = nav_sorted -%}
|
Reference in New Issue
Block a user