Skip to content

Commit

Permalink
Include a query where the user can exclude trophies based on title (#276
Browse files Browse the repository at this point in the history
)

* First step to developing a feature to exclude speicifc trophies by title

* Added support for exclusion by title

* Ran deno lint, deno format and deno test found in CONTRIBUTING

* Documented the latest addition in the README

* Updated README
  • Loading branch information
a2ys authored Jul 19, 2024
1 parent 4672f2d commit c48eee9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ If you want to specify multiple titles.
https://github-profile-trophy.vercel.app/?username=ryo-ma&title=Stars,Followers
```

You can also exclude the trophies you don't want to display.

```
https://github-profile-trophy.vercel.app/?username=ryo-ma&title=-Stars,-Followers
```

## Filter by ranks

You can filter the display by specifying the ranks.\
Expand Down
8 changes: 7 additions & 1 deletion src/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ export class Card {
trophyList.filterByHidden();

if (this.titles.length != 0) {
trophyList.filterByTitles(this.titles);
const includeTitles = this.titles.filter((title) =>
!title.startsWith("-")
);
if (includeTitles.length > 0) {
trophyList.filterByTitles(includeTitles);
}
trophyList.filterByExclusionTitles(this.titles);
}

if (this.ranks.length != 0) {
Expand Down
10 changes: 10 additions & 0 deletions src/trophy_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ export class TrophyList {
ranks.includes(trophy.rank)
);
}
filterByExclusionTitles(titles: Array<string>) {
const excludeTitles = titles.filter((title) => title.startsWith("-")).map(
(title) => title.substring(1),
);
if (excludeTitles.length > 0) {
this.trophies = this.trophies.filter((trophy) =>
!excludeTitles.includes(trophy.title)
);
}
}
sortByRank() {
this.trophies = this.trophies.toSorted((a: Trophy, b: Trophy) =>
RANK_ORDER.indexOf(a.rank) - RANK_ORDER.indexOf(b.rank)
Expand Down

0 comments on commit c48eee9

Please sign in to comment.