From 8b66e363b7ad817da1e8bb57623be257d550e9dc Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sat, 6 Feb 2016 00:45:37 -0800 Subject: [PATCH] Add top 20 quotes --- src/quotesite.nim | 21 ++++++++++++++++++++- src/templates/layout.mustache | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/quotesite.nim b/src/quotesite.nim index 1b4aac9..54e8d85 100644 --- a/src/quotesite.nim +++ b/src/quotesite.nim @@ -162,6 +162,25 @@ routes: redirect "/quotes/" & row[0] except: fail() + get "/top": + try: + var + rows = db.getAllRows(sql"SELECT * from quotes where deleted=0 and votes > 0 order by votes desc LIMIT 20") + ctx = newContext() + quoteSeq = newSeq[Context]() + + for row in items(rows): + var c = newContext() + c.contextQuote row[0].parseInt(), row + quoteSeq.add c + + ctx["quotes"] = quoteSeq + + renderMustache("top 20 quotes", browseTemplate, ctx) + + except: + fail() + get "/@kind/@id": var title: string = "" @@ -183,7 +202,7 @@ routes: of "quotes": rows = db.getAllRows(sql"SELECT * FROM quotes WHERE id = ?", qid) - title = "quote #" & $qid & " by " & rows[0][2] + title = "#" & $qid & " by " & rows[0][2] else: if (@"kind").startsWith "hashtag-": let channel = (@"kind").replace("hashtag-", "#") diff --git a/src/templates/layout.mustache b/src/templates/layout.mustache index a6418e5..688341f 100644 --- a/src/templates/layout.mustache +++ b/src/templates/layout.mustache @@ -7,6 +7,7 @@
home channel + top submit