Skip to content

Commit

Permalink
Update themes, cards and more
Browse files Browse the repository at this point in the history
  • Loading branch information
max1mde committed Nov 11, 2024
1 parent 2dc8d55 commit 68e9c9c
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 588 deletions.
64 changes: 10 additions & 54 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,23 @@ import {
renderError,
} from "../src/common/utils.js";
import { fetchStats } from "../src/fetchers/stats-fetcher.js";
import { isLocaleAvailable } from "../src/translations.js";

export default async (req, res) => {
const {
username,
hide,
hide_title,
hide_border,
card_width,
hide_rank,
title,
description,
show_icons,
include_all_commits,
line_height,
title_color,
ring_color,
icon_color,
text_color,
text_bold,
bg_color,
theme,
cache_seconds,
email,
exclude_repo,
custom_title,
locale,
disable_animations,
border_radius,
number_format,
border_color,
rank_icon,
show,
hide_border,
} = req.query;
res.setHeader("Content-Type", "image/svg+xml");

Expand All @@ -53,35 +40,19 @@ export default async (req, res) => {
);
}

if (locale && !isLocaleAvailable(locale)) {
return res.send(
renderError("Something went wrong", "Language not found", {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
);
}

try {
const showStats = parseArray(show);
const stats = await fetchStats(
username,
parseBoolean(include_all_commits),
parseArray(exclude_repo),
showStats.includes("prs_merged") ||
showStats.includes("prs_merged_percentage"),
showStats.includes("discussions_started"),
showStats.includes("discussions_answered"),
);

let cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.CARD_CACHE_SECONDS, 10),
parseInt(CONSTANTS.CARD_CACHE_SECONDS, 10),
CONSTANTS.TWELVE_HOURS,
CONSTANTS.TWO_DAY,
);

cacheSeconds = process.env.CACHE_SECONDS
? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds
: cacheSeconds;
Expand All @@ -93,29 +64,18 @@ export default async (req, res) => {

return res.send(
renderStatsCard(stats, {
hide: parseArray(hide),
show_icons: parseBoolean(show_icons),
hide_title: parseBoolean(hide_title),
hide_border: parseBoolean(hide_border),
card_width: parseInt(card_width, 10),
hide_rank: parseBoolean(hide_rank),
card_width: 10,
include_all_commits: parseBoolean(include_all_commits),
line_height,
title_color,
ring_color,
icon_color,
text_color,
text_bold: parseBoolean(text_bold),
bg_color,
theme,
email,
title_text: title,
description_text: description,
custom_title,
border_radius,
border_color,
number_format,
locale: locale ? locale.toLowerCase() : null,
disable_animations: parseBoolean(disable_animations),
rank_icon,
show: showStats,
}),
);
} catch (err) {
Expand All @@ -127,10 +87,6 @@ export default async (req, res) => {
); // Use lower cache period for errors.
return res.send(
renderError(err.message, err.secondaryMessage, {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
);
Expand Down
14 changes: 8 additions & 6 deletions src/cards/stats-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,16 @@ const renderStatsCard = (stats, options = {}) => {
text_color,
text_bold = true,
bg_color,
theme = "default",
theme = "beach",
custom_title,
border_radius,
border_color,
number_format = "short",
disable_animations = false,
rank_icon = "default",
show = [],
title_text,
description_text,
email,
} = options;

const lheight = parseInt(String(line_height), 10);
Expand Down Expand Up @@ -350,7 +352,7 @@ const renderStatsCard = (stats, options = {}) => {
width: cardWidth,
height,
border_radius,
theme: "beach",
theme: theme,
});

card.setHideBorder(hide_border);
Expand Down Expand Up @@ -404,7 +406,7 @@ const renderStatsCard = (stats, options = {}) => {
font-family="'Segoe UI', Ubuntu, Sans-Serif"
fill="white"
>
${custom_title ? custom_title : name}
${title_text ? title_text : name}
</text>
`;

Expand All @@ -419,7 +421,7 @@ const renderStatsCard = (stats, options = {}) => {
font-family="'Segoe UI', Ubuntu, Sans-Serif"
fill="white"
>
${"A very long description about me"}
${description_text ? description_text : ""}
</text>
`;

Expand All @@ -434,7 +436,7 @@ const renderStatsCard = (stats, options = {}) => {
font-family="'Segoe UI', Ubuntu, Sans-Serif"
fill="white"
>
${"example@email.com"}
${email ? email : ""}
</text>
`;

Expand Down
4 changes: 1 addition & 3 deletions src/cards/top-languages-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,12 +802,10 @@ const renderTopLanguages = (topLangs, options = {}) => {
}

const card = new Card({
customTitle: custom_title,
defaultTitle: i18n.t("langcard.title"),
title: custom_title,
width,
height,
border_radius,
colors,
});

if (disable_animations) {
Expand Down
5 changes: 3 additions & 2 deletions src/cards/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export type CommonOptions = {
};

export type StatCardOptions = CommonOptions & {
hide: string[];
show_icons: boolean;
hide_title: boolean;
card_width: number;
Expand All @@ -27,7 +26,9 @@ export type StatCardOptions = CommonOptions & {
ring_color: string;
text_bold: boolean;
rank_icon: RankIcon;
show: string[];
title_text: string;
email: string,
description_text: string;
};

export type RepoCardOptions = CommonOptions & {
Expand Down
Loading

0 comments on commit 68e9c9c

Please sign in to comment.