front/home: add version and build time
This commit is contained in:
parent
82e7c6ebe9
commit
da3faa556f
4 changed files with 58 additions and 1 deletions
|
@ -4,6 +4,11 @@ const fs = require('fs');
|
||||||
const glob = require('glob');
|
const glob = require('glob');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
const execSync = require('child_process').execSync;
|
||||||
|
|
||||||
|
function getVersion() {
|
||||||
|
return execSync('git describe --always --dirty --long --tags').toString();
|
||||||
|
}
|
||||||
|
|
||||||
function getConfig() {
|
function getConfig() {
|
||||||
const ini = require('ini');
|
const ini = require('ini');
|
||||||
|
@ -34,6 +39,10 @@ function getConfig() {
|
||||||
delete config.database;
|
delete config.database;
|
||||||
config.service.userRanks = config.service.userRanks.split(/,\s*/);
|
config.service.userRanks = config.service.userRanks.split(/,\s*/);
|
||||||
config.service.tagCategories = config.service.tagCategories.split(/,\s*/);
|
config.service.tagCategories = config.service.tagCategories.split(/,\s*/);
|
||||||
|
config.meta = {
|
||||||
|
version: getVersion(),
|
||||||
|
buildDate: new Date().toUTCString(),
|
||||||
|
};
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<div class='content-wrapper transparent' id='home'>
|
<div class='content-wrapper transparent' id='home'>
|
||||||
<div class='messages'></div>
|
<div class='messages'></div>
|
||||||
<h1>{{name}}</h1>
|
<h1>{{name}}</h1>
|
||||||
|
<footer>Version: <span class="version">{{version}}</span> (built {{buildDate}})</footer>
|
||||||
</div>
|
</div>
|
||||||
|
|
44
static/js/util.js
Normal file
44
static/js/util.js
Normal 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};
|
|
@ -1,5 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const util = require('../util.js');
|
||||||
const config = require('../config.js');
|
const config = require('../config.js');
|
||||||
const BaseView = require('./base_view.js');
|
const BaseView = require('./base_view.js');
|
||||||
|
|
||||||
|
@ -11,7 +12,9 @@ class HomeView extends BaseView {
|
||||||
|
|
||||||
render(section) {
|
render(section) {
|
||||||
this.showView(this.template({
|
this.showView(this.template({
|
||||||
'name': config.basic.name,
|
name: config.basic.name,
|
||||||
|
version: config.meta.version,
|
||||||
|
buildDate: util.formatRelativeTime(config.meta.buildDate),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue