{{ define "main" }}
<section class="home-about">
	<div class="avatar">
        {{ if isset .Site.Params "avatarurl" }}
        <img class={{ .Site.Params.AvatarSize | default "size-m" }} src='{{ .Scratch.Get "avatarImgSrc" }}' alt="{{ .Site.Params.AvatarAltText|default "avatar" }}">
        {{ end }}
	</div>

    <h1>{{ .Site.Title }}</h1>
    {{ if isset .Site.Params "description" }}
        <h2>{{ .Site.Params.Description }}</h2>
    {{ end }}

</section>

<div class="flex-break"></div>

{{ if isset .Site.Params "socialicons" }}
<div class="gk-social-icons">
    <ul class="gk-social-icons-list">
        {{ range .Site.Params.SocialIcons }}
        <li class="gk-social-icon">
            <a href="{{ .url }}" target="_blank" rel="{{ if .rel }}{{ .rel }} {{ end }}noopener noreferrer" aria-label="Learn more on {{ .name }}">
                <img class="svg-inject" src="{{ relURL "svg/icons/" }}{{ .name | lower }}.svg" alt="">
            </a>
        </li>
        {{ end }}
    </ul>
</div>
{{ end }}

{{ if (or
    (and (fileExists "content/_index.md") .Content)
    (fileExists "content/index-about.md")) }}
        <section class="home-content">
            {{ or .Content (readFile "index-about.md" | markdownify) }}
        </section>
{{ end }}

{{ if isset .Site.Params "showpostsonhomepage" }}

    <div class="home-posts list-posts">
        <h2>{{ i18n (.Site.Params.ShowPostsOnHomePage | humanize) }}</h2>

    {{ $posts := where .Site.Pages "Params.type" "post" }}

    {{ if eq .Site.Params.ShowPostsOnHomePage "popular" }}
        {{ range $posts.ByWeight | first (or .Site.Params.NumberPostsOnHomePage 4) }}
            {{- partial "list-posts.html" . -}}
        {{ end }}
    {{ else if eq .Site.Params.ShowPostsOnHomePage "recent" }}
        {{ range $posts.ByDate.Reverse | first (or .Site.Params.NumberPostsOnHomePage 4) }}
            {{- partial "list-posts.html" . -}}
        {{ end }}
    {{ end }}
    </div>

{{ end }}
{{ end }}
