From 60bb9991d4e8c38dd5421f80792d0b657786e210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1?= <git@imaniti.org> Date: Thu, 5 Jan 2023 12:01:37 +0100 Subject: [PATCH] [ADD] wip - RSS feed for the main page --- main/feeds.py | 58 +++++++++++++++++++ .../main/blocks/card_link_block.html | 2 +- .../templates/main/feed_item_description.html | 3 + 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 main/feeds.py create mode 100644 main/templates/main/feed_item_description.html diff --git a/main/feeds.py b/main/feeds.py new file mode 100644 index 00000000..4b6c9d63 --- /dev/null +++ b/main/feeds.py @@ -0,0 +1,58 @@ +from django.contrib.syndication.views import Feed +from django.shortcuts import render +from django.urls import reverse +from main.models import MainArticlesPage, MainArticlePage + +class LatestArticlesFeed(Feed): + def get_object( + self: LatestArticlesFeed, + request, + title: str + ) -> MainArticlesPage: + return MainArticlesPage.objects.get(title=title) + + def title( + self: LatestArticlesFeed, + obj: MainArticlesPage + ) -> str: + return obj.title + + def link( + self: LatestArticlesFeed, + obj: MainArticlesPage + ) -> str: + return obj.get_full_url() + + def description( + self: LatestArticlesFeed, + obj: MainArticlesPage + ) -> str: + return obj.perex + + def items( + self: LatestArticlesFeed, + obj: MainArticlesPage + ) -> list: + return obj.get_children().type(MainArticlePage)[:32] + + def item_title( + self: LatestArticlesFeed, + obj: MainArticlePage + ) -> str: + return obj.title + + def item_description( + self: LatestArticlesFeed, + item: MainArticlePage + ): + return render( + None, + "main/feed_item_description.html", + {"item": item}, + ) + + def item_link( + self: LatestArticlesFeed, + item: MainArticlePage + ) -> str: + return item.get_full_url() diff --git a/main/templates/main/blocks/card_link_block.html b/main/templates/main/blocks/card_link_block.html index e642f0c4..06bc1bdd 100644 --- a/main/templates/main/blocks/card_link_block.html +++ b/main/templates/main/blocks/card_link_block.html @@ -16,7 +16,7 @@ <a href="{{ target_url }}"> {{ self.title }} </a> - </h1> + </h2> <div class="font-light text-sm break-words"> {{ self.text | default_if_none:'' | richtext }} </div> diff --git a/main/templates/main/feed_item_description.html b/main/templates/main/feed_item_description.html new file mode 100644 index 00000000..e44f14f7 --- /dev/null +++ b/main/templates/main/feed_item_description.html @@ -0,0 +1,3 @@ +{% for block in item.content %} + {% include_block block %} +{% endfor %} -- GitLab