Skip to content
Permalink
Browse files

RSS/Atom for Blog (#3681)

* rss/atom for /blog/ posts
  • Loading branch information...
Pomax committed Sep 25, 2019
1 parent 32ff278 commit 183011f09db5e187a9ecefc282ccb61319910c66
Showing with 100 additions and 38 deletions.
  1. +1 −0 Pipfile
  2. +40 −38 Pipfile.lock
  3. +4 −0 network-api/networkapi/settings.py
  4. +7 −0 network-api/networkapi/urls.py
  5. +48 −0 network-api/networkapi/wagtailpages/rss.py
@@ -4,6 +4,7 @@ verify_ssl = true
name = "pypi"

[packages]
beautifulsoup4 = "*"
"boto3" = "*"
Django = "==2.2.5"
dj-database-url = "*"

Some generated files are not rendered by default. Learn more.

@@ -75,6 +75,7 @@
CLOUDINARY_CLOUD_NAME=(str, ''),
CLOUDINARY_API_KEY=(str, ''),
CLOUDINARY_API_SECRET=(str, ''),
FEED_LIMIT=(int, 10),
)

# Read in the environment
@@ -587,3 +588,6 @@

# Use network_url to check if we're running prod or not
NETWORK_SITE_URL = env('NETWORK_SITE_URL')

# RSS / ATOM settings
FEED_LIMIT = env('FEED_LIMIT')
@@ -4,6 +4,7 @@
from django.conf.urls.static import static
from django.contrib import admin
from django.views.generic.base import RedirectView
from django.urls import path

from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls
@@ -12,6 +13,7 @@

from networkapi.views import EnvVariablesView, review_app_help_view
from networkapi.buyersguide import views as buyersguide_views
from networkapi.wagtailpages.rss import RSSFeed, AtomFeed
from experiments import views as experiment_views

admin.autodiscover()
@@ -55,6 +57,11 @@
# Buyer's Guide / Privacy Not Included
url(r'^privacynotincluded/', include('networkapi.buyersguide.urls')),

# Blog RSS feed
path('blog/rss/', RSSFeed()),
path('blog/atom/', AtomFeed()),

# wagtail-managed data
url(r'', include(wagtail_urls)),
)

@@ -0,0 +1,48 @@
from django.conf import settings
from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Atom1Feed

from bs4 import BeautifulSoup

from .models import IndexPage


class RSSFeed(Feed):
"""
Blog page RSS feed, using the content:encoded serializer above
"""

title = 'Mozilla Foundation Blog'
link = 'https://foundation.mozilla.org/blog/'
feed_url = 'https://foundation.mozilla.org/blog/rss/'
description = 'The Mozilla Foundation Blog'

def items(self):
blog_index = IndexPage.objects.get(title__iexact='blog')
blog_pages = blog_index.get_all_entries()
return blog_pages[:settings.FEED_LIMIT]

def item_title(self, item):
return item.title

def item_link(self, item):
return item.full_url

def item_description(self, item):
page = item.specific
html = str(page.body)
parsed = BeautifulSoup(html, 'html.parser')
text = parsed.get_text()[:1000]
if len(text) == 1000:
text = f'{text}[...]'
return text

def item_pubdate(self, item):
return item.first_published_at


class AtomFeed(RSSFeed):
feed_type = Atom1Feed
link = RSSFeed.link
feed_url = 'https://foundation.mozilla.org/blog/atom/'
subtitle = RSSFeed.description

0 comments on commit 183011f

Please sign in to comment.
You can’t perform that action at this time.