forked from mirrored/github-readme-stats
* Change default stats card width with hide rank
* Add tests for stats card with card_width
* Add card_width Stats Card description to readme
* fix: add icon width to stats-card min width calculation
* fix: fixes rank circle padding problem
This commit fixes a padding problem that was introduced in
f9c0e0bff6. In the new code, the padding
around the rank circle will be 50 when the stats card is bigger than
450. When it is smaller than 450 the left and right padding will shrink
equally.
* style: run prettier
* tests: add extra stats 'card_width' tests
This commit makes sure we also test the stats card width for the case that the 'show_icons'
option is enabled.
* style: run prettier
Co-authored-by: rickstaa <rick.staa@outlook.com>
89 lines
2.2 KiB
JavaScript
89 lines
2.2 KiB
JavaScript
require("dotenv").config();
|
|
const {
|
|
renderError,
|
|
parseBoolean,
|
|
parseArray,
|
|
clampValue,
|
|
CONSTANTS,
|
|
} = require("../src/common/utils");
|
|
const fetchStats = require("../src/fetchers/stats-fetcher");
|
|
const renderStatsCard = require("../src/cards/stats-card");
|
|
const blacklist = require("../src/common/blacklist");
|
|
const { isLocaleAvailable } = require("../src/translations");
|
|
|
|
module.exports = async (req, res) => {
|
|
const {
|
|
username,
|
|
hide,
|
|
hide_title,
|
|
hide_border,
|
|
card_width,
|
|
hide_rank,
|
|
show_icons,
|
|
count_private,
|
|
include_all_commits,
|
|
line_height,
|
|
title_color,
|
|
icon_color,
|
|
text_color,
|
|
bg_color,
|
|
theme,
|
|
cache_seconds,
|
|
custom_title,
|
|
locale,
|
|
disable_animations,
|
|
border_radius,
|
|
border_color,
|
|
} = req.query;
|
|
res.setHeader("Content-Type", "image/svg+xml");
|
|
|
|
if (blacklist.includes(username)) {
|
|
return res.send(renderError("Something went wrong"));
|
|
}
|
|
|
|
if (locale && !isLocaleAvailable(locale)) {
|
|
return res.send(renderError("Something went wrong", "Language not found"));
|
|
}
|
|
|
|
try {
|
|
const stats = await fetchStats(
|
|
username,
|
|
parseBoolean(count_private),
|
|
parseBoolean(include_all_commits),
|
|
);
|
|
|
|
const cacheSeconds = clampValue(
|
|
parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10),
|
|
CONSTANTS.FOUR_HOURS,
|
|
CONSTANTS.ONE_DAY,
|
|
);
|
|
|
|
res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
|
|
|
|
return res.send(
|
|
renderStatsCard(stats, {
|
|
hide: parseArray(hide),
|
|
show_icons: parseBoolean(show_icons),
|
|
hide_title: parseBoolean(hide_title),
|
|
hide_border: parseBoolean(hide_border),
|
|
card_width: parseInt(card_width, 10),
|
|
hide_rank: parseBoolean(hide_rank),
|
|
include_all_commits: parseBoolean(include_all_commits),
|
|
line_height,
|
|
title_color,
|
|
icon_color,
|
|
text_color,
|
|
bg_color,
|
|
theme,
|
|
custom_title,
|
|
border_radius,
|
|
border_color,
|
|
locale: locale ? locale.toLowerCase() : null,
|
|
disable_animations: parseBoolean(disable_animations),
|
|
}),
|
|
);
|
|
} catch (err) {
|
|
return res.send(renderError(err.message, err.secondaryMessage));
|
|
}
|
|
};
|