related communities

This commit is contained in:
rimu 2024-01-15 18:32:58 +13:00
parent eee7c59b57
commit e045dc7f2d
2 changed files with 26 additions and 1 deletions

View file

@ -137,6 +137,12 @@ def show_community(community: Community):
posts = posts.order_by(desc(Post.last_active))
posts = posts.paginate(page=page, per_page=100, error_out=False)
if community.topic_id:
related_communities = Community.query.filter_by(topic_id=community.topic_id).\
filter(Community.id != community.id, Community.banned == False).order_by(Community.name)
else:
related_communities = []
description = shorten_string(community.description, 150) if community.description else None
og_image = community.image.source_url if community.image_id else None
@ -149,7 +155,7 @@ def show_community(community: Community):
is_moderator=is_moderator, is_owner=is_owner, is_admin=is_admin, mods=mod_list, posts=posts, description=description,
og_image=og_image, POST_TYPE_IMAGE=POST_TYPE_IMAGE, POST_TYPE_LINK=POST_TYPE_LINK, SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING,
SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, SUBSCRIPTION_OWNER=SUBSCRIPTION_OWNER, SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR,
etag=f"{community.id}{sort}_{hash(community.last_active)}",
etag=f"{community.id}{sort}_{hash(community.last_active)}", related_communities=related_communities,
next_url=next_url, prev_url=prev_url, low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1',
rss_feed=f"https://{current_app.config['SERVER_NAME']}/community/{community.link()}/feed", rss_feed_name=f"{community.title} posts on PieFed",
content_filters=content_filters, moderating_communities=moderating_communities(current_user.get_id()),

View file

@ -147,6 +147,25 @@
</div>
</div>
{% endif %}
{% if related_communities %}
<div class="card mt-3">
<div class="card-header">
<h2>{{ _('Related communities') }}</h2>
</div>
<div class="card-body">
<ul class="list-group list-group-flush">
{% for community in related_communities %}
<li class="list-group-item">
<a href="/c/{{ community.link() }}"><img src="{{ community.icon_image() }}" class="community_icon rounded-circle" loading="lazy" />
{{ community.display_name() }}
</a>
</li>
{% endfor %}
</ul>
<p class="mt-4"><a class="btn btn-primary" href="/communities">{{ _('Explore communities') }}</a></p>
</div>
</div>
{% endif %}
</div>
</div>
<div class="row">