mirror of
https://github.com/tiennm99/github-readme-stats.git
synced 2026-05-14 08:58:28 +00:00
feat: added "exclude_repo" option to Top Langs (#493)
* 🚀 Added "exclude_repo" option to Top Langs * chore: code style update Co-authored-by: Anurag <hazru.anurag@gmail.com>
This commit is contained in:
+6
-1
@@ -24,6 +24,7 @@ module.exports = async (req, res) => {
|
||||
cache_seconds,
|
||||
layout,
|
||||
langs_count,
|
||||
exclude_repo,
|
||||
} = req.query;
|
||||
let topLangs;
|
||||
|
||||
@@ -34,7 +35,11 @@ module.exports = async (req, res) => {
|
||||
}
|
||||
|
||||
try {
|
||||
topLangs = await fetchTopLanguages(username, langs_count);
|
||||
topLangs = await fetchTopLanguages(
|
||||
username,
|
||||
langs_count,
|
||||
parseArray(exclude_repo),
|
||||
);
|
||||
|
||||
const cacheSeconds = clampValue(
|
||||
parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
|
||||
|
||||
@@ -168,6 +168,7 @@ You can provide multiple comma-separated values in bg_color option to render a g
|
||||
- `layout` - Switch between two available layouts `default` & `compact`
|
||||
- `card_width` - Set the card's width manually _(number)_
|
||||
- `langs_count` - Show more languages on the card, between 1-10, defaults to 5 _(number)_
|
||||
- `exclude_repo` - Exclude specified repositories _(Comma-separated values)_
|
||||
|
||||
> :warning: **Important:**
|
||||
> Language names should be uri-escaped, as specified in [Percent Encoding](https://en.wikipedia.org/wiki/Percent-encoding)
|
||||
@@ -221,6 +222,14 @@ Endpoint: `api/top-langs?username=anuraghazra`
|
||||
[](https://github.com/anuraghazra/github-readme-stats)
|
||||
```
|
||||
|
||||
### Exclude individual repositories
|
||||
|
||||
You can use `?exclude_repo=repo1,repo2` parameter to exclude individual repositories.
|
||||
|
||||
```md
|
||||
[](https://github.com/anuraghazra/github-readme-stats)
|
||||
```
|
||||
|
||||
### Hide individual languages
|
||||
|
||||
You can use `?hide=language1,language2` parameter to hide individual languages.
|
||||
|
||||
@@ -11,6 +11,7 @@ const fetcher = (variables, token) => {
|
||||
# fetch only owner repos & not forks
|
||||
repositories(ownerAffiliations: OWNER, isFork: false, first: 100) {
|
||||
nodes {
|
||||
name
|
||||
languages(first: 10, orderBy: {field: SIZE, direction: DESC}) {
|
||||
edges {
|
||||
size
|
||||
@@ -33,7 +34,7 @@ const fetcher = (variables, token) => {
|
||||
);
|
||||
};
|
||||
|
||||
async function fetchTopLanguages(username, langsCount = 5) {
|
||||
async function fetchTopLanguages(username, langsCount = 5, exclude_repo = []) {
|
||||
if (!username) throw Error("Invalid username");
|
||||
|
||||
langsCount = clampValue(parseInt(langsCount), 1, 10);
|
||||
@@ -46,6 +47,22 @@ async function fetchTopLanguages(username, langsCount = 5) {
|
||||
}
|
||||
|
||||
let repoNodes = res.data.data.user.repositories.nodes;
|
||||
let repoToHide = {};
|
||||
|
||||
// populate repoToHide map for quick lookup
|
||||
// while filtering out
|
||||
if (exclude_repo) {
|
||||
exclude_repo.forEach((repoName) => {
|
||||
repoToHide[repoName] = true;
|
||||
});
|
||||
}
|
||||
|
||||
// filter out repositories to be hidden
|
||||
repoNodes = repoNodes
|
||||
.sort((a, b) => b.size - a.size)
|
||||
.filter((name) => {
|
||||
return !repoToHide[name.name];
|
||||
});
|
||||
|
||||
repoNodes = repoNodes
|
||||
.filter((node) => {
|
||||
|
||||
Reference in New Issue
Block a user