mirror of
https://github.com/anuraghazra/github-readme-stats.git
synced 2024-12-21 06:11:29 +08:00
b8330a88e1
* compact layout for top langs card * 🐞 FIX: most used lang should be first, apply correct colors, removed nested svgs and height set * 🐞 FIX: conditionally rendering layout compact * 🐞 FIX: border radius on lang progressbar * refactor: refactored code & fixed bugs * fix: toFixed * chore: change string interpolation * docs: updated readme Co-authored-by: anuraghazra <hazru.anurag@gmail.com>
57 lines
1.1 KiB
JavaScript
57 lines
1.1 KiB
JavaScript
require("dotenv").config();
|
|
const {
|
|
renderError,
|
|
clampValue,
|
|
parseBoolean,
|
|
parseArray,
|
|
CONSTANTS,
|
|
} = require("../src/utils");
|
|
const fetchTopLanguages = require("../src/fetchTopLanguages");
|
|
const renderTopLanguages = require("../src/renderTopLanguages");
|
|
|
|
module.exports = async (req, res) => {
|
|
const {
|
|
username,
|
|
hide,
|
|
hide_title,
|
|
card_width,
|
|
title_color,
|
|
text_color,
|
|
bg_color,
|
|
theme,
|
|
cache_seconds,
|
|
layout
|
|
} = req.query;
|
|
let topLangs;
|
|
|
|
res.setHeader("Content-Type", "image/svg+xml");
|
|
|
|
try {
|
|
topLangs = await fetchTopLanguages(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(
|
|
renderTopLanguages(topLangs, {
|
|
theme,
|
|
hide_title: parseBoolean(hide_title),
|
|
card_width: parseInt(card_width, 10),
|
|
hide: parseArray(hide),
|
|
title_color,
|
|
text_color,
|
|
bg_color,
|
|
theme,
|
|
layout
|
|
})
|
|
);
|
|
};
|