diff --git a/main/templates/main/includes/article_carousel_item.html b/main/templates/main/includes/article_carousel_item.html index cfb1cb81d68106b5c2adb2bc348fe59461b17328..1c35bf523577b2017b5a221962cb527e34a9f641 100644 --- a/main/templates/main/includes/article_carousel_item.html +++ b/main/templates/main/includes/article_carousel_item.html @@ -3,29 +3,17 @@ <div> <div class="flex max-w-md items-start xl:mr-2"> {% image article_item.image fill-144x144 as image %} - {% if article.shared_from %} - <a href="{{ page.url }}sdilene?sdilene={{ article.slug|urlencode }}" rel="noindex" class="mr-4 shrink-0"> - {% else %} - <a href="{{ article_item.url }}" class="mr-4 shrink-0"> - {% endif %} + <a href="{{ article_item.get_url }}" {{ article_item.get_rel }} class="mr-4 shrink-0"> <img src="{{ image.url }}" alt="" class="w-16 xl:w-36"> </a> <div class="flex flex-col justify-between items-start"> <span class="text-green-500 mb-2">{{ article_item.date | date }}</span> - {% if article.shared_from %} - <a href="{{ page.url }}sdilene?sdilene={{ article.slug|urlencode }}" rel="noindex" class="font-alt leading-5 text-base uppercase lg:text-base mb-2"> - {% else %} - <a href="{{ article_item.url }}" class="font-alt leading-5 text-base uppercase lg:text-base mb-2"> - {% endif %} + <a href="{{ article_item.get_url }}" {{ article_item.get_rel }} class="font-alt leading-5 text-base uppercase lg:text-base mb-2"> {{ article_item.title }} </a> - {% if article_item.shared_from %} - {% include 'main/includes/href_button.html' with btn_link="{{ page.url }}sdilene?sdilene={{ article_item.slug|urlencode }}" btn_text="Zjistit více" noindex=True %} - {% else %} - {% include 'main/includes/href_button.html' with btn_link=article_item.url btn_text="Zjistit více" %} - {% endif %} + {% include 'main/includes/href_button.html' with btn_link=article_item.get_url noindex=article_item.get_no_index btn_text="Zjistit více" %} </div> </div> </div> diff --git a/main/templates/main/includes/person_article_preview.html b/main/templates/main/includes/person_article_preview.html index d75d4d71a59b854fcba0888c0b6770866f5f2423..aea44558b494149fefab630365157e03f7434035 100644 --- a/main/templates/main/includes/person_article_preview.html +++ b/main/templates/main/includes/person_article_preview.html @@ -20,12 +20,7 @@ <span class="bg-violet-600 mb-1 mr-1 px-2 py-2">{{ tag }}</span> {% endfor %} </div> - {% if article_page.shared_from %} - <a href="{{ page.url }}sdilene?sdilene={{ article_page.slug|urlencode }}" rel="noindex"> - {% else %} - <a href="{{ article_page.url }}"> - {% endif %} - + <a href="{{ article_page.get_url }}"> <h4 class="head-3xl mb-4"> {{ article_page.title }} </h4> @@ -33,11 +28,7 @@ <p class="mb-6"> {{ article_page.perex }} </p> - {% if article_page.shared_from %} - {% include 'main/includes/href_button.html' with btn_link="{{ page.url }}sdilene?sdilene={{ article_page.slug|urlencode }}" btn_text="Číst dále" noindex=True %} - {% else %} - {% include 'main/includes/href_button.html' with btn_link=article_page.url btn_text="Číst dále" %} - {% endif %} + {% include 'main/includes/href_button.html' with btn_link=article_page.get_url noindex=article_page.get_no_index btn_text="Číst dále" %} </div> </div> {% endfor %} diff --git a/main/templates/main/includes/small_article_preview.html b/main/templates/main/includes/small_article_preview.html index 0dce780eff82813ef8aae6114e332143d3f6d561..ea26c67808f3106a87658e777ddf3f49b4965ea7 100644 --- a/main/templates/main/includes/small_article_preview.html +++ b/main/templates/main/includes/small_article_preview.html @@ -13,11 +13,7 @@ <h4 class="font-alt leading-5 text-base uppercase lg:text-base mb-2"> {{ article_page.title }} </h4> - {% if article_page.shared_from %} - {% include 'main/includes/href_button.html' with btn_link="{{ page.url }}sdilene?sdilene={{ article_page.slug|urlencode }}" btn_text="Číst dále" noindex=True %} - {% else %} - {% include 'main/includes/href_button.html' with btn_link=article_page.url btn_text="Číst dále" %} - {% endif %} + {% include 'main/includes/href_button.html' with btn_link=article_page.get_url noindex=article_page.get_no_index btn_text="Číst dále" %} </div> </div> {% endfor %} diff --git a/shared/models.py b/shared/models.py index 3528d5b76e384ab863a4ba5ac71cc8adcfc1e399..b41bbd8371c01e8cf06f9282c5ff66e35725ce9f 100644 --- a/shared/models.py +++ b/shared/models.py @@ -2,6 +2,7 @@ import logging from collections import namedtuple from enum import Enum from functools import reduce +from urllib.parse import quote from django.apps import apps from django.core.paginator import Paginator @@ -101,6 +102,32 @@ class ArticleMixin(models.Model): class Meta: abstract = True + @property + def get_no_index(self): + """ + Indicates that a link should contain rel="noindex" + """ + return self.shared_from is not None + + @property + def get_rel(self): + """ + Returns "rel" property for a link to this article + """ + return 'rel="noindex"' if self.no_index else "" + + @property + def get_url(self): + if self.shared_from is not None: + return f"{self.shared_from.url}/sdilene?sdilene={quote(self.slug)}" + return self.url + + @property + def get_full_url(self): + if self.shared_from is not None: + return f"{self.shared_from.url}/sdilene?sdilene={quote(self.slug)}" + return self.full_url + @property def articles_page(self): return ( diff --git a/shared/templates/shared/article_preview.html b/shared/templates/shared/article_preview.html index 1ed708203349580d88d613e1d7272ae5183d89af..28fbb8474065d96ad3983d8ce3a44fbb7dad0f4a 100644 --- a/shared/templates/shared/article_preview.html +++ b/shared/templates/shared/article_preview.html @@ -7,18 +7,10 @@ itemscope="" > - {% if article.shared_from %} - <link itemprop="mainEntityOfPage" href="{{ page.url }}sdilene?sdilene={{ article.slug|urlencode }}"> - {% else %} - <link itemprop="mainEntityOfPage" href="{{ article.url }}"> - {% endif %} + <link itemprop="mainEntityOfPage" href="{{ article.get_url }}"> <div class="article-card-cover"> - {% if article.shared_from %} - <a href="{{ page.url }}sdilene?sdilene={{ article.slug|urlencode }}" rel="noindex" itemprop="image" itemtype="http://schema.org/ImageObject" itemscope=""> - {% else %} - <a href="{{ article.url }}" itemprop="image" itemtype="http://schema.org/ImageObject" itemscope=""> - {% endif %} + <a href="{{ article.get_url }}" {{ article.get_rel }} itemprop="image" itemtype="http://schema.org/ImageObject" itemscope=""> {% if article.thumb_image %} {% image article.thumb_image fill-356x192 as img %} {% image article.thumb_image fill-714x384 as img_2x %} @@ -38,17 +30,17 @@ <div class="article-card-sharing"> <div class="social-icon-group"> <a - href="https://www.facebook.com/sharer/sharer.php?u={{ article.url|urlencode }}" + href="https://www.facebook.com/sharer/sharer.php?u={{ article.get_url|urlencode }}" onclick="window.open(this.href, 'pop-up', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" class="social-icon social-icon--fill bg-brands-facebook text-white text-sm social-icon--4" ><i class="ico--facebook"></i></a> <a - href="https://twitter.com/intent/tweet?text={{ article.title|urlencode }}&url={{ article.url|urlencode }}" + href="https://twitter.com/intent/tweet?text={{ article.title|urlencode }}&url={{ article.get_url|urlencode }}" onclick="window.open(this.href, 'pop-up', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" class="social-icon social-icon--fill bg-brands-twitter text-white text-sm social-icon--4" ><i class="ico--twitter"></i></a> <a - href="https://www.linkedin.com/sharing/share-offsite/?url={{ article.full_url|urlencode }}" + href="https://www.linkedin.com/sharing/share-offsite/?url={{ article.get_full_url|urlencode }}" onclick="window.open(this.href, 'pop-up', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" class="social-icon social-icon--fill bg-brands-linkedin text-white text-sm social-icon--4"> <i class="ico--linkedin"></i> @@ -72,11 +64,7 @@ </div> <div class="card__body article-card__body{% if article.is_black %} text-white{% endif %}"> - {% if article.shared_from %} - <a href="{{ page.url }}sdilene?sdilene={{ article.slug|urlencode }}" rel="noindex"> - {% else %} - <a href="{{ article.url }}"> - {% endif %} + <a href="{{ article.get_url }}" {{ article.get_rel }}> <h1 class="card-headline mb-4"> {{ article.title }} </h1> diff --git a/shared/templates/styleguide/2.3.x/article_card.html b/shared/templates/styleguide/2.3.x/article_card.html index b8361e7d12d9f12babad016d33e63a9d5096f8f8..fa7eb5482ce77b92437395b5e87a0bb315a00ff0 100644 --- a/shared/templates/styleguide/2.3.x/article_card.html +++ b/shared/templates/styleguide/2.3.x/article_card.html @@ -4,11 +4,7 @@ <link itemprop="mainEntityOfPage" href="{% pageurl article %}"> <div class="article-card-cover"> - {% if article.shared_from %} - <a href="{{ page.url }}sdilene?sdilene={{ article.slug|urlencode }}" rel="noindex" itemprop="image" itemtype="http://schema.org/ImageObject" itemscope=""> - {% else %} - <a href="{% pageurl article %}" itemprop="image" itemtype="http://schema.org/ImageObject" itemscope=""> - {% endif %} + <a href="{{ article.get_url }}" {{ article.get_rel }} itemprop="image" itemtype="http://schema.org/ImageObject" itemscope=""> {% image article.image width-800 as img %} <img src="{{ img.url }}" alt="{{ article.title }}"> <meta itemprop="url" content="{{ img.url }}"> @@ -17,12 +13,12 @@ <div class="article-card-sharing"> <div class="social-icon-group "> <a - href="https://www.facebook.com/sharer/sharer.php?u={{ article.full_url|urlencode }}" + href="https://www.facebook.com/sharer/sharer.php?u={{ article.get_full_url|urlencode }}" onclick="window.open(this.href, 'pop-up', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" class="social-icon social-icon--fill bg-brands-facebook text-white text-sm social-icon--4" ><i class="ico--facebook"></i></a> <a - href="https://twitter.com/intent/tweet?text={{ article.title|urlencode }}&url={{ article.full_url|urlencode }}" + href="https://twitter.com/intent/tweet?text={{ article.title|urlencode }}&url={{ article.get_full_url|urlencode }}" onclick="window.open(this.href, 'pop-up', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" class="social-icon social-icon--fill bg-brands-twitter text-white text-sm social-icon--4" ><i class="ico--twitter"></i></a> @@ -40,7 +36,7 @@ </div> <div class="card__body article-card__body"> - <a href="{% pageurl article %}"> + <a href="{{ article.get_url }}" {{ article.get_rel }}> <h1 class="card-headline mb-4">{{ article.title }}</h1> </a> <p class="card-body-text flex-grow">{{ article.perex }}</p> diff --git a/uniweb/templates/uniweb/uniweb_article_page.html b/uniweb/templates/uniweb/uniweb_article_page.html index 6f12882106778cb2b5c4b56a229e85a0bb8f8fb8..63f02a2d40c91f42ee7e2b5cc3616103ec19abab 100644 --- a/uniweb/templates/uniweb/uniweb_article_page.html +++ b/uniweb/templates/uniweb/uniweb_article_page.html @@ -5,7 +5,7 @@ <article itemtype="http://schema.org/BlogPosting" itemscope=""> <header> - <link itemprop="mainEntityOfPage" href="{% pageurl page %}"> + <link itemprop="mainEntityOfPage" href="{{ page.get_url }}"> <meta itemprop="datePublished" content="{{ page.first_published_at }}"> <meta itemprop="dateModified" content="{{ page.last_published_at }}"> @@ -49,7 +49,7 @@ <section class="mt-16 md:mt-24"> {% if related_articles %} - <h1 class="head-alt-base md:head-alt-md pb-4">Další {{ page.get_parent.title }}</h1> + <h1 class="head-alt-base md:head-alt-md pb-4">Další {{ page.articles_page.title }}</h1> <div class="article-card-list grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 lg:gap-8"> {% for article in related_articles %} {% include "styleguide/2.3.x/article_card.html" %} @@ -58,9 +58,9 @@ {% endif %} <div class="text-center mt-8 md:mt-16"> - <a href="{% pageurl page.get_parent %}" class="btn btn--icon text-xl"> + <a href="{% pageurl page.articles_page %}" class="btn btn--icon text-xl"> <div class="btn__body-wrap"> - <div class="btn__body ">{{ page.get_parent.title }}</div> + <div class="btn__body ">{{ page.articles_page.title }}</div> <div class="btn__icon "> <i class="ico--chevron-right"></i> </div>