use --short flag on git rev-parse

This commit is contained in:
Akbar Rahman 2023-02-06 14:42:37 +00:00
parent df8febd3cf
commit a91f5dcdfc
Signed by: alvierahman90
GPG Key ID: 20609519444A1269
2 changed files with 4 additions and 6 deletions

View File

@ -1,6 +1,6 @@
install: install:
cp 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 sed "s/N2W_COMMIT = \"\"/N2W_COMMIT = \"$$(git rev-parse --short HEAD)\"/" notes2web.py > /usr/local/bin/notes2web.py
pip3 install -r requirements.txt pip3 install -r requirements.txt
mkdir -p /opt/notes2web mkdir -p /opt/notes2web
cp -r templates /opt/notes2web cp -r templates /opt/notes2web

View File

@ -22,8 +22,6 @@ INDEX_TEMPLATE_HEAD = None
EXTRA_INDEX_CONTENT = None EXTRA_INDEX_CONTENT = None
N2W_COMMIT = "" N2W_COMMIT = ""
# how many characters of a commit to show on landing page
COMMIT_SHA1_NCHARS = 7
def is_plaintext(filename): def is_plaintext(filename):
@ -71,7 +69,7 @@ def get_inherited_tags(file, base_folder):
def git_head_sha1(working_dir): def git_head_sha1(working_dir):
git_response = subprocess.run( git_response = subprocess.run(
[ 'git', f"--git-dir={working_dir.joinpath('.git')}", 'rev-parse', 'HEAD' ], [ 'git', f"--git-dir={working_dir.joinpath('.git')}", 'rev-parse', '--short', 'HEAD' ],
stdout=subprocess.PIPE stdout=subprocess.PIPE
).stdout.decode('utf-8') ).stdout.decode('utf-8')
@ -405,8 +403,8 @@ def main(args):
with open(args.home_index) as fp2: with open(args.home_index) as fp2:
html = re.sub(r'\$title\$', args.output_dir.parts[0], fp2.read()) 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'\$h1title\$', args.output_dir.parts[0], html)
html = re.sub(r'\$n2w_commit\$', N2W_COMMIT[0:COMMIT_SHA1_NCHARS], html) html = re.sub(r'\$n2w_commit\$', N2W_COMMIT, html)
html = re.sub(r'\$notes_git_head_sha1\$', git_head_sha1(args.notes)[0:COMMIT_SHA1_NCHARS], html) html = re.sub(r'\$notes_git_head_sha1\$', git_head_sha1(args.notes), html)
html = re.sub(r'\$data\$', json.dumps(all_entries), html) html = re.sub(r'\$data\$', json.dumps(all_entries), html)