Added Hall of Fame
This commit is contained in:
65
pages/explore/halloffame/halloffame.go
Normal file
65
pages/explore/halloffame/halloffame.go
Normal file
@ -0,0 +1,65 @@
|
||||
package halloffame
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
// Get ...
|
||||
func Get(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
maxYear := time.Now().Year() - 1
|
||||
hallOfFameEntries := []*utils.HallOfFameEntry{}
|
||||
|
||||
animes := arn.FilterAnime(func(anime *arn.Anime) bool {
|
||||
if len(anime.StartDate) < 4 {
|
||||
return false
|
||||
}
|
||||
|
||||
if anime.StartDateTime().Year() > maxYear {
|
||||
return false
|
||||
}
|
||||
|
||||
if anime.Status != "finished" {
|
||||
return false
|
||||
}
|
||||
|
||||
if anime.Type != "tv" {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
arn.SortAnimeByQuality(animes)
|
||||
|
||||
yearsAdded := map[int]bool{}
|
||||
|
||||
for _, anime := range animes {
|
||||
year := anime.StartDateTime().Year()
|
||||
|
||||
_, exists := yearsAdded[year]
|
||||
|
||||
if exists {
|
||||
continue
|
||||
}
|
||||
|
||||
hallOfFameEntries = append(hallOfFameEntries, &utils.HallOfFameEntry{
|
||||
Year: year,
|
||||
Anime: anime,
|
||||
})
|
||||
|
||||
yearsAdded[year] = true
|
||||
}
|
||||
|
||||
sort.Slice(hallOfFameEntries, func(i, j int) bool {
|
||||
return hallOfFameEntries[i].Year > hallOfFameEntries[j].Year
|
||||
})
|
||||
|
||||
return ctx.HTML(components.HallOfFame(hallOfFameEntries, user))
|
||||
}
|
Reference in New Issue
Block a user