mirror of
https://github.com/anuraghazra/github-readme-stats.git
synced 2024-12-15 06:04:17 +08:00
f1df178643
* Add Card Translations
* Add tests and documentation for `?lang` option
* Card Translations: update Italian
* Run Prettier
* Correct German Translations.
Co-authored-by: schmelto <30869493+schmelto@users.noreply.github.com>
* refactor: added i18n class to manage translation logic & improved code
* Make the new src/translations.js more concise
* Update translations.js
Co-authored-by: schmelto <30869493+schmelto@users.noreply.github.com>
* Revert 4175484d69
* fix: overlap because of language length
Co-authored-by: lrusso96 <russo.1699981@studenti.uniroma1.it>
Co-authored-by: schmelto <30869493+schmelto@users.noreply.github.com>
Co-authored-by: Anurag <hazru.anurag@gmail.com>
83 lines
1.9 KiB
JavaScript
83 lines
1.9 KiB
JavaScript
require("dotenv").config();
|
|
const {
|
|
renderError,
|
|
parseBoolean,
|
|
parseArray,
|
|
clampValue,
|
|
CONSTANTS,
|
|
isLocaleAvailable,
|
|
} = require("../src/common/utils");
|
|
const fetchStats = require("../src/fetchers/stats-fetcher");
|
|
const renderStatsCard = require("../src/cards/stats-card");
|
|
const blacklist = require("../src/common/blacklist");
|
|
|
|
module.exports = async (req, res) => {
|
|
const {
|
|
username,
|
|
hide,
|
|
hide_title,
|
|
hide_border,
|
|
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,
|
|
} = req.query;
|
|
let stats;
|
|
|
|
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 {
|
|
stats = await fetchStats(
|
|
username,
|
|
parseBoolean(count_private),
|
|
parseBoolean(include_all_commits),
|
|
);
|
|
|
|
const cacheSeconds = clampValue(
|
|
parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
|
|
CONSTANTS.TWO_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),
|
|
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,
|
|
locale: locale ? locale.toLowerCase() : null,
|
|
}),
|
|
);
|
|
} catch (err) {
|
|
return res.send(renderError(err.message, err.secondaryMessage));
|
|
}
|
|
};
|