Skip to content

Commit dda878c

Browse files
committed
Add sidebar, including dynamic table of contents with scrollspy.
1 parent 9f1def5 commit dda878c

File tree

6 files changed

+56
-428
lines changed

6 files changed

+56
-428
lines changed

TeachersTimesLocations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ To contact the teaching staff send a private message through [Piazza](https://pi
2929
*Instructor:* Ibrahim Awwal
3030
* Final Exam:
3131
* **Location:** TBD
32-
* **Time:** Wednesday, Dec. 17, 3-6pm
32+
* **Time:** Wednesday, Dec. 17, 3-6pm

_includes/footer.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
<p>Published with <a href="http://pages.github.com">GitHub Pages</a></p>
55
</footer>
66
</div>
7+
8+
<script src="/javascripts/main.js"></script>

_layouts/default.html

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,32 @@
22
<html>
33

44
{% include head.html %}
5-
<body>
5+
<body data-spy="scroll" data-target="#side-nav-toc">
66

77
{% include header.html %}
88
<!-- MAIN CONTENT -->
99
<div class="container">
1010
<div class="row">
11-
<div id="main_content_wrap" class="col-md-9">
11+
<div id="main_content_wrap" class="col-md-9" >
12+
<h1>{{ page.title }}</h1>
1213
{{ content }}
1314
</div>
14-
<div class="col-md-3">
15-
<ul class="nav nav-stacked" id="side_nav">
15+
<div class="col-md-3 hidden-xs hidden-sm" id="right-sidebar">
16+
<h4>Recent Announcements</h4>
17+
<ul class="nav" id="posts-sidebar">
18+
{% for post in site.posts %}
19+
<li>
20+
<a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
21+
</li>
22+
{% endfor %}
1623
</ul>
24+
{% if page.disableTOC != true %}
25+
<div id="side-nav-toc" class="affix">
26+
<h4>Contents</h4>
27+
<ul class="nav nav-stacked nav-pills">
28+
</ul>
29+
</div>
30+
{% endif %}
1731
</div>
1832
</div>
1933
</div>

index.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
layout: default
3+
disableTOC: true
34
---
45

56
<div id="header_wrap" class="container">
@@ -10,13 +11,17 @@ layout: default
1011
</div>
1112

1213
<div id="posts">
13-
<ul class="post-list">
14-
{% for post in site.posts %}
15-
<li>
16-
<h4>
17-
<a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
18-
</h4>
19-
</li>
20-
{% endfor %}
21-
</ul>
14+
<ul class="post-list">
15+
{% for post in site.posts %}
16+
<li>
17+
<h3 class="post-title">
18+
<a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
19+
</h4>
20+
<span class="post-time">
21+
Posted on <time datetime="{{post.date}}">{{ post.date | date: "%A %B %d, %Y"}}</time>
22+
</span>
23+
<p>{{ post.excerpt }}<a class="post-link" href="{{ post.url | prepend: site.baseurl }}">...</a></p>
24+
</li>
25+
{% endfor %}
26+
</ul>
2227
</div>

javascripts/main.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
console.log('This would be the main JS file.');
1+
if ($("h2").length == 0){
2+
$("#side-nav-toc").css({
3+
display: "none",
4+
visibility: "hidden"
5+
});
6+
console.log("Hide TOC");
7+
}
8+
9+
$("h2").each(function(index, heading){
10+
var $el = $(heading);
11+
if($el.attr('id')){
12+
$("#side-nav-toc ul").append("<li><a href='#"+$el.attr('id')+"'>"+$el.text()+"</a></li>");
13+
}
14+
15+
});

0 commit comments

Comments
 (0)