{{ define "main" }}
  <section id="about">
  {{ if isset .Site.Params "description" }}
    {{ .Site.Params.description | $.Page.RenderString }}
  {{ end }}
  {{ if isset .Site.Params "social" }}
      <p>Find me on
      {{ $length := (len .Site.Params.social) }}
      {{ range $index, $elem := .Site.Params.social}}
      {{ if eq $elem.name "email" }}
        <a class="icon" target="_blank" rel="noopener" href="mailto:{{ $elem.link }}" aria-label="Email">
          <i class="fas fa-envelope" aria-hidden="true"></i>
        </a>
        {{ else if eq $elem.name "rss" }}
        <a class="icon" target="_blank" rel="noopener" href="{{ $elem.link }}" aria-label="RSS">
          <i class="fas fa-rss" aria-hidden="true"></i>
        </a>
        {{ else if eq $elem.name "scholar" }}
        <a class="icon" target="_blank" rel="noopener" href="{{ $elem.link }}" aria-label="Google Scholar">
          <i class="fas fa-graduation-cap" aria-hidden="true"></i>
        </a>
        {{ else }}
        <a class="icon" target="_blank" rel="noopener" href="{{ $elem.link }}" aria-label="{{ $elem.name }}">
          <i class="fab fa-{{ lower $elem.name }}" aria-hidden="true"></i>
        </a>
        {{ end }}
        {{ if (lt (add $index 2) $length) }}
          {{- print " , " -}}
        {{ else if (lt (add $index 1) $length) }}
          {{- print " and " -}}
        {{ else }}
          {{- print "." -}}
        {{ end }}
      {{ end }}
      </p>
  {{ end }}
  {{ partial "optional-about.html" . }}
  </section>

  <section id="writing">
    <span class="h1"><a href="{{ .Site.Params.mainSection | absURL }}">{{ .Site.Params.mainSectionTitle | default "Writings" }}</a></span>
    {{ if (and (and (isset .Site.Params "tagsoverview") (eq .Site.Params.tagsOverview true)) (gt (len .Site.Taxonomies.tags) 0)) }}
    <span class="h2">Topics</span>
    <span class="widget tagcloud">
      {{ $AllRegularPagesCount := len .Site.RegularPages }}
      {{ range $elem := .Site.Taxonomies.tags.Alphabetical }}
      <a style="font-size: {{ (add 0.5 (mul 5 (div (float $elem.Count) $AllRegularPagesCount))) }}rem;" href="{{ $elem.Page.Permalink }}">
        {{- .Page.Title -}}
      </a>
      {{ end }}
    </span>
    <span class="h2">Most recent</span>
    {{ end }}

    {{ $showAllPostsOnHomePage := false }}
    {{ if (isset .Site.Params "showallpostsonhomepage") }}
      {{ $showAllPostsOnHomePage = .Site.Params.ShowAllPostsOnHomePage }}
    {{ end }}
    {{ $dataFormat := .Site.Params.dateFormat | default "2006-01-02" }}
    {{ $mainPosts := (sort ( where site.RegularPages "Type" "in" site.Params.mainSections ) "Date" "desc") }}
    {{ if $showAllPostsOnHomePage }}
    <ul class="post-list">
      {{ range (.Paginate $mainPosts).Pages }}
        <li class="post-item">
          <div class="meta"><time datetime="{{ time .Date }}" itemprop="datePublished">{{ .Date.Format $dataFormat }}</time></div>
          <span><a href="{{ .Permalink }}">{{ if .Title }} {{- .Title -}} {{ else }} {{- print "Untitled" -}}{{ end }}</a></span>
        </li>
      {{ end }}
    </ul>

    {{ partial "pagination.html" . }}

    {{ else }}
    <ul class="post-list">
      {{ .Scratch.Set "count" 5 }}
      {{ if isset .Site.Params "postsonhomepage" }}
        {{ .Scratch.Set "count" .Site.Params.postsOnHomePage }}
      {{ end }}
      {{ range (first (.Scratch.Get "count") $mainPosts) }}
        <li class="post-item">
          <div class="meta"><time datetime="{{ time .Date }}" itemprop="datePublished">{{ .Date.Format $dataFormat }}</time></div>
          <span><a href="{{ .Permalink }}">{{ if .Title }} {{- .Title -}} {{ else }} {{- print "Untitled" -}}{{ end }}</a></span>
        </li>
      {{ end }}
    </ul>
    {{ end }}
  </section>

  {{ $showProjectsList := false }}
  {{ if (isset .Site.Params "showprojectslist") }}
    {{ $showProjectsList = .Site.Params.showProjectsList }}
  {{ else if .Site.Data.projects }}
    {{ $showProjectsList = true }}
  {{ end }}
  {{ if $showProjectsList }}
    {{ $projectsUrl := "#" }}
    {{ if isset .Site.Params "projectsurl" }}
      {{ $projectsUrl = .Site.Params.projectsUrl }}
    {{ end }}
  <section id="projects">
    <span class="h1"><a href="{{ $projectsUrl }}">Projects</a></span>
    <ul class="project-list">
        {{ range .Site.Data.projects.list }}
        <li class="project-item">
          <a href="{{ .url }}">{{ .name }}</a>: {{ .desc | markdownify }}
        </li>
        {{ end }}
    </ul>
  </section>
  {{ end }}
{{ end }}
