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

{{- if $params.related.enable | and ("aside" | 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 -}}
    <div class="details related-details open">
      <div class="details-summary related-summary">
        {{ dict "Class" "fa-solid fa-fire fa-fade text-danger" | partial "plugin/icon.html" }}
        <span class="related-title">{{ T "single.relatedContent" }}</span>
        {{- dict "Class" "details-icon fa-solid fa-angle-right" | partial "plugin/icon.html" -}}
      </div>
      <div class="details-content related-content">
        <ul class="related-list">
          {{- range $i, $p := . -}}
            {{- $title := cond (.Param "capitalizeTitles") (title .LinkTitle) .LinkTitle -}}
            <li class="related-item">
              <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>
      </div>
    </div>
  {{- end -}}
{{- end -}}
