From 12558bf71842bae12424ce3df86790421bfc85f4 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 23 Nov 2016 18:07:02 +0900 Subject: [PATCH] Show relations --- jobs/airing-anime.go | 21 +++++++++++++++++++-- main.go | 9 ++++++++- pages/airing/airing.go | 9 +++++++-- pages/anime/anime.pixy | 8 ++++++++ pages/anime/anime.styl | 20 ++++++++++++++++++-- 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/jobs/airing-anime.go b/jobs/airing-anime.go index de10c05a..23017af0 100644 --- a/jobs/airing-anime.go +++ b/jobs/airing-anime.go @@ -12,6 +12,11 @@ type AiringAnimeCache struct { Anime []*arn.Anime `json:"anime"` } +// AiringAnimeCacheSmall ... +type AiringAnimeCacheSmall struct { + Anime []*arn.AnimeSmall `json:"anime"` +} + // AiringAnime ... func AiringAnime() { animeList, err := arn.GetAiringAnime() @@ -24,8 +29,20 @@ func AiringAnime() { sort.Sort(arn.AnimeByPopularity(animeList)) - saveErr := arn.SetObject("Cache", "airingAnime", &AiringAnimeCache{ - Anime: animeList, + // Convert to small anime list + var animeListSmall []*arn.AnimeSmall + + for _, anime := range animeList { + animeListSmall = append(animeListSmall, &arn.AnimeSmall{ + ID: anime.ID, + Title: anime.Title, + Image: anime.Image, + Watching: anime.Watching, + }) + } + + saveErr := arn.SetObject("Cache", "airingAnime", &AiringAnimeCacheSmall{ + Anime: animeListSmall, }) if saveErr != nil { diff --git a/main.go b/main.go index 08bafaeb..e2204ebf 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "io/ioutil" + "runtime" "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/components" @@ -23,6 +24,7 @@ var app = aero.New() func main() { app.SetStyle(components.BundledCSS) + app.Config.GZipCache = false // user, _ := arn.GetUserByNick("Akyoto") // user.CoverImage.URL = "https://www.pixelstalk.net/wp-content/uploads/2016/10/Hanyijie-sky-scenery-ship-anime-art-1920x1080.jpg" @@ -42,7 +44,12 @@ func main() { }) app.Get("/hello", func(ctx *aero.Context) string { - return "Hello World" + return ctx.Text("Hello World") + }) + + app.Get("/gc", func(ctx *aero.Context) string { + runtime.GC() + return ctx.Text("Ran garbage collector") }) app.Layout = func(ctx *aero.Context, content string) string { diff --git a/pages/airing/airing.go b/pages/airing/airing.go index 706706c5..d7e0b6f3 100644 --- a/pages/airing/airing.go +++ b/pages/airing/airing.go @@ -9,7 +9,12 @@ import ( // Get ... func Get(ctx *aero.Context) string { - var airingAnimeCache jobs.AiringAnimeCache - arn.GetObject("Cache", "airingAnime", &airingAnimeCache) + airingAnimeCache := new(jobs.AiringAnimeCache) + err := arn.GetObject("Cache", "airingAnime", airingAnimeCache) + + if err != nil { + return ctx.Error(500, "Couldn't fetch airing anime", err) + } + return ctx.HTML(components.Airing(airingAnimeCache.Anime)) } diff --git a/pages/anime/anime.pixy b/pages/anime/anime.pixy index 91e0ed2a..90f5f8ee 100644 --- a/pages/anime/anime.pixy +++ b/pages/anime/anime.pixy @@ -36,6 +36,14 @@ component Anime(anime *arn.Anime) //- each watcher in friendsWatching //- +avatar(watcher) + if len(anime.Relations) > 0 + h3.anime-header Relations + .relations + each relation in anime.Relations + a.relation.ajax(href="/anime/" + toString(relation.ID), title=relation.Anime().Title.Romaji) + img.anime-image.relation-image(src=relation.Anime().Image, alt=relation.Anime().Title.Romaji) + span= arn.Capitalize(relation.Type) + if len(anime.Genres) > 0 h3.anime-header Genres .light-button-group diff --git a/pages/anime/anime.styl b/pages/anime/anime.styl index 5d96e708..0f276695 100644 --- a/pages/anime/anime.styl +++ b/pages/anime/anime.styl @@ -117,16 +117,32 @@ display flex flex-flow row wrap justify-content flex-start - font-size 0.9em + font-size 0.9rem .light-button display inline-block - padding 0.5em 1em + padding 0.5rem 1rem border-radius 3px &:hover color white !important background-color linkHoverColor +.relations + float left + display flex + flex-flow row wrap + +.relation + display flex + flex-flow column + font-size 0.9rem + align-items center + padding 0.5rem + +.relation-image + width 100px + height 141px + .entry-error color red !important