From ebeb45ac5a1e920e27ff25502089ef0131e5f1bd Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Thu, 21 Sep 2023 16:58:44 -0400 Subject: [PATCH] Support pagination when viewing language-filtered posts Ref T805 --- collections.go | 15 +++++++++------ templates/chorus-collection.tmpl | 12 ++++++------ templates/collection.tmpl | 12 ++++++------ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/collections.go b/collections.go index ac08592..f8d7498 100644 --- a/collections.go +++ b/collections.go @@ -74,6 +74,7 @@ type ( DisplayCollection struct { *CollectionObj Prefix string + NavSuffix string IsTopLevel bool CurrentPage int TotalPages int @@ -260,16 +261,16 @@ func (c *Collection) RedirectingCanonicalURL(isRedir bool) string { // PrevPageURL provides a full URL for the previous page of collection posts, // returning a /page/N result for pages >1 -func (c *Collection) PrevPageURL(prefix string, n int, tl bool) string { +func (c *Collection) PrevPageURL(prefix, navSuffix string, n int, tl bool) string { u := "" if n == 2 { // Previous page is 1; no need for /page/ prefix if prefix == "" { - u = "/" + u = navSuffix + "/" } // Else leave off trailing slash } else { - u = fmt.Sprintf("/page/%d", n-1) + u = fmt.Sprintf("%s/page/%d", navSuffix, n-1) } if tl { @@ -279,11 +280,12 @@ func (c *Collection) PrevPageURL(prefix string, n int, tl bool) string { } // NextPageURL provides a full URL for the next page of collection posts -func (c *Collection) NextPageURL(prefix string, n int, tl bool) string { +func (c *Collection) NextPageURL(prefix, navSuffix string, n int, tl bool) string { + if tl { - return fmt.Sprintf("/page/%d", n+1) + return fmt.Sprintf("%s/page/%d", navSuffix, n+1) } - return fmt.Sprintf("/%s%s/page/%d", prefix, c.Alias, n+1) + return fmt.Sprintf("/%s%s%s/page/%d", prefix, c.Alias, navSuffix, n+1) } func (c *Collection) DisplayTitle() string { @@ -1084,6 +1086,7 @@ func handleViewCollectionLang(app *App, w http.ResponseWriter, r *http.Request) coll := newDisplayCollection(c, cr, page) coll.Language = lang + coll.NavSuffix = fmt.Sprintf("/lang:%s", lang) ttlPosts, err := app.db.GetCollLangTotalPosts(coll.ID, lang) if err != nil { diff --git a/templates/chorus-collection.tmpl b/templates/chorus-collection.tmpl index 2bc165d..0fb5eaf 100644 --- a/templates/chorus-collection.tmpl +++ b/templates/chorus-collection.tmpl @@ -9,8 +9,8 @@ {{if .CustomCSS}}{{end}} - {{if gt .CurrentPage 1}}{{end}} - {{if lt .CurrentPage .TotalPages}}{{end}} + {{if gt .CurrentPage 1}}{{end}} + {{if lt .CurrentPage .TotalPages}}{{end}} {{if not .IsPrivate}}{{end}} @@ -92,11 +92,11 @@ body#collection header nav.tabs a:first-child { {{if gt .TotalPages 1}}{{end}} diff --git a/templates/collection.tmpl b/templates/collection.tmpl index 6e3d2dc..16ef873 100644 --- a/templates/collection.tmpl +++ b/templates/collection.tmpl @@ -9,8 +9,8 @@ {{if .CustomCSS}}{{end}} - {{if gt .CurrentPage 1}}{{end}} - {{if lt .CurrentPage .TotalPages}}{{end}} + {{if gt .CurrentPage 1}}{{end}} + {{if lt .CurrentPage .TotalPages}}{{end}} {{if not .IsPrivate}}{{end}} @@ -107,11 +107,11 @@ {{if gt .TotalPages 1}}{{end}}