Show featured hashtags on profile

main
Bob Mottram 2023-05-03 11:34:54 +01:00
parent 916cff39fb
commit 0db51c842c
2 changed files with 48 additions and 0 deletions

View File

@ -1946,6 +1946,51 @@ def get_featured_hashtags(actor_json: {}) -> str:
return result.strip()
def get_featured_hashtags_as_html(actor_json: {}) -> str:
"""returns a html string containing featured hashtags
"""
result = ''
if not actor_json.get('tag'):
return result
if not isinstance(actor_json['tag'], list):
return result
for tag_dict in actor_json['tag']:
if not tag_dict.get('type'):
continue
if not isinstance(tag_dict['type'], str):
continue
if not tag_dict['type'].endswith('Hashtag'):
continue
if not tag_dict.get('name'):
continue
if not isinstance(tag_dict['name'], str):
continue
if not tag_dict.get('href'):
continue
if not isinstance(tag_dict['href'], str):
continue
tag_name = tag_dict['name']
if not tag_name:
continue
if tag_name.startswith('#'):
tag_name = tag_name[1:]
if not tag_name:
continue
tag_url = tag_dict['href']
if '://' not in tag_url:
continue
if not valid_hash_tag(tag_name):
continue
result += \
'<a href="' + tag_dict['href'] + '" ' + \
'class="mention hashtag" rel="tag" ' + \
'tabindex="10">#' + tag_name + '</a> '
result = result.strip()
if result:
result = '<p>' + result + '</p>'
return result
def set_featured_hashtags(actor_json: {}, hashtags: str,
append: bool = False) -> None:
"""sets featured hashtags

View File

@ -36,6 +36,7 @@ from utils import remove_eol
from languages import get_actor_languages
from skills import get_skills
from theme import get_themes_list
from person import get_featured_hashtags_as_html
from person import get_featured_hashtags
from person import person_box_json
from person import get_actor_json
@ -268,6 +269,7 @@ def html_profile_after_search(recent_posts_cache: {}, max_recent_posts: int,
add_emoji_to_display_name(session, base_dir, http_prefix,
nickname, domain,
profile_description, False, translate)
profile_description += get_featured_hashtags_as_html(profile_json)
outbox_url = None
if not profile_json.get('outbox'):
if debug:
@ -738,6 +740,7 @@ def html_profile(signing_priv_key_pem: str,
profile_description, False, translate)
if profile_description:
profile_description = standardize_text(profile_description)
profile_description += get_featured_hashtags_as_html(profile_json)
posts_button = 'button'
following_button = 'button'
moved_button = 'button'