From 71d66905bd10679fc4293015c5502b52b8f04bb5 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Thu, 28 Dec 2023 20:39:26 +1300 Subject: [PATCH] add summary text field to Pages and Notes --- app/activitypub/routes.py | 3 ++- app/activitypub/util.py | 3 ++- app/post/routes.py | 2 +- app/utils.py | 2 ++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/activitypub/routes.py b/app/activitypub/routes.py index 1d58c09f..abb22f2b 100644 --- a/app/activitypub/routes.py +++ b/app/activitypub/routes.py @@ -14,7 +14,7 @@ from app.activitypub.util import public_key, users_total, active_half_year, acti lemmy_site_data, instance_weight, is_activitypub_request, downvote_post_reply, downvote_post, upvote_post_reply, \ upvote_post, activity_already_ingested, make_image_sizes, delete_post_or_comment, community_members from app.utils import gibberish, get_setting, is_image_url, allowlist_html, html_to_markdown, render_template, \ - domain_from_url, markdown_to_html, community_membership, ap_datetime + domain_from_url, markdown_to_html, community_membership, ap_datetime, markdown_to_text import werkzeug.exceptions INBOX = [] @@ -1016,6 +1016,7 @@ def comment_ap(comment_id): reply.author.followers_url() ], 'content': reply.body_html, + 'summary': markdown_to_text(reply.body), 'mediaType': 'text/html', 'published': ap_datetime(reply.created_at), 'distinguished': False, diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 805c0cb2..aca2370e 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -21,7 +21,7 @@ from PIL import Image, ImageOps from io import BytesIO from app.utils import get_request, allowlist_html, html_to_markdown, get_setting, ap_datetime, markdown_to_html, \ - is_image_url, domain_from_url, gibberish, ensure_directory_exists + is_image_url, domain_from_url, gibberish, ensure_directory_exists, markdown_to_text def public_key(): @@ -121,6 +121,7 @@ def post_to_activity(post: Post, community: Community): "name": post.title, "cc": [], "content": post.body_html, + "summary": markdown_to_text(post.body), "mediaType": "text/html", "source": { "content": post.body, diff --git a/app/post/routes.py b/app/post/routes.py index b75d6d54..9e34a613 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -610,7 +610,7 @@ def post_reply_report(post_id: int, comment_id: int): form = ReportPostForm() if form.validate_on_submit(): report = Report(reasons=form.reasons_to_string(form.reasons.data), description=form.description.data, - type=1, reporter_id=current_user.id, suspect_post_id=post.id, suspect_community_id=post.community.id, + type=2, reporter_id=current_user.id, suspect_post_id=post.id, suspect_community_id=post.community.id, suspect_user_id=post_reply.author.id, suspect_post_reply_id=post_reply.id) db.session.add(report) diff --git a/app/utils.py b/app/utils.py index 1881fa8e..15eed1ae 100644 --- a/app/utils.py +++ b/app/utils.py @@ -191,6 +191,8 @@ def markdown_to_html(markdown_text) -> str: def markdown_to_text(markdown_text) -> str: + if not markdown_text or markdown_text == '': + return '' return markdown_text.replace("# ", '')