From c384610c2a94e8206f650d9ea8a94b30fc4c079d Mon Sep 17 00:00:00 2001 From: tycrek Date: Thu, 21 Oct 2021 15:24:32 -0600 Subject: [PATCH] Added GitHub Stars badge to build script (resolves #418) --- _build.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/_build.js b/_build.js index 6bd9fd6..ad8aff8 100644 --- a/_build.js +++ b/_build.js @@ -93,6 +93,9 @@ function generateServiceSection(data) { // Append the Repo badge to the name if (item.repo) name = name.concat('
', repoLink(item.repo)); + // Append the Star badge to the name + if (item.repo) name = name.concat('
', starBadge(item.repo)); + // Build the row const tableItem = `| ${name} | ${eyes} | ${text} |${EOL}`; @@ -122,6 +125,18 @@ function repoLink(repo) { return `[![Repo](https://img.shields.io/badge/open-source-3DA639?style=flat-square&logo=${repoHost})](${repo})`; } +/** + * Returns a badge displaying the number of GitHub Stars for a repository. + * @param {String} repo The repository url + */ +function starBadge(repo) { + if (repo.startsWith('https://github.com/')) { + const [user, repoName] = repo.split('github.com/')[1].split('/'); + if (!repoName || repoName === '') return ''; + return `![GitHub Repo stars](https://img.shields.io/github/stars/${user}/${repoName}?logo=github&style=flat-square)`; + } else return ''; +} + /** * Returns a badge displaying user for a Firefox addon/extension * @param {String} link URL to extension WITHOUT trailing slash