diff --git a/genres.go b/genres.go new file mode 100644 index 00000000..0ec2f74b --- /dev/null +++ b/genres.go @@ -0,0 +1,49 @@ +package main + +import "sort" + +// Genres ... +var Genres []string + +// GenreIcons ... +var GenreIcons = map[string]string{ + "Action": "bomb", + "Adventure": "diamond", + "Cars": "car", + "Comedy": "smile-o", + "Drama": "heartbeat", + "Ecchi": "heart-o", + "Fantasy": "tree", + "Game": "gamepad", + "Harem": "group", + "Hentai": "venus-mars", + "Historical": "history", + "Horror": "frown-o", + "Kids": "child", + "Martial Arts": "hand-rock-o", + "Magic": "magic", + "Mecha": "reddit-alien", + "Military": "fighter-jet", + "Music": "music", + "Mystery": "question", + "Psychological": "lightbulb-o", + "Romance": "heart", + "Sci-Fi": "space-shuttle", + "School": "graduation-cap", + "Seinen": "male", + "Shounen": "male", + "Shoujo": "female", + "Slice of Life": "hand-peace-o", + "Sports": "soccer-ball-o", + "Supernatural": "magic", + "Super Power": "flash", + "Thriller": "hourglass-end", + "Vampire": "eye", +} + +func init() { + for k := range GenreIcons { + Genres = append(Genres, k) + } + sort.Strings(Genres) +} diff --git a/main.go b/main.go index 89c742cc..8aaff89e 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,12 @@ package main import ( - "bytes" "fmt" "io/ioutil" + "sort" "strconv" + "strings" + "time" "github.com/aerojs/aero" "github.com/animenotifier/arn" @@ -34,6 +36,21 @@ func main() { ctx.HTML(Render.Dashboard()) }) + app.Get("/all/anime", func(ctx *aero.Context) { + start := time.Now() + var titles []string + + results := make(chan *arn.Anime) + arn.Scan("Anime", results) + + for anime := range results { + titles = append(titles, anime.Title.Romaji) + } + sort.Strings(titles) + + ctx.Text(s(len(titles)) + " anime fetched in " + s(time.Since(start)) + "\n\n" + strings.Join(titles, "\n")) + }) + app.Get("/anime/:id", func(ctx *aero.Context) { id, _ := strconv.Atoi(ctx.Params.ByName("id")) anime, err := arn.GetAnime(id) @@ -82,18 +99,12 @@ func main() { ctx.JSON(user) }) - app.Get("/all", func(ctx *aero.Context) { - var buffer bytes.Buffer + app.Get("/genres", func(ctx *aero.Context) { + ctx.HTML(Render.Layout(Render.GenreOverview(), css)) + }) - results := make(chan *arn.Anime) - arn.Scan("Anime", results) - - for anime := range results { - buffer.WriteString(anime.Title.Romaji) - buffer.WriteByte('\n') - } - - ctx.Text(buffer.String()) + app.Get("/_/genres", func(ctx *aero.Context) { + ctx.HTML(Render.GenreOverview()) }) app.Get("/scripts.js", func(ctx *aero.Context) { diff --git a/pages/anime/anime.pixy b/pages/anime/anime.pixy index 7cf54e37..567b6510 100644 --- a/pages/anime/anime.pixy +++ b/pages/anime/anime.pixy @@ -42,6 +42,7 @@ component Anime(anime *arn.Anime) each genre in anime.Genres if genre != "" a.light-button.ajax(href="/anime/genres/" + arn.FixGenre(genre)) + i(class="fa fa-" + GenreIcons[genre] + " fa-fw") span= genre if len(anime.Studios) > 0 diff --git a/pages/dashboard/dashboard.pixy b/pages/dashboard/dashboard.pixy index 009190ed..af0f7d98 100644 --- a/pages/dashboard/dashboard.pixy +++ b/pages/dashboard/dashboard.pixy @@ -1,14 +1,17 @@ component Dashboard section header - h1 ARN 4.0 - p The next version of notify.moe is currently being built here! + h2 ARN 4.0 + p Shht! The next version of notify.moe is currently being built here. hr - p Some test links: ul li a.ajax(href="/anime/21499") Sousei no Onmyouji li a.ajax(href="/anime/1000001") RWBY li - a(href="/api/anime/1000001") RWBY (JSON API) \ No newline at end of file + a(href="/api/anime/1000001") RWBY (JSON API) + li + a.ajax(href="/genres") Genre Overview + li + a(href="/all/anime") All anime titles on notify.moe (text file) \ No newline at end of file diff --git a/pages/genres/genres.pixy b/pages/genres/genres.pixy new file mode 100644 index 00000000..814353df --- /dev/null +++ b/pages/genres/genres.pixy @@ -0,0 +1,13 @@ +component GenreOverview + section + header + h2 Genres + + each genre in Genres + p + a(href="/genres/" + arn.FixGenre(genre)) + Icon(GenreIcons[genre]) + span= genre + +component Icon(name string) + i(class="fa fa-fw fa-" + name) \ No newline at end of file