Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct the TOC if conditions #782

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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