{{- define "main" }}
  {{- $topics := .Site.Taxonomies.topics }}
  {{- range $firstLevel, $first := .Site.Data.topics }}
    {{- $topic := urlize $firstLevel }}
    {{- $count := (index $topics $topic).Pages | uniq | len }}
    <h2>
      {{- if gt $count 0 }}
        <a href="/topics/{{ $topic }}">{{ $firstLevel }} ({{ $count }})</a>
      {{- else }}
        {{ $firstLevel }}
      {{- end }}
    </h2>
    <ul>
    {{- range $secondLevel, $second := $first.topics }}
      {{- $topic := printf "%s/%s" (urlize $firstLevel) (urlize $secondLevel) }}
      {{- $count := (index $topics $topic).Pages | uniq | len }}
      <li><h3>
        {{- if gt $count 0 }}
          <a href="/topics/{{ $topic }}">{{ $secondLevel }} ({{ $count }})</a>
        {{- else }}
          {{ $secondLevel }}
        {{- end }}
      </h3></li>
      <ul>
      {{- range $thirdLevel, $ignored := $second.topics }}
        {{- $topic = (printf "%s/%s/%s" (urlize $firstLevel) (urlize $secondLevel)
           (urlize $thirdLevel)) }}
        {{- $count := (index $topics $topic).Pages | uniq | len }}
        <li>
          {{- if gt $count 0 }}
            <a href="/topics/{{ $topic }}">{{ $thirdLevel }} ({{ $count }})</a>
          {{- else }}
            {{ $thirdLevel }}
          {{- end }}
        </li>
      {{- end }}
      </ul>
    {{- end }}
    </ul>
  {{- end }}
{{- end }}