diff options
| author | Samuel Johnson <[email protected]> | 2025-12-11 03:29:40 -0500 |
|---|---|---|
| committer | Samuel Johnson <[email protected]> | 2025-12-11 03:29:40 -0500 |
| commit | 388456b88100aeeb6ca2c0806e1bffba381e944a (patch) | |
| tree | edc4c72718beb95d4aaf3fd6cce201cb203fb826 | |
| parent | 6e60ede1270c65654ee53e8a24cb310e0b1ab725 (diff) | |
Don't show next if there is no next
| -rw-r--r-- | cmd/web/handlers/blog.go | 13 | ||||
| -rw-r--r-- | ui/html/pages/index.tmpl.html | 4 |
2 files changed, 11 insertions, 6 deletions
diff --git a/cmd/web/handlers/blog.go b/cmd/web/handlers/blog.go index e9512c0..4c81669 100644 --- a/cmd/web/handlers/blog.go +++ b/cmd/web/handlers/blog.go @@ -19,11 +19,12 @@ type blogContext struct { err *log.Logger db *sql.DB - Post models.Post - Rows []models.Post - Name string - IsAuth bool - Offset int + Post models.Post + Rows []models.Post + Name string + IsAuth bool + PagePopulated bool + Offset int } func (ctx *blogContext) viewPost(w http.ResponseWriter, r *http.Request) { @@ -186,6 +187,7 @@ func (ctx *blogContext) post(w http.ResponseWriter, r *http.Request) { func (ctx *blogContext) index(w http.ResponseWriter, r *http.Request) { ctx.Rows = []models.Post{} ctx.IsAuth = false + ctx.PagePopulated = false if r.URL.Path != "/" { http.NotFound(w, r) @@ -221,6 +223,7 @@ func (ctx *blogContext) index(w http.ResponseWriter, r *http.Request) { p.FormattedTime = p.Time.Format(time.ANSIC) ctx.Rows = append(ctx.Rows, p) + ctx.PagePopulated = true } files := []string{ diff --git a/ui/html/pages/index.tmpl.html b/ui/html/pages/index.tmpl.html index 3f30833..fa5a9bb 100644 --- a/ui/html/pages/index.tmpl.html +++ b/ui/html/pages/index.tmpl.html @@ -49,7 +49,9 @@ {{if ne .Offset 0}} <a href="/?offset={{sub .Offset 10}}" class="nav_tag">Previous</a> {{end}} - <a href="/?offset={{add .Offset 10}}">Next</a> + {{if .PagePopulated}} + <a href="/?offset={{add .Offset 10}}">Next</a> + {{end}} </div> </div> {{end}} |
