Added genre lists

This commit is contained in:
Eduard Urbach 2016-11-03 09:01:23 +09:00
parent eacf0e2399
commit 8f3ef01285
6 changed files with 52 additions and 38 deletions

View File

@ -41,8 +41,8 @@ component Anime(anime *arn.Anime)
.light-button-group .light-button-group
each genre in anime.Genres each genre in anime.Genres
if genre != "" if genre != ""
a.light-button.ajax(href="/anime/genres/" + arn.FixGenre(genre)) a.light-button.ajax(href="/genres/" + arn.FixGenre(genre))
i(class="fa fa-" + GenreIcons[genre] + " fa-fw") Icon(GenreIcons[genre])
span= genre span= genre
if len(anime.Studios) > 0 if len(anime.Studios) > 0

View File

@ -9,5 +9,7 @@ component GenreOverview
Icon(GenreIcons[genre]) Icon(GenreIcons[genre])
span= genre span= genre
component Icon(name string) component AnimeInGenre(genre string, animeList []*arn.Anime)
i(class="fa fa-fw fa-" + name) h2= genre
each anime in animeList
p= anime.Title.Romaji + " (" + s(anime.Watching) + ")"

2
components/icon.pixy Normal file
View File

@ -0,0 +1,2 @@
component Icon(name string)
i(class="fa fa-fw fa-" + name)

27
helper.go Normal file
View File

@ -0,0 +1,27 @@
package main
import "fmt"
// Converts anything into a string
func s(v interface{}) string {
return fmt.Sprintf("%v", v)
}
// Contains ...
func Contains(list []string, a string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
// Map ...
func Map(original []string, f func(string) string) []string {
mapped := make([]string, len(original))
for index, value := range original {
mapped[index] = f(value)
}
return mapped
}

51
main.go
View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"sort" "sort"
"strconv" "strconv"
@ -12,10 +11,6 @@ import (
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
) )
func s(v interface{}) string {
return fmt.Sprintf("%v", v)
}
func main() { func main() {
app := aero.New() app := aero.New()
@ -107,39 +102,27 @@ func main() {
ctx.HTML(Render.GenreOverview()) ctx.HTML(Render.GenreOverview())
}) })
app.Get("/genres/:name", func(ctx *aero.Context) {
genreName := ctx.Params.ByName("name")
var animeList []*arn.Anime
results := make(chan *arn.Anime)
arn.Scan("Anime", results)
for anime := range results {
genres := Map(anime.Genres, arn.FixGenre)
if Contains(genres, genreName) {
animeList = append(animeList, anime)
}
}
ctx.HTML(Render.Layout(Render.AnimeInGenre(genreName, animeList), css))
})
app.Get("/scripts.js", func(ctx *aero.Context) { app.Get("/scripts.js", func(ctx *aero.Context) {
ctx.SetHeader("Content-Type", "application/javascript") ctx.SetHeader("Content-Type", "application/javascript")
ctx.Respond(js) ctx.Respond(js)
}) })
// layout := aero.NewTemplate("layout.pug")
// template := aero.NewTemplate("anime.pug")
// app.Get("/anime/:id", func(ctx *aero.Context) {
// id, _ := strconv.Atoi(ctx.Params.ByName("id"))
// anime, err := arn.GetAnime(id)
// if err != nil {
// ctx.Respond("Anime not found")
// return
// }
// content := template.Render(map[string]interface{}{
// "anime": anime,
// })
// final := layout.Render(map[string]interface{}{
// "content": content,
// })
// final = strings.Replace(final, cssSearch, cssReplace, 1)
// ctx.Respond(final)
// })
// app.Get("/t", func(ctx *aero.Context) {
// ctx.Respond(templates.Hello("abc"))
// })
app.Run() app.Run()
} }