diff --git a/husk_helpers.py b/husk_helpers.py index 27181cd..1c825af 100644 --- a/husk_helpers.py +++ b/husk_helpers.py @@ -1,9 +1,29 @@ import os +from collections import deque #import toml #base_url = toml.load('settings.toml')["general"]["base_url"] +def sort_branch( lst ): + ''' + sorts directories before files and + sorts both alphabetically + ''' + files = [] + dirs = [] + for path in lst: + if path.endswith(".md"): + files.append(path) + else: + dirs.append(path) + files.sort() + dirs.sort() + return [*dirs, *files] + def make_tree(path="templates/content"): + ''' + creates a dictionary of the directories and files of the doc repository + ''' if '/' in path: tree = dict(name=path, children=[], type="directory") else: @@ -12,7 +32,7 @@ def make_tree(path="templates/content"): except OSError: pass #ignore errors else: - lst.sort() + lst = sort_branch(lst) for name in lst: fn = os.path.join(path, name) if os.path.isdir(fn) and not fn.endswith(".git"): @@ -23,6 +43,9 @@ def make_tree(path="templates/content"): return tree def cut_path_tree(tree, subdir, file_ending): + ''' + pruning of the tree structure from make_tree() + ''' if subdir.endswith('/'): subdir = subdir[:-1] for key, val in tree.items(): @@ -36,6 +59,9 @@ def cut_path_tree(tree, subdir, file_ending): return tree def cut_filetype_tree(tree, filetype): + ''' + removes file type of the links stored in make_tree() + ''' for key, val in tree.items(): if isinstance(val, list): for item in val: @@ -46,6 +72,10 @@ def cut_filetype_tree(tree, filetype): return tree def list_files(path): + ''' + creates a simple, one dimensional list of the doc repository + filters markdown files only + ''' doc_files = [] for root, dirs, files in os.walk(path): for file in files: @@ -54,6 +84,10 @@ def list_files(path): return doc_files def build_index(path, file_ending): + ''' + builds the searchable JSON object containing all markdown files + with metadata + ''' searchable = dict(index=[]) file_list = list_files(path) for item in file_list: diff --git a/start_site.py b/start_site.py index 8e40b84..075515b 100644 --- a/start_site.py +++ b/start_site.py @@ -40,7 +40,7 @@ def index(): def content(path="README"): with open(os.path.join(app.root_path, content_path, f'{path}.md'), "r") as _f: md_file = _f.read() - md = markdown.Markdown(extensions=['toc',TocExtension(toc_class="HolyGrail-ads", title=""),"fenced_code", "codehilite", "mdx_math"], extension_configs={"mdx_math": {"enable_dollar_delimiter": True}}) + md = markdown.Markdown(extensions=['toc',TocExtension(toc_class="HolyGrail-ads", title=""),"fenced_code", "codehilite", "tables", "mdx_math"], extension_configs={"mdx_math": {"enable_dollar_delimiter": True}}) html = md.convert(md_file) formatter = HtmlFormatter(style=highlight_style, full=True, cssclass="codehilite") css_string = formatter.get_style_defs()