diff options
author | mblum <me@mblum.me> | 2017-07-06 09:56:14 +0300 |
---|---|---|
committer | mblum <me@mblum.me> | 2017-07-07 08:27:52 +0300 |
commit | 8ecb6bdf9375d4f8f7d9109c3f48ef9f9652d378 (patch) | |
tree | 75618429d6d0ea14ff4ad0c7bfd6401c79df7e83 /layouts/partials | |
parent | b39b3ef0528c81dd09076f33c5026584bd5c766b (diff) |
[TOC] Posts and _default single layouts now have a table-of-contents.html partial that parses .Content for headers
[TOC] Table of Contents can be disabled / enabled with `toc`: `true / false`
[BANNER] images at the tops of posts are now in a partial and configured with `banner:` [{ `src`: , `alt`: }]
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 |