Skip to content

Commit

Permalink
Merge pull request #14 from stuartmaxwell/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartmaxwell authored Apr 28, 2024
2 parents c07e6cd + 1a2584c commit b5c5fd5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
5 changes: 4 additions & 1 deletion djpress/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def item_title(self: "ContentFeed", item: Content) -> str:

def item_description(self: "ContentFeed", item: Content) -> str:
"""Return the description of the post."""
return item.truncated_content_markdown
description = item.truncated_content_markdown
if item.is_truncated:
description += f'<p><a href="{self.item_link(item)}">Read more</a></p>'
return description

def item_link(self: "ContentFeed", item: Content) -> str:
"""Return the link to the post."""
Expand Down
2 changes: 1 addition & 1 deletion djpress/templates/djpress/snippets/post_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="card-body">
<h2 class="card-title"><a href="{% url 'djpress:post_detail' post.slug %}">{{ post.title }}</a></h2>
<p class="card-text">{{ post.truncated_content_markdown|safe }}</p>
{% if '<!--more-->' in post.content %}
{% if post.is_truncated %}
<p><a href="{% url 'djpress:post_detail' post.slug %}">Read more</a></p>
{% endif %}
<p>
Expand Down
27 changes: 26 additions & 1 deletion djpress/test_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def test_latest_posts_feed(client):
assert response["Content-Type"] == "application/rss+xml; charset=utf-8"

feed = response.content.decode("utf-8")
print(feed)
assert "<title>stuartm.nz</title>" in feed
assert "<link>http://testserver/rss</link>" in feed
assert "<description>stuartm.nz updates</description>" in feed
Expand All @@ -31,3 +30,29 @@ def test_latest_posts_feed(client):
assert "<description>&lt;p&gt;Content of post 1.&lt;/p&gt;</description>" in feed
assert "<title>Post 2</title>" in feed
assert "<description>&lt;p&gt;Content of post 2.&lt;/p&gt;</description>" in feed


@pytest.mark.django_db
def test_truncated_posts_feed(client):
user = User.objects.create_user(username="testuser", password="testpass")
Content.objects.create(
title="Post 1",
content="Content of post 1.<!--more-->Truncated content",
author=user,
status="published",
)

url = reverse("djpress:rss_feed")
response = client.get(url)

assert response.status_code == 200
assert response["Content-Type"] == "application/rss+xml; charset=utf-8"

feed = response.content.decode("utf-8")
assert "<title>stuartm.nz</title>" in feed
assert "<link>http://testserver/rss</link>" in feed
assert "<description>stuartm.nz updates</description>" in feed
assert "<item>" in feed
assert "<title>Post 1</title>" in feed
assert "Truncated content" not in feed
assert '&lt;a href="/post/post-1/"&gt;Read more&lt;/a&gt;&lt;/p&gt;' in feed

0 comments on commit b5c5fd5

Please sign in to comment.