From 67e45a6e0d834847925774bbc1790466ba7769d0 Mon Sep 17 00:00:00 2001 From: Snowsune Date: Tue, 4 Nov 2025 19:00:28 -0500 Subject: [PATCH] Add rss to bookclub! --- apps/bookclub/feeds.py | 72 +++++++++++++++++++++ apps/bookclub/templates/bookclub/index.html | 6 ++ apps/bookclub/urls.py | 3 +- 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 apps/bookclub/feeds.py diff --git a/apps/bookclub/feeds.py b/apps/bookclub/feeds.py new file mode 100644 index 0000000..00a2153 --- /dev/null +++ b/apps/bookclub/feeds.py @@ -0,0 +1,72 @@ +from django.contrib.syndication.views import Feed +from django.urls import reverse +from django.utils.feedgenerator import Rss201rev2Feed +from .models import MonthlyComic + + +class BookClubFeed(Feed): + title = "Vixi's Webcomic Club!" + link = "/bookclub/" + description = "Monthly webcomic read-togethers at snowsune.net!" + feed_type = Rss201rev2Feed + + def items(self): + """Return all monthly comics ordered by most recent""" + return MonthlyComic.objects.all().order_by("-updated_at") + + def item_title(self, item): + """Return the title of each comic entry""" + return f"Monthly Comic - {item.updated_at.date()}" + + def item_description(self, item): + """Return the description/blurb of each comic""" + if item.blurb_html: + return item.blurb_html + return item.blurb or "Monthly comic read" + + def item_link(self, item): + """Return the URL for the bookclub page""" + # Django's Feed class will automatically make this absolute + return reverse("bookclub:index") + + def item_pubdate(self, item): + """Return the publication date""" + return item.updated_at + + def item_author_name(self, item): + """Return the author name""" + return "Snowsune Book Club" + + def item_categories(self, item): + """Return categories for the comic""" + return ["comics", "bookclub", "webcomics"] + + def item_enclosure_url(self, item): + """Return the preview image URL if available""" + if item.preview_image: + return item.preview_image.url + return None + + def item_enclosure_length(self, item): + """Return the image file size if available""" + if item.preview_image: + try: + return item.preview_image.size + except: + return 0 + return 0 + + def item_enclosure_mime_type(self, item): + """Return the image MIME type""" + if item.preview_image: + # Guess MIME type from file extension + ext = item.preview_image.name.lower().split(".")[-1] + mime_types = { + "jpg": "image/jpeg", + "jpeg": "image/jpeg", + "png": "image/png", + "gif": "image/gif", + "webp": "image/webp", + } + return mime_types.get(ext, "image/jpeg") + return None diff --git a/apps/bookclub/templates/bookclub/index.html b/apps/bookclub/templates/bookclub/index.html index 6284105..f6027ee 100644 --- a/apps/bookclub/templates/bookclub/index.html +++ b/apps/bookclub/templates/bookclub/index.html @@ -12,6 +12,12 @@ {% endblock %} {% block content %} +
+ + 📡 RSS Feed + +
+ {% if comic %}
{% if comic.preview_image %} diff --git a/apps/bookclub/urls.py b/apps/bookclub/urls.py index a981174..8a3b123 100644 --- a/apps/bookclub/urls.py +++ b/apps/bookclub/urls.py @@ -1,8 +1,9 @@ from django.urls import path -from . import views +from . import views, feeds app_name = "bookclub" urlpatterns = [ path("", views.bookclub_view, name="index"), + path("feed/", feeds.BookClubFeed(), name="rss_feed"), ]