From 8d58fa92b6532f9e73f9928b566ff80c72b8004b Mon Sep 17 00:00:00 2001 From: cottongin Date: Mon, 6 Apr 2026 17:39:37 -0400 Subject: [PATCH] feat: in-app ePub reader with epub.js, TOC sidebar, chapter navigation Made-with: Cursor --- src/routes/issues.py | 27 +++++++++++ templates/issues.html | 5 +- templates/reader.html | 109 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 templates/reader.html diff --git a/src/routes/issues.py b/src/routes/issues.py index aaf6302..0b45a00 100644 --- a/src/routes/issues.py +++ b/src/routes/issues.py @@ -46,6 +46,33 @@ def cover_image(issue_id): return send_file(issue.cover_path, mimetype="image/jpeg") +@issues_bp.route("/issues//read") +def read(issue_id): + issue = Issue.query.get_or_404(issue_id) + if not os.path.exists(issue.epub_path): + flash("ePub file not found.", "error") + return redirect(url_for("issues.index")) + + article_count = len(json.loads(issue.article_ids)) + if issue.issue_type == "single_article": + article_ids = json.loads(issue.article_ids) + article = Article.query.get(article_ids[0]) if article_ids else None + title = article.title if article else "Single Article" + elif issue.issue_type == "multi_week": + w1 = issue.week_start.isocalendar()[1] + w2 = issue.week_end.isocalendar()[1] + title = f"Weeks {w1}\u2013{w2}" + else: + title = f"Week {issue.week_start.isocalendar()[1]}" + + return render_template( + "reader.html", + issue=issue, + title=title, + article_count=article_count, + ) + + @issues_bp.route("/issues//regenerate", methods=["POST"]) def regenerate(issue_id): issue = Issue.query.get_or_404(issue_id) diff --git a/templates/issues.html b/templates/issues.html index 91b1580..a3e665e 100644 --- a/templates/issues.html +++ b/templates/issues.html @@ -27,7 +27,10 @@ {{ item.issue.cover_method }} {{ item.issue.created_at.strftime('%b %d, %Y %H:%M') }} - + + Read + + Download
diff --git a/templates/reader.html b/templates/reader.html new file mode 100644 index 0000000..e7d5bed --- /dev/null +++ b/templates/reader.html @@ -0,0 +1,109 @@ + + + + + + {{ title }} — PI Weekly Reader + + + + + +
+ ← Issues +

{{ title }}

+ +
+
+
+

Table of Contents

+
+
+
+
+ + + + + +