Merge pull request #247 from youssefhabri/add-related-soundtracks

Add related soundtracks to soundtrack page
This commit is contained in:
Eduard Urbach 2020-02-12 12:53:38 +09:00 committed by GitHub
commit 86d990f761
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View File

@ -19,7 +19,21 @@ func Get(ctx aero.Context) error {
return ctx.Error(http.StatusNotFound, "Track not found", err)
}
relatedTracks := arn.FilterSoundTracks(func(t *arn.SoundTrack) bool {
return !t.IsDraft && len(t.Media) > 0 && t.ID != track.ID && isRelated(track.Anime(), t)
})
customCtx := ctx.(*middleware.OpenGraphContext)
customCtx.OpenGraph = getOpenGraph(track)
return ctx.HTML(components.SoundTrackPage(track, user))
return ctx.HTML(components.SoundTrackPage(track, relatedTracks, user))
}
func isRelated(anime []*arn.Anime, track *arn.SoundTrack) bool {
for _, anime := range anime {
if arn.Contains(track.Tags, "anime:"+anime.ID) {
return true
}
}
return false
}

View File

@ -1,4 +1,4 @@
component SoundTrackPage(track *arn.SoundTrack, user *arn.User)
component SoundTrackPage(track *arn.SoundTrack, relatedTracks []*arn.SoundTrack, user *arn.User)
SoundTrackTabs(track, user)
.soundtrack-full-page
@ -37,6 +37,13 @@ component SoundTrackPage(track *arn.SoundTrack, user *arn.User)
li
a.soundtrack-link(href=link.URL, target="_blank")= link.Title
if len(relatedTracks) > 0
.widget.mountable
h3.widget-title Related
.soundtracks.anime-soundtracks
each relatedTrack in relatedTracks
SoundTrackMini(relatedTrack, user)
//- TODO: This is quite ineffective, performance-wise
if len(track.OsuBeatmaps()) > 0 || len(track.EtternaBeatmaps()) > 0
.widget.mountable