Limit the number of featured hashtags

main
Bob Mottram 2023-05-03 12:03:00 +01:00
parent d27212a0d4
commit aaeb49b202
1 changed files with 10 additions and 0 deletions

View File

@ -1915,6 +1915,7 @@ def get_featured_hashtags(actor_json: {}) -> str:
return result return result
if not isinstance(actor_json['tag'], list): if not isinstance(actor_json['tag'], list):
return result return result
ctr = 0
for tag_dict in actor_json['tag']: for tag_dict in actor_json['tag']:
if not tag_dict.get('type'): if not tag_dict.get('type'):
continue continue
@ -1943,6 +1944,9 @@ def get_featured_hashtags(actor_json: {}) -> str:
if not valid_hash_tag(tag_name): if not valid_hash_tag(tag_name):
continue continue
result += '#' + tag_name + ' ' result += '#' + tag_name + ' '
ctr += 1
if ctr >= 10:
break
return result.strip() return result.strip()
@ -1954,6 +1958,7 @@ def get_featured_hashtags_as_html(actor_json: {}) -> str:
return result return result
if not isinstance(actor_json['tag'], list): if not isinstance(actor_json['tag'], list):
return result return result
ctr = 0
for tag_dict in actor_json['tag']: for tag_dict in actor_json['tag']:
if not tag_dict.get('type'): if not tag_dict.get('type'):
continue continue
@ -1985,6 +1990,9 @@ def get_featured_hashtags_as_html(actor_json: {}) -> str:
'<a href="' + tag_dict['href'] + '" ' + \ '<a href="' + tag_dict['href'] + '" ' + \
'class="mention hashtag" rel="tag" ' + \ 'class="mention hashtag" rel="tag" ' + \
'tabindex="10">#' + tag_name + '</a> ' 'tabindex="10">#' + tag_name + '</a> '
ctr += 1
if ctr >= 10:
break
result = result.strip() result = result.strip()
if result: if result:
result = '<p>' + result + '</p>' result = '<p>' + result + '</p>'
@ -2023,6 +2031,8 @@ def set_featured_hashtags(actor_json: {}, hashtags: str,
"href": url "href": url
}) })
tags_used.append(tag_str) tags_used.append(tag_str)
if len(result) >= 10:
break
# add any non-hashtags to the result # add any non-hashtags to the result
if actor_json.get('tag'): if actor_json.get('tag'):
for tag_dict in actor_json['tag']: for tag_dict in actor_json['tag']: