~bouncepaw/betula

betula: Remove paginator if there is only one page v1 APPLIED

~danilax86: 2
 Remove paginator if there is only one page
 Fix calculating total pages logic

 3 files changed, 23 insertions(+), 10 deletions(-)
#1020732 .build.yml success
betula/patches/.build.yml: SUCCESS in 2m5s

[Remove paginator if there is only one page][0] from [~danilax86][1]

[0]: https://lists.sr.ht/~bouncepaw/betula/patches/42484
[1]: mailto:danila@danilax86.space

✓ #1020732 SUCCESS betula/patches/.build.yml https://builds.sr.ht/~bouncepaw/job/1020732
LGTM. Applied. Thanks!
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~bouncepaw/betula/patches/42484/mbox | git am -3
Learn more about email & git

[PATCH betula 1/2] Remove paginator if there is only one page Export this patch

From: Danila Gorelko <danila@danilax86.space>

---
 web/paginator-fragment.gohtml | 22 +++++++++++++---------
 web/templates.go              |  4 ++++
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/web/paginator-fragment.gohtml b/web/paginator-fragment.gohtml
index c48e79c..9e05783 100644
--- a/web/paginator-fragment.gohtml
+++ b/web/paginator-fragment.gohtml
@@ -1,11 +1,15 @@
{{define "paginator"}}
	<div class="paginator">
		{{range .Pages}}
			{{if .IsCurrent}}
				<b class="paginator-entry">{{.Number}}</b>
			{{else}}
				<a class="paginator-entry" href="{{.URL}}"{{if .IsNext}} rel="next"{{else if .IsPrev}} rel="prev"{{end}}>{{.Number}}</a>
			{{end}}
		{{end}}
	</div>
    {{if .OnlyOnePage}}
    {{else}}
        <div class="paginator">
            {{range .Pages}}
                {{if .IsCurrent}}
                    <b class="paginator-entry">{{.Number}}</b>
                {{else}}
                    <a class="paginator-entry"
                       href="{{.URL}}"{{if .IsNext}} rel="next"{{else if .IsPrev}} rel="prev"{{end}}>{{.Number}}</a>
                {{end}}
            {{end}}
        </div>
    {{end}}
{{end}}
diff --git a/web/templates.go b/web/templates.go
index 9179164..b069fe9 100644
--- a/web/templates.go
+++ b/web/templates.go
@@ -143,6 +143,10 @@ func (c *dataCommon) Pages() []types.Page {
	return c.paginator
}

func (c *dataCommon) OnlyOnePage() bool {
	return len(c.Pages()) == 1
}

func (c *dataCommon) Fill(C dataCommon) {
	if c == nil {
		panic("common data is nil! Initialize it at templateExec invocation.")
-- 
2.38.5

[PATCH betula 2/2] Fix calculating total pages logic Export this patch

From: Danila Gorelko <danila@danilax86.space>

Fixes: https://todo.sr.ht/~bouncepaw/betula/63
---
 types/types.go | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/types/types.go b/types/types.go
index 228e8e9..fcbb9c5 100644
--- a/types/types.go
+++ b/types/types.go
@@ -5,6 +5,7 @@ import (
	"fmt"
	"git.sr.ht/~bouncepaw/mycomarkup/v5/util"
	"html/template"
	"math"
	"net/url"
	"strings"
)
@@ -102,8 +103,12 @@ type Page struct {
	IsNext    bool
}

func countPages(totalPosts uint) uint {
	return uint(math.Ceil(float64(totalPosts) / float64(PostsPerPage)))
}

func PaginatorFromURL(url *url.URL, currentPage uint, totalPosts uint) (pages []Page) {
	totalPages := uint(totalPosts/PostsPerPage) + 1
	totalPages := countPages(totalPosts)
	values := url.Query()
	pages = make([]Page, totalPages)

-- 
2.38.5
betula/patches/.build.yml: SUCCESS in 2m5s

[Remove paginator if there is only one page][0] from [~danilax86][1]

[0]: https://lists.sr.ht/~bouncepaw/betula/patches/42484
[1]: mailto:danila@danilax86.space

✓ #1020732 SUCCESS betula/patches/.build.yml https://builds.sr.ht/~bouncepaw/job/1020732
LGTM. Applied. Thanks!