diff options
Diffstat (limited to 'layouts/partials')
-rw-r--r-- | layouts/partials/banner.html | 5 | ||||
-rw-r--r-- | layouts/partials/table-of-contents.html | 34 |
2 files changed, 39 insertions, 0 deletions
diff --git a/layouts/partials/banner.html b/layouts/partials/banner.html new file mode 100644 index 0000000..fc99e71 --- /dev/null +++ b/layouts/partials/banner.html @@ -0,0 +1,5 @@ +<div class="well post-banner"> + {{ range .Params.banner }} + <img class="banner-img" src="{{ .src }}" alt="{{ .alt }}"></img> + {{ end }} +</div>
\ No newline at end of file diff --git a/layouts/partials/table-of-contents.html b/layouts/partials/table-of-contents.html new file mode 100644 index 0000000..2b6f532 --- /dev/null +++ b/layouts/partials/table-of-contents.html @@ -0,0 +1,34 @@ + <!-- ignore empty links with + --> +{{ $headers := findRE "<h[1-6].*?>(.|\n])+?</h[1-6]>" .Content }} +<!-- at least one header to link to --> +{{ $has_headers := ge (len $headers) 1 }} +<!-- a post can explicitly disable Table of Contents with toc: false --> +{{ $show_toc := (eq $.Params.toc true) }} +{{ if and $has_headers $show_toc }} +<div class="table-of-contents toc bd-callout"> + <!-- TOC header --> + <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 .) }} + <!-- generate li array of the proper depth --> + {{ 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> + <!-- close list --> + {{ range seq $next_heading }} + </ul> + {{end}} + {{end}} + {{end}} + {{ end }} +</div> +{{ end }}
\ No newline at end of file |