1+ {%- comment -%}
2+ Include as: {%- include components/breadcrumbs.html -%}
3+ Depends on: page, site.
4+ Includes: components/site_nav.html.
5+ Results in: HTML for the breadcrumbs component.
6+ Overwrites:
7+ nav_list_link, site_nav, nav_list_simple, nav_list_link_class, nav_category,
8+ nav_anchor_splits, nav_breadcrumbs, nav_split, nav_split_next, nav_split_test,
9+ nav_breadcrumb_link, nav_list_end_less, nav_list_end_count, nav_end_index, nav_breadcrumb.
10+ {%- endcomment -%}
11+
12+ {%- if page.url != "/" and page.parent and page.title -%}
13+
14+ {%- capture nav_list_link -%}
15+ < a href ="{{ page.url | relative_url }} " class ="nav-list-link ">
16+ {%- endcapture -%}
17+
18+ {%- capture site_nav -%}
19+ {%- include_cached components/site_nav.html all=true -%}
20+ {%- endcapture -%}
21+
22+ {%- capture nav_list_simple -%}
23+ < ul class ="nav-list ">
24+ {%- endcapture -%}
25+
26+ {%- capture nav_list_link_class %} class="nav-list-link">
27+ {%- endcapture -%}
28+
29+ {%- capture nav_category -%}
30+ < div class ="nav-category ">
31+ {%- endcapture -%}
32+
33+ {%- assign nav_anchor_splits =
34+ site_nav | split: nav_list_link |
35+ first | split: nav_category |
36+ last | split: "</ a > " -%}
37+
38+ {%- comment -%}
39+ The ordinary pages (if any) and the collections pages (if any) are separated by
40+ occurrences of nav_category.
41+
42+ Any ancestor nav-links of the page are contained in the last group of pages,
43+ immediately preceding nav-lists. After splitting at "</ a> ", the anchor that
44+ was split is a potential ancestor link when the following split starts with
45+ a nav-list.
46+
47+ The array nav_breadcrumbs is the stack of current potential ancestors of the
48+ current page. A split that contains one or more "</ ul> "s requires that number
49+ of potential ancestors to be popped from the stack.
50+
51+ The number of occurrences of a string in nav_split_next is computed by removing
52+ them all, then dividing the resulting size difference by the length of the string.
53+ {%- endcomment %}
54+
55+ {%- assign nav_breadcrumbs = "" | split: "" -%}
56+
57+ {%- for nav_split in nav_anchor_splits -%}
58+ {%- unless forloop.last -%}
59+
60+ {%- assign nav_split_next = nav_anchor_splits[forloop.index] | strip -%}
61+
62+ {%- assign nav_split_test =
63+ nav_split_next | remove_first: nav_list_simple | prepend: nav_list_simple -%}
64+ {%- if nav_split_test == nav_split_next -%}
65+ {%- assign nav_breadcrumb_link =
66+ nav_split | split: "< a " | last | prepend: "< a " |
67+ replace: nav_list_link_class, "> " | append: "</ a > " -%}
68+ {%- assign nav_breadcrumbs = nav_breadcrumbs | push: nav_breadcrumb_link -%}
69+ {%- endif -%}
70+
71+ {%- if nav_split_next contains "</ ul> " -%}
72+ {%- assign nav_list_end_less = nav_split_next | remove: "</ ul> " -%}
73+ {%- assign nav_list_end_count =
74+ nav_split_next.size | minus: nav_list_end_less.size | divided_by: 5 -%}
75+ {% for nav_end_index in (1..nav_list_end_count) %}
76+ {%- assign nav_breadcrumbs = nav_breadcrumbs | pop -%}
77+ {%- endfor -%}
78+ {%- endif -%}
79+
80+ {%- endunless -%}
81+ {%- endfor -%}
82+
83+ < nav aria-label ="Breadcrumb " class ="breadcrumb-nav ">
84+ < ol class ="breadcrumb-nav-list ">
85+ {%- for nav_breadcrumb in nav_breadcrumbs %}
86+ < li class ="breadcrumb-nav-list-item "> {{ nav_breadcrumb }}</ li >
87+ {%- endfor %}
88+ < li class ="breadcrumb-nav-list-item "> < span > {{ page.title }}</ span > </ li >
89+ </ ol >
90+ </ nav >
91+
92+ {% if site.nav_error_report %}
93+ {{ nav_error_report }}
94+ {% endif %}
95+
96+ {%- endif -%}
0 commit comments