Fix gradient themes

This commit is contained in:
Nathan Chu 2020-07-29 09:19:47 -04:00
parent bd0ef4afc1
commit be285cb33e
4 changed files with 13 additions and 16 deletions

View file

@ -44,7 +44,6 @@ const renderRepoCard = (repo, options = {}) => {
const multiLineDescription = wrapTextMultiline(desc); const multiLineDescription = wrapTextMultiline(desc);
const descriptionLines = multiLineDescription.length; const descriptionLines = multiLineDescription.length;
const lineHeight = 10; const lineHeight = 10;
const isGradient = !(bg_color == undefined || bg_color.length == 6 || bg_color.length == 3)
const height = const height =
(descriptionLines > 1 ? 120 : 110) + descriptionLines * lineHeight; (descriptionLines > 1 ? 120 : 110) + descriptionLines * lineHeight;
@ -56,7 +55,7 @@ const renderRepoCard = (repo, options = {}) => {
bg_color, bg_color,
theme, theme,
}); });
const gradientBgColor = isGradient ? bg_color.split(',') : undefined; const isGradient = typeof bgColor == 'object';
const totalStars = kFormatter(stargazers.totalCount); const totalStars = kFormatter(stargazers.totalCount);
const totalForks = kFormatter(forkCount); const totalForks = kFormatter(forkCount);
@ -76,9 +75,9 @@ const renderRepoCard = (repo, options = {}) => {
`; `;
const gradient = isGradient ? ` const gradient = isGradient ? `
<defs> <defs>
<linearGradient id="gradient" gradientTransform="rotate(${gradientBgColor[0]})"> <linearGradient id="gradient" gradientTransform="rotate(${bgColor[0]})">
<stop offset="0%" stop-color="#${gradientBgColor[1]}" /> <stop offset="0%" stop-color="#${bgColor[1]}" />
<stop offset="100%" stop-color="#${gradientBgColor[2]}" /> <stop offset="100%" stop-color="#${bgColor[2]}" />
</linearGradient> </linearGradient>
</defs>` </defs>`
: undefined : undefined

View file

@ -54,7 +54,6 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
const lheight = parseInt(line_height); const lheight = parseInt(line_height);
const isGradient = !(bg_color == undefined || bg_color.length == 6 || bg_color.length == 3)
// returns theme based colors with proper overrides and defaults // returns theme based colors with proper overrides and defaults
const { titleColor, textColor, iconColor, bgColor } = getCardColors({ const { titleColor, textColor, iconColor, bgColor } = getCardColors({
@ -65,7 +64,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
theme, theme,
}); });
const gradientBgColor = isGradient ? bg_color.split(',') : undefined; const isGradient = typeof bgColor == 'object';
// Meta data for creating text nodes with createTextNode function // Meta data for creating text nodes with createTextNode function
const STATS = { const STATS = {
stars: { stars: {
@ -154,9 +153,9 @@ const gradientBgColor = isGradient ? bg_color.split(',') : undefined;
const gradient = isGradient ? ` const gradient = isGradient ? `
<defs> <defs>
<linearGradient id="gradient" gradientTransform="rotate(${gradientBgColor[0]})"> <linearGradient id="gradient" gradientTransform="rotate(${bgColor[0]})">
<stop offset="0%" stop-color="#${gradientBgColor[1]}" /> <stop offset="0%" stop-color="#${bgColor[1]}" />
<stop offset="100%" stop-color="#${gradientBgColor[2]}" /> <stop offset="100%" stop-color="#${bgColor[2]}" />
</linearGradient> </linearGradient>
</defs>` </defs>`
: undefined : undefined

View file

@ -93,7 +93,6 @@ const renderTopLanguages = (topLangs, options = {}) => {
const totalLanguageSize = langs.reduce((acc, curr) => { const totalLanguageSize = langs.reduce((acc, curr) => {
return acc + curr.size; return acc + curr.size;
}, 0); }, 0);
const isGradient = !(bg_color == undefined || bg_color.length == 6 || bg_color.length == 3)
// 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,
@ -101,7 +100,7 @@ const renderTopLanguages = (topLangs, options = {}) => {
bg_color, bg_color,
theme, theme,
}); });
const gradientBgColor = isGradient ? bg_color.split(',') : undefined; const isGradient = typeof bgColor == 'object';
let width = isNaN(card_width) ? 300 : card_width; let width = isNaN(card_width) ? 300 : card_width;
let height = 45 + (langs.length + 1) * 40; let height = 45 + (langs.length + 1) * 40;
@ -175,9 +174,9 @@ const renderTopLanguages = (topLangs, options = {}) => {
} }
const gradient = isGradient ? ` const gradient = isGradient ? `
<defs> <defs>
<linearGradient id="gradient" gradientTransform="rotate(${gradientBgColor[0]})"> <linearGradient id="gradient" gradientTransform="rotate(${bgColor[0]})">
<stop offset="0%" stop-color="#${gradientBgColor[1]}" /> <stop offset="0%" stop-color="#${bgColor[1]}" />
<stop offset="100%" stop-color="#${gradientBgColor[2]}" /> <stop offset="100%" stop-color="#${bgColor[2]}" />
</linearGradient> </linearGradient>
</defs>` </defs>`
: undefined : undefined

View file

@ -61,7 +61,7 @@ function clampValue(number, min, max) {
} }
function fallbackColor(color, fallbackColor) { function fallbackColor(color, fallbackColor) {
return (isValidHexColor(color) && `#${color}`) || fallbackColor; return (isValidHexColor(color) && `#${color}`) || (color.includes(',') && color.split(',')) || fallbackColor;
} }
function request(data, headers) { function request(data, headers) {