mirror of
https://github.com/Aviortheking/codestats-readme.git
synced 2025-04-22 10:42:08 +00:00
feat: added hide_langs_below option
This commit is contained in:
parent
7c104cf8c5
commit
4a8fd03d8d
@ -11,6 +11,7 @@ const renderTopLanguages = require("../src/renderTopLanguages");
|
|||||||
module.exports = async (req, res) => {
|
module.exports = async (req, res) => {
|
||||||
const {
|
const {
|
||||||
username,
|
username,
|
||||||
|
hide_langs_below,
|
||||||
hide_title,
|
hide_title,
|
||||||
card_width,
|
card_width,
|
||||||
title_color,
|
title_color,
|
||||||
@ -42,6 +43,7 @@ module.exports = async (req, res) => {
|
|||||||
theme,
|
theme,
|
||||||
hide_title: parseBoolean(hide_title),
|
hide_title: parseBoolean(hide_title),
|
||||||
card_width: parseInt(card_width, 10),
|
card_width: parseInt(card_width, 10),
|
||||||
|
hide_langs_below: parseFloat(hide_langs_below, 10),
|
||||||
title_color,
|
title_color,
|
||||||
text_color,
|
text_color,
|
||||||
bg_color,
|
bg_color,
|
||||||
|
@ -30,15 +30,22 @@ const renderTopLanguages = (topLangs, options = {}) => {
|
|||||||
title_color,
|
title_color,
|
||||||
text_color,
|
text_color,
|
||||||
bg_color,
|
bg_color,
|
||||||
|
hide_langs_below,
|
||||||
theme,
|
theme,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
const langs = Object.values(topLangs);
|
let langs = Object.values(topLangs);
|
||||||
|
|
||||||
const totalSize = langs.reduce((acc, curr) => {
|
const totalSize = langs.reduce((acc, curr) => {
|
||||||
return acc + curr.size;
|
return acc + curr.size;
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
|
// hide langs
|
||||||
|
langs = langs.filter((lang) => {
|
||||||
|
if (!hide_langs_below) return true;
|
||||||
|
return (lang.size / totalSize) * 100 > hide_langs_below;
|
||||||
|
});
|
||||||
|
|
||||||
// returns theme based colors with proper overrides and defaults
|
// returns theme based colors with proper overrides and defaults
|
||||||
const { titleColor, textColor, bgColor } = getCardColors({
|
const { titleColor, textColor, bgColor } = getCardColors({
|
||||||
title_color,
|
title_color,
|
||||||
|
@ -58,6 +58,20 @@ describe("Test renderTopLanguages", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should hide_langs_below", () => {
|
||||||
|
document.body.innerHTML = renderTopLanguages(langs, {
|
||||||
|
hide_langs_below: 34,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(queryAllByTestId(document.body, "lang-name")[0]).toBeInTheDocument(
|
||||||
|
"HTML"
|
||||||
|
);
|
||||||
|
expect(queryAllByTestId(document.body, "lang-name")[1]).toBeInTheDocument(
|
||||||
|
"javascript"
|
||||||
|
);
|
||||||
|
expect(queryAllByTestId(document.body, "lang-name")[2]).not.toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
it("should resize the height correctly depending on langs", () => {
|
it("should resize the height correctly depending on langs", () => {
|
||||||
document.body.innerHTML = renderTopLanguages(langs, {});
|
document.body.innerHTML = renderTopLanguages(langs, {});
|
||||||
expect(document.querySelector("svg")).toHaveAttribute("height", "205");
|
expect(document.querySelector("svg")).toHaveAttribute("height", "205");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user