mirror of https://gitlab.com/bashrc2/epicyon
Replace gemini-style links with html links
parent
9426a72f76
commit
feb3b9cb4f
48
blog.py
48
blog.py
|
|
@ -45,6 +45,7 @@ from posts import create_blogs_timeline
|
|||
from newswire import rss2header
|
||||
from newswire import rss2footer
|
||||
from cache import get_person_from_cache
|
||||
from flags import is_image_file
|
||||
|
||||
|
||||
def _no_of_blog_replies(base_dir: str, http_prefix: str, translate: {},
|
||||
|
|
@ -198,6 +199,52 @@ def _get_blog_replies(base_dir: str, http_prefix: str, translate: {},
|
|||
return ''
|
||||
|
||||
|
||||
def html_blog_post_gemini_links(content: str) -> str:
|
||||
"""Converts gemini-style links to html
|
||||
"""
|
||||
if '=> ' not in content:
|
||||
return content
|
||||
ctr = 0
|
||||
sections = content.split('=> ')
|
||||
for section in sections:
|
||||
if ctr == 0:
|
||||
ctr += 1
|
||||
continue
|
||||
if ' ' not in section:
|
||||
ctr += 1
|
||||
continue
|
||||
web_link_str = section.split(' ', 1)[0]
|
||||
if '://' not in web_link_str or \
|
||||
'.' not in web_link_str:
|
||||
ctr += 1
|
||||
continue
|
||||
after_web_link = section.split(web_link_str, 1)[1]
|
||||
after_str = ''
|
||||
if '<' in after_web_link:
|
||||
after_str = after_web_link.split('<', 1)[0]
|
||||
elif '\n' in after_web_link:
|
||||
after_str = after_web_link.split('\n', 1)[0]
|
||||
else:
|
||||
ctr += 1
|
||||
continue
|
||||
if is_image_file(web_link_str) and \
|
||||
not web_link_str.endswith('.svg'):
|
||||
link_str = '<img loading="lazy" ' + \
|
||||
'decoding="async" src="' + \
|
||||
web_link_str + '" alt="' + after_str + \
|
||||
'" title="' + after_str + '">\n'
|
||||
else:
|
||||
link_str = '<a href="' + web_link_str + '"' + \
|
||||
'tabindex="10" ' + \
|
||||
'rel="nofollow noopener noreferrer" ' + \
|
||||
'target="_blank">' + after_str + '</a>'
|
||||
|
||||
content = content.replace('=> ' + web_link_str + ' ' + after_str,
|
||||
link_str)
|
||||
ctr += 1
|
||||
return content
|
||||
|
||||
|
||||
def html_blog_post_markdown(content: str) -> str:
|
||||
"""Converts any markdown to html
|
||||
"""
|
||||
|
|
@ -399,6 +446,7 @@ def _html_blog_post_content(debug: bool, session, authorized: bool,
|
|||
|
||||
# convert any markdown
|
||||
blog_str = html_blog_post_markdown(blog_str)
|
||||
blog_str = html_blog_post_gemini_links(blog_str)
|
||||
|
||||
if replies == 0:
|
||||
blog_str += blog_separator + '\n'
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@ from maps import get_event_time_span_from_post
|
|||
from session import get_json_valid
|
||||
from session import get_json
|
||||
from blog import html_blog_post_markdown
|
||||
from blog import html_blog_post_gemini_links
|
||||
|
||||
# maximum length for display name within html posts
|
||||
MAX_DISPLAY_NAME_LENGTH = 42
|
||||
|
|
@ -3141,6 +3142,8 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
# replace any markdown headers with html
|
||||
if post_is_blog:
|
||||
object_content = html_blog_post_markdown(object_content)
|
||||
# replace gemini-style links with html links
|
||||
object_content = html_blog_post_gemini_links(object_content)
|
||||
# show quote toot link
|
||||
quote_url = get_quote_toot_url(post_json_object)
|
||||
if quote_url:
|
||||
|
|
|
|||
Loading…
Reference in New Issue