diff --git a/apps/threads.lua b/apps/threads.lua index 417f8ad..343011b 100644 --- a/apps/threads.lua +++ b/apps/threads.lua @@ -69,6 +69,11 @@ app:get("thread", "/:slug", function(self) end self.thread = thread + local post_count = Posts:count(db.clause({ + thread_id = thread.id + })) + self.pages = math.ceil(post_count / POSTS_PER_PAGE) + if self.params.after then local after_id = tonumber(self.params.after) local post_position = Posts:count(db.clause({ @@ -77,13 +82,9 @@ app:get("thread", "/:slug", function(self) })) self.page = math.floor((post_position - 1) / POSTS_PER_PAGE) + 1 else - self.page = tonumber(self.params.page) or 1 + self.page = math.max(1, math.min(tonumber(self.params.page) or 1, self.pages)) end - local post_count = Posts:count(db.clause({ - thread_id = thread.id - })) - self.pages = math.ceil(post_count / POSTS_PER_PAGE) -- self.page = math.max(1, math.min(self.page, self.pages)) local posts = db.query([[ SELECT