{{ 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 }}" {{ if .rel }}rel="{{ .rel }}" {{ end }} 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 os.FileExists "index-about.md" }}
<div class="markdown-content">
  {{ readFile "index-about.md" | markdownify }}
</div>
{{ end }}

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

<div class="home-grid">
  <div class="home-posts-column home-posts list-posts">
    <h2>Recent Posts</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>

  {{ $projects := where .Site.RegularPages "Params.type" "projects" }}
  {{ if gt (len $projects) 0 }}
  <div class="home-projects-card">
    <h2>Project Updates</h2>
    {{ range $projects.ByLastmod.Reverse | first (or $.Site.Params.NumberProjectsOnHomePage 3) }}
    {{ $project := . }}
    <div class="home-project-entry">
      <a href="{{ .Permalink }}">{{ .Title }}</a>
      <div class="home-project-meta">
        {{ with .Params.status }}
        {{ $color := $project.Params.statusColor | default "#9e9e9e" }}
        <span class="home-project-status" style="color: {{ $color }}; border: 1px solid {{ $color }}; background-color: {{ $color }}20;">{{ . }}</span>
        &middot;
        {{ end }}
        Updated {{ $project.Lastmod.Format "Jan 2, 2006" }}
      </div>
    </div>
    {{ end }}
    <a class="view-all" href="/projects/">View all projects &rarr;</a>
  </div>
  {{ end }}
</div>

{{ end }}

{{ end }}
