diff --git a/epilogue/archive_generator.py b/epilogue/archive_generator.py index 9d72d4e..80892fd 100644 --- a/epilogue/archive_generator.py +++ b/epilogue/archive_generator.py @@ -1,6 +1,7 @@ import os import logging import shutil +import math from itertools import chain from traceback import print_exc @@ -9,6 +10,7 @@ import chevron import bbcode import html +from .forum import DEFAULT_POSTS_PER_PAGE from .wiki import Template, Renderer, Linker, NAMESPACES as WIKI_NAMESPACES logging.basicConfig(level=logging.INFO) @@ -190,6 +192,8 @@ class ArchiveGenerator(): "target": "page-0.html" }) + total_pages = math.ceil((thread.num_replies + 1) / DEFAULT_POSTS_PER_PAGE) + page_links = [{"label": page + 1, "link": f"page-{page}.html"} for page in range(total_pages)] page = 0 while True: posts = [prepare_post(post) for post in forum.get_posts_in_thread(thread, page)] @@ -204,6 +208,7 @@ class ArchiveGenerator(): "thread": thread, "page": page, "next": page + 1, + "page_links": page_links, "prev": page - 1, "posts": posts }) diff --git a/epilogue/forum.py b/epilogue/forum.py index 7cc7dad..01e14f3 100644 --- a/epilogue/forum.py +++ b/epilogue/forum.py @@ -23,6 +23,9 @@ GET_POSTS = """ LIMIT ? OFFSET ? """.format(PREFIX) +DEFAULT_POSTS_PER_PAGE = 15 +DEFAULT_THREADS_PER_PAGE = 2000 + def fix_encoding (string): return string.encode("latin1", errors="ignore").decode(errors="ignore") @@ -50,7 +53,7 @@ class Forum(): cursor.execute(GET_BOARDS) return [Board(board) for board in cursor.fetchall()] - def get_threads_in_board (self, board, page=0, per_page=2000): + def get_threads_in_board (self, board, page=0, per_page=DEFAULT_THREADS_PER_PAGE): try: board = board.id except ValueError: pass @@ -58,7 +61,7 @@ class Forum(): cursor.execute(GET_THREADS, (board, per_page, page * per_page)) return [Thread(thread) for thread in cursor.fetchall()] - def get_posts_in_thread (self, thread, page=0, per_page=15): + def get_posts_in_thread (self, thread, page=0, per_page=DEFAULT_POSTS_PER_PAGE): try: thread = thread.id except ValueError: pass @@ -89,6 +92,7 @@ class Thread(): self.datetime = datetime.fromtimestamp(row['poster_time']) self.subject = fix_encoding(row['subject']) self.poster_name = fix_encoding(row['poster_name']) + self.num_replies = row['num_replies'] class Post(): def __init__ (self, row): diff --git a/static/style.css b/static/style.css index 766b24e..3bb8f22 100644 --- a/static/style.css +++ b/static/style.css @@ -11,7 +11,11 @@ ul.boards { margin-left: 0; padding-left: 0; } .label { font-weight: bold } article { border-top: 1px solid black; } section { margin-top: 15px; margin-bottom: 15px; } + .next { float: right; } +.pagination { margin-bottom: 10px; } +.pagination ul { list-style-type: none; margin-left: 0; padding-left: 0; display: inline; } +.pagination li { display: inline; } .page { padding-top: 15px; } .page table { width: 100%; } \ No newline at end of file diff --git a/templates/partials/pagination.mustache b/templates/partials/pagination.mustache index 63e9e10..e80f7a2 100644 --- a/templates/partials/pagination.mustache +++ b/templates/partials/pagination.mustache @@ -1,4 +1,9 @@
\ No newline at end of file diff --git a/templates/threads.mustache b/templates/threads.mustache index 5609904..7eda7d3 100644 --- a/templates/threads.mustache +++ b/templates/threads.mustache @@ -3,14 +3,16 @@Title | -Poster | +Poster | Date | +Replies |
---|---|---|---|---|
{{subject}} | {{poster_name}} | {{datetime}} | +{{num_replies}} |