From d8ff43dc28bb232bfcfa4395395ea88c7cd6abab Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Sun, 1 Jan 2023 02:29:51 +0900 Subject: [PATCH] Attach the first image of post to RSS feed (#333) --- users/views/identity.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/users/views/identity.py b/users/views/identity.py index a71b8b4..8007b14 100644 --- a/users/views/identity.py +++ b/users/views/identity.py @@ -6,6 +6,7 @@ from django.contrib.syndication.views import Feed from django.core import validators from django.http import Http404, JsonResponse from django.shortcuts import redirect +from django.utils import feedgenerator from django.utils.decorators import method_decorator from django.views.decorators.vary import vary_on_headers from django.views.generic import FormView, ListView, TemplateView, View @@ -128,6 +129,18 @@ class IdentityFeed(Feed): def item_pubdate(self, item: Post): return item.published + def item_enclosures(self, item: Post): + attachment = item.attachments.first() + if attachment is None: + return [] + + enc = feedgenerator.Enclosure( + url=attachment.full_url().absolute, + length=str(attachment.file.size), + mime_type=attachment.mimetype, + ) + return [enc] + class IdentityFollows(ListView): """