Skip to content

Commit e7e3e17

Browse files
committedFeb 4, 2019
Auto-Generated Table of Contents in Sidebar
1 parent 4025d7c commit e7e3e17

9 files changed

+147
-61
lines changed
 

‎_includes/sidebar.html

+53-55
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,21 @@
66
{% assign pageUrlWithoutExt = page.url | split: '.html' | first %}
77
{% assign childPages = site.pages | where: 'version', targetVersion | where: 'parent', pageUrlWithoutExt %}
88
{% assign siblingPages = site.pages | where: 'version', targetVersion | where: 'parent', page.parent %}
9-
<!-- Debug Output -->
10-
<ul class="debug">
11-
<li>Path: {{ page.path | jsonify }}</li>
12-
<li>URL: {{ page.url | jsonify }}</li>
13-
<li>URL (no ext): {{ pageUrlWithoutExt | jsonify }}</li>
14-
<li>Version: {{ page.version | jsonify }}</li>
15-
<li>Category: {{ page.category | jsonify }}</li>
16-
<li>Children: {{ childPages.size | jsonify }}</li>
17-
<li>Siblings: {{ siblingPages.size | jsonify }}</li>
18-
<li>Parent: {% if parentPage %} {{ parentPage.url | jsonify }} {% else %} null {% endif %}</li>
19-
</ul>
9+
2010
<a id="addPage" class="button" href="{{ site.github.repository_url }}">Add Page</a>
21-
<!-- If we have either, only display parent and child pages -->
22-
{% if parentPage or childPages.size > 0 %}
23-
{% if parentPage %}
24-
<a class="contentLink" href="{{ site.baseurl }}{{ parentPage.url }}#mainContent">&lt; Go Back</a>
25-
<a class="pageLink" href="{{ site.baseurl }}{{ parentPage.url }}">&lt; Go Back</a>
26-
{% else %}
27-
<a href="{{ site.baseurl }}/">&lt; Go Back</a>
11+
12+
<div class="sidebarcontent">
13+
<!-- If we are displaying anything but the top level page overview, display a back button -->
14+
{% if parentPage or childPages.size > 0 or page.notoc != true %}
15+
{% if parentPage %}
16+
<a class="contentLink" href="{{ site.baseurl }}{{ parentPage.url }}#mainContent">&lt; Go Back</a>
17+
<a class="pageLink" href="{{ site.baseurl }}{{ parentPage.url }}">&lt; Go Back</a>
18+
{% else %}
19+
<a href="{{ site.baseurl }}/">&lt; Go Back</a>
20+
{% endif %}
2821
{% endif %}
22+
23+
<!-- If we have child pages, display an overview of them -->
2924
{% if childPages.size > 0 %}
3025
<h4>{{ page.title }}</h4>
3126
<ul>
@@ -36,6 +31,11 @@ <h4>{{ page.title }}</h4>
3631
</li>
3732
{% endfor %}
3833
</ul>
34+
<!-- If we have a page-local table of contents, display that one -->
35+
{% elsif page.notoc != true %}
36+
<h4>{{ page.title }}</h4>
37+
{% include toc.html html=content h_max=3 sanitize=true %}
38+
<!-- If we have sibling pages, display links to them -->
3939
{% elsif siblingPages.size > 0 %}
4040
<h4>{{ parentPage.title }}</h4>
4141
<ul>
@@ -46,48 +46,46 @@ <h4>{{ parentPage.title }}</h4>
4646
</li>
4747
{% endfor %}
4848
</ul>
49+
<!-- Otherwise, display top-level manual pages grouped by category. -->
4950
{% else %}
50-
<h4>{{ page.title }}</h4>
51+
{% assign sortedPages = site.pages | where: 'version', targetVersion | sort: 'displayOrder' %}
52+
{% for category in site.topLevelCategories %}
53+
<h4>{{ category.title }}</h4>
54+
<ul>
55+
{% for pageItem in sortedPages %}
56+
{% if pageItem.category and pageItem.category == category.id %}
57+
<li>
58+
<a class="contentLink" href="{{ site.baseurl }}{{ pageItem.url }}#mainContent">{{ pageItem.title }}</a>
59+
<a class="pageLink" href="{{ site.baseurl }}{{ pageItem.url }}">{{ pageItem.title }}</a>
60+
</li>
61+
{% endif %}
62+
{% endfor %}
63+
</ul>
64+
{% endfor %}
5165
{% endif %}
52-
<!-- Otherwise, display top-level manual pages grouped by category. -->
53-
{% else %}
54-
{% assign sortedPages = site.pages | where: 'version', targetVersion | sort: 'displayOrder' %}
55-
{% for category in site.topLevelCategories %}
56-
<h4>{{ category.title }}</h4>
66+
<!-- Display available versions of this page -->
67+
{% assign versionPath = page.version | prepend: '/' %}
68+
{% assign urlAfterVersion = page.url | split: versionPath | last %}
69+
{% assign versionPages = "" | split: "" %}
70+
{% for pageItem in site.pages %}
71+
{% assign itemVersionPath = pageItem.version | prepend: '/' %}
72+
{% assign itemUrlAfterVersion = pageItem.url | split: itemVersionPath | last %}
73+
{% if itemUrlAfterVersion == urlAfterVersion %}
74+
{% assign versionPages = versionPages | push: pageItem %}
75+
{% endif %}
76+
{% endfor %}
77+
{% assign sortedVersionPages = versionPages | sort:"version" %}
78+
<div class="versionList">
79+
<h4>Versions:</h4>
5780
<ul>
58-
{% for pageItem in sortedPages %}
59-
{% if pageItem.category and pageItem.category == category.id %}
60-
<li>
61-
<a class="contentLink" href="{{ site.baseurl }}{{ pageItem.url }}#mainContent">{{ pageItem.title }}</a>
62-
<a class="pageLink" href="{{ site.baseurl }}{{ pageItem.url }}">{{ pageItem.title }}</a>
63-
</li>
81+
{% for pageItem in sortedVersionPages %}
82+
{% if pageItem.version == targetVersion %}
83+
<li id="activeVersion">{{ pageItem.version }}</li>
84+
{% else %}
85+
<li><a href="{{ site.baseurl }}{{ pageItem.url }}">{{ pageItem.version }}</a></li>
6486
{% endif %}
6587
{% endfor %}
6688
</ul>
67-
{% endfor %}
68-
{% endif %}
69-
<!-- Display available versions of this page -->
70-
{% assign versionPath = page.version | prepend: '/' %}
71-
{% assign urlAfterVersion = page.url | split: versionPath | last %}
72-
{% assign versionPages = "" | split: "" %}
73-
{% for pageItem in site.pages %}
74-
{% assign itemVersionPath = pageItem.version | prepend: '/' %}
75-
{% assign itemUrlAfterVersion = pageItem.url | split: itemVersionPath | last %}
76-
{% if itemUrlAfterVersion == urlAfterVersion %}
77-
{% assign versionPages = versionPages | push: pageItem %}
78-
{% endif %}
79-
{% endfor %}
80-
{% assign sortedVersionPages = versionPages | sort:"version" %}
81-
<div class="versionList">
82-
<h4>Versions:</h4>
83-
<ul>
84-
{% for pageItem in sortedVersionPages %}
85-
{% if pageItem.version == targetVersion %}
86-
<li id="activeVersion">{{ pageItem.version }}</li>
87-
{% else %}
88-
<li><a href="{{ site.baseurl }}{{ pageItem.url }}">{{ pageItem.version }}</a></li>
89-
{% endif %}
90-
{% endfor %}
91-
</ul>
89+
</div>
9290
</div>
9391
</nav>

‎_includes/toc.html

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{% capture tocWorkspace %}
2+
{% comment %}
3+
Version 1.0.6
4+
https://github.com/allejo/jekyll-toc
5+
6+
"...like all things liquid - where there's a will, and ~36 hours to spare, there's usually a/some way" ~jaybe
7+
8+
Usage:
9+
{% include toc.html html=content sanitize=true class="inline_toc" id="my_toc" h_min=2 h_max=3 %}
10+
11+
Parameters:
12+
* html (string) - the HTML of compiled markdown generated by kramdown in Jekyll
13+
14+
Optional Parameters:
15+
* sanitize (bool) : false - when set to true, the headers will be stripped of any HTML in the TOC
16+
* class (string) : '' - a CSS class assigned to the TOC
17+
* id (string) : '' - an ID to assigned to the TOC
18+
* h_min (int) : 1 - the minimum TOC header level to use; any header lower than this value will be ignored
19+
* h_max (int) : 6 - the maximum TOC header level to use; any header greater than this value will be ignored
20+
* ordered (bool) : false - when set to true, an ordered list will be outputted instead of an unordered list
21+
* item_class (string) : '' - add custom class(es) for each list item; has support for '%level%' placeholder, which is the current heading level
22+
* baseurl (string) : '' - add a base url to the TOC links for when your TOC is on another page than the actual content
23+
* anchor_class (string) : '' - add custom class(es) for each anchor element
24+
25+
Output:
26+
An ordered or unordered list representing the table of contents of a markdown block. This snippet will only
27+
generate the table of contents and will NOT output the markdown given to it
28+
{% endcomment %}
29+
30+
{% capture my_toc %}{% endcapture %}
31+
{% assign orderedList = include.ordered | default: false %}
32+
{% assign minHeader = include.h_min | default: 1 %}
33+
{% assign maxHeader = include.h_max | default: 6 %}
34+
{% assign nodes = include.html | split: '<h' %}
35+
{% assign firstHeader = true %}
36+
37+
{% capture listModifier %}{% if orderedList %}1.{% else %}-{% endif %}{% endcapture %}
38+
39+
{% for node in nodes %}
40+
{% if node == "" %}
41+
{% continue %}
42+
{% endif %}
43+
44+
{% assign headerLevel = node | replace: '"', '' | slice: 0, 1 | times: 1 %}
45+
46+
{% if headerLevel < minHeader or headerLevel > maxHeader %}
47+
{% continue %}
48+
{% endif %}
49+
50+
{% if firstHeader %}
51+
{% assign firstHeader = false %}
52+
{% assign minHeader = headerLevel %}
53+
{% endif %}
54+
55+
{% assign indentAmount = headerLevel | minus: minHeader | add: 1 %}
56+
{% assign _workspace = node | split: '</h' %}
57+
58+
{% assign _idWorkspace = _workspace[0] | split: 'id="' %}
59+
{% assign _idWorkspace = _idWorkspace[1] | split: '"' %}
60+
{% assign html_id = _idWorkspace[0] %}
61+
62+
{% capture _hAttrToStrip %}{{ _workspace[0] | split: '>' | first }}>{% endcapture %}
63+
{% assign header = _workspace[0] | replace: _hAttrToStrip, '' %}
64+
65+
{% assign space = '' %}
66+
{% for i in (1..indentAmount) %}
67+
{% assign space = space | prepend: ' ' %}
68+
{% endfor %}
69+
70+
{% unless include.item_class == blank %}
71+
{% capture listItemClass %}{:.{{ include.item_class | replace: '%level%', headerLevel }}}{% endcapture %}
72+
{% endunless %}
73+
74+
{% capture my_toc %}{{ my_toc }}
75+
{{ space }}{{ listModifier }} {{ listItemClass }} [{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}]({% if include.baseurl %}{{ include.baseurl }}{% endif %}#{{ html_id }}){% if include.anchor_class %}{:.{{ include.anchor_class }}}{% endif %}{% endcapture %}
76+
{% endfor %}
77+
78+
{% if include.class %}
79+
{% capture my_toc %}{:.{{ include.class }}}
80+
{{ my_toc | lstrip }}{% endcapture %}
81+
{% endif %}
82+
83+
{% if include.id %}
84+
{% capture my_toc %}{: #{{ include.id }}}
85+
{{ my_toc | lstrip }}{% endcapture %}
86+
{% endif %}
87+
{% endcapture %}{% assign tocWorkspace = '' %}{{ my_toc | markdownify | strip }}

‎index.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: "Home"
33
category: "introduction"
44
displayOrder: -100
55
version: "v3"
6+
notoc: true
67
---
78

89
Welcome to the Duality docs pages! If you're looking for a **developer manual**, check the side bar to your left.

‎pages/v2/Choosing-Duality.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ title: "Should You Use Duality?"
33
category: "introduction"
44
displayOrder: 10
55
version: "v2"
6+
notoc: true
67
---
78

89
Someone once said: "Every game engine sucks - but each in its own, unique way". Choosing an engine is not about going through a shopping list of billboard features, it's not even about deciding which one is "better". It's about setting priorities and identifying requirements: What does your game need, and what do _you_ need, as a developer? What do you value? This guide is here to help you decide whether your next project should be made with Duality.
910

1011
_If you haven't read the info page yet, [head over here](https://www.duality2d.net) first._
1112

12-
* TOC
13-
{:toc}
14-
1513
# About Duality
1614

1715
So let's take a close, honest look. If you're with us by the end of this chapter, Duality and you have a solid chance.

‎pages/v2/List-of-Community-Projects.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: "List of Community Projects"
33
category: "development"
44
displayOrder: 0
55
version: "v2"
6+
notoc: true
67
---
78

89
The following is a list of projects that are maintained and published by the community. Feel free to add your own if you think that it could be useful to others!

‎pages/v2/Requirements.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: "Requirements"
33
category: "introduction"
44
displayOrder: 0
55
version: "v2"
6+
notoc: true
67
---
78

89
To launch a Duality application, the end user needs the [.Net Framework 4.5](https://www.google.de/#hl=en&q=.net+framework+4.5) on Windows machines, or the equivalent [Mono](http://www.mono-project.com/) version on non-Windows machines. The actual hardware minimum to launch a Duality application depends on the application itself.

‎pages/v3/Choosing-Duality.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ title: "Should You Use Duality?"
33
category: "introduction"
44
displayOrder: 10
55
version: "v3"
6+
notoc: true
67
---
78

89
Someone once said: "Every game engine sucks - but each in its own, unique way". Choosing an engine is not about going through a shopping list of billboard features, it's not even about deciding which one is "better". It's about setting priorities and identifying requirements: What does your game need, and what do _you_ need, as a developer? What do you value? This guide is here to help you decide whether your next project should be made with Duality.
910

1011
_If you haven't read the info page yet, [head over here](https://www.duality2d.net) first._
1112

12-
* TOC
13-
{:toc}
14-
1513
# About Duality
1614

1715
So let's take a close, honest look. If you're with us by the end of this chapter, Duality and you have a solid chance.

‎pages/v3/List-of-Community-Projects.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: "List of Community Projects"
33
category: "development"
44
displayOrder: 0
55
version: "v3"
6+
notoc: true
67
---
78

89
The following is a list of projects that are maintained and published by the community. Feel free to add your own if you think that it could be useful to others!

‎pages/v3/Requirements.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: "Requirements"
33
category: "introduction"
44
displayOrder: 0
55
version: "v3"
6+
notoc: true
67
---
78

89
To launch a Duality application, the end user needs the [.Net Framework 4.5](https://www.google.de/#hl=en&q=.net+framework+4.5) on Windows machines, or the equivalent [Mono](http://www.mono-project.com/) version on non-Windows machines. The actual hardware minimum to launch a Duality application depends on the application itself, but graphics support for OpenGL 3.0 or OpenGL ES 2.0 is a common baseline.

0 commit comments

Comments
 (0)
Please sign in to comment.