@ -610,6 +610,30 @@ type CollectionPage struct {
CollAlias string
CollAlias string
}
}
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 {
func NewCollectionObj ( c * Collection ) * CollectionObj {
return & CollectionObj {
return & CollectionObj {
Collection : * c ,
Collection : * c ,
@ -951,16 +975,29 @@ func handleViewCollectionTag(app *App, w http.ResponseWriter, r *http.Request) e
coll := newDisplayCollection ( c , cr , page )
coll := newDisplayCollection ( c , cr , page )
taggedPostIDs , err := app . db . GetAllPostsTaggedIDs ( c , tag , cr . isCollOwner )
if err != nil {
return err
}
ttlPosts := len ( taggedPostIDs )
pagePosts := coll . Format . PostsPerPage ( )
coll . TotalPages = int ( math . Ceil ( float64 ( ttlPosts ) / float64 ( pagePosts ) ) )
if coll . TotalPages > 0 && page > coll . TotalPages {
redirURL := fmt . Sprintf ( "/page/%d" , coll . TotalPages )
if ! app . cfg . App . SingleUser {
redirURL = fmt . Sprintf ( "/%s%s%s" , cr . prefix , coll . Alias , redirURL )
}
return impart . HTTPError { http . StatusFound , redirURL }
}
coll . Posts , _ = app . db . GetPostsTagged ( app . cfg , c , tag , page , cr . isCollOwner )
coll . Posts , _ = app . db . GetPostsTagged ( app . cfg , c , tag , page , cr . isCollOwner )
if coll . Posts != nil && len ( * coll . Posts ) == 0 {
if coll . Posts != nil && len ( * coll . Posts ) == 0 {
return ErrCollectionPageNotFound
return ErrCollectionPageNotFound
}
}
// Serve collection
// Serve collection
displayPage := struct {
displayPage := TagCollectionPage {
CollectionPage
Tag string
} {
CollectionPage : CollectionPage {
CollectionPage : CollectionPage {
DisplayCollection : coll ,
DisplayCollection : coll ,
StaticPage : pageForReq ( app , r ) ,
StaticPage : pageForReq ( app , r ) ,