Skip to content

Commit

Permalink
Restore RSS feed functionality
Browse files Browse the repository at this point in the history
The resolution and treatment of the feeds_description text _roughly_ follows the
existing pattern as can be seen at
https://github.com/Princeton-CDH/cdh-web/blob/bfd904f78a98a49c499acac89a3e76a56d6c778b/cdhweb/pages/models.py#L153-L179
  • Loading branch information
haydngreatnews committed Aug 19, 2024
1 parent 650210c commit eb1c865
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 eb1c865

Please sign in to comment.