Skip to content

Commit cb4e3ed

Browse files
committed
Experimenting with styles
1 parent 9b68589 commit cb4e3ed

File tree

2 files changed

+216
-0
lines changed

2 files changed

+216
-0
lines changed

_includes/elements/indices.html

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{% assign collection_list = site.collections %}
2+
3+
{% assign ordered = '' | split: '' %}
4+
{% assign endered = '' | split: '' %}
5+
{% assign unorder = '' | split: '' %}
6+
{% for collection in collection_list %}
7+
{% unless collection.label == 'posts' or collection.docs.size == 0 %}
8+
{% if collection.tab-order %}
9+
{% if collection.tab-order < 0 %}{% assign endered = endered | push: collection %}
10+
{% else %}{% assign ordered = ordered | push: collection %}
11+
{% endif %}
12+
{% else %}{% assign unorder = unorder | push: collection %}
13+
{% endif %}
14+
{% endunless %}
15+
16+
{%- comment %} delegate to extension point for actual rendering of link list {% endcomment -%}
17+
{% include render_indices.liquid doc_list=doc_list collection_label=collection.label page_title=page.title %}
18+
{% endfor %}
19+
{% assign ordered = ordered | sort: 'tab-order' %}
20+
{% assign endered = endered | sort: 'tab-order' | reverse %}
21+
{% assign collection_list = ordered | concat: unorder | concat: endered %}
22+
23+
{%- comment %} these fixed items (search & collection tabs) need to be above the tab segments {% endcomment -%}
24+
25+
<div id="sidebar-collection-tabs" class="ui inverted vertical secondary pointing fixed menu">
26+
{% for collection in collection_list %}
27+
{% capture tab_class %}{% if forloop.first %}active {% endif %}item{% endcapture %}
28+
<a class="{{ tab_class }}" data-tab="{{ collection.label | downcase }}">{{ collection.title }}</a>
29+
{% endfor %}
30+
</div>
31+
32+
<div class="ui inverted large fixed menu">
33+
<div class="item">
34+
{% include elements/search.html %}
35+
</div>
36+
</div>

_includes/render_indices.liquid

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
{%- comment -%}
2+
3+
render_indices
4+
creates the individual links in the sidebar
5+
- pages, layouts, and guide-indexes are indented when parented
6+
7+
params:
8+
doc_list=<array of document objects to create links for>
9+
collection_label=<name of collection the docs belong to>
10+
page_title=<title of the calling page>
11+
no_indent=<pipe delimited list of layouts that should not be indented>
12+
13+
{%- endcomment -%}
14+
15+
{%- comment -%}push prior state{%- endcomment -%}
16+
{%- assign __no_indenting = no_indenting -%}
17+
{%- assign __link = link -%}
18+
{%- assign __url = url -%}
19+
{%- assign __item_id = item_id -%}
20+
{%- assign __item_class = item_class -%}
21+
{%- assign __path_bits = path_bits -%}
22+
{%- assign __n = n -%}
23+
{%- assign __indent = indent -%}
24+
25+
{% assign no_indenting = include.no_indent | split: '|' %}
26+
{% for doc in include.doc_list %}
27+
{% capture link %}{{ doc.title }}{% endcapture %}
28+
{% capture url %}{{ doc.url }}#/{{ include.collection_label | downcase }}/{% endcapture %}
29+
{% capture item_id %}{% if doc.title == include.page_title %} id="active-page-index"{% endif %}{% endcapture %}
30+
{% capture item_class %}{% if doc.title == include.page_title %}active {% endif %}item{% endcapture %}
31+
{% unless no_indenting contains doc.layout %}
32+
{% assign path_bits = doc.relative_path | split: '.' | first | split: '/' %}
33+
{% assign n = path_bits.size | minus: 2 %}
34+
{% if n == 0 %}{% assign item_class = item_class | append: ' header' %}{% endif %}
35+
{% if n > 3 %}{% assign n = 3 %}{% endif %}
36+
{% capture indent %}{% for i in (1..n) %}&ensp;{% endfor %}{% endcapture %}
37+
{% capture link %}{{ indent }}{{ doc.title }}{% endcapture %}
38+
{% endunless %}
39+
<a{{ item_id }} class="very tight smaller text {{ item_class }}" href="{{ site.baseurl }}{{ url }}">{{ link }}</a>
40+
{% endfor %}
41+
42+
{% capture tab_class %}ui {% if forloop.first %}active {% endif %}inverted tab segment{% endcapture %}
43+
<div class="{{ tab_class }}" data-tab="{{ collection.label | downcase }}">
44+
<div class="ui inverted link list">
45+
{% assign doc_list = collection.docs %}
46+
47+
{% unless collection.ignore-page-order %}
48+
{% assign ordered_doc_list = '' | split: '' %}
49+
50+
{%- comment %} first, calculate max_depth as deepest level index {% endcomment -%}
51+
{% assign max_depth = 0 %}
52+
{% for doc in doc_list %}
53+
{% assign depth = doc.path | split:'/' | size | minus:2 %} {%- comment %} minus one to convert from length to index, minus two to ignore root collection directory (e.g. _guides/) {% endcomment -%}
54+
{% if depth > max_depth %}{% assign max_depth = depth %}{% endif %}
55+
{% endfor %}
56+
57+
{%- comment %} separate docs into levels, and sort by user-defined order value {% endcomment -%}
58+
{%- comment %} ordering: 0 is first, -1 is last, undefined orders go in the middle alphabetically
59+
first ---------> middle ----------------------> last --------->|
60+
[0..positive N]..[no order defined, use alpha]..[negative N..-1]
61+
{% endcomment -%}
62+
{% assign leveled = '' | split: '' %}
63+
{% for i in (0..max_depth) %}
64+
{% assign new = '' | split: '' %}
65+
{% assign ordered = '' | split: '' %}
66+
{% assign endered = '' | split: '' %}
67+
{% assign unorder = '' | split: '' %}
68+
{% for doc in doc_list %}
69+
{% assign depth = doc.path | split:'/' | size | minus:2 %}
70+
{% if depth == i %}
71+
{% if doc.order %}
72+
{% if doc.order < 0 %}{% assign endered = endered | push: doc %}
73+
{% else %}{% assign ordered = ordered | push: doc %}
74+
{% endif %}
75+
{% else %}{% assign unorder = unorder | push: doc %}
76+
{% endif %}
77+
{% endif %}
78+
{% endfor %}
79+
{% assign ordered = ordered | sort: 'order' %}
80+
{% assign endered = endered | sort: 'order' %}
81+
{% assign new = ordered | concat: unorder | concat: endered %}
82+
{% assign leveled = leveled | push: new %}
83+
{% endfor %}
84+
85+
{%- comment %} set root and make current be root {% endcomment -%}
86+
{%- assign root = '' | split: '' -%}
87+
{%- assign root = root | push: 0 -%} {%- comment %} level index {% endcomment -%}
88+
{%- assign root = root | push: 0 -%} {%- comment %} group index {% endcomment -%}
89+
{%- assign curr = root -%}
90+
{%- comment %} create a stack and initialize it with the root node {% endcomment -%}
91+
{%- assign stack = '' | split: '' -%}
92+
{%- assign stack = stack | push: root -%}
93+
94+
{%- comment %} fake a while loop with a fake infinite loop, being sure to bail when all nodes are processed {% endcomment -%}
95+
{%- assign enough = doc_list.size | times: 2 -%} {%- comment %} estimate the worst case number of iterations required {% endcomment -%}
96+
{%- for ever in (0..enough) -%}
97+
{%- if stack.size == 0 %}{% break %}{% endif -%}
98+
{%- comment %} if we have a current node, record it, push next sibling on the stack, and move on to first child {% endcomment -%}
99+
{%- if curr -%}
100+
{%- comment %} print curr {% endcomment -%}
101+
{%- assign l = curr[0] -%} {%- comment %} level {% endcomment -%}
102+
{%- assign e = curr[1] -%} {%- comment %} entry {% endcomment -%}
103+
{%- assign d = leveled[l][e] -%} {%- comment %} doc {% endcomment -%}
104+
{%- assign p = d.path | split: '/' -%} {%- comment %} path parts {% endcomment -%}
105+
{%- assign t = p | last | split: '.' | first -%} {%- comment %} title, minus file extension {% endcomment -%}
106+
{%- assign _ = p | pop -%} {%- comment %} drop file part {% endcomment -%}
107+
{%- assign s = _ | last -%} {%- comment %} section (containing folder) {% endcomment -%}
108+
109+
{%- comment %} record node docs in visitation order {% endcomment -%}
110+
{%- assign ordered_doc_list = ordered_doc_list | push: d -%}
111+
112+
{%- comment %} clear current node now that it's recorded {% endcomment -%}
113+
{%- assign curr = nil -%}
114+
115+
{%- comment %} find and push next sibling in current group (if any) {% endcomment -%}
116+
{%- assign e1 = e | plus: 1 -%}
117+
{%- assign en = leveled[l].size | minus: 1 -%}
118+
{%- for ei in (e1..en) -%} {%- comment %} look forward from current entry's index {% endcomment -%}
119+
{%- assign di = leveled[l][ei] -%}
120+
{%- assign pi = di.path | split: '/' -%}
121+
{%- assign pi = pi | pop -%}
122+
{%- assign si = pi | last -%}
123+
{%- if si == s %} {%- comment %} siblings share the same section {% endcomment -%}
124+
{%- comment %} ..and each higher path component also needs to match so we don't falsely select a separate subtree using the same names {% endcomment -%}
125+
{%- assign full_match = true -%}
126+
{%- for i in (0..l) -%}{%- unless pi[i] == p[i] -%}{%- assign full_match = false -%}{%- break -%}{%- endunless -%}{%- endfor -%}
127+
{%- if full_match -%}
128+
{%- assign next_item = '' | split: '' -%}
129+
{%- assign next_item = next_item | push: l -%}
130+
{%- assign next_item = next_item | push: ei -%}
131+
{%- assign stack = stack | push: next_item -%}
132+
{%- break -%}
133+
{%- endif -%}
134+
{%- endif -%}
135+
{%- endfor -%}
136+
137+
{%- comment %} find and set curr to first matching child in next level group (if any) {% endcomment -%}
138+
{%- if l < max_depth -%}
139+
{%- assign l1 = l | plus: 1 -%}
140+
{%- assign ei = 0 -%} {%- comment %} start at beginning of entry group {% endcomment -%}
141+
{%- for di in leveled[l1] -%}
142+
{%- assign pi = di.path | split:'/' -%}
143+
{%- if pi[l1] == t %} {%- comment %} children are found in directories that match their parent's title {% endcomment -%}
144+
{%- comment %} ..and each higher path component also needs to match so we don't falsely select a separate subtree using the same names {% endcomment -%}
145+
{%- assign full_match = true -%}
146+
{%- for i in (0..l) -%}{%- unless pi[i] == p[i] -%}{%- assign full_match = false -%}{%- break -%}{%- endunless -%}{%- endfor -%}
147+
{%- if full_match -%}
148+
{%- assign curr = '' | split: '' -%}
149+
{%- assign curr = curr | push: l1 -%}
150+
{%- assign curr = curr | push: ei -%}
151+
{%- break -%}
152+
{%- endif -%}
153+
{%- endif -%}
154+
{%- assign ei = ei | plus: 1 -%}
155+
{%- endfor -%}
156+
{%- endif -%}
157+
158+
{%- comment %} if no current node, pop from stack and start the loop over {% endcomment -%}
159+
{%- else -%}
160+
{%- assign curr = stack | last -%}
161+
{%- assign stack = stack | pop %}
162+
{%- endif -%}
163+
{%- endfor -%}
164+
165+
{% assign doc_list = ordered_doc_list %}
166+
{% endunless %}
167+
168+
</div>
169+
170+
</div>
171+
172+
{%- comment -%}pop prior state{%- endcomment -%}
173+
{%- assign indent = __indent -%}
174+
{%- assign n = __n -%}
175+
{%- assign path_bits = __path_bits -%}
176+
{%- assign item_class = __item_class -%}
177+
{%- assign item_id = __item_id -%}
178+
{%- assign url = __url -%}
179+
{%- assign link = __link -%}
180+
{%- assign no_indenting = __no_indenting -%}

0 commit comments

Comments
 (0)