Never display the ToC when it would be empty (#532)

This commit is contained in:
Clément Joly 2021-08-27 17:29:50 +00:00 committed by GitHub
parent 4970e61c7b
commit e5ba0272de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,13 +1,13 @@
{{- $headers := findRE "<h[1-6].*?>(.|\n])+?</h[1-6]>" .Content -}}
{{- $has_headers := ge (len $headers) 1 -}}
{{- if $has_headers -}}
<div class="toc"> <div class="toc">
<details {{if (.Param "TocOpen") }} open{{ end }}> <details {{if (.Param "TocOpen") }} open{{ end }}>
<summary accesskey="c" title="(Alt + C)"> <summary accesskey="c" title="(Alt + C)">
<div class="details">{{- i18n "toc" | default "Table of Contents" }}</div> <div class="details">{{- i18n "toc" | default "Table of Contents" }}</div>
</summary> </summary>
<div class="inner">
{{- $headers := findRE "<h[1-6].*?>(.|\n])+?</h[1-6]>" .Content -}}
{{- $has_headers := ge (len $headers) 1 -}}
{{- if $has_headers -}}
<div class="inner">
{{- $largest := 6 -}} {{- $largest := 6 -}}
{{- range $headers -}} {{- range $headers -}}
{{- $headerLevel := index (findRE "[1-6]" . 1) 0 -}} {{- $headerLevel := index (findRE "[1-6]" . 1) 0 -}}
@ -87,7 +87,7 @@
{{- end -}} {{- end -}}
{{- end }} {{- end }}
</ul> </ul>
{{- end }}
</div> </div>
</details> </details>
</div> </div>
{{- end }}