Skip to content

Commit 7ea6e43

Browse files
committed
added toc to the sidebar
- added table of content to the sidebar - added js to highlight current position
1 parent f1c42bb commit 7ea6e43

5 files changed

Lines changed: 90 additions & 6 deletions

File tree

_config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ defaults:
6262
path: ""
6363
values:
6464
image: /images/sharingduckdb.jpg
65-
#toc: true
65+
toc: true
6666

6767
repository: "duckdb/duckdb-web"
6868

@@ -82,7 +82,7 @@ star_count: "14.4k"
8282

8383
toc:
8484
min_level: 1
85-
max_level: 3
86-
ordered_list: true
85+
max_level: 2
86+
ordered_list: false
8787

8888
exclude: ['Gemfile', 'Gemfile.lock', 'node_modules', 'vendor/bundle', 'vendor/cache', 'vendor/gems', 'vendor/ruby', 'bundle']

_layouts/docu.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
</div>
147147

148148
{% assign ct = content | toc %}
149-
{% include anchor_headings.html html=ct %}
149+
{% include anchor_headings.html html=content %}
150150

151151
{% if page.url contains 'overview' %}
152152
<div class="index">
@@ -172,7 +172,16 @@ <h5>About this page</h5>
172172

173173
</div>
174174

175-
<div id="sidebar"></div>
175+
<div id="sidebar">
176+
{% assign toc_only = content | toc_only %}
177+
{% assign toc_text_only = toc_only | strip_html | remove: ' ' %}
178+
{% if toc_text_only.size > 10 %}
179+
<div class="toc_menu">
180+
<h5>In this article</h5>
181+
{{ toc_only }}
182+
</div>
183+
{% endif %}
184+
</div>
176185

177186

178187

_plugins/toc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def inject_anchors_into_html
55
@entries.each do |entry|
66
# NOTE: `entry[:id]` is automatically URL encoded by Nokogiri
77
entry[:text].replace(
8-
%(<a class="anchor" style="text-decoration: none;" href="##{entry[:id]}">#{entry[:text]}</a>)
8+
%(<a class="anchor" href="##{entry[:id]}">#{entry[:text]}</a>)
99
)
1010
end
1111

css/docu.scss

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,55 @@ body.documentation{
249249
background: $black50;
250250
position: relative;
251251
width: 22%;
252+
padding: 100px 20px 20px 20px;
252253
@media only screen and (max-width: 1200px) {
253254
display: none;
254255
}
255256
}
257+
.toc_menu{
258+
position: sticky;
259+
top: 100px;
260+
h5{
261+
color: $black400;
262+
font-size: 12px;
263+
font-style: normal;
264+
font-weight: 450;
265+
text-transform: uppercase;
266+
margin-left: 12px;
267+
}
268+
ul#toc{
269+
list-style: none;
270+
padding: 0;
271+
margin: 0;
272+
margin-top: 20px;
273+
font-size: 14px;
274+
position: relative;
275+
li{
276+
line-height: 1;
277+
&.current a{
278+
background: #EFEFEF;
279+
color: black;
280+
font-weight: 600;
281+
}
282+
}
283+
a{
284+
color: $black400;
285+
text-decoration: none;
286+
padding: 8px 12px;
287+
background: $black50;
288+
border-radius: 100px;
289+
display: inline-block;
290+
text-overflow: ellipsis;
291+
overflow: hidden;
292+
white-space: nowrap;
293+
max-width: 100%;
294+
line-height: 1;
295+
&:hover{
296+
background: $black100;
297+
}
298+
}
299+
}
300+
}
256301
blockquote {
257302
border-radius: 10px;
258303
margin: 0;

js/script.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,4 +683,34 @@ $(document).ready(function(){
683683
})
684684
}
685685

686+
/** HIGHLIGHT TOC MENU **/
687+
if ($('body').hasClass('documentation')) {
688+
var headings = $('#main_content_wrap h2');
689+
var tocEntries = $('.toc-entry');
690+
691+
$(window).on('scroll', function() {
692+
var scrollPos = $(window).scrollTop() + 150; // top offset
693+
var documentHeight = $(document).height();
694+
695+
headings.each(function(index, element) {
696+
var id = $(element).attr('id');
697+
var offset = $(element).offset().top;
698+
699+
if (scrollPos >= offset) {
700+
tocEntries.removeClass('current');
701+
$('.toc-entry a[href="#' + id + '"]').parent().addClass('current');
702+
}
703+
});
704+
705+
if (scrollPos + $(window).height() >= documentHeight - 20) {
706+
tocEntries.removeClass('current');
707+
$('.toc-entry:last').addClass('current');
708+
}
709+
710+
});
711+
}
712+
713+
714+
715+
686716
});

0 commit comments

Comments
 (0)