github-readme-stats/api/top-langs.js
Mohammed Mushahid Qureshi 465faa7c32
fix: hide in top_languages interfering with number of languages displayed (#959)
* added a dark theme like the github dark theme

* fixed hide in top_languages interfering with number of languages displayed

* fixed hide in top_languages interfering with number of languages displayed

* fixed hide in top_languages interfering with number of languages displayed

* fixed misplaced function argument

* style(themes): Add GitHub dark theme (#758)

This styling falls in line with the recently released GitHub dark mode

Co-authored-by: Anurag Hazra <hazru.anurag@gmail.com>

* docs: add covid fund link (#1019)

* docs: add `npm install` step to CONTRIBUTING.md (#1015)

* fix: apply parseBoolean to hide_border in pin.js (#1014)

* feat: limit langs shown on wakatime card (#988)

* fix: fixed javascript oof moment

Co-authored-by: Issy <48881813+issy@users.noreply.github.com>
Co-authored-by: Anurag Hazra <hazru.anurag@gmail.com>
Co-authored-by: Mike Beaton <mjsbeaton@gmail.com>
Co-authored-by: Florian Bussmann <hallo@florian-bussmann.de>
2021-04-27 01:12:24 +05:30

81 lines
1.9 KiB
JavaScript

require("dotenv").config();
const {
renderError,
clampValue,
parseBoolean,
parseArray,
CONSTANTS,
} = require("../src/common/utils");
const fetchTopLanguages = require("../src/fetchers/top-languages-fetcher");
const renderTopLanguages = require("../src/cards/top-languages-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,
title_color,
text_color,
bg_color,
theme,
cache_seconds,
layout,
langs_count,
exclude_repo,
custom_title,
locale,
border_radius
} = req.query;
let topLangs;
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 {
topLangs = await fetchTopLanguages(
username,
langs_count,
parseArray(exclude_repo),
parseArray(hide),
);
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(
renderTopLanguages(topLangs, {
custom_title,
hide_title: parseBoolean(hide_title),
hide_border: parseBoolean(hide_border),
card_width: parseInt(card_width, 10),
hide: parseArray(hide),
title_color,
text_color,
bg_color,
theme,
layout,
border_radius,
locale: locale ? locale.toLowerCase() : null,
}),
);
} catch (err) {
return res.send(renderError(err.message, err.secondaryMessage));
}
};