website/layouts/partials/templates/blocks.html

22 lines
703 B
HTML

{{ .ctx.Scratch.Set "sections" slice }}
<ul id="markdown-toc">
{{ range .ctx.Scratch.Get "blocks" }}
{{ if .block }}
{{ $.ctx.Scratch.Set "section" (partial "templates/block" .) }}
{{ else}}
{{ $.ctx.Scratch.Set "section" .content }}
{{ end }}
{{ $section := $.ctx.Scratch.Get "section" }}
{{ $headers := findRE "<h2.*?>(.|\n)*?</h2>" $section }}
{{ range $headers }}
{{ $id := . | strings.TrimPrefix "<h2 id=\"" }}
{{ $id := $id | replaceRE "\">.*" "" }}
{{ $header := . | replaceRE "</?h2.*?>" "" | htmlUnescape | safeHTML }}
<li><a href="#{{ $id }}">{{ $header }}</a></li>
{{ end }}
{{ $.ctx.Scratch.Add "sections" $section }}
{{ end }}
</ul>
{{ range .ctx.Scratch.Get "sections" }}
{{ . }}
{{ end }}