Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -32,6 +32,7 @@ export default async (req, res) => {
border_color,
show_owner,
hide_border,
description_lines_count,
} = req.query;

res.setHeader("Content-Type", "image/svg+xml");
Expand Down Expand Up @@ -91,6 +92,7 @@ export default async (req, res) => {
locale: locale ? locale.toLowerCase() : null,
show_owner: parseBoolean(show_owner),
hide_border: parseBoolean(hide_border),
description_lines_count,
}),
);
} catch (err) {
Expand Down
8 changes: 6 additions & 2 deletions src/cards/gist.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getCardColors } from "../common/color.js";
import { kFormatter, wrapTextMultiline } from "../common/fmt.js";
import { encodeHTML } from "../common/html.js";
import { icons } from "../common/icons.js";
import { parseEmojis } from "../common/ops.js";
import { parseEmoji, clampValues } from "../common/ops.js";

/** Import language colors.
*
Expand All @@ -27,6 +27,7 @@ const languageColors = require("../common/languageColors.json"); // now works
const ICON_SIZE = 16;
const CARD_DEFAULT_WIDTH = 400;
const HEADER_MAX_LENGTH = 35;
const DESCRIPTION_MAX_LINES = 10;

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

// returns theme based colors with proper overrides and defaults
Expand All @@ -67,7 +69,9 @@ const renderGistCard = (gistData, options = {}) => {
});

const lineWidth = 59;
const linesLimit = 10;
const linesLimit = description_lines_count
? clampValue(description_lines_count, 1, DESCRIPTION_MAX_LINES)
: DESCRIPTION_MAX_LINES;
const desc = parseEmojis(description || "No description provided");
const multiLineDescription = wrapTextMultiline(desc, lineWidth, linesLimit);
const descriptionLines = multiLineDescription.length;
Expand Down