mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 11:26:56 -08:00
move code to standard places #125
This commit is contained in:
parent
d6d8a83ed5
commit
4f3bb0863d
3 changed files with 8 additions and 14 deletions
|
@ -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'<a href=https://' + app.config['SERVER_NAME'] + r'/community/lookup/'
|
||||
return re.sub(pattern, server + r'\g<1>/\g<2>>' + r'!\g<1>@\g<2></a>', 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
|
||||
|
|
|
@ -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'<a href=https://' + current_app.config['SERVER_NAME'] + r'/community/lookup/'
|
||||
return re.sub(pattern, server + r'\g<1>/\g<2>>' + r'!\g<1>@\g<2></a>', link)
|
||||
|
||||
|
||||
def domain_from_url(url: str, create=True) -> Domain:
|
||||
parsed_url = urlparse(url.lower().replace('www.', ''))
|
||||
if parsed_url and parsed_url.hostname:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue