From 6c5d41e708924d72d5ea82ae6fbb3fb9e3a08b18 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Mon, 31 Jan 2022 17:49:05 +0100 Subject: [PATCH] [help] introduce searx.user_help.get_variables() --- searx/user_help.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/searx/user_help.py b/searx/user_help.py index 0be198d18..ec04aee07 100644 --- a/searx/user_help.py +++ b/searx/user_help.py @@ -48,14 +48,7 @@ def render(markdown: str, variables=Dict[str, str], filename='') -> HelpPage: return HelpPage(title=first_line.strip('# '), content=content) -def initialize(app: flask.Flask): - """ - Renders the user documentation. Must be called after all Flask routes have been - registered, because the documentation might try to link to them with Flask's `url_for`. - - We render the user documentation once on startup to improve performance. - """ - +def get_variables(app: flask.Flask): variables = { 'brand.git_url': GIT_URL, 'brand.public_instances': get_setting('brand.public_instances'), @@ -71,13 +64,28 @@ def initialize(app: flask.Flask): variables['stats'] = url_for('stats') variables['search'] = url_for('search') + return variables + + +def initialize(app: flask.Flask): + """ + Renders the user documentation. Must be called after all Flask routes have been + registered, because the documentation might try to link to them with Flask's `url_for`. + + We render the user documentation once on startup to improve performance. + """ + + variables = get_variables(app) + for pagename in _TOC: filename = 'help/en/' + pagename + '.md' file_content = pkg_resources.resource_string(__name__, filename).decode() if pagename == 'about': try: - file_content += pkg_resources.resource_string(__name__, 'templates/__common__/aboutextend.html').decode() + file_content += pkg_resources.resource_string( + __name__, 'templates/__common__/aboutextend.html' + ).decode() except FileNotFoundError: pass PAGES[pagename] = render(file_content, variables, filename=filename)