Added anime grid for genres (up to 100 for now)

This commit is contained in:
2017-11-30 01:47:12 +01:00
parent 1c2cd2cee7
commit 91b6ae7efd
7 changed files with 46 additions and 86 deletions

View File

@ -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
}