Add a components TOC partial because rendering order prevents the markdown renderer .TableOfContents from working

This commit is contained in:
John Ewart 2022-06-14 19:00:19 -07:00
parent 661bc71a27
commit 2437bc17ab
8 changed files with 45 additions and 7 deletions

View File

@ -31,4 +31,6 @@
</tr>
{{ end }}
</table>
{{ end }}
{{ end }}
{{ partial "components/componenttoc.html" . }}

View File

@ -0,0 +1,24 @@
{{ $headers := findRE "<h[1-6].*?>(.|\n])+?</h[1-6]>" .Page.Content }}
{{ $has_headers := ge (len $headers) 1 }}
{{ if $has_headers }}
<div class="table-of-contents toc bd-callout">
<h4 class="text-muted">Table of Contents</h4>
{{ range $headers }}
{{ $header := . }}
{{ range first 1 (findRE "<h[1-6]" $header 1) }} {{ range findRE "[1-6]" . 1 }} {{ $next_heading :=(int .) }} {{
range seq $next_heading }} <ul class="toc-h{{ . }}">
{{end}}
{{ $base := ($.Page.File.LogicalName) }}
{{ $anchorId := ($header | plainify | htmlEscape | urlize) }}
{{ $href := delimit (slice $base $anchorId) "#" | string }}
<a href="{{ relref $.Page $href }}">
<li>{{ $header | plainify | htmlEscape }}</li>
</a>
{{ range seq $next_heading }}
</ul>
{{end}}
{{end}}
{{end}}
{{ end }}
</div>
{{ end }}

View File

@ -22,4 +22,6 @@
</tr>
{{ end }}
</table>
{{ end }}
{{ end }}
{{ partial "components/componenttoc.html" . }}

View File

@ -22,4 +22,6 @@
</tr>
{{ end }}
</table>
{{ end }}
{{ end }}
{{ partial "components/componenttoc.html" . }}

View File

@ -24,4 +24,6 @@
</tr>
{{ end }}
</table>
{{ end }}
{{ end }}
{{ partial "components/componenttoc.html" . }}

View File

@ -25,4 +25,6 @@
</tr>
{{ end }}
</table>
{{ end }}
{{ end }}
{{ partial "components/componenttoc.html" . }}

View File

@ -36,4 +36,6 @@
{{ end }}
</table>
{{ end }}
</div>
</div>
{{ partial "components/componenttoc.html" . }}

View File

@ -36,4 +36,6 @@
</tr>
{{ end }}
</table>
{{ end }}
{{ end }}
{{ partial "components/componenttoc.html" . }}