Add image to RSS feed

Some readers don't support non-ico `favicon.ico` files
This commit is contained in:
Jake Howard 2023-11-29 14:04:04 +00:00
parent 1c9e1b4f74
commit 7127afbc94
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 23 additions and 0 deletions

View file

@ -0,0 +1,18 @@
from django.utils.feedgenerator import DefaultFeed
class CustomFeed(DefaultFeed):
"""
A custom feed generator with additional features.
"""
def __init__(self, request, **kwargs):
super().__init__(**kwargs)
self.request = request
def add_root_elements(self, handler) -> None:
super().add_root_elements(handler)
handler.startElement("image", {})
handler.addQuickElement("url", self.request.build_absolute_uri("favicon.ico"))
handler.addQuickElement("title", self.feed["title"])
handler.addQuickElement("link", self.feed["link"])
handler.endElement("image")

View file

@ -20,6 +20,7 @@ from website.contrib.singleton_page.utils import SingletonPageCache
from website.home.models import HomePage
from website.search.models import SearchPage
from .feed_generators import CustomFeed
from .models import BasePage
@ -60,6 +61,7 @@ class KeybaseView(TemplateView):
class AllPagesFeed(Feed):
feed_type = CustomFeed
link = "/"
def __init__(self) -> None:
@ -87,6 +89,9 @@ class AllPagesFeed(Feed):
return response
def feed_extra_kwargs(self, obj):
return {**super().feed_extra_kwargs(obj), "request": self.request}
def title(self) -> str:
return f"All Pages Feed :: {get_site_title()}"