From 19ecc21022979f9bc85627590d5ad080a1086b0a Mon Sep 17 00:00:00 2001
From: Julian Rother <julianr@fsmpi.rwth-aachen.de>
Date: Wed, 16 Oct 2019 14:14:51 +0200
Subject: [PATCH] Auto-inject commit hash for all static urls to invalidate
 browser caches

---
 template_helper.py  |  7 ++++++-
 templates/base.html | 18 +++++++++---------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/template_helper.py b/template_helper.py
index 26be0e7..2effb59 100644
--- a/template_helper.py
+++ b/template_helper.py
@@ -13,9 +13,14 @@ app.add_template_global(min, name='min')
 app.add_template_global(max, name='max')
 
 # get git commit
-output = subprocess.check_output(['git', "log", "-g", "-1", "--pretty=%H # %h # %d # %s"]).decode('UTF-8').split('#', 3)
+output = subprocess.check_output(['git', "log", "-g", "-1", "--pretty=%H#%h#%d#%s"]).decode('UTF-8').split('#', 3)
 app.jinja_env.globals['gitversion'] = {'hash': output[1], 'longhash': output[0], 'branch': output[2], 'msg': output[3]}
 
+@app.url_defaults
+def static_version_inject(endpoint, values):
+	if endpoint == 'static':
+		values['v'] = app.jinja_env.globals['gitversion']['longhash']
+
 @app.template_global()
 def ismod(*args):
 	return ('user' in session)
diff --git a/templates/base.html b/templates/base.html
index 1b88686..4a85f2d 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -15,11 +15,11 @@
 		<meta name="viewport" content="width=device-width, initial-scale=1">
 
 		<link href="{{url_for('static', filename='bootstrap/bootstrap.css')}}" rel="stylesheet">
-		<link rel="stylesheet" type="text/css" href="{{url_for('static', filename='style.css', v='bdd2884')}}">
+		<link rel="stylesheet" type="text/css" href="{{url_for('static', filename='style.css')}}">
 		<link rel="stylesheet" href="{{url_for('static', filename='font-awesome/css/all.css')}}">
-		<link rel="stylesheet" type="text/css" href="{{url_for('static', filename='videojs/video-js.css', v='d042c96')}}">
-		<link rel="stylesheet" type="text/css" href="{{url_for('static', filename='videojs/videojs.markers.css', v='d042c96')}}">
-		<link rel="stylesheet" type="text/css" href="{{url_for('static', filename='videojs/videojs-resolution-switcher.css', v='d042c96')}}">
+		<link rel="stylesheet" type="text/css" href="{{url_for('static', filename='videojs/video-js.css')}}">
+		<link rel="stylesheet" type="text/css" href="{{url_for('static', filename='videojs/videojs.markers.css')}}">
+		<link rel="stylesheet" type="text/css" href="{{url_for('static', filename='videojs/videojs-resolution-switcher.css')}}">
 		{% if ismod() %}
 		<link rel="stylesheet" type="text/css" href="{{url_for('static', filename='bootstrap-multiselect.css')}}">
 		{% endif %}
@@ -32,11 +32,11 @@
 		<script src="{{url_for('static', filename='bootstrap-multiselect.js')}}"></script>
 		<script src="{{url_for('static', filename='plotly.min.js')}}"></script>
 		{% endif %}
-		<script src="{{url_for('static', filename='videojs/video.js', v='d042c96')}}"></script>
-		<script src="{{url_for('static', filename='videojs/lang/de.js', v='d042c96')}}"></script>
-		<script src="{{url_for('static', filename='videojs/videojs-resolution-switcher.js', v='d042c96')}}"></script>
-		<script src="{{url_for('static', filename='videojs/videojs.hotkeys.js', v='d042c96')}}"></script>
-		<script src="{{url_for('static', filename='videojs/videojs-markers.js', v='d042c96')}}"></script>
+		<script src="{{url_for('static', filename='videojs/video.js')}}"></script>
+		<script src="{{url_for('static', filename='videojs/lang/de.js')}}"></script>
+		<script src="{{url_for('static', filename='videojs/videojs-resolution-switcher.js')}}"></script>
+		<script src="{{url_for('static', filename='videojs/videojs.hotkeys.js')}}"></script>
+		<script src="{{url_for('static', filename='videojs/videojs-markers.js')}}"></script>
 		{% endblock %}
 	</head>
 	<body>
-- 
GitLab