Skip to content

Commit

Permalink
fix: correct the TOC if conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Nov 14, 2022
1 parent e956f98 commit a29c019
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
4 changes: 4 additions & 0 deletions layouts/partials/functions/toc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{- $enable := and (default true .Params.toc) (default true .Site.Params.toc) -}}
{{- $toc := .TableOfContents -}}
{{- $valid := and $toc (and (ne $toc "<nav id=\"TableOfContents\"></nav>") (gt .WordCount .Site.Params.tocWordCount)) -}}
{{- return and $enable $valid -}}
5 changes: 1 addition & 4 deletions layouts/partials/post/panel/toc.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{{- $enable := and (default true .Params.toc) (default true .Site.Params.toc) -}}
{{- $toc := .TableOfContents -}}
{{- $valid := and $toc (and (ne $toc "<nav id=\"TableOfContents\"></nav>") (gt .WordCount .Site.Params.tocWordCount)) -}}
{{- if and $enable $valid -}}
{{- if partial "functions/toc" . -}}
<a class="action action-toc{{ if eq .Type "docs" }} d-lg-none{{ end }}" href="#postTOC" aria-controls="Table of contents" role="button" title="Table of contents">
<i class="fas fa-fw fa-list-alt"></i>
</a>
Expand Down
2 changes: 2 additions & 0 deletions layouts/partials/post/toc-wrapper.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{- if partial "functions/toc" . -}}
<div id="postTOC" class="mt-2 mb-4 d-block d-lg-none">
<h2 class="text-surface mb-3">{{ i18n "table_of_contents" }}</h2>
<div id="post-toc-container"></div>
</div>
{{- end -}}
7 changes: 2 additions & 5 deletions layouts/partials/post/toc.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{{- $enable := and (default true .Params.toc) (default true .Site.Params.toc) -}}
{{- $toc := .TableOfContents -}}
{{- $valid := and $toc (and (ne $toc "<nav id=\"TableOfContents\"></nav>") (gt .WordCount .Site.Params.tocWordCount)) -}}
{{- if and $enable $valid -}}
{{- if partial "functions/toc" . -}}
<div id="postTOC">
<h2 class="mb-3">
{{- i18n "table_of_contents" -}}
<a class="anchor ms-1" href="#postTOC"><i class="fas fa-link"></i></a>
</h2>
{{ $toc }}
{{ .TableOfContents }}
</div>
{{- end -}}
7 changes: 2 additions & 5 deletions layouts/partials/sidebar/toc.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{{- $enable := and (default true .Params.toc) (default true .Site.Params.toc) -}}
{{- $toc := .TableOfContents -}}
{{- $valid := and $toc (and (ne $toc "<nav id=\"TableOfContents\"></nav>") (gt .WordCount .Site.Params.tocWordCount)) -}}
{{- if and $enable $valid -}}
{{- if partial "functions/toc" . -}}
<div class="accordion post-toc d-none d-lg-block">
<div class="accordion-item row mb-4 card component" id="postTOC">
<div class="card-header accordion-header">
Expand All @@ -11,7 +8,7 @@ <h2 class="card-title fs-4 my-2 text-surface d-none d-lg-block">{{ i18n "table_o
</a>
</div>
<div class="card-body collapse accordion-collapse accordion-body d-lg-block" id="post-toc" aria-labelledby="post-toc-header">
{{ $toc }}
{{ .TableOfContents }}
</div>
</div>
</div>
Expand Down

0 comments on commit a29c019

Please sign in to comment.