single.html 1.9 KB

123456789101112131415161718192021222324252627282930313233
  1. {{ define "title" }}{{ .Title }} – {{ .Site.Title }}{{ end }}
  2. {{ define "main" }}
  3. <header class="title-header">
  4. <h1>{{ if .Draft }}<i>(Draft)</i> {{ end }}{{ .Title }}</h1>
  5. <div class="title-header-date">
  6. {{- if eq .Date.IsZero false }}
  7. <time>{{ .Date.Format "Monday, January 2, 2006" }}</time>
  8. {{- end }}
  9. {{- if (and (eq .Lastmod.IsZero false) (ne .Lastmod .Date)) }}
  10. &mdash; last updated <time>{{ .Lastmod.Format "January 2, 2006" }}</time>
  11. {{- end }}
  12. </div>
  13. {{ if or (.Params.toc) (and (ne .Params.toc false) (isset .Site.Params "tocwordthreshold") (ge .Site.Params.TocWordThreshold 0) (gt .WordCount .Site.Params.TocWordThreshold)) }}
  14. {{/* If the front matter parameter is true, show the toc */}}
  15. {{/* Elif the front matter parameter is false, don't show the toc */}}
  16. {{/* Elif the front matter parameter is not set, show the toc if the site parameter is set, non-negative, and less than the word count */}}
  17. <p></p>
  18. <div class="table-of-contents">
  19. <details open="open">
  20. <summary>
  21. <span class="table-of-contents-title">Table of Contents</span>
  22. </summary>
  23. {{ $toc := .TableOfContents -}}
  24. {{/* Workaround for an extra layer of indentation (https://discourse.gohugo.io/t/2303) */}}
  25. {{- $toc := replaceRE `<nav(.*)>(\s*)<ul>\s*<li>\s*<ul>` `<nav${1}>${2}<ul>` $toc -}}
  26. {{- $toc := replaceRE `</ul>\s*</li>\s*</ul>(\s*)</nav>` `</ul>${1}</nav>` $toc -}}
  27. {{- safeHTML $toc }}
  28. </details>
  29. </div>
  30. {{ end }}
  31. </header>
  32. {{ .Content | replaceRE "(<h[1-9] id=\"([^\"]+)\".+)(</h[1-9]+>)" (printf "${1}<aside class=\"heading-anchor\"><a href=\"#${2}\" aria-label=\"Anchor\"><img src=\"%s\" class=\"color-adapting-image\" height=\"20\"></a></aside>${3}" ("images/chain-link.svg" | relURL)) | safeHTML }}
  33. {{ end }}