{{- /* Related Content */ -}}
{{- /* https://gohugo.io/content-management/related/ */ -}}
{{- $params := partial "function/params.html" -}}

{{- if $params.related.enable | and ("footer" | in $params.related.position) | and (not $params.password) -}}
  {{- $posts := .Site.Store.Get "mainSectionPages" -}}
  {{- if .Site.Params.page.hiddenFromRelated -}}
    {{- $posts = where $posts "Params.hiddenfromrelated" false -}}
  {{- else -}}
    {{- $posts = where $posts "Params.hiddenfromrelated" "!=" true -}}
  {{- end -}}
  {{- $related := $posts.Related . | first ($params.related.count | default 5) -}}
  {{- with $related -}}
    <hr class="awesome-hr" />
    <h2 id="see-also">{{ T "single.relatedContent" }}</h2>
    <ul>
      {{- range $i, $p := . -}}
        {{- $title := cond (.Param "capitalizeTitles") (title .LinkTitle) .LinkTitle -}}
        <li>
          <a href="{{ .RelPermalink }}" title="{{ $title }}">{{ $title }}</a>
          {{- with .HeadingsFiltered -}}
            <ul>
              {{- range . -}}
                {{- $link := printf "%s#%s" $p.RelPermalink .ID | safeURL -}}
                <li>
                  <a href="{{ $link }}" title="{{ .Title }}">{{ .Title }}</a>
                </li>
              {{- end -}}
            </ul>
          {{- end -}}
        </li>
      {{- end -}}
    </ul>
  {{- end -}}
{{- end -}}
