diff --git a/app/__init__.py b/app/__init__.py index 87882c0e..64ce80f8 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -99,19 +99,6 @@ def create_app(config_class=Config): from app.search import bp as search_bp app.register_blueprint(search_bp) - def get_resource_as_string(name, charset='utf-8'): - with app.open_resource(name) as f: - return f.read().decode(charset) - - app.jinja_env.globals['get_resource_as_string'] = get_resource_as_string - - def community_link_to_href(link: str) -> str: - pattern = r"!([a-zA-Z0-9_.-]*)@([a-zA-Z0-9_.-]*)\b" - server = r'/\g<2>>' + r'!\g<1>@\g<2>', link) - - app.jinja_env.filters['community_links'] = community_link_to_href - # send error reports via email if app.config['MAIL_SERVER'] and app.config['MAIL_ERRORS']: auth = None diff --git a/app/utils.py b/app/utils.py index a62a5d42..0a12ce53 100644 --- a/app/utils.py +++ b/app/utils.py @@ -252,6 +252,12 @@ def microblog_content_to_title(html: str) -> str: return result +def community_link_to_href(link: str) -> str: + pattern = r"!([a-zA-Z0-9_.-]*)@([a-zA-Z0-9_.-]*)\b" + server = r'/\g<2>>' + r'!\g<1>@\g<2>', link) + + def domain_from_url(url: str, create=True) -> Domain: parsed_url = urlparse(url.lower().replace('www.', '')) if parsed_url and parsed_url.hostname: diff --git a/pyfedi.py b/pyfedi.py index 040d22c2..410baaec 100644 --- a/pyfedi.py +++ b/pyfedi.py @@ -11,7 +11,7 @@ from flask import session, g, json, request, current_app from app.constants import POST_TYPE_LINK, POST_TYPE_IMAGE, POST_TYPE_ARTICLE from app.models import Site from app.utils import getmtime, gibberish, shorten_string, shorten_url, digits, user_access, community_membership, \ - can_create_post, can_upvote, can_downvote, shorten_number, ap_datetime, current_theme + can_create_post, can_upvote, can_downvote, shorten_number, ap_datetime, current_theme, community_link_to_href app = create_app() cli.register(app) @@ -44,6 +44,7 @@ with app.app_context(): app.jinja_env.globals['can_downvote'] = can_downvote app.jinja_env.globals['theme'] = current_theme app.jinja_env.globals['file_exists'] = os.path.exists + app.jinja_env.filters['community_links'] = community_link_to_href app.jinja_env.filters['shorten'] = shorten_string app.jinja_env.filters['shorten_url'] = shorten_url