Skip to content

Commit

Permalink
Theme: Avoid empty TOC and disable TOC on non-content pages
Browse files Browse the repository at this point in the history
* No TOC on group index pages.
* No TOC if there are no headings.

This applies allejo/jekyll-toc#60 as hotfix.
  • Loading branch information
Krinkle committed Sep 20, 2021
1 parent dbcc6da commit 4adc274
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
22 changes: 11 additions & 11 deletions _includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

{%- endcomment -%}
<aside class="sidebar" role="complementary">
{%- if include.blocks -%}
{%- for block in site.data[include.blocks] -%}
{%- assign block_type = block.type | default: "group" -%}
{%- assign block_title = block.title -%}
Expand Down Expand Up @@ -96,14 +95,15 @@ <h4 {%- if block_expand %} class="sidebar-title-open"{% endif %}>{% if block_url
{%- endfor -%}

{%- if include.toc -%}
<hr>
{%- endif -%}
{%- endif -%}

{%- if include.toc -%}
<div class="toc-wrapper">
<h4>Table of contents</h4>
{%- include toc.html html=content sanitize=true h_max=3 ordered=true skip_no_ids=true class="toc" item_class="sidebar-item" -%}
</div>
{%- endif -%}
{%- capture jekyll_toc -%}
{%- include toc.html html=content sanitize=true h_max=3 ordered=true skip_no_ids=true class="toc" item_class="sidebar-item" -%}
{%- endcapture -%}
{%- if jekyll_toc != '' -%}
{%- if include.blocks -%}
<hr>
{%- endif -%}
<div class="toc-wrapper">
<h4>Table of contents</h4>{{ jekyll_toc }}</div>
{%- endif -%}
{%- endif %}
</aside>
2 changes: 1 addition & 1 deletion _includes/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@
{% capture jekyll_toc %}<{{ listModifier }}{{ rootAttributes }}>{{ nodes | shift | join: '>' }}>{% endcapture %}
{% endif %}
{% endif %}
{% endcapture %}{% assign tocWorkspace = '' %}{{ deprecation_warnings }}{{ jekyll_toc }}
{% endcapture %}{% assign tocWorkspace = '' %}{{ deprecation_warnings }}{{ jekyll_toc -}}
2 changes: 2 additions & 0 deletions _layouts/group.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
layout: page-api
amethyst:
toc: false

# Parameters:
#
Expand Down
6 changes: 5 additions & 1 deletion _layouts/page-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@ <h1>{{ page.title }}</h1>
{%- endif %}
{{- content }}
</div>
{% include sidebar.html blocks="sidebar_api" toc=true %}
{%- assign toc = true -%}
{%- if layout.amethyst.toc == false -%}
{%- assign toc = false -%}
{%- endif %}
{% include sidebar.html blocks="sidebar_api" toc=toc %}
</div>
7 changes: 6 additions & 1 deletion _sass/amethyst.scss
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,10 @@ table {
padding-left: 4px;
}

.sidebar hr {
margin-bottom: $size-spacing;
}

.sidebar-list {
margin-top: 0;
padding: 0;
Expand Down Expand Up @@ -750,7 +754,8 @@ table {
margin: 0;
padding: 0;
}
.toc .sidebar-item {
.toc .sidebar-item,
.toc .sidebar-item a {
border-left: 0;
}

Expand Down

0 comments on commit 4adc274

Please sign in to comment.