Skip to content

Commit

Permalink
💄 hide gap in authors list when no one has a profile picture
Browse files Browse the repository at this point in the history
  • Loading branch information
krmax44 committed Oct 1, 2024
1 parent f64f799 commit 8d713dd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
31 changes: 17 additions & 14 deletions fragdenstaat_de/fds_blog/templates/fds_blog/includes/_authors.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
{% load thumbnail %}
{% load i18n %}
{% load blog_tags %}
{% if authors %}
<div class="hstack gap-3 align-content-center">
{# authors are also linked with text below, so spare screenreaders/keyboard nav #}
<div class="blog-author-images" aria-hidden="true">
{% for author in authors %}
{% if author.user.profile_photo %}
<a href="{{ author.get_absolute_url }}" tabindex="-1">
<img width="32"
height="32"
src="{% thumbnail author.user.profile_photo 64x64 %}"
alt=""
class="rounded-circle" />
</a>
{% endif %}
{% endfor %}
</div>
{% if authors|has_author_images %}
{# authors are also linked with text below, so spare screenreaders/keyboard nav #}
<div class="blog-author-images" aria-hidden="true">
{% for author in authors %}
{% if author.user.profile_photo %}
<a href="{{ author.get_absolute_url }}" tabindex="-1">
<img width="32"
height="32"
src="{% thumbnail author.user.profile_photo 64x64 %}"
alt=""
class="rounded-circle" />
</a>
{% endif %}
{% endfor %}
</div>
{% endif %}
<div class="d-md-flex flex-wrap align-items-center">
<p class="m-0">
{% trans "by" %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="d-flex flex-column col-lg-5 p-3 p-md-4 order-lg-first border-blue blog-top-feature-meta">
{% include "fds_blog/includes/_item_meta.html" with hide_date=True %}
<div class="mt-auto pt-3">
{% include "fds_blog/includes/_authors.html" with authors=article.authors.all hide_date=True %}
{% include "fds_blog/includes/_authors.html" with authors=article.get_authors hide_date=True %}
</div>
</div>
</div>
Expand Down
9 changes: 7 additions & 2 deletions fragdenstaat_de/fds_blog/templatetags/blog_tags.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import re
from typing import Tuple
from typing import List, Tuple

from django import template

from ..managers import articles_published
from ..models import Article
from ..models import Article, Author

register = template.Library()

Expand Down Expand Up @@ -46,3 +46,8 @@ def get_blog_preview(context, amount=6):
articles = Article.published.all()[:amount]

return {"articles": articles, "request": context.get("request")}


@register.filter
def has_author_images(authors: List[Author]) -> bool:
return any(author.user and author.user.profile_photo for author in authors)

0 comments on commit 8d713dd

Please sign in to comment.