Skip to content

Commit 8762d1b

Browse files
committed
adding start to navigation with children
Signed-off-by: Vanessa Sochat <[email protected]>
1 parent 00aadf1 commit 8762d1b

File tree

4 files changed

+68
-12
lines changed

4 files changed

+68
-12
lines changed

_data/toc.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
- title: "Getting Started"
22
url: "docs/getting-started"
3+
children:
4+
- title: Features
5+
url: "docs/getting-started#features"
6+
- title: Development
7+
url: "docs/getting-started#development"
8+
- title: Customization
9+
url: "docs/getting-started#customization"
310
- title: "About"
411
url: "about"
512
- title: "News"

_docs/getting-started.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,15 @@ that are still browsable easily via search or the table of contents on the right
110110

111111
The `pages` folder uses the same page layout, but is not part of the docs collection.
112112
The two are provided to create a distinction between website pages (e.g., about,
113-
feed.xml) and documentation pages. Whether you place your page under
114-
"pages" or "docs," for those pages that you want added to the navigation,
113+
feed.xml) and documentation pages.
114+
115+
### Navigation
116+
117+
Whether you place your page under "pages" or "docs," for those pages that you want added to the navigation,
115118
you should add them to `_data/toc.yml`. If you've defined a `permalink` in the
116119
front end matter, you can use that (e.g., "About" below). If you haven't and
117120
want to link to docs, the url is the path starting with the docs folder.
121+
Here is an example of a flat structure:
118122

119123
```yaml
120124
- title: "Getting Started"
@@ -125,6 +129,24 @@ want to link to docs, the url is the path starting with the docs folder.
125129
url: "news"
126130
```
127131
132+
And here is an example with nested children (currently active in the example):
133+
134+
```yaml
135+
- title: "Getting Started"
136+
url: "docs/getting-started"
137+
children:
138+
- title: Features
139+
url: "docs/getting-started#features"
140+
- title: Development
141+
url: "docs/getting-started#development"
142+
- title: Customization
143+
url: "docs/getting-started#customization"
144+
- title: "About"
145+
url: "about"
146+
- title: "News"
147+
url: "news"
148+
```
149+
128150
### News Posts
129151
130152
It might be the case that your site or group has news items that would

_includes/footer.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@
4242

4343
</footer>
4444
<script src="{{ site.baseurl }}/assets/js/application.js"></script>
45-
<!--<script src="{{ site.baseurl }}/assets/js/application.a59e2a89.js"></script>-->
45+
<script>
46+
$(".pancakes-parent").on('click', function(){
47+
console.log($(this).next());
48+
$(this).next().find('.pancakes-child').toggle();
49+
})
50+
</script>
4651
{% assign slashes = page.url | split: "/" %}
4752
<script>console.log('{{ slashes | size }}')</script>
4853
<script>app.initialize({version:"0.17.4", url:{base:'{{ site.baseurl }}'}})</script>

_includes/sidebar.html

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="md-sidebar__scrollwrap">
33
<div class="md-sidebar__inner">
44
<nav class="md-nav md-nav--primary" data-md-level="0">
5-
<label class="md-nav__title md-nav__title--site" for="__drawer"><span class="md-nav__button md-logo"><img height="48" src="{{%20site.logo%20}}" width="48"></span> {{ site.title }}</label>
5+
<label class="md-nav__title md-nav__title--site" for="__drawer"><span class="md-nav__button md-logo"><img height="48" src="../{{ site.logo }}" width="48"></span> {{ site.title }}</label>
66
<div class="md-nav__source">
77
<a class="md-source" data-md-source="github" href="{{ site.repo }}" title="Go to repository">
88
<div class="md-source__icon">
@@ -14,30 +14,52 @@
1414
</div></a>
1515
</div>
1616

17-
1817
<ul class="md-nav__list" data-md-scrollfix="">
1918
<li class="md-nav__item md-nav__item--active">
20-
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" id="__toc" type="checkbox"> <label class="md-nav__link md-nav__link--active" for="__toc">Home</label> <a class="md-nav__link md-nav__link--active" href="{{ site.baseurl }}/" title="Home">Home</a>
19+
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" id="__toc" type="checkbox">
20+
<label class="md-nav__link md-nav__link--active" for="__toc">Home</label>
21+
<a class="md-nav__link md-nav__link--active" href="{{ site.baseurl }}/" title="Home">Home</a>
2122

2223
<nav class="md-nav md-nav--secondary">
2324
<label class="md-nav__title" for="__toc">Table of contents</label>
2425
<ul class="md-nav__list" data-md-scrollfix="">
26+
2527
{% for section in site.data.toc %}
26-
<li class="md-nav__item">
28+
<li class="md-nav__item {% if forloop.first%}{% else %}md-nav__item--nested{% endif %}">
2729
<a class="md-nav__link" href="#{{ section.title | slugify }}"
2830
id="pancakes-{{ section.title | slugify }}"
2931
title="{{ section.title }}">{{ section.title }}</a>
32+
{% if section.children %}<nav class="md-nav">
33+
<ul class="md-nav__list">
34+
{% for child in section.children %}<li class="md-nav__item">
35+
<a href="#{{ child.title | slugify }}"
36+
title="{{ child.title }}"
37+
class="md-nav__link child-{{ section.title | slugify }}">{{ child.title }}</a>
38+
</li>{% endfor %}
39+
</ul>
40+
</nav>{% endif %}
3041
</li>
3142
{% endfor %}
3243
</ul>
3344
</nav>
3445
</li>
3546

36-
{% for section in site.data.toc %}
37-
<li class="md-nav__item">
38-
<a class="md-nav__link" href="{{ site.baseurl }}/{{ section.url }}" title="{{ section.title }}">{{ section.title }}</a>
39-
</li>
40-
{% endfor %}
47+
{% for section in site.data.toc %}
48+
<li class="md-nav__item md-nav__item--nested">
49+
<a class="md-nav__link pancakes-parent" {% if section.children %}href="#pancakes-{{ section.title | slugify }}"{% else %}href="{{ site.baseurl }}/{{ section.url }}"{% endif %}
50+
id="pancakes-{{ section.title | slugify }}"
51+
title="{{ section.title }}">{{ section.title }}</a>
52+
{% if section.children %}<nav class="md-nav">
53+
<ul class="md-nav__list">
54+
{% for child in section.children %}<li class="md-nav__item">
55+
<a href="{{ site.baseurl }}{{ child.url }}"
56+
title="{{ child.title }}" style="display:none"
57+
class="md-nav__link pancakes-child">{{ child.title }}</a>
58+
</li>{% endfor %}
59+
</ul>
60+
</nav>{% endif %}
61+
</li>
62+
{% endfor %}
4163
</ul>
4264
</nav>
4365
</div>

0 commit comments

Comments
 (0)