Added lyrics display
This commit is contained in:
parent
16d0e17aa5
commit
06c09bc1ff
@ -10,8 +10,6 @@ import (
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
const maxDescriptionLength = 170
|
||||
|
||||
// Get renders a company page.
|
||||
func Get(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
@ -22,11 +20,7 @@ func Get(ctx *aero.Context) string {
|
||||
return ctx.Error(http.StatusNotFound, "Company not found", err)
|
||||
}
|
||||
|
||||
description := company.Description
|
||||
|
||||
if len(description) > maxDescriptionLength {
|
||||
description = description[:maxDescriptionLength-3] + "..."
|
||||
}
|
||||
description := utils.CutLongDescription(company.Description)
|
||||
|
||||
openGraph := &arn.OpenGraph{
|
||||
Tags: map[string]string{
|
||||
|
@ -175,6 +175,7 @@ func Configure(app *aero.Application) {
|
||||
l.Page("/soundtracks/tag/:tag", soundtracks.FilterByTag)
|
||||
l.Page("/soundtracks/tag/:tag/from/:index", soundtracks.FilterByTag)
|
||||
l.Page("/soundtrack/:id", soundtrack.Get)
|
||||
l.Page("/soundtrack/:id/lyrics", soundtrack.Lyrics)
|
||||
l.Page("/soundtrack/:id/edit", soundtrack.Edit)
|
||||
l.Page("/soundtrack/:id/history", soundtrack.History)
|
||||
|
||||
|
34
pages/soundtrack/lyrics.go
Normal file
34
pages/soundtrack/lyrics.go
Normal file
@ -0,0 +1,34 @@
|
||||
package soundtrack
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
// Lyrics of a soundtrack.
|
||||
func Lyrics(ctx *aero.Context) string {
|
||||
id := ctx.Get("id")
|
||||
track, err := arn.GetSoundTrack(id)
|
||||
user := utils.GetUser(ctx)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusNotFound, "Track not found", err)
|
||||
}
|
||||
|
||||
openGraph := getOpenGraph(ctx, track)
|
||||
|
||||
if track.Lyrics.Native != "" {
|
||||
openGraph.Tags["og:description"] = utils.CutLongDescription(track.Lyrics.Native)
|
||||
}
|
||||
|
||||
if track.Lyrics.Romaji != "" {
|
||||
openGraph.Tags["og:description"] = utils.CutLongDescription(track.Lyrics.Romaji)
|
||||
}
|
||||
|
||||
ctx.Data = openGraph
|
||||
return ctx.HTML(components.SoundTrackLyricsPage(track, user))
|
||||
}
|
28
pages/soundtrack/lyrics.pixy
Normal file
28
pages/soundtrack/lyrics.pixy
Normal file
@ -0,0 +1,28 @@
|
||||
component SoundTrackLyricsPage(track *arn.SoundTrack, user *arn.User)
|
||||
SoundTrackTabs(track, user)
|
||||
|
||||
.soundtrack-full-page
|
||||
if track.Title.ByUser(user) == ""
|
||||
h1.mountable untitled
|
||||
else
|
||||
h1.mountable= track.Title.ByUser(user)
|
||||
|
||||
.widget-form
|
||||
if !track.HasLyrics()
|
||||
p.no-data.mountable No lyrics available for this track.
|
||||
else
|
||||
if track.Lyrics.Romaji != ""
|
||||
.widget
|
||||
h3.widget-title.mountable Romaji
|
||||
RenderLyrics(track.Lyrics.Romaji)
|
||||
|
||||
if track.Lyrics.Native != ""
|
||||
.widget
|
||||
h3.widget-title.mountable Native
|
||||
RenderLyrics(track.Lyrics.Native)
|
||||
|
||||
component RenderLyrics(text string)
|
||||
each paragraph in strings.Split(text, "\n\n")
|
||||
p.lyrics-paragraph.mountable
|
||||
each line in strings.Split(paragraph, "\n")
|
||||
span.lyrics-line= line
|
2
pages/soundtrack/lyrics.scarlet
Normal file
2
pages/soundtrack/lyrics.scarlet
Normal file
@ -0,0 +1,2 @@
|
||||
.lyrics-line
|
||||
display block
|
@ -20,6 +20,20 @@ func Get(ctx *aero.Context) string {
|
||||
return ctx.Error(http.StatusNotFound, "Track not found", err)
|
||||
}
|
||||
|
||||
ctx.Data = getOpenGraph(ctx, track)
|
||||
return ctx.HTML(components.SoundTrackPage(track, user))
|
||||
}
|
||||
|
||||
func getOpenGraph(ctx *aero.Context, track *arn.SoundTrack) *arn.OpenGraph {
|
||||
openGraph := &arn.OpenGraph{
|
||||
Tags: map[string]string{
|
||||
"og:title": track.Title.ByUser(nil),
|
||||
"og:url": "https://" + ctx.App.Config.Domain + track.Link(),
|
||||
"og:site_name": ctx.App.Config.Domain,
|
||||
"og:type": "music.song",
|
||||
},
|
||||
}
|
||||
|
||||
descriptionTags := []string{}
|
||||
|
||||
for _, tag := range track.Tags {
|
||||
@ -30,15 +44,6 @@ func Get(ctx *aero.Context) string {
|
||||
descriptionTags = append(descriptionTags, tag)
|
||||
}
|
||||
|
||||
openGraph := &arn.OpenGraph{
|
||||
Tags: map[string]string{
|
||||
"og:title": track.Title.ByUser(user),
|
||||
"og:url": "https://" + ctx.App.Config.Domain + track.Link(),
|
||||
"og:site_name": ctx.App.Config.Domain,
|
||||
"og:type": "music.song",
|
||||
},
|
||||
}
|
||||
|
||||
if track.MainAnime() != nil {
|
||||
openGraph.Tags["og:image"] = track.MainAnime().ImageLink("large")
|
||||
openGraph.Tags["og:description"] = track.MainAnime().Title.Canonical + " (" + strings.Join(descriptionTags, ", ") + ")"
|
||||
@ -56,7 +61,5 @@ func Get(ctx *aero.Context) string {
|
||||
openGraph.Tags["og:video"] = "https://www.youtube.com/v/" + youtube[0].ServiceID
|
||||
}
|
||||
|
||||
ctx.Data = openGraph
|
||||
|
||||
return ctx.HTML(components.SoundTrackPage(track, user))
|
||||
return openGraph
|
||||
}
|
||||
|
@ -47,8 +47,8 @@ component SoundTrackPage(track *arn.SoundTrack, user *arn.User)
|
||||
|
||||
for index, beatmap := range track.EtternaBeatmaps()
|
||||
li
|
||||
a.beatmap(href="https://etternaonline.com/song/view/" + beatmap, target="_blank")= "Etterna Beatmap #" + strconv.Itoa(index + 1)
|
||||
|
||||
a.beatmap(href="https://etternaonline.com/song/view/" + beatmap, target="_blank")= "Etterna Beatmap #" + strconv.Itoa(index + 1)
|
||||
|
||||
.widget.mountable
|
||||
h3.widget-title Tags
|
||||
|
||||
@ -74,6 +74,11 @@ component SoundTrackTabs(track *arn.SoundTrack, user *arn.User)
|
||||
.tabs
|
||||
TabLike(strconv.Itoa(len(track.Likes)), "heart", "track", track, user)
|
||||
Tab("Soundtrack", "music", track.Link())
|
||||
|
||||
if track.HasLyrics()
|
||||
Tab("Lyrics", "font", track.Link() + "/lyrics")
|
||||
|
||||
if user != nil
|
||||
Tab("Edit", "pencil", track.Link() + "/edit")
|
||||
|
||||
Tab("History", "history", track.Link() + "/history")
|
||||
|
12
utils/CutLongDescription.go
Normal file
12
utils/CutLongDescription.go
Normal file
@ -0,0 +1,12 @@
|
||||
package utils
|
||||
|
||||
const maxDescriptionLength = 170
|
||||
|
||||
// CutLongDescription cuts a long description for use in OpenGraph tags.
|
||||
func CutLongDescription(description string) string {
|
||||
if len(description) > maxDescriptionLength {
|
||||
return description[:maxDescriptionLength-3] + "..."
|
||||
}
|
||||
|
||||
return description
|
||||
}
|
Loading…
Reference in New Issue
Block a user