From 9f3cbac3c44731a9e1b5047ccd22c8a9aa66dc4d Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Fri, 11 May 2018 12:52:29 +1000 Subject: [PATCH] Advertise the WebSub hub inside all Atom feeds, to make sure subscribers know it exists --- entries/views/feeds.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/entries/views/feeds.py b/entries/views/feeds.py index 5f0b4ff..b7a042d 100644 --- a/entries/views/feeds.py +++ b/entries/views/feeds.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.contrib.sites.models import Site from django.contrib.syndication.views import Feed from django.urls import reverse @@ -8,6 +9,13 @@ from ..kinds import on_home from ..models import Entry +class Atom1FeedWithHub(Atom1Feed): + def add_root_elements(self, handler): + super().add_root_elements(handler) + handler.startElement('link', {'rel': 'hub', 'href': settings.PUSH_HUB}) + handler.endElement('link') + + class EntriesFeed(Feed): def item_title(self, entry): return entry.title @@ -59,7 +67,7 @@ class RssByKind(EntriesFeed): class AtomByKind(RssByKind): - feed_type = Atom1Feed + feed_type = Atom1FeedWithHub subtitle = RssByKind.description @@ -80,5 +88,5 @@ class RssHomeEntries(EntriesFeed): class AtomHomeEntries(RssHomeEntries): - feed_type = Atom1Feed + feed_type = Atom1FeedWithHub subtitle = RssHomeEntries.description