|
1 | 1 | {%- comment -%}
|
2 | 2 | Include as: {%- include components/breadcrumbs.html -%}
|
3 | 3 | Depends on: page, site.
|
| 4 | + Includes: components/site_nav.html. |
4 | 5 | Results in: HTML for the breadcrumbs component.
|
5 | 6 | Overwrites:
|
6 |
| - node, pages_list, parent_page, grandparent_page. |
| 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. |
7 | 10 | {%- endcomment -%}
|
8 | 11 |
|
9 |
| -{%- if page.url != "/" and page.parent -%} |
| 12 | +{%- if page.url != "/" and page.parent and page.title -%} |
10 | 13 |
|
11 | 14 | {%- capture nav_list_link -%}
|
12 | 15 | <a href="{{ page.url | relative_url }}" class="nav-list-link">
|
13 | 16 | {%- endcapture -%}
|
14 | 17 |
|
15 | 18 | {%- capture site_nav -%}
|
16 |
| -{%- include_cached components/site_nav.html -%} |
| 19 | +{%- include_cached components/site_nav.html all=true -%} |
17 | 20 | {%- endcapture -%}
|
18 | 21 |
|
19 |
| -{%- if site_nav contains nav_list_link -%} |
20 |
| - |
21 |
| - {%- capture nav_list_simple -%} |
22 |
| - <ul class="nav-list"> |
23 |
| - {%- endcapture -%} |
24 |
| - |
25 |
| - {%- capture nav_list_link_class %} class="nav-list-link"> |
26 |
| - {%- endcapture -%} |
27 |
| - |
28 |
| - {%- capture nav_category -%} |
29 |
| - <div class="nav-category"> |
30 |
| - {%- endcapture -%} |
31 |
| - |
32 |
| - {%- assign nav_anchor_splits = |
33 |
| - site_nav | split: nav_list_link | |
34 |
| - first | split: nav_category | |
35 |
| - last | split: "</a>" -%} |
36 |
| - |
37 |
| - {%- comment -%} |
38 |
| - The ordinary pages (if any) and the collections pages (if any) are separated by |
39 |
| - occurrences of nav_category. |
40 |
| - |
41 |
| - Any ancestor nav-links of the page are contained in the last group of pages, |
42 |
| - immediately preceding nav-lists. After splitting at "</a>", the anchor that |
43 |
| - was split is a potential ancestor link when the following split starts with |
44 |
| - a nav-list. |
45 |
| - |
46 |
| - The array nav_breadcrumbs is the stack of current potential ancestors of the |
47 |
| - current page. A split that contains one or more "</ul>"s requires that number |
48 |
| - of potential ancestors to be popped from the stack. |
49 |
| - |
50 |
| - The number of occurrences of a string in nav_split_next is computed by removing |
51 |
| - them all, then dividing the resulting size difference by the length of the string. |
52 |
| - {%- endcomment %} |
53 |
| - |
54 |
| - {%- assign nav_breadcrumbs = "" | split: "" -%} |
55 |
| - |
56 |
| - {%- for nav_split in nav_anchor_splits -%} |
57 |
| - {%- unless forloop.last -%} |
58 |
| - |
59 |
| - {%- assign nav_split_next = nav_anchor_splits[forloop.index] | strip -%} |
60 |
| - |
61 |
| - {%- assign nav_split_test = |
62 |
| - nav_split_next | remove_first: nav_list_simple | prepend: nav_list_simple -%} |
63 |
| - {%- if nav_split_test == nav_split_next -%} |
64 |
| - {%- assign nav_breadcrumb_link = |
65 |
| - nav_split | split: "<a " | last | prepend: "<a " | |
66 |
| - replace: nav_list_link_class, ">" | append: "</a>" -%} |
67 |
| - {%- assign nav_breadcrumbs = nav_breadcrumbs | push: nav_breadcrumb_link -%} |
68 |
| - {%- endif -%} |
69 |
| - |
70 |
| - {%- if nav_split_next contains "</ul>" -%} |
71 |
| - {%- assign nav_list_end_less = nav_split_next | remove: "</ul>" -%} |
72 |
| - {%- assign nav_list_end_count = |
73 |
| - nav_split_next.size | minus: nav_list_end_less.size | divided_by: 5 -%} |
74 |
| - {% for nav_end_index in (1..nav_list_end_count) %} |
75 |
| - {%- assign nav_breadcrumbs = nav_breadcrumbs | pop -%} |
76 |
| - {%- endfor -%} |
77 |
| - {%- endif -%} |
78 |
| - |
79 |
| - {%- endunless -%} |
80 |
| - {%- endfor -%} |
| 22 | +{%- capture nav_list_simple -%} |
| 23 | +<ul class="nav-list"> |
| 24 | +{%- endcapture -%} |
81 | 25 |
|
82 |
| - {%- assign nav_parent_link = nav_breadcrumbs[-1] -%} |
83 |
| - {%- assign nav_grandparent_link = nav_breadcrumbs[-2] -%} |
| 26 | +{%- capture nav_list_link_class %} class="nav-list-link"> |
| 27 | +{%- endcapture -%} |
84 | 28 |
|
85 |
| -{%- else -%} |
| 29 | +{%- capture nav_category -%} |
| 30 | +<div class="nav-category"> |
| 31 | +{%- endcapture -%} |
86 | 32 |
|
87 |
| - {%- comment -%} |
88 |
| - Pages whose links are excluded from the main navigation may still have |
89 |
| - breadcrumbs. Determining them appears to require inspecting the front matter |
90 |
| - of all the pages in the same group. For sites with 100s of pages, this is too |
91 |
| - inefficient in Jekyll 3 (also when the for-loop is replaced by where-filters). |
92 |
| - {%- endcomment -%} |
| 33 | +{%- assign nav_anchor_splits = |
| 34 | + site_nav | split: nav_list_link | |
| 35 | + first | split: nav_category | |
| 36 | + last | split: "</a>" -%} |
93 | 37 |
|
94 |
| - {%- assign pages_list = site[page.collection] | default: site.html_pages -%} |
| 38 | +{%- comment -%} |
| 39 | + The ordinary pages (if any) and the collections pages (if any) are separated by |
| 40 | + occurrences of nav_category. |
95 | 41 |
|
96 |
| - {%- assign parent_page = nil -%} |
97 |
| - {%- assign grandparent_page = nil -%} |
98 |
| - |
99 |
| - {%- for node in pages_list -%} |
| 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. |
100 | 50 |
|
101 |
| - {%- if node.has_children and page.grand_parent -%} |
| 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 %} |
102 | 54 |
|
103 |
| - {%- if node.title == page.parent and node.parent == page.grand_parent -%} |
104 |
| - {%- assign parent_page = node -%} |
105 |
| - {%- endif -%} |
106 |
| - {%- if node.title == page.grand_parent -%} |
107 |
| - {%- assign grandparent_page = node -%} |
108 |
| - {%- endif -%} |
109 |
| - {%- if parent_page and grandparent_page -%} |
110 |
| - {%- break -%} |
111 |
| - {%- endif -%} |
| 55 | +{%- assign nav_breadcrumbs = "" | split: "" -%} |
112 | 56 |
|
113 |
| - {%- elsif node.has_children and node.title == page.parent and node.parent == nil -%} |
| 57 | +{%- for nav_split in nav_anchor_splits -%} |
| 58 | +{%- unless forloop.last -%} |
114 | 59 |
|
115 |
| - {%- assign parent_page = node -%} |
116 |
| - {%- break -%} |
| 60 | +{%- assign nav_split_next = nav_anchor_splits[forloop.index] | strip -%} |
117 | 61 |
|
118 |
| - {%- endif -%} |
| 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 -%} |
119 | 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 -%} |
120 | 77 | {%- endfor -%}
|
121 |
| - |
122 |
| - {%- capture nav_parent_link -%} |
123 |
| - <a href="{{ parent_page.url | relative_url }}">{{ page.parent }}</a> |
124 |
| - {%- endcapture -%} |
125 |
| - |
126 |
| - {%- if page.grand_parent %} |
127 |
| - {%- capture nav_grandparent_link -%} |
128 |
| - <a href="{{ grandparent_page.url | relative_url }}">{{ page.grand_parent }}</a> |
129 |
| - {%- endcapture -%} |
130 |
| - {%- endif -%} |
131 |
| - |
132 | 78 | {%- endif -%}
|
133 | 79 |
|
| 80 | +{%- endunless -%} |
| 81 | +{%- endfor -%} |
| 82 | + |
134 | 83 | <nav aria-label="Breadcrumb" class="breadcrumb-nav">
|
135 | 84 | <ol class="breadcrumb-nav-list">
|
136 |
| - {%- if nav_grandparent_link %} |
137 |
| - <li class="breadcrumb-nav-list-item">{{ nav_grandparent_link }}</li> |
138 |
| - {%- endif %} |
139 |
| - <li class="breadcrumb-nav-list-item">{{ nav_parent_link }}</li> |
| 85 | + {%- for nav_breadcrumb in nav_breadcrumbs %} |
| 86 | + <li class="breadcrumb-nav-list-item">{{ nav_breadcrumb }}</li> |
| 87 | + {%- endfor %} |
140 | 88 | <li class="breadcrumb-nav-list-item"><span>{{ page.title }}</span></li>
|
141 | 89 | </ol>
|
142 | 90 | </nav>
|
143 | 91 |
|
| 92 | +{% if site.nav_error_report %} |
| 93 | +{{ nav_error_report }} |
| 94 | +{% endif %} |
| 95 | + |
144 | 96 | {%- endif -%}
|
0 commit comments