Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions apps/bookclub/feeds.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions apps/bookclub/templates/bookclub/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
{% endblock %}

{% block content %}
<div style="margin-bottom: 1rem; text-align: right;">
<a href="{% url 'bookclub:rss_feed' %}" style="text-decoration: none; color: var(--text-color);" title="RSS Feed">
📡 RSS Feed
</a>
</div>

{% if comic %}
<div class="comic-info">
{% if comic.preview_image %}
Expand Down
3 changes: 2 additions & 1 deletion apps/bookclub/urls.py
Original file line number Diff line number Diff line change
@@ -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"),
]
Loading