diff options
| author | Markus Heiser <markus.heiser@darmarit.de> | 2022-03-12 10:18:08 +0100 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarit.de> | 2022-03-12 11:36:31 +0100 |
| commit | b1912607ae9783d6ccf648bd7706a64eca5bedb9 (patch) | |
| tree | a27ada16192c85d3bd7fa25714a113e2d621433f /searx/user_help.py | |
| parent | bb71ebc3945b8e345bebe45a7d393afba6366ab9 (diff) | |
[mod] replace /help by /info pages and include pages in project docs
This patch implements a bolierplate to share content from info-pages of the
SearXNG instance (URL /info) with the project documentation (path /docs/user).
The info pages are using Markdown (CommonMark), to include them in the project
documentation (reST) the myst-parser [1] is used in the Sphinx-doc build chain.
If base_url is known (defined in settings.yml) links to the instance are also
inserted into the project documentation::
searxng_extra/docs_prebuild
[1] https://www.sphinx-doc.org/en/master/usage/markdown.html
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/user_help.py')
| -rw-r--r-- | searx/user_help.py | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/searx/user_help.py b/searx/user_help.py deleted file mode 100644 index 1914c7c84..000000000 --- a/searx/user_help.py +++ /dev/null @@ -1,61 +0,0 @@ -# pyright: basic -from typing import Dict, NamedTuple -import pkg_resources - -import flask -from flask.helpers import url_for -import mistletoe - -from . import get_setting -from .version import GIT_URL - - -class HelpPage(NamedTuple): - title: str - content: str - - -# Whenever a new .md file is added to help/ it needs to be added here -_TOC = ('about',) - -PAGES: Dict[str, HelpPage] = {} -""" Maps a filename under help/ without the file extension to the rendered page. """ - - -def render(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. - """ - - 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 pagename in _TOC: - file_content = pkg_resources.resource_string(__name__, 'help/en/' + pagename + '.md').decode() - markdown = define_link_targets + file_content - assert file_content.startswith('# ') - title = file_content.split('\n', maxsplit=1)[0].strip('# ') - content: str = mistletoe.markdown(markdown) - - if pagename == 'about': - try: - content += pkg_resources.resource_string(__name__, 'templates/__common__/aboutextend.html').decode() - except FileNotFoundError: - pass - PAGES[pagename] = HelpPage(title=title, content=content) |