-
Notifications
You must be signed in to change notification settings - Fork 33
/
sidebar.html
executable file
·146 lines (129 loc) · 5.76 KB
/
sidebar.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{% comment %}
Partial for the textbook sidebar. Renders each chapter and its sections from
_data/toc.yml .
Much of the logic here is to add active classes to the currently active
section. The currently active section / chapter should be highlighted in the
sidebar.
If a chapter or any of its sections are the current page, we should display the
chapter's sections. Otherwise, we hide the sections to keep the sidebar short.
We also prefix the sidebar entries with the chapter/section number. We assume
a 1-level nesting; we will label 1.2, but not 1.2.1.
{% endcomment %}
{% assign chapter_num = 1 %}
<nav id="js-sidebar" class="c-textbook__sidebar">
{% if site.textbook_logo %}<a href="{{ site.textbook_logo_link }}"><img src="{{ site.textbook_logo | relative_url }}" class="textbook_logo" id="sidebar-logo" data-turbolinks-permanent/></a>{% endif %}
<h2 class="c-sidebar__title">{{ site.title }}</h2>
<ul class="c-sidebar__chapters">
{% for chapter in site.data.toc %}
{% comment %}
If the entry is a divider, render a divider and move to next entry.
{% endcomment %}
{% if chapter.divider %}
<li class="c-sidebar__divider"></li>
{% continue %}
{% elsif chapter.header %}
<li><h2 class="c-sidebar__title">{{ chapter.header }}</li>
{% continue %}
{% endif %}
{% comment %}
If the entry is the current page, assign a CSS class to highlight it.
{% endcomment %}
{% if page.url contains chapter.url %}
{% assign active_class = "c-sidebar__entry--active" %}
{% else %}
{% assign active_class = "" %}
{% endif %}
{% assign topUrl = chapter.url | relative_url %}
{% unless chapter.external == true %}
{% assign topUrl = topUrl | append: '.html' %}
{% endunless %}
<li class="c-sidebar__chapter">
<a class="c-sidebar__entry {{ active_class }}"
href="{{ topUrl }}"
>
{% unless chapter.not_numbered or site.number_toc_chapters != true %}
{{ chapter_num }}.
{% endunless %}
{{ chapter.title }}
</a>
{% if chapter.sections %}
{% comment %}
By default, all sections are hidden. We show a chapter's sections
if the chapter or any of its sections are the current page.
{% endcomment %}
{% assign any_section_active = 0 %}
{% for section in chapter.sections %}
{% if page.url contains section.url or chapter.expand_sections %}
{% assign any_section_active = 1 %}
{% elsif section.subsections %}
{% for subsection in section.subsections %}
{% if page.url contains subsection.url %}
{% assign any_section_active = 1 %}
{% endif %}
{% endfor %}
{% elsif page.url contains chapter.url %}
{% assign any_section_active = 1 %}
{% endif %}
{% endfor %}
{% if any_section_active > 0 or site.collapse_inactive_chapters == false %}
{% assign hide_section_class = "" %}
{% else %}
{% assign hide_section_class = "u-hidden-visually" %}
{% endif %}
{% assign section_num = 1 %}
<ul class="c-sidebar__sections {{ hide_section_class }}">
{% for section in chapter.sections %}
{% comment %}
If the entry is the current page, assign a CSS class to highlight
it.
{% endcomment %}
{% if page.url contains section.url %}
{% assign active_class = "c-sidebar__entry--active" %}
{% else %}
{% assign active_class = "" %}
{% endif %}
<li class="c-sidebar__section">
<a class="c-sidebar__entry {{ active_class }}"
href="{{ section.url | relative_url | append: '.html'}}"
>
{% unless chapter.not_numbered or section.not_numbered or site.number_toc_chapters != true %}
{{ chapter_num }}.{{ section_num }}
{% endunless %}
{{ section.title }}
</a>
{% assign subsection_num = 1 %}
{% for subsection in section.subsections %}
{% comment %}
Now add sub-sections. These will always be shown if they exist.
{% endcomment %}
{% if page.url contains subsection.url %}
{% assign active_class = "c-sidebar__entry--active" %}
{% else %}
{% assign active_class = "" %}
{% endif %}
<li class="c-sidebar__subsection">
<a class="c-sidebar__entry {{ active_class }}"
href="{{ subsection.url | relative_url | append: '.html'}}"
>
{% unless chapter.not_numbered or section.not_numbered or subsection.not_numbered or site.number_toc_chapters != true %}
{{ chapter_num }}.{{ section_num }}.{{ subsection_num }}
{% assign subsection_num = subsection_num | plus: 1 %}
{% endunless %}
{{ subsection.title }}
</a>
{% endfor %}
</li>
{% unless chapter.not_numbered or section.not_numbered %}
{% assign section_num = section_num | plus: 1 %}
{% endunless %}
{% endfor %}
</ul>
{% endif %}
</li>
{% unless chapter.not_numbered %}
{% assign chapter_num = chapter_num | plus: 1 %}
{% endunless %}
{% endfor %}
</ul>
<p class="sidebar_footer">{{ site.sidebar_footer_text }}</p>
</nav>