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

Added card_width argument to gist card #3405

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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 api/gist.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default async (req, res) => {
border_color,
show_owner,
hide_border,
card_width,
} = req.query;

res.setHeader("Content-Type", "image/svg+xml");
Expand Down Expand Up @@ -82,6 +83,7 @@ export default async (req, res) => {
locale: locale ? locale.toLowerCase() : null,
show_owner: parseBoolean(show_owner),
hide_border: parseBoolean(hide_border),
card_width: parseInt(card_width),
}),
);
} catch (err) {
Expand Down
4 changes: 3 additions & 1 deletion src/cards/gist-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const languageColors = require("../common/languageColors.json"); // now works
const ICON_SIZE = 16;
const CARD_DEFAULT_WIDTH = 400;
const HEADER_MAX_LENGTH = 35;
const MIN_CARD_WIDTH = 280;

/**
* @typedef {import('./types').GistCardOptions} GistCardOptions Gist card options.
Expand All @@ -54,6 +55,7 @@ const renderGistCard = (gistData, options = {}) => {
border_color,
show_owner = false,
hide_border = false,
card_width,
} = options;

// returns theme based colors with proper overrides and defaults
Expand Down Expand Up @@ -118,7 +120,7 @@ const renderGistCard = (gistData, options = {}) => {
? `${header.slice(0, HEADER_MAX_LENGTH)}...`
: header,
titlePrefixIcon: icons.gist,
width: CARD_DEFAULT_WIDTH,
width: card_width ? (card_width < MIN_CARD_WIDTH ? MIN_CARD_WIDTH : card_width) : CARD_DEFAULT_WIDTH,
height,
border_radius,
colors: {
Expand Down