Skip to content

Commit c48eee9

Browse files
authored
Include a query where the user can exclude trophies based on title (#276)
* 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
1 parent 4672f2d commit c48eee9

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ If you want to specify multiple titles.
124124
https://github-profile-trophy.vercel.app/?username=ryo-ma&title=Stars,Followers
125125
```
126126

127+
You can also exclude the trophies you don't want to display.
128+
129+
```
130+
https://github-profile-trophy.vercel.app/?username=ryo-ma&title=-Stars,-Followers
131+
```
132+
127133
## Filter by ranks
128134

129135
You can filter the display by specifying the ranks.\

src/card.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ export class Card {
2929
trophyList.filterByHidden();
3030

3131
if (this.titles.length != 0) {
32-
trophyList.filterByTitles(this.titles);
32+
const includeTitles = this.titles.filter((title) =>
33+
!title.startsWith("-")
34+
);
35+
if (includeTitles.length > 0) {
36+
trophyList.filterByTitles(includeTitles);
37+
}
38+
trophyList.filterByExclusionTitles(this.titles);
3339
}
3440

3541
if (this.ranks.length != 0) {

src/trophy_list.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ export class TrophyList {
7676
ranks.includes(trophy.rank)
7777
);
7878
}
79+
filterByExclusionTitles(titles: Array<string>) {
80+
const excludeTitles = titles.filter((title) => title.startsWith("-")).map(
81+
(title) => title.substring(1),
82+
);
83+
if (excludeTitles.length > 0) {
84+
this.trophies = this.trophies.filter((trophy) =>
85+
!excludeTitles.includes(trophy.title)
86+
);
87+
}
88+
}
7989
sortByRank() {
8090
this.trophies = this.trophies.toSorted((a: Trophy, b: Trophy) =>
8191
RANK_ORDER.indexOf(a.rank) - RANK_ORDER.indexOf(b.rank)

0 commit comments

Comments
 (0)