Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/curttimson/hugo-theme-massively.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrm3l <t.fabritz@gmail.com>2019-03-29 18:11:25 +0300
committerCurtis Timson <curt@live.co.uk>2019-03-29 18:11:25 +0300
commit3e897a825d7add7faa799369c40c92e5f165fcab (patch)
tree2eb257af8ac56e4a7cd40075ab066f721ce60377
parent7bd7a83100cf2c96b3f3dfa0b2433591c6534d69 (diff)
Fix Pagination Limit curtistimson/hugo-theme-massively#23 (#58)5.1.0
* Fix Pagination Limit curtistimson/hugo-theme-massively#23 * Provide a default value for pages * Better indentation * Make first and last optional * Resolving review issues * Consistent param names, theme name and dir provided * Bump min version * Bump package version * Full min version * Bump version to 5.1.0
-rw-r--r--exampleSite/config-prod.toml8
-rw-r--r--exampleSite/config.toml8
-rw-r--r--i18n/en.toml4
-rw-r--r--layouts/index.html21
-rw-r--r--layouts/partials/posts/pagination.html129
-rw-r--r--package-lock.json2
-rw-r--r--package.json2
-rw-r--r--static/assets/css/main.css19
8 files changed, 149 insertions, 44 deletions
diff --git a/exampleSite/config-prod.toml b/exampleSite/config-prod.toml
index 8be62f8..d027559 100644
--- a/exampleSite/config-prod.toml
+++ b/exampleSite/config-prod.toml
@@ -11,9 +11,11 @@ disqusShortname = ""
# Below parameters can be set to override default post settings
# [params.posts]
-# foldername = "post"
-# pagesize = "6"
-# featuredpost = "true"
+# folderName = "post"
+# pageSize = "6"
+# featuredPost = "true"
+# paginationPages = 2
+# showFirstLast = false
[languages]
[languages.en]
diff --git a/exampleSite/config.toml b/exampleSite/config.toml
index c8cf5cc..31abfe6 100644
--- a/exampleSite/config.toml
+++ b/exampleSite/config.toml
@@ -11,9 +11,11 @@ disqusShortname = ""
# Below parameters can be set to override default post settings
# [params.posts]
-# foldername = "post"
-# pagesize = "6"
-# featuredpost = "true"
+# folderName = "post"
+# pageSize = "6"
+# featuredPost = "true"
+# paginationPages = 2
+# showFirstLast = false
[languages]
[languages.en]
diff --git a/i18n/en.toml b/i18n/en.toml
index fbd9f5d..6c14f59 100644
--- a/i18n/en.toml
+++ b/i18n/en.toml
@@ -26,3 +26,7 @@
other = "Next"
[PAGINATION_PREVIOUS]
other = "Prev"
+[PAGINATION_FIRST]
+ other = "First"
+[PAGINATION_LAST]
+ other = "Last" \ No newline at end of file
diff --git a/layouts/index.html b/layouts/index.html
index ae90e4d..b8eb2e2 100644
--- a/layouts/index.html
+++ b/layouts/index.html
@@ -35,24 +35,9 @@
{{ end }}
{{ partial "posts/list.html" (dict "posts" $postsPaging "siteData" (index .Site.Data .Site.Language.Lang)) }}
- <!-- Footer -->
- {{ if gt $postsPaging.TotalPages 1 }}
- <footer>
- <div class="pagination">
- {{ if $postsPaging.HasPrev }}
- <a href="{{ $postsPaging.Prev.URL }}" class="previous"></a>
- {{ end }}
- {{ range $postsPaging.Pagers }}
- {{ if lt .PageNumber 10 }}
- <a href="{{ .URL }}" class="page{{ if eq .PageNumber $postsPaging.PageNumber }} active{{ end }}">{{ .PageNumber }}</a>
- {{ end }}
- {{ end }}
- {{ if $postsPaging.HasNext }}
- <a href="{{ $postsPaging.Next.URL }}" class="next">{{ i18n "NEXT" . }}</a>
- {{ end }}
- </div>
- </footer>
- {{ end }}
+ {{ $paginator := .Paginator }}
+ {{ $outer := . }}
+ {{ partial "posts/pagination.html" (dict "paginator" $paginator "outer" $outer)}}
</div>
diff --git a/layouts/partials/posts/pagination.html b/layouts/partials/posts/pagination.html
index e67a900..2f65bde 100644
--- a/layouts/partials/posts/pagination.html
+++ b/layouts/partials/posts/pagination.html
@@ -1,18 +1,119 @@
-<!-- Footer -->
-{{ if gt .paging.TotalPages 1 }}
+{{ $paginator := .paginator }}
+{{ $outer := .outer}}
+
+<!-- Thanks to https://glennmccomb.com/articles/how-to-build-custom-hugo-pagination/ -->
+
+<!-- Show first and last link-->
+{{ $show_first_last := $outer.Site.Params.Posts.showFirstLast | default false }}
+
+<!-- Number of links either side of the current page. -->
+{{ $adjacent_links := $outer.Site.Params.Posts.paginationPages | default 2 }}
+
+<!-- $max_links = ($adjacent_links * 2) + 1 -->
+{{ $max_links := (add (mul $adjacent_links 2) 1) }}
+
+<!-- $lower_limit = $adjacent_links + 1 -->
+{{ $lower_limit := (add $adjacent_links 1) }}
+
+<!-- $upper_limit = $paginator.TotalPages - $adjacent_links -->
+{{ $upper_limit := (sub $paginator.TotalPages $adjacent_links) }}
+
+{{ if gt $paginator.TotalPages 1 }}
<footer>
<div class="pagination">
- {{ if .paging.HasPrev }}
- <a href="{{ .paging.Prev.URL }}" class="previous">{{ i18n "PAGINATION_PREVIOUS" . }}</a>
- {{ end }}
- {{ range .paging.Pagers }}
- {{ if lt .PageNumber 10 }}
- <a href="{{ .URL }}" class="page{{ if eq .PageNumber .paging.PageNumber }} active{{ end }}">{{ .PageNumber }}</a>
- {{ end }}
- {{ end }}
- {{ if .paging.HasNext }}
- <a href="{{ .paging.Next.URL }}" class="next">{{ i18n "PAGINATION_NEXT" . }}</a>
- {{ end }}
+ <ul class="pagination">
+
+ <!-- First page. -->
+ {{ if $show_first_last }}
+ {{ if ne $paginator.PageNumber 1 }}
+ <li>
+ <a href="{{ $paginator.First.URL }}" class="extra first">
+ {{ i18n "PAGINATION_FIRST" . }}
+ </a>
+ </li>
+ {{ end }}
+ {{ end }}
+ <!-- Previous page. -->
+ {{ if $paginator.HasPrev }}
+ <li>
+ <a href="{{ $paginator.Prev.URL }}" class="previous">
+ {{ i18n "PAGINATION_PREVIOUS" . }}
+ </a>
+ </li>
+ {{ end }}
+
+ <!-- Page numbers. -->
+ {{ range $paginator.Pagers }}
+ {{ $outer.Scratch.Set "page_number_flag" false }}
+
+ <!-- Advanced page numbers. -->
+ {{ if gt $paginator.TotalPages $max_links }}
+
+ <!-- Lower limit pages. -->
+ <!-- If the user is on a page which is in the lower limit. -->
+ {{ if le $paginator.PageNumber $lower_limit }}
+
+ <!-- If the current loop page is less than max_links. -->
+ {{ if le .PageNumber $max_links }}
+ {{ $outer.Scratch.Set "page_number_flag" true }}
+ {{ end }}
+
+ <!-- Upper limit pages. -->
+ <!-- If the user is on a page which is in the upper limit. -->
+ {{ else if ge $paginator.PageNumber $upper_limit }}
+
+ <!-- If the current loop page is greater than total pages minus $max_links -->
+ {{ if gt .PageNumber (sub $paginator.TotalPages $max_links) }}
+ {{ $outer.Scratch.Set "page_number_flag" true }}
+ {{ end }}
+
+ <!-- Middle pages. -->
+ {{ else }}
+
+ {{ if and ( ge .PageNumber (sub $paginator.PageNumber $adjacent_links) ) ( le .PageNumber (add $paginator.PageNumber $adjacent_links) ) }}
+ {{ $outer.Scratch.Set "page_number_flag" true }}
+ {{ end }}
+
+ {{ end }}
+
+ <!-- Simple page numbers. -->
+ {{ else }}
+
+ {{ $outer.Scratch.Set "page_number_flag" true }}
+
+ {{ end }}
+
+ <!-- Output page numbers. -->
+ {{ if eq ($outer.Scratch.Get "page_number_flag") true }}
+ <li>
+ <a href="{{ .URL }}" class="page{{ if eq . $paginator }} active{{ end }}">
+ {{ .PageNumber }}
+ </a>
+ </li>
+ {{ end }}
+
+ {{ end }}
+
+ <!-- Next page. -->
+ {{ if $paginator.HasNext }}
+ <li>
+ <a href="{{ $paginator.Next.URL }}" class="next">
+ {{ i18n "PAGINATION_NEXT" . }}
+ </a>
+ </li>
+ {{ end }}
+
+ <!-- Last page. -->
+ {{ if $show_first_last }}
+ {{ if ne $paginator.PageNumber $paginator.TotalPages }}
+ <li>
+ <a href="{{ $paginator.Last.URL }}" class="extra last">
+ {{ i18n "PAGINATION_LAST" . }}
+ </a>
+ </li>
+ {{ end }}
+ {{ end }}
+ </ul>
</div>
</footer>
-{{ end }}
+{{ end }} \ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index b5edaf3..0e8383b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,5 +1,5 @@
{
"name": "hugo-theme-massively",
- "version": "5.0.0",
+ "version": "5.1.0",
"lockfileVersion": 1
}
diff --git a/package.json b/package.json
index e54ee7e..d456632 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "hugo-theme-massively",
- "version": "5.0.0",
+ "version": "5.1.0",
"description": "HTML5 UP theme Massively for Hugo",
"main": "index.js",
"repository": {
diff --git a/static/assets/css/main.css b/static/assets/css/main.css
index bffca55..ac9c3ce 100644
--- a/static/assets/css/main.css
+++ b/static/assets/css/main.css
@@ -2937,12 +2937,12 @@
text-transform: uppercase;
}
- .pagination .next, .pagination .previous {
+ .pagination .next, .pagination .previous, .pagination .first, .pagination .last {
text-decoration: none;
padding: 0 1.75rem;
}
- .pagination .next:before, .pagination .previous:before {
+ .pagination .next:before, .pagination .previous:before, .pagination .first:before, .pagination .last:before {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
font-family: FontAwesome;
@@ -2951,7 +2951,7 @@
text-transform: none !important;
}
- .pagination .next:before, .pagination .previous:before {
+ .pagination .next:before, .pagination .previous:before , .pagination .first:before, .pagination .last:before{
display: inline-block;
color: inherit !important;
}
@@ -2960,13 +2960,24 @@
content: '\f104';
margin-right: 0.9375em;
}
+
+ .pagination .first:before {
+ content: '\f100';
+ margin-right: 0.9375em;
+ }
.pagination .next:before {
content: '\f105';
float: right;
margin-left: 0.9375em;
}
-
+
+ .pagination .last:before {
+ content: '\f101';
+ float: right;
+ margin-left: 0.9375em;
+ }
+
@media screen and (max-width: 980px) {
.pagination a, .pagination span {