diff --git a/app/community/routes.py b/app/community/routes.py index 70ffdbc0..9b9477d8 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -1,3 +1,4 @@ +from collections import namedtuple from io import BytesIO from random import randint @@ -17,7 +18,7 @@ from app.constants import SUBSCRIPTION_MEMBER, SUBSCRIPTION_OWNER, POST_TYPE_LIN SUBSCRIPTION_PENDING, SUBSCRIPTION_MODERATOR from app.inoculation import inoculation from app.models import User, Community, CommunityMember, CommunityJoinRequest, CommunityBan, Post, \ - File, PostVote, utcnow, Report, Notification, InstanceBlock, ActivityPubLog + File, PostVote, utcnow, Report, Notification, InstanceBlock, ActivityPubLog, Topic from app.community import bp from app.utils import get_setting, render_template, allowlist_html, markdown_to_html, validation_required, \ shorten_string, gibberish, community_membership, ap_datetime, \ @@ -170,11 +171,42 @@ def show_community(community: Community): per_page = 300 posts = posts.paginate(page=page, per_page=per_page, error_out=False) + breadcrumbs = [] + breadcrumb = namedtuple("Breadcrumb", ['text', 'url']) + breadcrumb.text = _('Home') + breadcrumb.url = '/' + breadcrumbs.append(breadcrumb) + 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) + topics = [] + previous_topic = Topic.query.get(community.topic_id) + topics.append(previous_topic) + while previous_topic.parent_id: + topic = Topic.query.get(previous_topic.parent_id) + topics.append(topic) + previous_topic = topic + topics = list(reversed(topics)) + + breadcrumb = namedtuple("Breadcrumb", ['text', 'url']) + breadcrumb.text = _('Topics') + breadcrumb.url = '/topics' + breadcrumbs.append(breadcrumb) + + existing_url = '/topic' + for topic in topics: + breadcrumb = namedtuple("Breadcrumb", ['text', 'url']) + breadcrumb.text = topic.name + breadcrumb.url = f"{existing_url}/{topic.machine_name}" + breadcrumbs.append(breadcrumb) + existing_url = breadcrumb.url else: related_communities = [] + breadcrumb = namedtuple("Breadcrumb", ['text', 'url']) + breadcrumb.text = _('Communities') + breadcrumb.url = '/communities' + breadcrumbs.append(breadcrumb) description = shorten_string(community.description, 150) if community.description else None og_image = community.image.source_url if community.image_id else None @@ -184,7 +216,7 @@ def show_community(community: Community): prev_url = url_for('activitypub.community_profile', actor=community.ap_id if community.ap_id is not None else community.name, page=posts.prev_num, sort=sort, layout=post_layout) if posts.has_prev and page != 1 else None - return render_template('community/community.html', community=community, title=community.title, + return render_template('community/community.html', community=community, title=community.title, breadcrumbs=breadcrumbs, 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, diff --git a/app/post/routes.py b/app/post/routes.py index c310b27e..e418eb60 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -1,3 +1,4 @@ +from collections import namedtuple from datetime import datetime from random import randint @@ -16,7 +17,7 @@ from app.community.forms import CreatePostForm from app.post.util import post_replies, get_comment_branch, post_reply_count from app.constants import SUBSCRIPTION_MEMBER, POST_TYPE_LINK, POST_TYPE_IMAGE from app.models import Post, PostReply, \ - PostReplyVote, PostVote, Notification, utcnow, UserBlock, DomainBlock, InstanceBlock, Report, Site, Community + PostReplyVote, PostVote, Notification, utcnow, UserBlock, DomainBlock, InstanceBlock, Report, Site, Community, Topic from app.post import bp from app.utils import get_setting, render_template, allowlist_html, markdown_to_html, validation_required, \ shorten_string, markdown_to_text, gibberish, ap_datetime, return_304, \ @@ -172,7 +173,45 @@ def show_post(post_id: int): og_image = post.image.source_url if post.image_id else None description = shorten_string(markdown_to_text(post.body), 150) if post.body else None + breadcrumbs = [] + breadcrumb = namedtuple("Breadcrumb", ['text', 'url']) + breadcrumb.text = _('Home') + breadcrumb.url = '/' + breadcrumbs.append(breadcrumb) + + 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) + topics = [] + previous_topic = Topic.query.get(community.topic_id) + topics.append(previous_topic) + while previous_topic.parent_id: + topic = Topic.query.get(previous_topic.parent_id) + topics.append(topic) + previous_topic = topic + topics = list(reversed(topics)) + + breadcrumb = namedtuple("Breadcrumb", ['text', 'url']) + breadcrumb.text = _('Topics') + breadcrumb.url = '/topics' + breadcrumbs.append(breadcrumb) + + existing_url = '/topic' + for topic in topics: + breadcrumb = namedtuple("Breadcrumb", ['text', 'url']) + breadcrumb.text = topic.name + breadcrumb.url = f"{existing_url}/{topic.machine_name}" + breadcrumbs.append(breadcrumb) + existing_url = breadcrumb.url + else: + related_communities = [] + breadcrumb = namedtuple("Breadcrumb", ['text', 'url']) + breadcrumb.text = _('Communities') + breadcrumb.url = '/communities' + breadcrumbs.append(breadcrumb) + response = render_template('post/post.html', title=post.title, post=post, is_moderator=is_moderator, community=post.community, + breadcrumbs=breadcrumbs, related_communities=related_communities, canonical=post.ap_id, form=form, replies=replies, THREAD_CUTOFF_DEPTH=constants.THREAD_CUTOFF_DEPTH, description=description, og_image=og_image, POST_TYPE_IMAGE=constants.POST_TYPE_IMAGE, POST_TYPE_LINK=constants.POST_TYPE_LINK, POST_TYPE_ARTICLE=constants.POST_TYPE_ARTICLE, diff --git a/app/static/styles.css b/app/static/styles.css index 678b1cb5..abe90c6f 100644 --- a/app/static/styles.css +++ b/app/static/styles.css @@ -720,6 +720,14 @@ div.navbar { background-color: var(--bs-card-cap-bg); } +#subtopic_nav { + position: relative; + left: -15px; +} +#subtopic_nav li a { + border: dotted 2px transparent; +} + /* high contrast */ @media (prefers-contrast: more) { :root { diff --git a/app/static/styles.scss b/app/static/styles.scss index f28ac5dd..69d75c46 100644 --- a/app/static/styles.scss +++ b/app/static/styles.scss @@ -338,6 +338,14 @@ div.navbar { } } +#subtopic_nav { + position: relative; + left: -15px; + li a { + border: dotted 2px transparent; + } +} + /* high contrast */ @media (prefers-contrast: more) { diff --git a/app/templates/community/community.html b/app/templates/community/community.html index 8ce6fb26..ef5b3b5c 100644 --- a/app/templates/community/community.html +++ b/app/templates/community/community.html @@ -12,11 +12,9 @@
{{ _('This post is hosted on beehaw.org which has higher standards of behaviour than most places. Be nice.') }}
{% endif %} + {% if post.community.ap_id and '@lemmy.ml' in post.community.ap_id %} +{{ _('This post is hosted on lemmy.ml which will ban you for saying anything negative about China, Russia or Putin. Tread carefully.') }}
+ {% endif %} {{ render_form(form) }} {% if not low_bandwidth %} {% if markdown_editor %} @@ -196,6 +199,25 @@ {% endif %} + {% if related_communities %} +