diff --git a/djpress/feeds.py b/djpress/feeds.py index 42eefb4..fa85ee3 100644 --- a/djpress/feeds.py +++ b/djpress/feeds.py @@ -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'

Read more

' + return description def item_link(self: "ContentFeed", item: Content) -> str: """Return the link to the post.""" diff --git a/djpress/templates/djpress/snippets/post_summary.html b/djpress/templates/djpress/snippets/post_summary.html index 96199f5..ed34fb3 100644 --- a/djpress/templates/djpress/snippets/post_summary.html +++ b/djpress/templates/djpress/snippets/post_summary.html @@ -2,7 +2,7 @@

{{ post.title }}

{{ post.truncated_content_markdown|safe }}

- {% if '' in post.content %} + {% if post.is_truncated %}

Read more

{% endif %}

diff --git a/djpress/test_feeds.py b/djpress/test_feeds.py index 9cb3845..93cc404 100644 --- a/djpress/test_feeds.py +++ b/djpress/test_feeds.py @@ -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 "stuartm.nz" in feed assert "http://testserver/rss" in feed assert "stuartm.nz updates" in feed @@ -31,3 +30,29 @@ def test_latest_posts_feed(client): assert "<p>Content of post 1.</p>" in feed assert "Post 2" in feed assert "<p>Content of post 2.</p>" 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.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 "stuartm.nz" in feed + assert "http://testserver/rss" in feed + assert "stuartm.nz updates" in feed + assert "" in feed + assert "Post 1" in feed + assert "Truncated content" not in feed + assert '<a href="/post/post-1/">Read more</a></p>' in feed