diff --git a/api/index.js b/api/index.js index f602a49..e04b1ad 100644 --- a/api/index.js +++ b/api/index.js @@ -66,6 +66,16 @@ async function fetchStats(username) { return stats; } +const createTextNode = (icon, label, value, lheight) => { + return ` + + ${icon} ${label}: + ${value} + `; +}; + const renderSVG = (stats, options) => { const { name, @@ -75,51 +85,34 @@ const renderSVG = (stats, options) => { totalPRs, contributedTo, } = stats; - const { hide, show_icons, hide_border } = options || {}; + const { hide, show_icons, hide_border, line_height } = options || {}; + + const lheight = line_height || 25; const STAT_MAP = { - stars: ` - - Total Stars: - ${totalStars} - `, - commits: ` - - 🕗 Total Commits: - ${totalCommits} - `, - prs: ` - - 🔀 Total PRs: - ${totalPRs} - `, - issues: ` - - Total Issues: - ${totalIssues} - `, - contribs: ` - 📕 Contributed to: - ${contributedTo} repos - `, + stars: createTextNode("★", "Total Stars", totalStars, lheight), + commits: createTextNode("🕗", "Total Commits", totalCommits, lheight), + prs: createTextNode("🔀", "Total PRs", totalPRs, lheight), + issues: createTextNode("ⓘ", "Total Issues", totalIssues, lheight), + contribs: createTextNode("📕", "Contributed to", contributedTo, lheight), }; const statItems = Object.keys(STAT_MAP) .filter((key) => !hide.includes(key)) .map((key) => STAT_MAP[key]); - const height = 45 + (statItems.length + 1) * 25; + const height = 45 + (statItems.length + 1) * lheight; return ` ${ @@ -140,28 +133,17 @@ module.exports = async (req, res) => { const hide = req.query.hide; const hide_border = req.query.hide_border; const show_icons = req.query.show_icons; + const line_height = req.query.line_height; - let { - name, - totalPRs, - totalCommits, - totalStars, - totalIssues, - contributedTo, - } = await fetchStats(username); + const stats = await fetchStats(username); res.setHeader("Content-Type", "image/svg+xml"); res.send( - renderSVG( - { - name, - totalStars, - totalCommits, - totalIssues, - totalPRs, - contributedTo, - }, - { hide: JSON.parse(hide || "[]"), show_icons, hide_border } - ) + renderSVG(stats, { + hide: JSON.parse(hide || "[]"), + show_icons, + hide_border, + line_height, + }) ); }; diff --git a/readme.md b/readme.md index 40eeacd..c06afe2 100644 --- a/readme.md +++ b/readme.md @@ -33,6 +33,7 @@ To enable icons you can pass `show_icons=true` in the query param like so Other options: - `&hide_border=true` hide the border box if you don't like it :D. +- `&line_height=30` control the line-height between text. ## Demo