Added GitHub Stars badge to build script (resolves #418)

This commit is contained in:
tycrek 2021-10-21 15:24:32 -06:00
parent 4fd9023a48
commit c384610c2a
No known key found for this signature in database
GPG Key ID: 25D74F3943625263
1 changed files with 15 additions and 0 deletions

View File

@ -93,6 +93,9 @@ function generateServiceSection(data) {
// Append the Repo badge to the name
if (item.repo) name = name.concat('<br/>', repoLink(item.repo));
// Append the Star badge to the name
if (item.repo) name = name.concat('<br/>', 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