Archived
1
0
This commit is contained in:
Jeff Becker 2018-03-09 10:05:03 -05:00
parent b61c22898e
commit c5479e2386
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
3 changed files with 12 additions and 11 deletions

View File

@ -285,14 +285,14 @@ func (self *FileCache) regenUkko() {
return return
} }
defer f.Close() defer f.Close()
template.genUkkoPaginated(self.prefix, self.name, f, self.database, i, false, nil, false) template.genUkkoPaginated(self.prefix, self.name, f, self.database, 10, i, false, nil, false)
j, err := os.Create(jname) j, err := os.Create(jname)
if err != nil { if err != nil {
log.Printf("failed to create json ukko", i, err) log.Printf("failed to create json ukko", i, err)
return return
} }
defer j.Close() defer j.Close()
template.genUkkoPaginated(self.prefix, self.name, j, self.database, i, true, nil, false) template.genUkkoPaginated(self.prefix, self.name, j, self.database, 10, i, true, nil, false)
} }
} }

View File

@ -136,13 +136,13 @@ func (self *nullHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
goto notfound goto notfound
} }
} }
if page == 0 { pages, _ := self.database.GetUkkoPageCount(10)
if path == "/o/" {
if self.invertPagination { if self.invertPagination {
pages, _ := self.database.GetUkkoPageCount(10)
page = int(pages) page = int(pages)
} }
} }
template.genUkkoPaginated(self.prefix, self.name, w, self.database, page, isjson, i18n, self.invertPagination) template.genUkkoPaginated(self.prefix, self.name, w, self.database, int(pages), page, isjson, i18n, self.invertPagination)
return return
} }
@ -181,7 +181,8 @@ func (self *nullHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(file, "ukko-") { if strings.HasPrefix(file, "ukko-") {
page := getUkkoPage(file) page := getUkkoPage(file)
template.genUkkoPaginated(self.prefix, self.name, w, self.database, page, isjson, i18n, self.invertPagination) pages, _ := self.database.GetUkkoPageCount(10)
template.genUkkoPaginated(self.prefix, self.name, w, self.database, int(pages), page, isjson, i18n, self.invertPagination)
return return
} }
if strings.HasPrefix(file, "thread-") { if strings.HasPrefix(file, "thread-") {

View File

@ -261,18 +261,18 @@ func (self *templateEngine) genBoardPage(allowFiles, requireCaptcha bool, prefix
func (self *templateEngine) genUkko(prefix, frontend string, wr io.Writer, database Database, json bool, i18n *I18N, invertPagination bool) { func (self *templateEngine) genUkko(prefix, frontend string, wr io.Writer, database Database, json bool, i18n *I18N, invertPagination bool) {
var page int64 var page int64
var err error pages, err := database.GetUkkoPageCount(10)
if invertPagination { if invertPagination {
page, err = database.GetUkkoPageCount(10) page = pages
} }
if err == nil { if err == nil {
self.genUkkoPaginated(prefix, frontend, wr, database, int(page), json, i18n, invertPagination) self.genUkkoPaginated(prefix, frontend, wr, database, int(pages), int(page), json, i18n, invertPagination)
} else { } else {
log.Println("genUkko()", err.Error()) log.Println("genUkko()", err.Error())
} }
} }
func (self *templateEngine) genUkkoPaginated(prefix, frontend string, wr io.Writer, database Database, page int, json bool, i18n *I18N, invertPagination bool) { func (self *templateEngine) genUkkoPaginated(prefix, frontend string, wr io.Writer, database Database, pages, page int, json bool, i18n *I18N, invertPagination bool) {
var threads []ThreadModel var threads []ThreadModel
for _, article := range database.GetLastBumpedThreadsPaginated("", 10, page*10) { for _, article := range database.GetLastBumpedThreadsPaginated("", 10, page*10) {
root := article[0] root := article[0]
@ -283,7 +283,7 @@ func (self *templateEngine) genUkkoPaginated(prefix, frontend string, wr io.Writ
} }
} }
obj := map[string]interface{}{"prefix": prefix, "threads": threads, "page": page} obj := map[string]interface{}{"prefix": prefix, "threads": threads, "page": page}
if invertPagination { if invertPagination && page < pages {
obj["prev"] = map[string]interface{}{"no": page + 1} obj["prev"] = map[string]interface{}{"no": page + 1}
} else if page > 0 { } else if page > 0 {
obj["prev"] = map[string]interface{}{"no": page - 1} obj["prev"] = map[string]interface{}{"no": page - 1}