mirror of
https://github.com/searxng/searxng
synced 2024-11-05 06:01:05 +00:00
[help] stop rendering documentation with Jinja2
To facilitate translation of the user documentation we move the templating logic outside of the user documentation.
This commit is contained in:
parent
284ac8bfd8
commit
105c5a6a98
@ -64,17 +64,8 @@ decentralized the Internet is, the more freedom we have!
|
|||||||
|
|
||||||
See the [SearXNG docs][brand.docs_url] and [SearXNG sources][brand.git_url]
|
See the [SearXNG docs][brand.docs_url] and [SearXNG sources][brand.git_url]
|
||||||
|
|
||||||
[url_for:index]: {{ url_for('index') }}
|
|
||||||
[url_for:preferences]: {{ url_for('preferences') }}
|
|
||||||
[url_for:stats]: {{ url_for('stats') }}
|
|
||||||
[brand.git_url]: {{ searx_git_url }}
|
|
||||||
[brand.public_instances]: {{ get_setting('brand.public_instances') }}
|
|
||||||
[brand.docs_url]: {{ get_setting('brand.docs_url') }}
|
|
||||||
|
|
||||||
[searx]: https://github.com/searx/searx
|
[searx]: https://github.com/searx/searx
|
||||||
[metasearch engine]: https://en.wikipedia.org/wiki/Metasearch_engine
|
[metasearch engine]: https://en.wikipedia.org/wiki/Metasearch_engine
|
||||||
[weblate]: https://weblate.bubu1.eu/projects/searxng/
|
[weblate]: https://weblate.bubu1.eu/projects/searxng/
|
||||||
[seeks project]: https://beniz.github.io/seeks/
|
[seeks project]: https://beniz.github.io/seeks/
|
||||||
[OpenSearch]: https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md
|
[OpenSearch]: https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md
|
||||||
|
|
||||||
{% include "__common__/aboutextend.html" ignore missing %}
|
|
||||||
|
@ -2,4 +2,5 @@
|
|||||||
{% block title %}{{ _('about') }} - {% endblock %}
|
{% block title %}{{ _('about') }} - {% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{{ help.about | safe }}
|
{{ help.about | safe }}
|
||||||
|
{% include "__common__/aboutextend.html" ignore missing %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
{% extends 'simple/base.html' %}
|
{% extends 'simple/base.html' %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{{ help.about | safe }}
|
{{ help.about | safe }}
|
||||||
|
{% include "__common__/aboutextend.html" ignore missing %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -3,6 +3,7 @@ import os.path
|
|||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
|
from flask.helpers import url_for
|
||||||
import mistletoe
|
import mistletoe
|
||||||
|
|
||||||
from . import get_setting
|
from . import get_setting
|
||||||
@ -19,21 +20,29 @@ def render(app: flask.Flask):
|
|||||||
|
|
||||||
We render the user documentation once on startup to improve performance.
|
We render the user documentation once on startup to improve performance.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
define_link_targets = ''.join(f'[{name}]: {url}\n' for name, url in link_targets.items())
|
||||||
|
|
||||||
for filename in pkg_resources.resource_listdir(__name__, 'help'):
|
for filename in pkg_resources.resource_listdir(__name__, 'help'):
|
||||||
rootname, ext = os.path.splitext(filename)
|
rootname, ext = os.path.splitext(filename)
|
||||||
|
|
||||||
if ext != '.md':
|
if ext != '.md':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
text = pkg_resources.resource_string(__name__, 'help/' + filename).decode()
|
markdown = pkg_resources.resource_string(__name__, 'help/' + filename).decode()
|
||||||
|
markdown = define_link_targets + markdown
|
||||||
base_url = get_setting('server.base_url') or None
|
HELP[rootname] = mistletoe.markdown(markdown)
|
||||||
# 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):
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
interpolated = flask.render_template_string(text, get_setting=get_setting, searx_git_url=GIT_URL)
|
|
||||||
|
|
||||||
HELP[rootname] = mistletoe.markdown(interpolated)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user