Added anime grid for genres (up to 100 for now)
This commit is contained in:
@ -1,21 +1,44 @@
|
||||
package genre
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
const animePerPage = 100
|
||||
|
||||
// Get ...
|
||||
func Get(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
genreName := ctx.Get("name")
|
||||
genre, err := arn.GetGenre(genreName)
|
||||
animes := []*arn.Anime{}
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(404, "Genre not found", err)
|
||||
for anime := range arn.StreamAnime() {
|
||||
if containsLowerCase(anime.Genres, genreName) {
|
||||
animes = append(animes, anime)
|
||||
}
|
||||
}
|
||||
|
||||
return ctx.HTML(components.Genre(genre, user))
|
||||
arn.SortAnimeByQuality(animes, "")
|
||||
|
||||
if len(animes) > animePerPage {
|
||||
animes = animes[:animePerPage]
|
||||
}
|
||||
|
||||
return ctx.HTML(components.Genre(genreName, animes, user))
|
||||
}
|
||||
|
||||
// containsLowerCase tells you whether the given element exists when all elements are lowercased.
|
||||
func containsLowerCase(array []string, search string) bool {
|
||||
for _, item := range array {
|
||||
if strings.ToLower(item) == search {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user