mirror of https://gitlab.com/bashrc2/epicyon
Limit length of content warnings
parent
ec776a07ea
commit
f8cd23a538
|
|
@ -2359,11 +2359,12 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
||||||
block_nostr: {}) -> str:
|
block_nostr: {}) -> str:
|
||||||
""" Shows a single post as html
|
""" Shows a single post as html
|
||||||
"""
|
"""
|
||||||
|
max_content_warning_length: int = 120
|
||||||
if not post_json_object:
|
if not post_json_object:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
# maximum number of different emoji reactions which can be added to a post
|
# maximum number of different emoji reactions which can be added to a post
|
||||||
max_reaction_types = 5
|
max_reaction_types: int = 5
|
||||||
|
|
||||||
# if downloads of avatar images aren't enabled then we can do more
|
# if downloads of avatar images aren't enabled then we can do more
|
||||||
# accurate timing of different parts of the code
|
# accurate timing of different parts of the code
|
||||||
|
|
@ -2372,7 +2373,7 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
||||||
# benchmark
|
# benchmark
|
||||||
post_start_time = time.time()
|
post_start_time = time.time()
|
||||||
|
|
||||||
post_actor = get_actor_from_post(post_json_object)
|
post_actor: str = get_actor_from_post(post_json_object)
|
||||||
|
|
||||||
_log_post_timing(enable_timing_log, post_start_time, '0')
|
_log_post_timing(enable_timing_log, post_start_time, '0')
|
||||||
|
|
||||||
|
|
@ -2382,8 +2383,8 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
||||||
|
|
||||||
_log_post_timing(enable_timing_log, post_start_time, '1')
|
_log_post_timing(enable_timing_log, post_start_time, '1')
|
||||||
|
|
||||||
avatar_position = ''
|
avatar_position: str = ''
|
||||||
message_id = ''
|
message_id: str = ''
|
||||||
if post_json_object.get('id'):
|
if post_json_object.get('id'):
|
||||||
message_id = remove_hash_from_post_id(post_json_object['id'])
|
message_id = remove_hash_from_post_id(post_json_object['id'])
|
||||||
message_id = remove_id_ending(message_id)
|
message_id = remove_id_ending(message_id)
|
||||||
|
|
@ -2391,23 +2392,23 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
||||||
_log_post_timing(enable_timing_log, post_start_time, '2')
|
_log_post_timing(enable_timing_log, post_start_time, '2')
|
||||||
|
|
||||||
# does this post have edits?
|
# does this post have edits?
|
||||||
edits_post_url = \
|
edits_post_url: str = \
|
||||||
remove_id_ending(message_id.strip()).replace('/', '#') + '.edits'
|
remove_id_ending(message_id.strip()).replace('/', '#') + '.edits'
|
||||||
account_dir = acct_dir(base_dir, nickname, domain) + '/'
|
account_dir = acct_dir(base_dir, nickname, domain) + '/'
|
||||||
|
|
||||||
message_id_str = ''
|
message_id_str: str = ''
|
||||||
if message_id:
|
if message_id:
|
||||||
message_id_str = ';' + message_id
|
message_id_str = ';' + message_id
|
||||||
|
|
||||||
domain_full = get_full_domain(domain, port)
|
domain_full = get_full_domain(domain, port)
|
||||||
|
|
||||||
page_number_param = ''
|
page_number_param: str = ''
|
||||||
if page_number:
|
if page_number:
|
||||||
page_number_param = '?page=' + str(page_number)
|
page_number_param = '?page=' + str(page_number)
|
||||||
|
|
||||||
# NOTE at the time when the post is generated we don't know what
|
# NOTE at the time when the post is generated we don't know what
|
||||||
# browser will be used to access it
|
# browser will be used to access it
|
||||||
ua_str = ''
|
ua_str: str = ''
|
||||||
|
|
||||||
# get the html post from the recent posts cache if it exists there
|
# get the html post from the recent posts cache if it exists there
|
||||||
post_html = \
|
post_html = \
|
||||||
|
|
@ -3222,6 +3223,10 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
||||||
add_emoji_to_display_name(session, base_dir, http_prefix,
|
add_emoji_to_display_name(session, base_dir, http_prefix,
|
||||||
nickname, domain,
|
nickname, domain,
|
||||||
summary_str, False, translate)
|
summary_str, False, translate)
|
||||||
|
cw_str = remove_long_words(cw_str, 40, [])
|
||||||
|
# truncate the content warning if it is too long
|
||||||
|
if len(cw_str) > max_content_warning_length:
|
||||||
|
cw_str = cw_str[:max_content_warning_length]
|
||||||
content_str += \
|
content_str += \
|
||||||
'<label class="cw"><span itemprop="description">' + \
|
'<label class="cw"><span itemprop="description">' + \
|
||||||
cw_str + '</span></label>\n'
|
cw_str + '</span></label>\n'
|
||||||
|
|
@ -3238,6 +3243,11 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
||||||
cw_content_str, post_json_object, page_number)
|
cw_content_str, post_json_object, page_number)
|
||||||
cw_content_str = \
|
cw_content_str = \
|
||||||
switch_words(base_dir, nickname, domain, cw_content_str)
|
switch_words(base_dir, nickname, domain, cw_content_str)
|
||||||
|
# break up excessively long words within content warning
|
||||||
|
cw_content_str = remove_long_words(cw_content_str, 40, [])
|
||||||
|
# truncate the content warning if it is too long
|
||||||
|
if len(cw_content_str) > max_content_warning_length:
|
||||||
|
cw_content_str = cw_content_str[:max_content_warning_length]
|
||||||
if not is_blog_post(post_json_object):
|
if not is_blog_post(post_json_object):
|
||||||
# get the content warning button
|
# get the content warning button
|
||||||
content_str += \
|
content_str += \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue