From e8fa40c0cab9955ef4b83b9e04d2154f3f460734 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 3 Apr 2017 21:35:09 -0400 Subject: [PATCH] fix boards.html --- .../backends/srndv2/src/srnd/null_cache.go | 2 +- contrib/backends/srndv2/src/srnd/templates.go | 76 +++++++++---------- 2 files changed, 36 insertions(+), 42 deletions(-) diff --git a/contrib/backends/srndv2/src/srnd/null_cache.go b/contrib/backends/srndv2/src/srnd/null_cache.go index b6ebcf4..22ee020 100644 --- a/contrib/backends/srndv2/src/srnd/null_cache.go +++ b/contrib/backends/srndv2/src/srnd/null_cache.go @@ -99,7 +99,7 @@ func (self *nullHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } if strings.HasPrefix(file, "boards.html") { - template.genFrontPage(10, self.prefix, self.name, ioutil.Discard, w, self.database) + template.genBoardList(self.prefix, self.name, w, self.database) return } diff --git a/contrib/backends/srndv2/src/srnd/templates.go b/contrib/backends/srndv2/src/srnd/templates.go index e78aca1..c139545 100644 --- a/contrib/backends/srndv2/src/srnd/templates.go +++ b/contrib/backends/srndv2/src/srnd/templates.go @@ -441,43 +441,41 @@ func (self *templateEngine) genGraphs(prefix string, wr io.Writer, db Database) } -// generate front page and board list +func (self *templateEngine) genBoardList(prefix, name string, wr io.Writer, db Database) { + // the graph for the front page + var frontpage_graph boardPageRows + + // for each group + groups := db.GetAllNewsgroups() + for _, group := range groups { + // posts this hour + hour := db.CountPostsInGroup(group, 3600) + // posts today + day := db.CountPostsInGroup(group, 86400) + // posts total + all := db.CountPostsInGroup(group, 0) + frontpage_graph = append(frontpage_graph, boardPageRow{ + All: all, + Day: day, + Hour: hour, + Board: group, + }) + } + param := map[string]interface{}{ + "prefix": prefix, + "frontend": name, + } + sort.Sort(frontpage_graph) + param["graph"] = frontpage_graph + _, err := io.WriteString(wr, self.renderTemplate("boardlist.mustache", param)) + if err != nil { + log.Println("error writing board list page", err) + } +} + +// generate front page func (self *templateEngine) genFrontPage(top_count int, prefix, frontend_name string, indexwr, boardswr io.Writer, db Database) { - /* - // the graph for the front page - var frontpage_graph boardPageRows - // for each group - groups := db.GetAllNewsgroups() - for _, group := range groups { - // posts this hour - hour := db.CountPostsInGroup(group, 3600) - // posts today - day := db.CountPostsInGroup(group, 86400) - // posts total - all := db.CountPostsInGroup(group, 0) - frontpage_graph = append(frontpage_graph, boardPageRow{ - All: all, - Day: day, - Hour: hour, - Board: group, - }) - } - - var posts_graph postsGraph - - posts := db.GetLastDaysPosts(10) - if posts == nil { - // wtf? - } else { - for _, entry := range posts { - posts_graph = append(posts_graph, postsGraphRow{ - day: entry.Time(), - Num: entry.Count(), - }) - } - } - */ models := db.GetLastPostedPostModels(prefix, 20) wr := indexwr @@ -488,7 +486,7 @@ func (self *templateEngine) genFrontPage(top_count int, prefix, frontend_name st /* sort.Sort(posts_graph) param["postsgraph"] = self.renderTemplate("posts_graph.mustache", map[string]interface{}{"graph": posts_graph}) - sort.Sort(frontpage_graph) + if len(frontpage_graph) > top_count { param["boardgraph"] = frontpage_graph[:top_count] } else { @@ -507,11 +505,7 @@ func (self *templateEngine) genFrontPage(top_count int, prefix, frontend_name st } /* wr = boardswr - param["graph"] = frontpage_graph - _, err = io.WriteString(wr, self.renderTemplate("boardlist.mustache", param)) - if err != nil { - log.Println("error writing board list page", err) - } + */ }