diff --git a/handler/template.go b/handler/template.go index 9a620cf..c90c498 100644 --- a/handler/template.go +++ b/handler/template.go @@ -110,6 +110,40 @@ func ParseTime(date time.Time) string { return date.Format("2006-01-02 15:04") } +func CreatePaginator(base, ending string, current_page, max_page int) template.HTML { + peek := 2 + limit := peek*peek + 1 + count := 0 + pages := "" + + pages += fmt.Sprintf(`«`, base, ending) + pages += fmt.Sprintf(`‹`, base, max(1, current_page-1), ending) + + for i := current_page - peek; (i <= max_page || max_page == -1) && count < limit; i++ { + if i < 1 { + continue + } + if i == current_page { + pages += fmt.Sprintf(`%d`, base, i, ending, i) + + } else { + pages += fmt.Sprintf(`%d`, base, i, ending, i) + + } + count++ + } + + pages += fmt.Sprintf(`›`, base, min(max_page, current_page+1), ending) + + if max_page == -1 { + pages += fmt.Sprintf(`»`, base, max_page, ending) + } else { + pages += fmt.Sprintf(`»`, base, max_page, ending) + } + + return template.HTML(pages) +} + func GetTemplateFunctions() template.FuncMap { return template.FuncMap{ "toInt": func(s string) int { @@ -151,5 +185,8 @@ func GetTemplateFunctions() template.FuncMap { "parseTime": func(date time.Time) string { return ParseTime(date) }, + "createPaginator": func(base, ending string, current_page, max_page int) template.HTML { + return CreatePaginator(base, ending, current_page, max_page) + }, } } diff --git a/template/css/style.css b/template/css/style.css index f5a302d..973e88c 100644 --- a/template/css/style.css +++ b/template/css/style.css @@ -125,15 +125,15 @@ input[type=submit], button:active, input[type=submit]:active, -.switch-button, -.pagination-button { +.switch-button:active, +.pagination-button:active { filter: brightness(0.85); } button:hover, input[type=submit]:hover, -.switch-button, -.pagination-button { +.switch-button:hover, +.pagination-button:hover { cursor: pointer; filter: brightness(1.2); } @@ -161,6 +161,17 @@ input[type=submit][hidden] { .pagination { text-align: center; } +.pagination .pagination-button { + margin-right: 5px; +} +.pagination #highlight { + filter: brightness(1.2); +} +.pagination #disabled { + pointer-events: none; + background-color: #222; + filter: brightness(1); +} nav { margin-top: 15px; diff --git a/template/css/style.scss b/template/css/style.scss index 27defca..60f3a1f 100644 --- a/template/css/style.scss +++ b/template/css/style.scss @@ -145,15 +145,15 @@ input[type="submit"], button:active, input[type="submit"]:active, -.switch-button, -.pagination-button { +.switch-button:active, +.pagination-button:active { filter: brightness($active-brightness); } button:hover, input[type="submit"]:hover, -.switch-button, -.pagination-button { +.switch-button:hover, +.pagination-button:hover { cursor: pointer; filter: brightness($hover-brightness); } @@ -180,6 +180,20 @@ input[type="submit"][hidden] { .pagination { text-align: center; + + .pagination-button { + margin-right: 5px; + } + + #highlight { + filter: brightness($hover-brightness); + } + + #disabled { + pointer-events: none; + background-color: $bg-secondary; + filter: brightness(1); + } } nav { diff --git a/template/pages/following.jet.html b/template/pages/following.jet.html index 1f9846f..14ffffa 100644 --- a/template/pages/following.jet.html +++ b/template/pages/following.jet.html @@ -8,17 +8,9 @@