From 2354a7515079df5a3d3d142b974da9a067d7276b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1?= <git@imaniti.org> Date: Tue, 31 Jan 2023 03:25:49 +0100 Subject: [PATCH] improve RSS feed - enclosures, RSS-specific blocks --- main/blocks.py | 1 + main/feeds.py | 19 +++++++++++++++++ .../templates/main/feed_item_description.html | 21 ++++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/main/blocks.py b/main/blocks.py index 5c4e6890..9499387a 100644 --- a/main/blocks.py +++ b/main/blocks.py @@ -1,4 +1,5 @@ from django.utils.text import slugify +from django.template.loader import render_to_string from wagtail.core.blocks import ( CharBlock, ListBlock, diff --git a/main/feeds.py b/main/feeds.py index 01837185..9d8986a7 100644 --- a/main/feeds.py +++ b/main/feeds.py @@ -1,3 +1,5 @@ +import typing + from datetime import datetime from django.contrib.syndication.views import Feed @@ -92,3 +94,20 @@ class LatestArticlesFeed(Feed): item: MainArticlePage ) -> str: return item.get_full_url() + + def item_enclosure_url( + self, + item: MainArticlePage + ) -> typing.Union[None, str]: + if item.image is None: + return None + + return item.image.get_rendition("format-webp").full_url + + item_enclosure_mime_type = "image/webp" + + def item_enclosure_length( + self, + item: MainArticlePage + ) -> int: + return item.image.file_size diff --git a/main/templates/main/feed_item_description.html b/main/templates/main/feed_item_description.html index e01e314b..c84b9682 100644 --- a/main/templates/main/feed_item_description.html +++ b/main/templates/main/feed_item_description.html @@ -1,5 +1,24 @@ {% load wagtailcore_tags %} +<p>{{ item.perex }}</p> + {% for block in item.content %} - {% include_block block %} + {% if block.block_type == "text" %} + {% comment %} + No need to wrap this in a <p>, as the value already does this + {% endcomment %} + {{ block.value }} + {% elif block.block_type == "quote" %} + <blockquote>„{{ block.value.quote }}“</blockquote> + <p>— {{ block.value.autor_name }}</p> + {% elif block.block_type == "download" %} + <p> + Soubor „{{ block.value.file }}“ ke stažení: <a href="{{ block.value.file.url }}">{{ block.value.file.url }}</a> + </p> + {% elif block.block_type == "image" %} + <a href="{{ block.value.href }}"> + <img src="{{ block.value.image.url }}"> + </a> + <p>{{ block.value.text }}</p> + {% endif %} {% endfor %} -- GitLab