Welcome to mirror list, hosted at ThFree Co, Russian Federation.

toc.html « partials « layouts - github.com/zwbetz-gh/cupper-hugo-theme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 55a2ccb2133a2e368b21d96f7e1da8861ffed6e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{{ $headings := findRE "<h2.*?>(.|\n])+?</h2>" .Content }}
{{ if ge (len $headings) 2 }}
  <nav class="toc" aria-labelledby="toc-heading">
    <h2 id="toc-heading">{{ T "table_of_contents" }}</h2>
    <ol>
      {{ range $headings }}
        <li>
          {{ $id := findRE "id=\".*\"" . }}
          {{ $id = index $id 0 }}
          {{ $id = strings.TrimPrefix "id=\"" $id }}
          {{ $id = strings.TrimSuffix "\"" $id }}
          <a href="#{{ $id }}">
            {{ . | htmlUnescape | plainify }}
          </a>
        </li>
      {{ end }}
    </ol>
  </nav>
{{ end }}