Add image to RSS feed
Some readers don't support non-ico `favicon.ico` files
This commit is contained in:
parent
1c9e1b4f74
commit
7127afbc94
2 changed files with 23 additions and 0 deletions
18
website/common/feed_generators.py
Normal file
18
website/common/feed_generators.py
Normal 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")
|
|
@ -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()}"
|
||||
|
||||
|
|
Loading…
Reference in a new issue