diff --git a/website/common/feed_generators.py b/website/common/feed_generators.py new file mode 100644 index 0000000..e8056ff --- /dev/null +++ b/website/common/feed_generators.py @@ -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") diff --git a/website/common/views.py b/website/common/views.py index 65e9d9e..d2a7721 100644 --- a/website/common/views.py +++ b/website/common/views.py @@ -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()}"