From c7b04653cb21e9727c55501fada49fcc250ed161 Mon Sep 17 00:00:00 2001 From: Alvie Rahman Date: Tue, 29 Jun 2021 19:06:34 +0100 Subject: [PATCH] add extra content to notes landing page --- notes2web.py | 13 ++++++++++++- templates/extra_index_content.html | 1 + templates/indexhead.html | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 templates/extra_index_content.html diff --git a/notes2web.py b/notes2web.py index a8a7764..f8d4aa8 100755 --- a/notes2web.py +++ b/notes2web.py @@ -14,6 +14,7 @@ TEXT_ARTICLE_TEMPLATE_FOOT = None TEXT_ARTICLE_TEMPLATE_HEAD = None INDEX_TEMPLATE_FOOT = None INDEX_TEMPLATE_HEAD = None +EXTRA_INDEX_CONTENT = None def get_files(folder): markdown = [] @@ -55,6 +56,7 @@ def get_args(): parser.add_argument('-i', '--template-index-head', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/templates/indexhead.html')) parser.add_argument('-I', '--template-index-foot', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/templates/indexfoot.html')) parser.add_argument('-s', '--stylesheet', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/styles.css')) + parser.add_argument('-e', '--extra-index-content', type=pathlib.Path, default=pathlib.Path('/opt/notes2web/templates/extra_index_content.html')) return parser.parse_args() @@ -73,6 +75,9 @@ def main(args): with open(args.template_index_head) as fp: INDEX_TEMPLATE_HEAD = fp.read() + with open(args.extra_index_content) as fp: + EXTRA_INDEX_CONTENT = fp.read() + if not os.path.exists(args.output_dir): os.makedirs(args.output_dir, exist_ok=True) @@ -114,6 +119,8 @@ def main(args): dirs_to_index = [args.output_dir.name] + get_dirs(args.output_dir) print(f"{dirs_to_index=}") + print(f"{os.path.commonpath(dirs_to_index)=}") + for directory in dirs_to_index: paths = os.listdir(directory) print(f"{paths=}") @@ -125,7 +132,6 @@ def main(args): continue fullpath = os.path.join(directory, path) - print(fullpath) if os.path.splitext(path)[1] == '.html': with open(fullpath) as fp: soup = bs(fp.read(), 'html.parser') @@ -150,6 +156,11 @@ def main(args): indexentries.sort(key=lambda entry: entry['isdirectory'], reverse=True) html = re.sub(r'\$title\$', directory, INDEX_TEMPLATE_HEAD) + html = re.sub(r'\$extra_content\$', + EXTRA_INDEX_CONTENT if directory == os.path.commonpath(dirs_to_index) else '', + html + ) + for entry in indexentries: html += f"
{entry['title']}{'/' if entry['isdirectory'] else ''}
" html += INDEX_TEMPLATE_FOOT diff --git a/templates/extra_index_content.html b/templates/extra_index_content.html new file mode 100644 index 0000000..b96810c --- /dev/null +++ b/templates/extra_index_content.html @@ -0,0 +1 @@ +

These are my personal notes. Correctness is not guaranteed.

diff --git a/templates/indexhead.html b/templates/indexhead.html index 6f5b02e..537ae7e 100644 --- a/templates/indexhead.html +++ b/templates/indexhead.html @@ -8,4 +8,5 @@

$title$

+ $extra_content$
../