Show relations

This commit is contained in:
Eduard Urbach 2016-11-23 18:07:02 +09:00
parent 3fe3d00134
commit 12558bf718
5 changed files with 60 additions and 7 deletions

View File

@ -12,6 +12,11 @@ type AiringAnimeCache struct {
Anime []*arn.Anime `json:"anime"` Anime []*arn.Anime `json:"anime"`
} }
// AiringAnimeCacheSmall ...
type AiringAnimeCacheSmall struct {
Anime []*arn.AnimeSmall `json:"anime"`
}
// AiringAnime ... // AiringAnime ...
func AiringAnime() { func AiringAnime() {
animeList, err := arn.GetAiringAnime() animeList, err := arn.GetAiringAnime()
@ -24,8 +29,20 @@ func AiringAnime() {
sort.Sort(arn.AnimeByPopularity(animeList)) sort.Sort(arn.AnimeByPopularity(animeList))
saveErr := arn.SetObject("Cache", "airingAnime", &AiringAnimeCache{ // Convert to small anime list
Anime: animeList, 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 { if saveErr != nil {

View File

@ -2,6 +2,7 @@ package main
import ( import (
"io/ioutil" "io/ioutil"
"runtime"
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/components"
@ -23,6 +24,7 @@ var app = aero.New()
func main() { func main() {
app.SetStyle(components.BundledCSS) app.SetStyle(components.BundledCSS)
app.Config.GZipCache = false
// user, _ := arn.GetUserByNick("Akyoto") // user, _ := arn.GetUserByNick("Akyoto")
// user.CoverImage.URL = "https://www.pixelstalk.net/wp-content/uploads/2016/10/Hanyijie-sky-scenery-ship-anime-art-1920x1080.jpg" // 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 { 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 { app.Layout = func(ctx *aero.Context, content string) string {

View File

@ -9,7 +9,12 @@ import (
// Get ... // Get ...
func Get(ctx *aero.Context) string { func Get(ctx *aero.Context) string {
var airingAnimeCache jobs.AiringAnimeCache airingAnimeCache := new(jobs.AiringAnimeCache)
arn.GetObject("Cache", "airingAnime", &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)) return ctx.HTML(components.Airing(airingAnimeCache.Anime))
} }

View File

@ -36,6 +36,14 @@ component Anime(anime *arn.Anime)
//- each watcher in friendsWatching //- each watcher in friendsWatching
//- +avatar(watcher) //- +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 if len(anime.Genres) > 0
h3.anime-header Genres h3.anime-header Genres
.light-button-group .light-button-group

View File

@ -117,16 +117,32 @@
display flex display flex
flex-flow row wrap flex-flow row wrap
justify-content flex-start justify-content flex-start
font-size 0.9em font-size 0.9rem
.light-button .light-button
display inline-block display inline-block
padding 0.5em 1em padding 0.5rem 1rem
border-radius 3px border-radius 3px
&:hover &:hover
color white !important color white !important
background-color linkHoverColor 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 .entry-error
color red !important color red !important