From df8febd3cfaaf59a5502bf880035994656755392 Mon Sep 17 00:00:00 2001 From: Alvie Rahman Date: Mon, 6 Feb 2023 14:39:10 +0000 Subject: [PATCH] put versions and commits on landing page --- Makefile | 3 ++- notes2web.py | 15 +++++++++++++++ templates/home_index.html | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b8eb4b7..1b77e0f 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ install: - cp notes2web.py n2w_add_uuid.py /usr/local/bin + cp n2w_add_uuid.py /usr/local/bin + sed "s/N2W_COMMIT = \"\"/N2W_COMMIT = \"$$(git rev-parse HEAD)\"/" notes2web.py > /usr/local/bin/notes2web.py pip3 install -r requirements.txt mkdir -p /opt/notes2web cp -r templates /opt/notes2web diff --git a/notes2web.py b/notes2web.py index 2f09a80..372097e 100755 --- a/notes2web.py +++ b/notes2web.py @@ -21,6 +21,10 @@ INDEX_TEMPLATE_FOOT = None INDEX_TEMPLATE_HEAD = None EXTRA_INDEX_CONTENT = None +N2W_COMMIT = "" +# how many characters of a commit to show on landing page +COMMIT_SHA1_NCHARS = 7 + def is_plaintext(filename): return re.match(r'^text/', magic.from_file(str(filename), mime=True)) is not None @@ -65,6 +69,15 @@ def get_inherited_tags(file, base_folder): return list(set(tags)) +def git_head_sha1(working_dir): + git_response = subprocess.run( + [ 'git', f"--git-dir={working_dir.joinpath('.git')}", 'rev-parse', 'HEAD' ], + stdout=subprocess.PIPE + ).stdout.decode('utf-8') + + return git_response.strip() + + def git_filehistory(working_dir, filename): print(f"{pathlib.Path(filename).relative_to(working_dir)=}") git_response = subprocess.run( @@ -392,6 +405,8 @@ def main(args): with open(args.home_index) as fp2: html = re.sub(r'\$title\$', args.output_dir.parts[0], fp2.read()) html = re.sub(r'\$h1title\$', args.output_dir.parts[0], html) + html = re.sub(r'\$n2w_commit\$', N2W_COMMIT[0:COMMIT_SHA1_NCHARS], html) + html = re.sub(r'\$notes_git_head_sha1\$', git_head_sha1(args.notes)[0:COMMIT_SHA1_NCHARS], html) html = re.sub(r'\$data\$', json.dumps(all_entries), html) diff --git a/templates/home_index.html b/templates/home_index.html index 1239b27..9c50c33 100644 --- a/templates/home_index.html +++ b/templates/home_index.html @@ -20,7 +20,7 @@ Browse here or by tag here.
-

page generated by notes2web

+

page generated by notes2web (commit $n2w_commit$) notes commit $notes_git_head_sha1$