Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render preview image url in card, when imageUrl is provided #3438

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cards/repo-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const renderRepoCard = (repo, options = {}) => {
isTemplate,
starCount,
forkCount,
openGraphImageUrl,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should add this as an optional option to the pin card:

const {
username,
repo,
hide_border,
title_color,
icon_color,
text_color,
bg_color,
theme,
show_owner,
cache_seconds,
locale,
border_radius,
border_color,
} = req.query;

} = repo;
const {
hide_border = false,
Expand Down Expand Up @@ -141,6 +142,7 @@ const renderRepoCard = (repo, options = {}) => {
height,
border_radius,
colors,
imageUrl: openGraphImageUrl,
});

card.disableAnimations();
Expand Down
23 changes: 23 additions & 0 deletions src/common/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Card {
* @param {string?=} args.customTitle Card custom title.
* @param {string?=} args.defaultTitle Card default title.
* @param {string?=} args.titlePrefixIcon Card title prefix icon.
* @param {string?=} args.imageUrl Card preview image.
* @param {number?=} args.imageHeight Card preview image.
* @param {object?=} args.colors Card colors arguments.
* @param {string} args.colors.titleColor Card title color.
* @param {string} args.colors.textColor Card text color.
Expand All @@ -27,6 +29,8 @@ class Card {
customTitle,
defaultTitle = "",
titlePrefixIcon,
imageUrl = "",
imageHeight = 200,
}) {
this.width = width;
this.height = height;
Expand All @@ -36,6 +40,8 @@ class Card {

this.border_radius = border_radius;

this.imageHeight = imageHeight;
this.imageUrl = imageUrl;
// returns theme based colors with proper overrides and defaults
rickstaa marked this conversation as resolved.
Show resolved Hide resolved
this.colors = colors;
this.title =
Expand All @@ -51,6 +57,10 @@ class Card {
this.animations = true;
this.a11yTitle = "";
this.a11yDesc = "";
if (this.imageUrl) {
this.height += this.imageHeight;
this.paddingY += this.imageHeight;
}
}

/**
Expand Down Expand Up @@ -199,6 +209,18 @@ class Card {
`;
};

renderImage = () => {
rickstaa marked this conversation as resolved.
Show resolved Hide resolved
if (!this.imageUrl) {
return "";
}
return `
<g transform="translate(0, 0)">
<image x="0" y="0" height="${this.imageHeight}"
href="${this.imageUrl}">
</image>
</g>`;
};

/**
* @param {string} body The inner body of the card.
* @returns {string} The rendered card.
Expand Down Expand Up @@ -264,6 +286,7 @@ class Card {
>
${body}
</g>
${this.renderImage()}
</svg>
`;
}
Expand Down
1 change: 1 addition & 0 deletions src/fetchers/repo-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const fetcher = (variables, token) => {
name
}
forkCount
openGraphImageUrl
}
query getRepo($login: String!, $repo: String!) {
user(login: $login) {
Expand Down
1 change: 1 addition & 0 deletions src/fetchers/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type RepositoryData = {
};
forkCount: number;
starCount: number;
openGraphImageUrl: string;
};

export type StatsData = {
Expand Down
2 changes: 2 additions & 0 deletions tests/__snapshots__/renderWakatimeCard.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ exports[`Test Render WakaTime Card should render correctly with compact layout 1
</svg>

</g>

</svg>
"
`;
Expand Down Expand Up @@ -302,6 +303,7 @@ exports[`Test Render WakaTime Card should render correctly with compact layout w
</svg>

</g>

</svg>
"
`;