|
@@ -1,5 +1,5 @@
|
|
|
-from typing import Dict
|
|
|
-import os.path
|
|
|
+# pyright: basic
|
|
|
+from typing import Dict, NamedTuple
|
|
|
import pkg_resources
|
|
|
|
|
|
import flask
|
|
@@ -9,8 +9,17 @@ import mistletoe
|
|
|
from . import get_setting
|
|
|
from .version import GIT_URL
|
|
|
|
|
|
-HELP: Dict[str, str] = {}
|
|
|
-""" Maps a filename under help/ without the file extension to the rendered HTML. """
|
|
|
+
|
|
|
+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):
|
|
@@ -37,12 +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
|
|
|
-
|
|
|
- markdown = pkg_resources.resource_string(__name__, 'help/' + filename).decode()
|
|
|
- markdown = define_link_targets + markdown
|
|
|
- HELP[rootname] = mistletoe.markdown(markdown)
|
|
|
+ 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 pagename == 'about':
|
|
|
+ try:
|
|
|
+ content += pkg_resources.resource_string(__name__, 'templates/__common__/aboutextend.html').decode()
|
|
|
+ except FileNotFoundError:
|
|
|
+ pass
|
|
|
+ PAGES[pagename] = HelpPage(title=title, content=content)
|