feat: current git commit hash shown to visitors

This commit is contained in:
ffqq 2023-07-13 00:28:28 +00:00
parent b133bd8d72
commit 48321233c3
3 changed files with 44 additions and 3 deletions

18
main
View File

@ -7,6 +7,7 @@ import json
import secrets import secrets
import datetime import datetime
import socket import socket
import subprocess
from itertools import groupby from itertools import groupby
from waitress import serve from waitress import serve
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
@ -126,6 +127,17 @@ def get_session(id):
return "error" return "error"
return post return post
def get_current_commit(output_format="full"):
if output_format == "short":
length = 8
else:
length = 40
try:
output = subprocess.check_output(["git", "rev-parse", f"--short={length}", "HEAD"]).decode().strip()
return output
except subprocess.CalledProcessError:
return "Error fetching git commit"
ALLOWED_EXTENSIONS = {"png", "apng", "jpg", "jpeg", "gif", "svg", "webp"} ALLOWED_EXTENSIONS = {"png", "apng", "jpg", "jpeg", "gif", "svg", "webp"}
@ -139,14 +151,16 @@ def main():
usersession = request.cookies.get("session_DO_NOT_SHARE") usersession = request.cookies.get("session_DO_NOT_SHARE")
conn = get_db_connection() conn = get_db_connection()
posts = conn.execute("SELECT * FROM posts ORDER BY created DESC;").fetchall() posts = conn.execute("SELECT * FROM posts ORDER BY created DESC;").fetchall()
commit_hash_long = get_current_commit()
commit_hash_short = get_current_commit(output_format="short")
conn.close() conn.close()
if usersession: if usersession:
userCookie = get_session(usersession) userCookie = get_session(usersession)
user = get_user(userCookie["id"]) user = get_user(userCookie["id"])
return render_template("main.html", userdata=user, posts=posts) return render_template("main.html", userdata=user, posts=posts, commit_hash_long=commit_hash_long, commit_hash_short=commit_hash_short)
else: else:
return render_template("main.html", posts=posts) return render_template("main.html", posts=posts, commit_hash_long=commit_hash_long, commit_hash_short=commit_hash_short)
@app.route("/chat", methods=("GET", "POST")) @app.route("/chat", methods=("GET", "POST"))
def chat(): def chat():

View File

@ -19,6 +19,20 @@ body {
z-index: 2; z-index: 2;
} }
.bottom {
margin: 0;
border: solid;
border-color: grey;
border-width: 0;
border-bottom-width: 1px;
background-color: white;
}
.bottom a {
color: lightgrey;
text-decoration: none;
}
.navbar .selected { .navbar .selected {
border: solid; border: solid;
border-color: #f1b739; border-color: #f1b739;
@ -332,6 +346,14 @@ body {
background-color: var(--gray-800); background-color: var(--gray-800);
} }
.bottom {
background-color: var(--gray-900);
}
.bottom a {
color: var(--gray-800)
}
.navbar a, a { .navbar a, a {
color: white; color: white;
border-size: 0px; border-size: 0px;

View File

@ -113,7 +113,12 @@
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
<div class="bottom">
<span>
<a href="https://codeberg.org/burger-software/burgercat">burgercat</a>
<a href="https://codeberg.org/burger-software/burgercat/commit/{{ commit_hash_long }}" style="float: right;">commit hash: {{ commit_hash_short }}</a>
</span>
</div>
<script src="/static/js/main.js"></script> <script src="/static/js/main.js"></script>
</body> </body>