diff --git a/api/gist.js b/api/gist.js index 049018a4fffd0..a771ae6a5a24f 100644 --- a/api/gist.js +++ b/api/gist.js @@ -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"); @@ -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) { diff --git a/src/cards/gist.js b/src/cards/gist.js index 62910420ad2f5..2816d4d175bfe 100644 --- a/src/cards/gist.js +++ b/src/cards/gist.js @@ -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. * @@ -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. @@ -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 @@ -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;