diff --git a/pages/company/company.go b/pages/company/company.go index 53fc0fb0..de7e9cad 100644 --- a/pages/company/company.go +++ b/pages/company/company.go @@ -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{ diff --git a/pages/index.go b/pages/index.go index e5506705..2f2b0617 100644 --- a/pages/index.go +++ b/pages/index.go @@ -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) diff --git a/pages/soundtrack/lyrics.go b/pages/soundtrack/lyrics.go new file mode 100644 index 00000000..24aae57a --- /dev/null +++ b/pages/soundtrack/lyrics.go @@ -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)) +} diff --git a/pages/soundtrack/lyrics.pixy b/pages/soundtrack/lyrics.pixy new file mode 100644 index 00000000..f8f90b44 --- /dev/null +++ b/pages/soundtrack/lyrics.pixy @@ -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 \ No newline at end of file diff --git a/pages/soundtrack/lyrics.scarlet b/pages/soundtrack/lyrics.scarlet new file mode 100644 index 00000000..73ee6e49 --- /dev/null +++ b/pages/soundtrack/lyrics.scarlet @@ -0,0 +1,2 @@ +.lyrics-line + display block \ No newline at end of file diff --git a/pages/soundtrack/soundtrack.go b/pages/soundtrack/soundtrack.go index 5d91d5aa..acfa6076 100644 --- a/pages/soundtrack/soundtrack.go +++ b/pages/soundtrack/soundtrack.go @@ -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 } diff --git a/pages/soundtrack/soundtrack.pixy b/pages/soundtrack/soundtrack.pixy index a7e1cdae..247a1532 100644 --- a/pages/soundtrack/soundtrack.pixy +++ b/pages/soundtrack/soundtrack.pixy @@ -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") diff --git a/utils/CutLongDescription.go b/utils/CutLongDescription.go new file mode 100644 index 00000000..199ba958 --- /dev/null +++ b/utils/CutLongDescription.go @@ -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 +}