load version dynamically

that way the whole dang cache doesnt get invalidated when the version
changes
This commit is contained in:
codl 2017-08-11 22:20:24 +02:00
parent 2f83630629
commit 51cf43d073
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
4 changed files with 22 additions and 3 deletions

14
assets/version.js Normal file
View File

@ -0,0 +1,14 @@
(function(){
if(!('fetch' in window)){
return
}
fetch('/api/about').then(r => r.json()).then(j => {
let ident = document.querySelector('#ident');
ident.textContent = j.service
if(j.version){
ident.textContent += ' ' + j.version
}
})
})();

View File

@ -23,7 +23,7 @@ def task_gen_logo():
def task_copy_asset():
import shutil
assets = ('icon.png', 'logotype.png')
assets = ('icon.png', 'logotype.png', 'version.js')
for asset in assets:
yield dict(
name=asset,

View File

@ -1,4 +1,4 @@
from flask import render_template, url_for, redirect, request, g, Response
from flask import render_template, url_for, redirect, request, g, Response, jsonify
from datetime import datetime, timedelta
import lib.twitter
import lib
@ -161,3 +161,7 @@ def logout():
db.session.commit()
g.viewer = None
return redirect(url_for('index'))
@app.route('/api/about')
def api_about():
return jsonify(service='Forget', version=version.version)

View File

@ -12,6 +12,7 @@
<meta name='og:type' content='website' />
<meta name='twitter:card' content='summary' />
<meta name='twitter:site:id' content='808418'/>
<script async src="{{ st('version.js') }}"></script>
</head>
<body>
<header>
@ -27,7 +28,7 @@
</header>
{% block body %}{% endblock %}
<footer>
<p>Forget {{version or "dev"}}</p>
<p id='ident'>Forget</p>
<p>A <a href="https://twitter.com/codl">codl</a> joint</p>
<p><a href="https://github.com/codl/forget">Code on Github</a></p>
</footer>