mirror of https://github.com/searxng/searxng.git
[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.
This commit is contained in:
parent
0f7bcd17b2
commit
c53c295573
|
@ -1,6 +1,5 @@
|
||||||
# pyright: basic
|
# pyright: basic
|
||||||
from typing import Dict, NamedTuple
|
from typing import Dict, NamedTuple
|
||||||
import os.path
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
|
@ -16,6 +15,9 @@ class HelpPage(NamedTuple):
|
||||||
content: str
|
content: str
|
||||||
|
|
||||||
|
|
||||||
|
# Whenever a new .md file is added to help/ it needs to be added here
|
||||||
|
_TOC = ('about',)
|
||||||
|
|
||||||
PAGES: Dict[str, HelpPage] = {}
|
PAGES: Dict[str, HelpPage] = {}
|
||||||
""" Maps a filename under help/ without the file extension to the rendered page. """
|
""" 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())
|
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 pagename in _TOC:
|
||||||
rootname, ext = os.path.splitext(filename)
|
file_content = pkg_resources.resource_string(__name__, 'help/' + pagename + '.md').decode()
|
||||||
|
|
||||||
if ext != '.md':
|
|
||||||
continue
|
|
||||||
|
|
||||||
file_content = pkg_resources.resource_string(__name__, 'help/' + filename).decode()
|
|
||||||
markdown = define_link_targets + file_content
|
markdown = define_link_targets + file_content
|
||||||
assert file_content.startswith('# ')
|
assert file_content.startswith('# ')
|
||||||
title = file_content.split('\n', maxsplit=1)[0].strip('# ')
|
title = file_content.split('\n', maxsplit=1)[0].strip('# ')
|
||||||
content: str = mistletoe.markdown(markdown)
|
content: str = mistletoe.markdown(markdown)
|
||||||
|
|
||||||
if filename == 'about.md':
|
if pagename == 'about':
|
||||||
try:
|
try:
|
||||||
content += pkg_resources.resource_string(__name__, 'templates/__common__/aboutextend.html').decode()
|
content += pkg_resources.resource_string(__name__, 'templates/__common__/aboutextend.html').decode()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
PAGES[rootname] = HelpPage(title=title, content=content)
|
PAGES[pagename] = HelpPage(title=title, content=content)
|
||||||
|
|
Loading…
Reference in New Issue