<!-- homepage -->
{{ partial "header.html" . }}

<h1>Homepage</h1>

<section>
  <h1>Recent News</h1>
  <!-- TODO: Find better ways so we can use custom views instead -->
  {{ range $name, $pages := .Site.Sections }}
    {{ if eq $name "news" }}
      {{ range first 5 $pages }}
        <article>
          <h1><a href="{{ .Page.RelPermalink }}">{{ .Page.Title }}</a></h1>
          <p>{{ .Page.Summary }}</p>
          <time datetime="{{ .Page.Date.Format "2006-01-02T15:04:05-07:00" }}">
            {{ .Page.Date.Format "January 2, 2006" }}
          </time>
          <a href="{{ .Page.RelPermalink }}">Read more</a>
        </article>
      {{ end }}
    {{ end }}
  {{ end }}
</section>

{{ partial "footer.html" . }}

<!-- homepage -->
{{ partial "header.html" . }}

<h1>Homepage</h1>

<section>
  <h1>Recent News</h1>
  {{ range first 5 (where .Data.Pages "Section" "news") }}
    <article>
      <h1><a href="{{ .RelPermalink }}">{{ .Title }}</a></h1>
      <p>{{ .Summary }}</p>
      <time datetime="{{ .Date.Format "2006-01-02T15:04:05-07:00" }}">
        {{ .Date.Format "January 2, 2006" }}
      </time>
      <a href="{{ .RelPermalink }}">Read more</a>
    </article>
  {{ end }}
</section>

{{ partial "footer.html" . }}

Simplify code around homepage latest news
Simplify code around homepage latest news

Hugo is capable of combine range with conditions (where) and
you can define from which sections pages will be pulled from.

By doing this, we remove complex logic around kind of page and
weird iterator.
