mirror of
https://github.com/anuraghazra/github-readme-stats.git
synced 2025-03-01 14:57:15 +08:00
* add new query param to hide specific languages in top languages card * [top-langs] add function to clean out the provided lang name * [top-langs] rename 'hide_lang' => 'hide', refactor logic for parsing the list of provided languages to hide * [top-langs] take list of languages to hide, as a json array * chore: minor changes * docs: added docs for hide lang Co-authored-by: anuraghazra <hazru.anurag@gmail.com>
62 lines
1.3 KiB
JavaScript
62 lines
1.3 KiB
JavaScript
require("dotenv").config();
|
|
const {
|
|
renderError,
|
|
parseBoolean,
|
|
parseJSON,
|
|
clampValue,
|
|
CONSTANTS,
|
|
} = require("../src/utils");
|
|
const fetchStats = require("../src/fetchStats");
|
|
const renderStatsCard = require("../src/renderStatsCard");
|
|
|
|
module.exports = async (req, res) => {
|
|
const {
|
|
username,
|
|
hide,
|
|
hide_title,
|
|
hide_border,
|
|
hide_rank,
|
|
show_icons,
|
|
line_height,
|
|
title_color,
|
|
icon_color,
|
|
text_color,
|
|
bg_color,
|
|
theme,
|
|
cache_seconds,
|
|
} = req.query;
|
|
let stats;
|
|
|
|
res.setHeader("Content-Type", "image/svg+xml");
|
|
|
|
try {
|
|
stats = await fetchStats(username);
|
|
} catch (err) {
|
|
return res.send(renderError(err.message));
|
|
}
|
|
|
|
const cacheSeconds = clampValue(
|
|
parseInt(cache_seconds || CONSTANTS.THIRTY_MINUTES, 10),
|
|
CONSTANTS.THIRTY_MINUTES,
|
|
CONSTANTS.ONE_DAY
|
|
);
|
|
|
|
res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
|
|
|
|
res.send(
|
|
renderStatsCard(stats, {
|
|
hide: parseJSON(hide),
|
|
show_icons: parseBoolean(show_icons),
|
|
hide_title: parseBoolean(hide_title),
|
|
hide_border: parseBoolean(hide_border),
|
|
hide_rank: parseBoolean(hide_rank),
|
|
line_height,
|
|
title_color,
|
|
icon_color,
|
|
text_color,
|
|
bg_color,
|
|
theme,
|
|
})
|
|
);
|
|
};
|