Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e6415ec

Browse files
committedOct 17, 2011
adding automaticaly generated toc to article pages, added java to scala tutorial, and did some refactoring
1 parent 96941a0 commit e6415ec

File tree

6 files changed

+811
-4
lines changed

6 files changed

+811
-4
lines changed
 

‎2.9.1/tutorials/scala-for-java-programmers.md

Lines changed: 719 additions & 0 deletions
Large diffs are not rendered by default.

‎README

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ OSX users might need to update RubyGems:
1616

1717
cd into the `scala-docs` directory, and build by:
1818

19-
jekyll --server --base-url '/scala-docs'
19+
jekyll --server
2020

21-
The generated site is available at `http://localhost:4000/scala-docs/`
21+
The generated site is available at `http://localhost:4000`
2222

2323

2424

‎_config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
baseurl: /scala-docs/
21
pygments: true
32
permalink: /:categories/:title.html
43

‎_layouts/default.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<!-- jquery js -->
2121
<script src="{{ site.baseurl }}/resources/javascript/jquery.js" type="text/javascript" ></script>
2222

23+
<!-- prettyprint js to prepend generated pre/code tags -->
2324
<script type="text/javascript">
2425
function styleCode()
2526
{
@@ -39,6 +40,29 @@
3940
if (a) { prettyPrint() }
4041
}
4142
</script>
43+
44+
<!-- Table of contents -->
45+
<script type="text/javascript">
46+
$(document).ready(function() {
47+
$("#toc").append('<p>In this article:</p>')
48+
$("h1, h2, h3").each(function(i) {
49+
var current = $(this);
50+
current.attr("id", "title" + i);
51+
52+
$("#toc").append("<a id='link" + i + "' href='#title" + i + "' title='" + current.attr("tagName") + "'>" + current.html() + "</a>");
53+
});
54+
});
55+
</script>
56+
57+
<style type="text/css">
58+
59+
#toc a { display:block; color:#0094FF;}
60+
61+
#toc a[title=H1] { font-size:18px;}
62+
#toc a[title=H2] { font-size:14px;}
63+
#toc a[title=H3] { font-size:10px;}
64+
</style>
65+
4266
</head>
4367
<body onload="styleCode()">
4468

@@ -48,6 +72,10 @@
4872
{% include topbar.txt %}
4973
{% endif %}
5074

75+
{% if page.type == 'overview %}
76+
<div id="toc" class="span6"></div>
77+
{% endif %}
78+
5179
<div class="container">
5280
<div class="row">
5381
<h1>{{ site.title }}</h1>

‎resources/javascript/toc.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
$(document).ready(function(){
2+
3+
// Construct an OL of this page's H2
4+
var navigation = '<ol class="navigation">';
5+
var h2index = 0;
6+
var h3index = 0;
7+
$('#pageContent h2, #pageContent h3, #pageContent > div > ol > li > a').each(function(index) {
8+
9+
// In each heading, construct an in-page link from its id, or the nested a[name]
10+
if ($(this).find('a[name]').length == 0) {
11+
var anchor = $(this).attr('id');
12+
}
13+
else {
14+
var anchor = $(this).find('a[name]').attr('name');
15+
}
16+
var link = '<a href="#' + anchor + '">' + $(this).text() + '</a>';
17+
if(this.tagName == 'A') {
18+
link = '<a href="' + $(this).attr('href') + '">' + $(this).text() + '</a>';
19+
}
20+
21+
if (this.tagName == 'H2') {
22+
// Close a nested OL list for the previous H3.
23+
if (h3index > 0) {
24+
navigation += '</ul>';
25+
}
26+
h3index = 0;
27+
28+
// Close the LI for the previous H2.
29+
if (h2index > 0) {
30+
navigation += '</li>';
31+
}
32+
h2index++;
33+
34+
// Output LI start tag and body for this H2.
35+
navigation += '<li>' + link;
36+
}
37+
38+
// Output a nested LI for this H3.
39+
if (this.tagName == 'H3' || (this.tagName == 'A' && $(this).parent('li').find('li').size() > 0) ) {
40+
h3index++;
41+
42+
// Start a new nested OL for the first H3.
43+
if (h3index == 1) {
44+
navigation += '<ul>';
45+
}
46+
47+
navigation += '<li>' + link + '</li>';
48+
}
49+
50+
});
51+
52+
// Close the LI for the last H2, and close the outer list.
53+
navigation += '</li></ol>';
54+
$('#toc').html(navigation);
55+
56+
// Next link
57+
var nextLink = $('.next a')
58+
if(nextLink && nextLink.size()) {
59+
$('#gotoc').after('<li><a href="' + $(nextLink).attr('href') + '">Next: ' + $(nextLink).text() + '</a></li>')
60+
}
61+
62+
});

0 commit comments

Comments
 (0)
Please sign in to comment.