Merge branch 'main' into domains

This commit is contained in:
rscmbbng 2024-03-10 19:26:45 +00:00
commit 66bd1bb01a
12 changed files with 242 additions and 115 deletions

View file

@ -115,13 +115,16 @@ def send_activity(sender: User, host: str, content: str):
def post_to_activity(post: Post, community: Community):
# local PieFed posts do not have a create or announce id
create_id = post.ap_create_id if post.ap_create_id else f"https://{current_app.config['SERVER_NAME']}/activities/create/{gibberish(15)}"
announce_id = post.ap_announce_id if post.ap_announce_id else f"https://{current_app.config['SERVER_NAME']}/activities/announce/{gibberish(15)}"
activity_data = {
"actor": f"https://{current_app.config['SERVER_NAME']}/c/{community.name}",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"object": {
"id": f"https://{current_app.config['SERVER_NAME']}/activities/create/{post.ap_create_id}",
"id": create_id,
"actor": f"https://{current_app.config['SERVER_NAME']}/u/{post.author.user_name}",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
@ -159,14 +162,14 @@ def post_to_activity(post: Post, community: Community):
f"https://{current_app.config['SERVER_NAME']}/c/{community.name}/followers"
],
"type": "Announce",
"id": f"https://{current_app.config['SERVER_NAME']}/activities/announce/{post.ap_announce_id}"
"id": announce_id
}
if post.edited_at is not None:
activity_data["object"]["object"]["updated"] = ap_datetime(post.edited_at)
if post.language is not None:
activity_data["object"]["object"]["language"] = {"identifier": post.language}
if post.type == POST_TYPE_LINK and post.url is not None:
activity_data["object"]["object"]["attachment"] = {"href": post.url, "type": "Link"}
activity_data["object"]["object"]["attachment"] = [{"href": post.url, "type": "Link"}]
if post.image_id is not None:
activity_data["object"]["object"]["image"] = {"url": post.image.view_url(), "type": "Image"}
if post.image.alt_text:
@ -578,66 +581,68 @@ def actor_json_to_model(activity_json, address, server):
def post_json_to_model(post_json, user, community) -> Post:
post = Post(user_id=user.id, community_id=community.id,
title=html.unescape(post_json['name']),
comments_enabled=post_json['commentsEnabled'],
sticky=post_json['stickied'] if 'stickied' in post_json else False,
nsfw=post_json['sensitive'],
nsfl=post_json['nsfl'] if 'nsfl' in post_json else False,
ap_id=post_json['id'],
type=constants.POST_TYPE_ARTICLE,
posted_at=post_json['published'],
last_active=post_json['published'],
instance_id=user.instance_id
)
if 'source' in post_json and \
post_json['source']['mediaType'] == 'text/markdown':
post.body = post_json['source']['content']
post.body_html = markdown_to_html(post.body)
elif 'content' in post_json:
post.body_html = allowlist_html(post_json['content'])
post.body = html_to_markdown(post.body_html)
if 'attachment' in post_json and \
len(post_json['attachment']) > 0 and \
'type' in post_json['attachment'][0]:
if post_json['attachment'][0]['type'] == 'Link':
post.url = post_json['attachment'][0]['href']
if is_image_url(post.url):
post.type = POST_TYPE_IMAGE
else:
post.type = POST_TYPE_LINK
try:
post = Post(user_id=user.id, community_id=community.id,
title=html.unescape(post_json['name']),
comments_enabled=post_json['commentsEnabled'],
sticky=post_json['stickied'] if 'stickied' in post_json else False,
nsfw=post_json['sensitive'],
nsfl=post_json['nsfl'] if 'nsfl' in post_json else False,
ap_id=post_json['id'],
type=constants.POST_TYPE_ARTICLE,
posted_at=post_json['published'],
last_active=post_json['published'],
instance_id=user.instance_id
)
if 'source' in post_json and \
post_json['source']['mediaType'] == 'text/markdown':
post.body = post_json['source']['content']
post.body_html = markdown_to_html(post.body)
elif 'content' in post_json:
post.body_html = allowlist_html(post_json['content'])
post.body = html_to_markdown(post.body_html)
if 'attachment' in post_json and len(post_json['attachment']) > 0 and 'type' in post_json['attachment'][0]:
if post_json['attachment'][0]['type'] == 'Link':
post.url = post_json['attachment'][0]['href']
if is_image_url(post.url):
post.type = POST_TYPE_IMAGE
else:
post.type = POST_TYPE_LINK
domain = domain_from_url(post.url)
# notify about links to banned websites.
already_notified = set() # often admins and mods are the same people - avoid notifying them twice
if domain:
if domain.notify_mods:
for community_member in post.community.moderators():
notify = Notification(title='Suspicious content', url=post.ap_id, user_id=community_member.user_id, author_id=user.id)
db.session.add(notify)
already_notified.add(community_member.user_id)
if domain.notify_admins:
for admin in Site.admins():
if admin.id not in already_notified:
notify = Notification(title='Suspicious content', url=post.ap_id, user_id=admin.id, author_id=user.id)
domain = domain_from_url(post.url)
# notify about links to banned websites.
already_notified = set() # often admins and mods are the same people - avoid notifying them twice
if domain:
if domain.notify_mods:
for community_member in post.community.moderators():
notify = Notification(title='Suspicious content', url=post.ap_id, user_id=community_member.user_id, author_id=user.id)
db.session.add(notify)
admin.unread_notifications += 1
if domain.banned:
post = None
if not domain.banned:
domain.post_count += 1
post.domain = domain
if 'image' in post_json and post:
image = File(source_url=post_json['image']['url'])
db.session.add(image)
post.image = image
already_notified.add(community_member.user_id)
if post is not None:
db.session.add(post)
community.post_count += 1
db.session.commit()
return post
if domain.notify_admins:
for admin in Site.admins():
if admin.id not in already_notified:
notify = Notification(title='Suspicious content', url=post.ap_id, user_id=admin.id, author_id=user.id)
db.session.add(notify)
admin.unread_notifications += 1
if domain.banned:
post = None
if not domain.banned:
domain.post_count += 1
post.domain = domain
if 'image' in post_json and post:
image = File(source_url=post_json['image']['url'])
db.session.add(image)
post.image = image
if post is not None:
db.session.add(post)
community.post_count += 1
db.session.commit()
return post
except KeyError as e:
current_app.logger.error(f'KeyError in post_json_to_model: ' + str(post_json))
return None
# Save two different versions of a File, after downloading it from file.source_url. Set a width parameter to None to avoid generating one of that size

View file

@ -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,

View file

@ -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,

View file

@ -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 {

View file

@ -338,6 +338,14 @@ div.navbar {
}
}
#subtopic_nav {
position: relative;
left: -15px;
li a {
border: dotted 2px transparent;
}
}
/* high contrast */
@media (prefers-contrast: more) {

View file

@ -12,11 +12,9 @@
<div class="community_header" style="background-image: url({{ community.header_image() }});">
<nav aria-label="breadcrumb" id="breadcrumb_nav" title="Navigation">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">{{ _('Home') }}</a></li>
{% if community.topic_id %}
<li class="breadcrumb-item"><a href="/topics">{{ _('Topics') }}</a></li>
<li class="breadcrumb-item"><a href="/topic/{{ community.topic.machine_name }}" rel="nofollow">{{ community.topic.name }}</a></li>
{% endif %}
{% for breadcrumb in breadcrumbs %}
<li class="breadcrumb-item">{% if breadcrumb.url %}<a href="{{ breadcrumb.url }}">{% endif %}{{ breadcrumb.text }}{% if breadcrumb.url %}</a>{% endif %}</li>
{% endfor %}
<li class="breadcrumb-item active">{{ (community.title + '@' + community.ap_domain)|shorten }}</li>
</ol>
</nav>
@ -31,11 +29,9 @@
<div class="row">
<nav aria-label="breadcrumb" id="breadcrumb_nav" title="Navigation">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">{{ _('Home') }}</a></li>
{% if community.topic_id %}
<li class="breadcrumb-item"><a href="/topics">{{ _('Topics') }}</a></li>
<li class="breadcrumb-item"><a href="/topic/{{ community.topic.machine_name }}" rel="nofollow">{{ community.topic.name }}</a></li>
{% endif %}
{% for breadcrumb in breadcrumbs %}
<li class="breadcrumb-item">{% if breadcrumb.url %}<a href="{{ breadcrumb.url }}">{% endif %}{{ breadcrumb.text }}{% if breadcrumb.url %}</a>{% endif %}</li>
{% endfor %}
<li class="breadcrumb-item active">{{ (community.title + '@' + community.ap_domain)|shorten }}</li>
</ol>
</nav>
@ -53,11 +49,9 @@
{% else %}
<nav aria-label="breadcrumb" id="breadcrumb_nav" title="Navigation">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">{{ _('Home') }}</a></li>
{% if community.topic_id %}
<li class="breadcrumb-item"><a href="/topics">{{ _('Topics') }}</a></li>
<li class="breadcrumb-item"><a href="/topic/{{ community.topic.machine_name }}" rel="nofollow">{{ community.topic.name }}</a></li>
{% endif %}
{% for breadcrumb in breadcrumbs %}
<li class="breadcrumb-item">{% if breadcrumb.url %}<a href="{{ breadcrumb.url }}">{% endif %}{{ breadcrumb.text }}{% if breadcrumb.url %}</a>{% endif %}</li>
{% endfor %}
<li class="breadcrumb-item active">{{ (community.title + '@' + community.ap_domain)|shorten }}</li>
</ol>
</nav>

View file

@ -3,11 +3,9 @@
<div class="col post_col post_type_image">
<nav aria-label="breadcrumb" id="breadcrumb_nav" title="Navigation">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">{{ _('Home') }}</a></li>
{% if community.topic_id %}
<li class="breadcrumb-item"><a href="/topics">{{ _('Topics') }}</a></li>
<li class="breadcrumb-item"><a href="/topic/{{ community.topic.machine_name }}" rel="nofollow">{{ community.topic.name }}</a></li>
{% endif %}
{% for breadcrumb in breadcrumbs %}
<li class="breadcrumb-item">{% if breadcrumb.url %}<a href="{{ breadcrumb.url }}">{% endif %}{{ breadcrumb.text }}{% if breadcrumb.url %}</a>{% endif %}</li>
{% endfor %}
<li class="breadcrumb-item"><a href="/c/{{ post.community.link() }}" title="{{ post.community.ap_domain }}">{{ post.community.title }}@{{ post.community.ap_domain }}</a></li>
<li class="breadcrumb-item active">{{ post.title|shorten(15) }}</li>
</ol>
@ -52,11 +50,9 @@
<div class="col post_col post_type_normal">
<nav aria-label="breadcrumb" id="breadcrumb_nav" title="Navigation">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">{{ _('Home') }}</a></li>
{% if community.topic_id %}
<li class="breadcrumb-item"><a href="/topics">{{ _('Topics') }}</a></li>
<li class="breadcrumb-item"><a href="/topic/{{ community.topic.machine_name }}" rel="nofollow">{{ community.topic.name }}</a></li>
{% endif %}
{% for breadcrumb in breadcrumbs %}
<li class="breadcrumb-item">{% if breadcrumb.url %}<a href="{{ breadcrumb.url }}">{% endif %}{{ breadcrumb.text }}{% if breadcrumb.url %}</a>{% endif %}</li>
{% endfor %}
<li class="breadcrumb-item"><a href="/c/{{ post.community.link() }}">{{ post.community.title }}@{{ post.community.ap_domain }}</a></li>
<li class="breadcrumb-item active">{{ post.title|shorten(15) }}</li>
</ol>

View file

@ -77,7 +77,7 @@
{% endif %}
{% endif %}
</div>
<div class="col-2"><a href="{{ url_for('post.post_options', post_id=post.id) }}" rel="nofollow" class="post_options" aria-label="{{ _('Options') }}"><span class="fe fe-options" title="Options"> </span></a></div>
<div class="col-6 text-right"><a href="{{ url_for('post.post_options', post_id=post.id) }}" rel="nofollow" class="post_options" aria-label="{{ _('Options') }}"><span class="fe fe-options" title="Options"> </span></a></div>
</div>
</div>
</div>

View file

@ -22,6 +22,9 @@
{% if post.community.ap_id and '@beehaw.org' in post.community.ap_id %}
<p>{{ _('This post is hosted on beehaw.org which has <a href="https://docs.beehaw.org/docs/core-principles/what-is-beehaw/" target="_blank" rel="nofollow">higher standards of behaviour than most places. Be nice</a>.') }}</p>
{% endif %}
{% if post.community.ap_id and '@lemmy.ml' in post.community.ap_id %}
<p>{{ _('This post is hosted on lemmy.ml which will ban you for saying anything negative about China, Russia or Putin. Tread carefully.') }}</p>
{% endif %}
{{ render_form(form) }}
{% if not low_bandwidth %}
{% if markdown_editor %}
@ -196,6 +199,25 @@
{% endif %}
</div>
</div>
{% 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() }}" aria-label="{{ _('Go to community') }}"><img src="{{ community.icon_image() }}" class="community_icon rounded-circle" loading="lazy" alt="" />
{{ 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 %}
{% if is_moderator %}
<div class="card mt-3">
<div class="card-header">

View file

@ -12,16 +12,18 @@
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">{{ _('Home') }}</a></li>
<li class="breadcrumb-item"><a href="/topics">{{ _('Topics') }}</a></li>
<li class="breadcrumb-item active">{{ topic.name|shorten }}</li>
{% for breadcrumb in breadcrumbs %}
<li class="breadcrumb-item">{% if breadcrumb.url %}<a href="{{ breadcrumb.url }}">{% endif %}{{ breadcrumb.text }}{% if breadcrumb.url %}</a>{% endif %}</li>
{% endfor %}
</ol>
</nav>
<h1 class="mt-2">{{ topic.name }}
</h1>
{% if sub_topics %}
<h3 class="mb-0" id="sub-topics">{{ _('Sub-topics') }}</h3>
<ul class="nav" role="listbox" aria-labelledby="sub-topics">
{% for topic in sub_topics %}
<li class="nav-item" role="option"><a class="nav-link" href="/topic/{{ topic.machine_name }}">{{ topic.name }}</a></li>
<h5 class="mb-0" id="sub-topics">{{ _('Sub-topics') }}</h5>
<ul id="subtopic_nav" class="nav" role="listbox" aria-labelledby="sub-topics">
{% for sub_topic in sub_topics %}
<li class="nav-item" role="option"><a class="nav-link" href="/topic/{{ topic_path }}/{{ sub_topic.machine_name }}">{{ sub_topic.name }}</a></li>
{% endfor %}
</ul>
{% endif %}

View file

@ -1,3 +1,4 @@
from collections import namedtuple
from datetime import timedelta, timezone
from random import randint
@ -18,8 +19,8 @@ from app.utils import render_template, user_filters_posts, moderating_communitie
community_membership, blocked_domains, validation_required, mimetype_from_url
@bp.route('/topic/<topic_name>', methods=['GET'])
def show_topic(topic_name):
@bp.route('/topic/<path:topic_path>', methods=['GET'])
def show_topic(topic_path):
page = request.args.get('page', 1, type=int)
sort = request.args.get('sort', '' if current_user.is_anonymous else current_user.default_sort)
@ -27,11 +28,26 @@ def show_topic(topic_name):
post_layout = request.args.get('layout', 'list' if not low_bandwidth else None)
# translate topic_name from /topic/fediverse to topic_id
topic = Topic.query.filter(Topic.machine_name == topic_name.strip().lower()).first()
topic_url_parts = topic_path.split('/')
last_topic_machine_name = topic_url_parts[-1]
breadcrumbs = []
existing_url = '/topic'
topic = None
for url_part in topic_url_parts:
topic = Topic.query.filter(Topic.machine_name == url_part.strip().lower()).first()
if topic:
breadcrumb = namedtuple("Breadcrumb", ['text', 'url'])
breadcrumb.text = topic.name
breadcrumb.url = f"{existing_url}/{topic.machine_name}" if topic.machine_name != last_topic_machine_name else ''
breadcrumbs.append(breadcrumb)
existing_url = breadcrumb.url
else:
abort(404)
current_topic = topic
if topic:
if current_topic:
# get posts from communities in that topic
posts = Post.query.join(Community, Post.community_id == Community.id).filter(Community.topic_id == topic.id, Community.banned == False)
posts = Post.query.join(Community, Post.community_id == Community.id).filter(Community.topic_id == current_topic.id, Community.banned == False)
# filter out nsfw and nsfl if desired
if current_user.is_anonymous:
@ -68,23 +84,23 @@ def show_topic(topic_name):
per_page = 300
posts = posts.paginate(page=page, per_page=per_page, error_out=False)
topic_communities = Community.query.filter(Community.topic_id == topic.id).order_by(Community.name)
topic_communities = Community.query.filter(Community.topic_id == current_topic.id).order_by(Community.name)
next_url = url_for('topic.show_topic',
topic_name=topic_name,
topic_path=topic_path,
page=posts.next_num, sort=sort, layout=post_layout) if posts.has_next else None
prev_url = url_for('topic.show_topic',
topic_name=topic_name,
topic_path=topic_path,
page=posts.prev_num, sort=sort, layout=post_layout) if posts.has_prev and page != 1 else None
sub_topics = Topic.query.filter_by(parent_id=topic.id).order_by(Topic.name).all()
sub_topics = Topic.query.filter_by(parent_id=current_topic.id).order_by(Topic.name).all()
return render_template('topic/show_topic.html', title=_(topic.name), posts=posts, topic=topic, sort=sort,
return render_template('topic/show_topic.html', title=_(current_topic.name), posts=posts, topic=current_topic, sort=sort,
page=page, post_layout=post_layout, next_url=next_url, prev_url=prev_url,
topic_communities=topic_communities, content_filters=content_filters,
sub_topics=sub_topics,
rss_feed=f"https://{current_app.config['SERVER_NAME']}/topic/{topic_name}.rss",
rss_feed_name=f"{topic.name} on {g.site.name}",
sub_topics=sub_topics, topic_path=topic_path, breadcrumbs=breadcrumbs,
rss_feed=f"https://{current_app.config['SERVER_NAME']}/topic/{topic_path}.rss",
rss_feed_name=f"{current_topic.name} on {g.site.name}",
show_post_community=True, moderating_communities=moderating_communities(current_user.get_id()),
joined_communities=joined_communities(current_user.get_id()),
inoculation=inoculation[randint(0, len(inoculation) - 1)],
@ -93,10 +109,12 @@ def show_topic(topic_name):
abort(404)
@bp.route('/topic/<topic_name>.rss', methods=['GET'])
@bp.route('/topic/<path:topic_path>.rss', methods=['GET'])
@cache.cached(timeout=600)
def show_topic_rss(topic_name):
topic = Topic.query.filter(Topic.machine_name == topic_name.strip().lower()).first()
def show_topic_rss(topic_path):
topic_url_parts = topic_path.split('/')
last_topic_machine_name = topic_url_parts[-1]
topic = Topic.query.filter(Topic.machine_name == last_topic_machine_name.strip().lower()).first()
if topic:
posts = Post.query.join(Community, Post.community_id == Community.id).filter(Community.topic_id == topic.id,
@ -105,12 +123,12 @@ def show_topic_rss(topic_name):
posts = posts.order_by(desc(Post.created_at)).limit(100).all()
fg = FeedGenerator()
fg.id(f"https://{current_app.config['SERVER_NAME']}/topic/{topic_name}")
fg.id(f"https://{current_app.config['SERVER_NAME']}/topic/{last_topic_machine_name}")
fg.title(f'{topic.name} on {g.site.name}')
fg.link(href=f"https://{current_app.config['SERVER_NAME']}/topic/{topic_name}", rel='alternate')
fg.link(href=f"https://{current_app.config['SERVER_NAME']}/topic/{last_topic_machine_name}", rel='alternate')
fg.logo(f"https://{current_app.config['SERVER_NAME']}/static/images/apple-touch-icon.png")
fg.subtitle(' ')
fg.link(href=f"https://{current_app.config['SERVER_NAME']}/topic/{topic_name}.rss", rel='self')
fg.link(href=f"https://{current_app.config['SERVER_NAME']}/topic/{last_topic_machine_name}.rss", rel='self')
fg.language('en')
for post in posts:
@ -174,10 +192,13 @@ def topic_create_post(topic_name):
def topics_for_form():
topics = Topic.query.order_by(Topic.name).all()
topics = Topic.query.filter_by(parent_id=None).order_by(Topic.name).all()
result = []
for topic in topics:
result.append((topic.id, topic.name))
sub_topics = Topic.query.filter_by(parent_id=topic.id).order_by(Topic.name).all()
for sub_topic in sub_topics:
result.append((sub_topic.id, ' --- ' + sub_topic.name))
return result

View file

@ -23,7 +23,7 @@ class Config(object):
RECAPTCHA_PRIVATE_KEY = os.environ.get("RECAPTCHA_PRIVATE_KEY")
MODE = os.environ.get('MODE') or 'development'
LANGUAGES = ['en']
FULL_AP_CONTEXT = os.environ.get('FULL_AP_CONTEXT') is not None
FULL_AP_CONTEXT = bool(int(os.environ.get('FULL_AP_CONTEXT', 0)))
CACHE_TYPE = os.environ.get('CACHE_TYPE') or 'FileSystemCache'
CACHE_REDIS_URL = os.environ.get('CACHE_REDIS_URL') or 'redis://localhost:6379/1'
CACHE_DIR = os.environ.get('CACHE_DIR') or '/dev/shm/pyfedi'