{{ $pag := $.Paginator }}
{{ if gt $pag.TotalPages 1 }}
<nav class="navigation pagination" role="navigation">
	<h2 class="screen-reader-text">Posts navigation</h2>
	<div class="nav-links">
		{{ if $pag.HasPrev }}
			<a class="prev page-numbers" href="{{ $pag.Prev.URL }}">Previous</a>
		{{ end }}
			{{ $.Scratch.Set "__paginator.ellipsed" false }}
			{{ range $pag.Pagers }}
			{{ $right := sub .TotalPages .PageNumber }}
			{{ $showNumber := or (le .PageNumber 3) (eq $right 0) }}
			{{ $showNumber := or $showNumber (and (gt .PageNumber (sub $pag.PageNumber 2)) (lt .PageNumber (add $pag.PageNumber 2)))  }}
			{{ if $showNumber }}
				{{ $.Scratch.Set "__paginator.ellipsed" false }}
				{{ $.Scratch.Set "__paginator.shouldEllipse" false }}
			{{ else }}
				{{ $.Scratch.Set "__paginator.shouldEllipse" (not ($.Scratch.Get "__paginator.ellipsed") ) }}
				{{ $.Scratch.Set "__paginator.ellipsed" true }}
			{{ end }}
				{{ if $showNumber }}
					<a class="page-numbers" href="{{ .URL }}">{{ .PageNumber }}</a>
				{{ else if ($.Scratch.Get "__paginator.shouldEllipse") }}
					<span aria-current="page" class="page-numbers current">{{ .PageNumber }}</span>
				{{ end }}
			{{ end }}
		{{ if $pag.HasNext }}
			<a class="next page-numbers" href="{{ $pag.Next.URL }}">Next</a>
		{{ end }}
	</div>
</nav>
{{ end }}
