Skip to content

Commit

Permalink
merge partials
Browse files Browse the repository at this point in the history
  • Loading branch information
cntrump committed Dec 26, 2019
1 parent e80b836 commit ec7ce7b
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 137 deletions.
70 changes: 2 additions & 68 deletions layouts/_default/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,74 +9,8 @@ <h1>{{ .Title }}</h1>
</article>
{{- end }}
<!-- Ranges through content/posts/*.md -->
<ul class="note-list">
{{- range $paginator.Pages }}
<li>
<a class="note" href="{{ .RelPermalink }}">
<p class="note-title">{{ .Title | safeHTML }}</p>
<p>{{ .Date.Format "2006-01-02" }}</p>
<p class="note-content">{{ .Summary | plainify | safeHTML }}{{ if .Truncated }}…{{ end }}</p>
{{- $relURL := .RelPermalink -}}
{{- $imgs := .Params.imgs -}}
{{- with .Params.imgs }}
<figure>
{{- $imgCount := len $imgs -}}
{{- range $imgs }}
{{- $imgurl := lower . -}}
{{- if and (not (hasPrefix $imgurl "http://")) (not (hasPrefix $imgurl "https://")) }}
{{- $imgurl = path.Join $relURL . -}}
{{- end }}
<img src="{{ $imgurl }}" alt />
{{- end }}
</figure>
{{- end }}
{{- if or .Params.categories .Params.tags }}
<p>
{{- range .Params.categories }}
{{- $url := print "/categories/" (. | urlize) "/" -}}
<object><a class="article-category" href={{ $url | relURL }}><span class="hashtag">#</span>{{ . }}</a></object>
{{- end }}
{{- range .Params.tags }}
{{- $url := print "/tags/" ( . | urlize) "/" -}}
<object><a class="article-tag" href={{ $url | relURL }}><span class="hashtag">#</span>{{ . }}</a></object>
{{- end }}
</p>
{{- end }}
</a>
</li>
{{- end }}
</ul>

{{- if gt $paginator.TotalPages 1 }}
{{- partial "note-list.html" $paginator -}}
{{- partial "pagination.html" $paginator -}}

{{- $pageIndex := $paginator.PageNumber -}}
{{- $totalPages := $paginator.TotalPages -}}
{{- $cols := 5.0 -}}
{{- $rows := math.Ceil (div $totalPages $cols) -}}
{{- $row := math.Ceil (div $pageIndex $cols) -}}
{{- $startPage := sub (mul $row $cols) $cols -}}
{{- $endPage := add $startPage $cols -}}

<div class="pagination">
<ul>
{{- if gt $row 1 }}
<li><a href="{{ $paginator.Prev.URL }}" class="previous_page">&laquo;</a></li>
{{- end }}

{{- range $paginator.Pagers }}
{{- if and (gt .PageNumber $startPage) (le .PageNumber $endPage) }}
{{- $active := "" -}}
{{- if eq .PageNumber $paginator.PageNumber }}
{{- $active = "active" -}}
{{- end }}
<li><a class="{{ $active }}" href="{{ .URL }}">{{ .PageNumber }}</a></li>
{{- end }}
{{- end }}

{{- if lt $row $rows }}
<li><a href="{{ $paginator.Next.URL }}" class="next_page">&raquo;</a></li>
{{- end }}
</ul>
</div>
{{- end }}
{{- end }}
71 changes: 2 additions & 69 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,7 @@
</div>
{{- end }}

<ul class="note-list">
{{- range $paginator.Pages }}
<li>
<a class="note" href="{{ .RelPermalink }}">
<p class="note-title">{{ .Title | safeHTML }}</p>
<p>{{ .Date.Format "2006-01-02" }}</p>
<p class="note-content">{{ .Summary | plainify | safeHTML }}{{ if .Truncated }}…{{ end }}</p>
{{- $relURL := .RelPermalink -}}
{{- $imgs := .Params.imgs -}}
{{- with .Params.imgs }}
<figure>
{{- $imgCount := len $imgs -}}
{{- range $imgs }}
{{- $imgurl := lower . -}}
{{- if and (not (hasPrefix $imgurl "http://")) (not (hasPrefix $imgurl "https://")) }}
{{- $imgurl = path.Join $relURL . -}}
{{- end }}
<img src="{{ $imgurl }}" alt />
{{- end }}
</figure>
{{- end }}
{{- if or .Params.categories .Params.tags }}
<p>
{{- range .Params.categories }}
{{- $url := print "/categories/" (. | urlize) "/" -}}
<object><a class="article-category" href={{ $url | relURL }}><span class="hashtag">#</span>{{ . }}</a></object>
{{- end }}
{{- range .Params.tags }}
{{- $url := print "/tags/" ( . | urlize) "/" -}}
<object><a class="article-tag" href={{ $url | relURL }}><span class="hashtag">#</span>{{ . }}</a></object>
{{- end }}
</p>
{{- end }}
</a>
</li>
{{- end }}
</ul>
{{- partial "note-list.html" $paginator -}}
{{- partial "pagination.html" $paginator -}}

{{- if gt $paginator.TotalPages 1 }}

{{- $pageIndex := $paginator.PageNumber -}}
{{- $totalPages := $paginator.TotalPages -}}
{{- $cols := 5.0 -}}
{{- $rows := math.Ceil (div $totalPages $cols) -}}
{{- $row := math.Ceil (div $pageIndex $cols) -}}
{{- $startPage := sub (mul $row $cols) $cols -}}
{{- $endPage := add $startPage $cols -}}

<div class="pagination">
<ul>
{{- if gt $row 1 }}
<li><a href="{{ $paginator.Prev.URL }}" class="previous_page">&laquo;</a></li>
{{- end }}

{{- range $paginator.Pagers }}
{{- if and (gt .PageNumber $startPage) (le .PageNumber $endPage) }}
{{- $active := "" -}}
{{- if eq .PageNumber $paginator.PageNumber }}
{{- $active = "active" -}}
{{- end }}
<li><a class="{{ $active }}" href="{{ .URL }}">{{ .PageNumber }}</a></li>
{{- end }}
{{- end }}

{{- if lt $row $rows }}
<li><a href="{{ $paginator.Next.URL }}" class="next_page">&raquo;</a></li>
{{- end }}
</ul>
</div>
{{- end }}
{{- end }}
41 changes: 41 additions & 0 deletions layouts/partials/note-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{- $paginator := . -}}

{{- if gt $paginator.TotalPages 0 }}
<ul class="note-list">
{{- range $paginator.Pages }}
<li>
<a class="note" href="{{ .RelPermalink }}">
<p class="note-title">{{ .Title | safeHTML }}</p>
<p>{{ .Date.Format "2006-01-02" }}</p>
<p class="note-content">{{ .Summary | plainify | safeHTML }}{{ if .Truncated }}…{{ end }}</p>
{{- $relURL := .RelPermalink -}}
{{- $imgs := .Params.imgs -}}
{{- with .Params.imgs }}
<figure>
{{- $imgCount := len $imgs -}}
{{- range $imgs }}
{{- $imgurl := lower . -}}
{{- if and (not (hasPrefix $imgurl "http://")) (not (hasPrefix $imgurl "https://")) }}
{{- $imgurl = path.Join $relURL . -}}
{{- end }}
<img src="{{ $imgurl }}" alt />
{{- end }}
</figure>
{{- end }}
{{- if or .Params.categories .Params.tags }}
<p>
{{- range .Params.categories }}
{{- $url := print "/categories/" (. | urlize) "/" -}}
<object><a class="article-category" href={{ $url | relURL }}><span class="hashtag">#</span>{{ . }}</a></object>
{{- end }}
{{- range .Params.tags }}
{{- $url := print "/tags/" ( . | urlize) "/" -}}
<object><a class="article-tag" href={{ $url | relURL }}><span class="hashtag">#</span>{{ . }}</a></object>
{{- end }}
</p>
{{- end }}
</a>
</li>
{{- end }}
</ul>
{{- end }}
34 changes: 34 additions & 0 deletions layouts/partials/pagination.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{- $paginator := . -}}

{{- if gt $paginator.TotalPages 1 }}

{{- $pageIndex := $paginator.PageNumber -}}
{{- $totalPages := $paginator.TotalPages -}}
{{- $cols := 5.0 -}}
{{- $rows := math.Ceil (div $totalPages $cols) -}}
{{- $row := math.Ceil (div $pageIndex $cols) -}}
{{- $startPage := sub (mul $row $cols) $cols -}}
{{- $endPage := add $startPage $cols -}}

<div class="pagination">
<ul>
{{- if gt $row 1 }}
<li><a href="{{ $paginator.Prev.URL }}" class="previous_page">&laquo;</a></li>
{{- end }}

{{- range $paginator.Pagers }}
{{- if and (gt .PageNumber $startPage) (le .PageNumber $endPage) }}
{{- $active := "" -}}
{{- if eq .PageNumber $paginator.PageNumber }}
{{- $active = "active" -}}
{{- end }}
<li><a class="{{ $active }}" href="{{ .URL }}">{{ .PageNumber }}</a></li>
{{- end }}
{{- end }}

{{- if lt $row $rows }}
<li><a href="{{ $paginator.Next.URL }}" class="next_page">&raquo;</a></li>
{{- end }}
</ul>
</div>
{{- end }}

0 comments on commit ec7ce7b

Please sign in to comment.