diff options
| author | Martin Fischer <martin@push-f.com> | 2022-01-31 13:23:49 +0100 |
|---|---|---|
| committer | Martin Fischer <martin@push-f.com> | 2022-02-01 06:29:22 +0100 |
| commit | c53c295573d6261be682cc506eefd5d8f0c04e07 (patch) | |
| tree | 201ddcd5886ad4466f83830df4e19caf12dd405c /searx/user_help.py | |
| parent | 0f7bcd17b21629850b441693615a99a0214af5b9 (diff) | |
[enh] make searx.user_help use an explicit TOC
When we have multiple help pages we want them
to be displayed in a specific order.
Diffstat (limited to 'searx/user_help.py')
| -rw-r--r-- | searx/user_help.py | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/searx/user_help.py b/searx/user_help.py index 62628ab40..ae08ce760 100644 --- a/searx/user_help.py +++ b/searx/user_help.py @@ -1,6 +1,5 @@ # pyright: basic from typing import Dict, NamedTuple -import os.path import pkg_resources import flask @@ -16,6 +15,9 @@ class HelpPage(NamedTuple): 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. """ @@ -44,21 +46,16 @@ def render(app: flask.Flask): define_link_targets = ''.join(f'[{name}]: {url}\n' for name, url in link_targets.items()) - for filename in pkg_resources.resource_listdir(__name__, 'help'): - rootname, ext = os.path.splitext(filename) - - if ext != '.md': - continue - - file_content = pkg_resources.resource_string(__name__, 'help/' + filename).decode() + for pagename in _TOC: + file_content = pkg_resources.resource_string(__name__, 'help/' + 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 filename == 'about.md': + if pagename == 'about': try: content += pkg_resources.resource_string(__name__, 'templates/__common__/aboutextend.html').decode() except FileNotFoundError: pass - PAGES[rootname] = HelpPage(title=title, content=content) + PAGES[pagename] = HelpPage(title=title, content=content) |