51 lines
910 B
Go
Raw Normal View History

2016-11-19 14:54:31 +00:00
package genres
import (
"github.com/aerogo/aero"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2016-11-19 14:54:31 +00:00
"github.com/animenotifier/notify.moe/components"
2017-11-30 02:21:37 +00:00
"github.com/animenotifier/notify.moe/utils"
2016-11-19 14:54:31 +00:00
)
// Get ...
2019-06-01 04:55:49 +00:00
func Get(ctx aero.Context) error {
2017-11-30 02:21:37 +00:00
user := utils.GetUser(ctx)
genres := []string{}
genreToAnime := map[string]*arn.Anime{}
2016-11-19 19:53:33 +00:00
for _, genre := range arn.Genres {
2017-11-30 01:59:19 +00:00
if genre == "Hentai" {
2016-11-20 10:26:11 +00:00
continue
}
genres = append(genres, genre)
2016-11-19 19:53:33 +00:00
}
2017-11-30 02:21:37 +00:00
allAnime := arn.AllAnime()
2018-03-14 00:02:41 +00:00
arn.SortAnimeByQuality(allAnime)
2017-11-30 02:21:37 +00:00
added := 0
for _, anime := range allAnime {
for _, genre := range anime.Genres {
// Skip genre that we don't care about
if !arn.Contains(genres, genre) {
continue
}
_, exists := genreToAnime[genre]
if !exists {
genreToAnime[genre] = anime
added++
}
}
if added >= len(genres) {
break
}
}
return ctx.HTML(components.Genres(genres, genreToAnime, user))
2016-11-19 14:54:31 +00:00
}