front/home: add version and build time

This commit is contained in:
rr- 2016-03-31 23:18:08 +02:00
parent 82e7c6ebe9
commit da3faa556f
4 changed files with 58 additions and 1 deletions

View file

@ -4,6 +4,11 @@ const fs = require('fs');
const glob = require('glob');
const path = require('path');
const util = require('util');
const execSync = require('child_process').execSync;
function getVersion() {
return execSync('git describe --always --dirty --long --tags').toString();
}
function getConfig() {
const ini = require('ini');
@ -34,6 +39,10 @@ function getConfig() {
delete config.database;
config.service.userRanks = config.service.userRanks.split(/,\s*/);
config.service.tagCategories = config.service.tagCategories.split(/,\s*/);
config.meta = {
version: getVersion(),
buildDate: new Date().toUTCString(),
};
return config;
}

View file

@ -1,4 +1,5 @@
<div class='content-wrapper transparent' id='home'>
<div class='messages'></div>
<h1>{{name}}</h1>
<footer>Version: <span class="version">{{version}}</span> (built {{buildDate}})</footer>
</div>

44
static/js/util.js Normal file
View file

@ -0,0 +1,44 @@
'use strict';
function formatRelativeTime(timeString) {
if (!timeString) {
return 'never';
}
const then = Date.parse(timeString);
const now = Date.now();
const difference = Math.abs(now - then) / 1000.0;
const future = now < then;
const descriptions = [
[60, 'a few seconds', null],
[60*2, 'a minute', null],
[60*60, '% minutes', 60],
[60*60*2, 'an hour', null],
[60*60*24, '% hours', 60*60],
[60*60*24*2, 'a day', null],
[60*60*24*30.42, '% days', 60*60*24],
[60*60*24*30.42*2, 'a month', null],
[60*60*24*30.42*12, '% months', 60*60*24*30.42],
[60*60*24*30.42*12*2, 'a year', null],
[8640000000000000/*max*/, '% years', 60*60*24*30.42*12],
];
let text = null;
for (let kv of descriptions) {
const multiplier = kv[0];
const template = kv[1];
const divider = kv[2];
if (difference < multiplier) {
text = template.replace(/%/, Math.round(difference / divider));
break;
}
}
if (text === 'a day') {
return future ? 'tomorrow' : 'yesterday';
}
return future ? 'in ' + text : text + ' ago';
}
module.exports = {formatRelativeTime: formatRelativeTime};

View file

@ -1,5 +1,6 @@
'use strict';
const util = require('../util.js');
const config = require('../config.js');
const BaseView = require('./base_view.js');
@ -11,7 +12,9 @@ class HomeView extends BaseView {
render(section) {
this.showView(this.template({
'name': config.basic.name,
name: config.basic.name,
version: config.meta.version,
buildDate: util.formatRelativeTime(config.meta.buildDate),
}));
}
}