git-stats-html
Version:
Turn git-stats result into HTML output.
48 lines (46 loc) • 1.29 kB
JavaScript
;
var ajs = require("ajs"),
ghLegend = require("github-calendar-legend"),
Daty = require("daty"),
mapO = require("map-o");
/**
* gitStatsHtml
* Turn git-stats result into HTML output.
*
* @name gitStatsHtml
* @function
* @param {Object} json The JSON returned by `git-stats --raw`
* @param {Function} cb The callback function.
*/
module.exports = function gitStatsHtml(json, cb) {
json.theme = {
levels: ghLegend
};
json.start = new Daty(json.start);
json.end = new Daty(json.end);
json.months = [];
var lastMonth = null;
json.levels.forEach(function (c, weekIndex) {
c.forEach(function (c) {
if (c.month === lastMonth) {
return;
}
json.months.push({
name: c.month,
index: weekIndex,
left: 13 + 12 * weekIndex
});
lastMonth = c.month;
});
});
if (json.months[1].index - json.months[0].index < 4) {
json.months.splice(0, 1);
}
mapO(json.currentStreak, function (value) {
return new Daty(value);
});
mapO(json.longestStreak, function (value) {
return new Daty(value);
});
ajs.renderFile(__dirname + "/template.html", json, cb);
};