Attach the first image of post to RSS feed (#333)

This commit is contained in:
TAKAHASHI Shuuji 2023-01-01 02:29:51 +09:00 committed by GitHub
parent 05adbace24
commit d8ff43dc28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@ from django.contrib.syndication.views import Feed
from django.core import validators from django.core import validators
from django.http import Http404, JsonResponse from django.http import Http404, JsonResponse
from django.shortcuts import redirect from django.shortcuts import redirect
from django.utils import feedgenerator
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views.decorators.vary import vary_on_headers from django.views.decorators.vary import vary_on_headers
from django.views.generic import FormView, ListView, TemplateView, View from django.views.generic import FormView, ListView, TemplateView, View
@ -128,6 +129,18 @@ class IdentityFeed(Feed):
def item_pubdate(self, item: Post): def item_pubdate(self, item: Post):
return item.published 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): class IdentityFollows(ListView):
""" """