diff options
author | Martin Fischer <martin@push-f.com> | 2022-01-15 09:34:08 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2022-01-23 08:01:55 +0100 |
commit | 105c5a6a9839c65a81b32cdf82278c5cc629ae4a (patch) | |
tree | 19a98367914435850612798dadbee48f5a289886 /searx/user_help.py | |
parent | 284ac8bfd8a3d1f762c98a0195b98a45cdd089d3 (diff) | |
download | searxng-105c5a6a9839c65a81b32cdf82278c5cc629ae4a.tar.gz searxng-105c5a6a9839c65a81b32cdf82278c5cc629ae4a.zip |
[help] stop rendering documentation with Jinja2
To facilitate translation of the user documentation we move
the templating logic outside of the user documentation.
Diffstat (limited to 'searx/user_help.py')
-rw-r--r-- | searx/user_help.py | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/searx/user_help.py b/searx/user_help.py index 1d3cbef37..bf7336777 100644 --- a/searx/user_help.py +++ b/searx/user_help.py @@ -3,6 +3,7 @@ import os.path import pkg_resources import flask +from flask.helpers import url_for import mistletoe from . import get_setting @@ -19,21 +20,29 @@ def render(app: flask.Flask): We render the user documentation once on startup to improve performance. """ - for filename in pkg_resources.resource_listdir(__name__, 'help'): - rootname, ext = os.path.splitext(filename) - if ext != '.md': - continue - text = pkg_resources.resource_string(__name__, 'help/' + filename).decode() + link_targets = { + 'brand.git_url': GIT_URL, + 'brand.public_instances': get_setting('brand.public_instances'), + 'brand.docs_url': get_setting('brand.docs_url'), + } + + base_url = get_setting('server.base_url') or None + # we specify base_url so that url_for works for base_urls that have a non-root path - base_url = get_setting('server.base_url') or None - # we specify base_url so that url_for works for base_urls that have a non-root path + with app.test_request_context(base_url=base_url): + link_targets['url_for:index'] = url_for('index') + link_targets['url_for:preferences'] = url_for('preferences') + link_targets['url_for:stats'] = url_for('stats') - with app.test_request_context(base_url=base_url): - # the request context is needed for Flask's url_for - # (otherwise we'd need to set app.config['SERVER_NAME'], - # which we don't want) + define_link_targets = ''.join(f'[{name}]: {url}\n' for name, url in link_targets.items()) - interpolated = flask.render_template_string(text, get_setting=get_setting, searx_git_url=GIT_URL) + for filename in pkg_resources.resource_listdir(__name__, 'help'): + rootname, ext = os.path.splitext(filename) + + if ext != '.md': + continue - HELP[rootname] = mistletoe.markdown(interpolated) + markdown = pkg_resources.resource_string(__name__, 'help/' + filename).decode() + markdown = define_link_targets + markdown + HELP[rootname] = mistletoe.markdown(markdown) |