diff --git a/README.md b/README.md index f5dae51..f2c1c0b 100644 --- a/README.md +++ b/README.md @@ -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.\ diff --git a/src/card.ts b/src/card.ts index 5087a5e..b2762b4 100644 --- a/src/card.ts +++ b/src/card.ts @@ -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) { diff --git a/src/trophy_list.ts b/src/trophy_list.ts index 7c0b083..b85fae7 100644 --- a/src/trophy_list.ts +++ b/src/trophy_list.ts @@ -76,6 +76,16 @@ export class TrophyList { ranks.includes(trophy.rank) ); } + filterByExclusionTitles(titles: Array) { + 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)