Skip to content

Commit

Permalink
Merge pull request #166 from springload/fix/rss-atom-feeds
Browse files Browse the repository at this point in the history
Restore RSS feed functionality
  • Loading branch information
haydngreatnews authored Aug 20, 2024
2 parents 2cd1aea + eb1c865 commit a30c32b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 26 additions & 0 deletions cdhweb/blog/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import bleach

from django.core.paginator import Paginator
from django.db import models
from django.shortcuts import get_object_or_404
Expand Down Expand Up @@ -224,6 +226,30 @@ def get_sitemap_urls(self, request):
urls[0]["priority"] = 0.6 # default is 0.5; slight increase
return urls

@cached_property
def feeds_description(self):
"""
Plaintext description for RSS and Atom feeds
Short description, then description, then looks for
the first paragraph of the text
"""
if self.short_description.strip():
return self.short_description.strip()

description = bleach.clean(self.description, tags=[], strip=True)
# Fall back to the first block of the page if
# there's no description, once the HTML is removed
if not description:
# Iterate over blocks and use content from first paragraph content
for block in self.body:
if block.block_type == "paragraph":
# Return the very first block
description = block
return bleach.clean(description, tags=[], strip=True)

return "" # We're really out of ideas, prevent a "None"


class BlogLinkPageArchived(LinkPage):
"""Container page that defines where blog posts can be created."""
Expand Down
4 changes: 2 additions & 2 deletions cdhweb/blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class RssBlogPostFeed(Feed):
"""Blog post RSS feed"""

title = "Center for Digital Humanities @ Princeton University Updates"
link = "/updates/"
link = "/blog/" # Not technically correct, but currently best-match
description = "Updates and news on work from the Center for Digital Humanities @ Princeton University"

def items(self):
Expand All @@ -21,7 +21,7 @@ def item_title(self, item):

def item_description(self, item):
"""blog post description, for feed content"""
return item.get_description()
return item.feeds_description

def item_link(self, item):
"""absolute link to blog post"""
Expand Down

0 comments on commit a30c32b

Please sign in to comment.