Added TagCollectionPage

* Implements PrevPageURL and NextPageURL
* This allows the collection-tag template to get proper urls for
  paginating using tags.
This commit is contained in:
Donald Feury 2021-02-24 23:49:15 -05:00
parent 530439772d
commit 9ed2687543
1 changed files with 25 additions and 4 deletions

View File

@ -562,6 +562,30 @@ type CollectionPage struct {
CanInvite bool
}
type TagCollectionPage struct {
CollectionPage
Tag string
}
func (tcp TagCollectionPage) PrevPageURL(prefix string, n int, tl bool) string {
u := fmt.Sprintf("/tag:%s", tcp.Tag)
if n > 2 {
u += fmt.Sprintf("/page/%d", n-1)
}
if tl {
return u
}
return "/" + prefix + tcp.Alias + u
}
func (tcp TagCollectionPage) NextPageURL(prefix string, n int, tl bool) string {
if tl {
return fmt.Sprintf("/tag:%s/page/%d", tcp.Tag, n+1)
}
return fmt.Sprintf("/%s%s/tag:%s/page/%d", prefix, tcp.Alias, tcp.Tag, n+1)
}
func NewCollectionObj(c *Collection) *CollectionObj {
return &CollectionObj{
Collection: *c,
@ -916,10 +940,7 @@ func handleViewCollectionTag(app *App, w http.ResponseWriter, r *http.Request) e
}
// Serve collection
displayPage := struct {
CollectionPage
Tag string
}{
displayPage := TagCollectionPage{
CollectionPage: CollectionPage{
DisplayCollection: coll,
StaticPage: pageForReq(app, r),